@dropins/storefront-cart 1.2.0 → 1.3.0-alpha03121610
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,3 +1,3 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as n,jsxs as y,Fragment as j}from"@dropins/tools/preact-jsx-runtime.js";import*as o from"@dropins/tools/preact-compat.js";import{useState as N,useCallback as Ft,useEffect as ot}from"@dropins/tools/preact-compat.js";import{classes as L,VComponent as X,Slot as w}from"@dropins/tools/lib.js";import{E as Mt}from"./EmptyCart.js";/* empty css */import{Divider as st,Skeleton as zt,SkeletonRow as qt,InLineAlert as Tt,Icon as q,CartList as lt,Button as T,Accordion as Ut,AccordionSection as Wt,CartItem as Jt,Price as O,Image as Kt}from"@dropins/tools/components.js";import"@dropins/tools/preact-hooks.js";import{g as Rt}from"./persisted-data.js";import{events as Yt}from"@dropins/tools/event-bus.js";import{s as Ht}from"./resetCart.js";import{u as ut}from"./updateProductsFromCart.js";import{S as Dt}from"./ChevronDown.js";import{useText as te}from"@dropins/tools/i18n.js";const ee=d=>o.createElement("svg",{id:"Icon_Chevron_right_Base","data-name":"Icon \\u2013 Chevron right \\u2013 Base",xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",...d},o.createElement("g",{id:"Large"},o.createElement("rect",{id:"Placement_area","data-name":"Placement area",width:24,height:24,fill:"#fff",opacity:0}),o.createElement("g",{id:"Chevron_right_icon","data-name":"Chevron right icon"},o.createElement("path",{vectorEffect:"non-scaling-stroke",id:"chevron",d:"M199.75,367.5l4.255,-4.255-4.255,-4.255",transform:"translate(-189.25 -351.0)",fill:"none",stroke:"currentColor"})))),dt=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("g",{clipPath:"url(#clip0_4797_15331)"},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M10.25 20.91L1.5 17.55V6.51996L10.25 9.92996V20.91Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.24023 4.64001L14.9902 8.06001V11.42",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{className:"error-icon",vectorEffect:"non-scaling-stroke",d:"M19 13.31L15.5 19.37H22.5L19 13.31Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{className:"error-icon",vectorEffect:"non-scaling-stroke",d:"M19.0202 17.11H18.9802L18.9502 15.56H19.0502L19.0202 17.11ZM18.9602 18.29V18.06H19.0502V18.29H18.9602Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19 12.16V6.51996L10.25 9.92996V20.91L14.27 19.37L14.4 19.32",stroke:"currentColor",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M1.5 6.51999L10.25 3.04999L19 6.51999L10.25 9.92999L1.5 6.51999Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})),o.createElement("defs",null,o.createElement("clipPath",{id:"clip0_4797_15331"},o.createElement("rect",{width:22,height:18.86,fill:"white",transform:"translate(1 2.54999)"})))),ne=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),gt=({className:d,children:U,heading:k,footer:v,emptyCart:_,products:u,outOfStockMessage:m,variant:S="primary",loading:h=!0,...c})=>n("div",{...c,className:L(["cart-cart-summary-list",d,`cart-cart-summary-list__background--${S}`]),children:h?n(re,{}):y(j,{children:[(k||m)&&y("div",{"data-testid":"cart-summary-list-heading-wrapper",className:L(["cart-cart-summary-list__heading",["cart-cart-summary-list__heading--full-width",!u]]),children:[k&&y(j,{children:[n(X,{node:k,className:"cart-cart-summary-list__heading-text"}),n(st,{variant:"primary",className:L(["cart-cart-summary-list__heading-divider"])})]}),m&&n(X,{node:m,className:"cart-cart-summary-list__out-of-stock-message"})]}),n("div",{className:L(["cart-cart-summary-list__content",["cart-cart-summary-list__content--empty",!u]]),children:u||n(X,{node:_,className:"cart-cart-summary-list__empty-cart"})}),v&&y(j,{children:[n(st,{variant:"primary",className:L(["cart-cart-summary-list__footer-divider"])}),n(X,{node:v,className:"cart-cart-summary-list__footer-text"})]})]})}),re=()=>n(zt,{"data-testid":"cart-summary-list-skeleton",className:"cart-cart-summary-list__skeleton",rowGap:"medium",children:n(qt,{variant:"row",size:"xlarge",fullWidth:!0,lines:3,multilineGap:"small"})}),ae=({initialData:d=null,hideHeading:U,hideFooter:k,routeProduct:v,routeEmptyCartCTA:_,routeCart:u,onItemUpdate:m,onItemRemove:S,maxItems:h,slots:c,attributesToHide:l=[],enableRemoveItem:$,enableUpdateItemQuantity:W,onItemsErrorsChange:Z,accordion:ft=!1,variant:B="primary",isLoading:mt,showMaxItems:J,showDiscount:ht,showSavings:yt,quantityType:vt,dropdownOptions:pt,...K})=>{var rt;const[F,kt]=N(!d),[a,Ct]=N(d),[E,wt]=N(new Set),[A,Lt]=N(new Map),s=(rt=Ht.config)==null?void 0:rt.shoppingCartDisplaySetting,[Q,_t]=N(J?!0:!h&&!J),i=te({file:"Cart.CartItem.file",files:"Cart.CartItem.files",heading:"Cart.Cart.heading",message:"Cart.CartItem.message",recipient:"Cart.CartItem.recipient",regularPrice:"Cart.CartItem.regularPrice",discountedPrice:"Cart.CartItem.discountedPrice",sender:"Cart.CartItem.sender",lowInventory:"Cart.CartItem.lowInventory",insufficientQuantity:"Cart.CartItem.insufficientQuantity",insufficientQuantityGeneral:"Cart.CartItem.insufficientQuantityGeneral",outOfStockHeading:"Cart.OutOfStockMessage.heading",outOfStockDescription:"Cart.OutOfStockMessage.message",outOfStockAlert:"Cart.OutOfStockMessage.alert",removeAction:"Cart.OutOfStockMessage.action",notAvailableMessage:"Cart.CartItem.notAvailableMessage",viewMore:"Cart.Cart.viewMore",viewAll:"Cart.Cart.viewAll",discountPercent:"Cart.CartItem.discountPercentage",savingsAmount:"Cart.CartItem.savingsAmount"}),G=(t,e)=>{wt(r=>(e?r.add(t):r.delete(t),new Set(r)))},M=(t,e)=>{Lt(r=>(e?r.set(t,e):r.delete(t),new Map(r)))},z=(t,e)=>{G(t.uid,!0),M(t.uid),$&&e===0?ut([{uid:t.uid,quantity:e}]).then(()=>{S==null||S({item:t})}).finally(()=>{G(t.uid,!1)}).catch(r=>{console.warn(r)}):W&&ut([{uid:t.uid,quantity:e}]).then(()=>{m==null||m({item:t})}).finally(()=>{G(t.uid,!1)}).catch(r=>{console.warn(r),M(t.uid,r.message)})},St=Ft(()=>{_t(t=>!t)},[]);ot(()=>{const t=Yt.on("cart/data",e=>{Ct(e),kt(!!mt)},{eager:!0});return()=>{t==null||t.off()}},[]),ot(()=>{Z&&Z(A)},[A,Z]);const Et=(t,e)=>{if(l.includes("image"))return;const r=n(Kt,{"data-testid":"cart-list-item-image",loading:e<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}});return n(w,{name:"Thumbnail",slot:c==null?void 0:c.Thumbnail,context:{item:t},children:v?n("a",{href:v(t),children:r}):r})},It=t=>{if(!l.includes("name"))return n("span",{"data-testid":"cart-list-item-title",children:v?n("a",{href:v(t),children:t.name}):t.name})},xt=t=>{if(l.includes("configurations"))return;const e={...t.bundleOptions,...t.selectedOptions,...t.customizableOptions,...t.recipient?{[i.recipient]:t.recipient}:null,...t.recipientEmail&&t.recipient?{[i.recipient]:`${t.recipient} (${t.recipientEmail})`}:null,...t.sender?{[i.sender]:t.sender}:null,...t.senderEmail&&t.sender?{[i.sender]:`${t.sender} (${t.senderEmail})`}:{},...t.message?{[i.message]:t.message}:null,...t.links&&t.links.count?t.links.count>1?{[i.files.replace("{count}",t.links.count.toString())]:t.links.result}:{[i.file.replace("{count}",t.links.count.toString())]:t.links.result}:null};if(Object.keys(e).length!==0)return e},Pt=t=>{var e,r,f,g;return(s==null?void 0:s.price)==="INCLUDING_TAX"?t.discounted?{amount:t.regularPrice.value,currency:t.regularPrice.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}:{amount:(e=t.taxedPrice)==null?void 0:e.value,currency:(r=t.taxedPrice)==null?void 0:r.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}:{amount:(f=t.regularPrice)==null?void 0:f.value,currency:(g=t.regularPrice)==null?void 0:g.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}},Nt=t=>{var e,r;return{amount:(e=t.savingsAmount)==null?void 0:e.value,currency:(r=t.savingsAmount)==null?void 0:r.currency,style:{font:"inherit"},"data-testid":"item-savings-amount"}},Ot=t=>(s==null?void 0:s.price)==="INCLUDING_EXCLUDING_TAX"?n(O,{amount:t.rowTotal.value,currency:t.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":i.regularPrice}):void 0,At=t=>{var f,g,p,C,I,x,P,at,it,ct;const e={"aria-label":i.regularPrice},r=t.discounted?{}:null;return["INCLUDING_TAX","INCLUDING_EXCLUDING_TAX"].includes(s==null?void 0:s.price)?(e.amount=(f=t.rowTotalIncludingTax)==null?void 0:f.value,e.currency=(g=t.rowTotalIncludingTax)==null?void 0:g.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="including-tax-item-total",r&&(e.amount=(p=t.total)==null?void 0:p.value,e.currency=(C=t.total)==null?void 0:C.currency,r.amount=(I=t.rowTotalIncludingTax)==null?void 0:I.value,r.currency=(x=t.rowTotalIncludingTax)==null?void 0:x.currency,r.sale=!0,r["aria-label"]=i.discountedPrice,r["data-testid"]="discount-total")):(e.amount=(P=t.total)==null?void 0:P.value,e.currency=(at=t.total)==null?void 0:at.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="regular-item-total",r&&(r.amount=(it=t.discountedTotal)==null?void 0:it.value,r.currency=(ct=t.discountedTotal)==null?void 0:ct.currency,r.sale=!0,r["aria-label"]=i.regularPrice,r["data-testid"]="discount-total")),{totalProps:e,discountProps:r}},Qt=t=>{var I,x,P;if(l.includes("warning"))return;const e=A.get(t.uid),r=(I=A.get(t.uid))==null?void 0:I.includes("The requested qty is not available"),f=E.has(t.uid),g=t.insufficientQuantity&&t.stockLevel?t.stockLevel==="noNumber"?i.insufficientQuantityGeneral:i.insufficientQuantity.replace("{inventory}",(x=t.stockLevel)==null?void 0:x.toString()).replace("{count}",t.quantity.toString()):"",p=t.lowInventory&&t.onlyXLeftInStock&&i.lowInventory.replace("{count}",(P=t.onlyXLeftInStock)==null?void 0:P.toString()),C=!t.outOfStock&&e&&r?i.notAvailableMessage:e;return!f&&(e||t.insufficientQuantity||t.lowInventory)?y("span",{"data-testid":"item-warning",children:[n(q,{source:ne,size:"16"}),C||g||p]}):void 0},Gt=t=>l!=null&&l.includes("alert")?void 0:!E.has(t.uid)&&t.outOfStock?y("span",{"data-testid":"item-alert",children:[n(q,{source:dt,size:"16"}),i.outOfStockAlert]}):void 0,Vt=t=>n(w,{name:"ProductAttributes",slot:c==null?void 0:c.ProductAttributes,context:{item:t}}),bt=t=>{if(!l.includes("sku"))return n("span",{"data-testid":"cart-list-item-sku",children:t.sku})},Xt=t=>n(w,{name:"Footer",slot:c==null?void 0:c.Footer,context:{item:t,handleItemsLoading:G,handleItemsError:M,onItemUpdate:m}}),R=t=>a!=null&&a.totalQuantity?a.items.filter(t).map((e,r)=>{var p;const{totalProps:f,discountProps:g}=At(e);return n(Jt,{updating:E==null?void 0:E.has(e.uid),loading:F,"data-testid":`cart-list-item-entry-${e.uid}`,image:Et(e,r),title:It(e),sku:bt(e),price:l.includes("price")?void 0:n(O,{...Pt(e)}),quantity:l.includes("quantity")?void 0:e.quantity,total:y(j,{children:[l.includes("total")?void 0:n(O,{...f}),l.includes("totalDiscount")?void 0:g&&n(O,{...g})]}),attributes:Vt(e),configurations:xt(e),totalExcludingTax:l.includes("totalExcludingTax")?void 0:Ot(e),taxIncluded:(s==null?void 0:s.price)==="INCLUDING_TAX",taxExcluded:!l.includes("totalExcludingTax")&&(s==null?void 0:s.price)==="INCLUDING_EXCLUDING_TAX",warning:Qt(e),alert:Gt(e),quantityType:vt,dropdownOptions:pt,onQuantity:W?C=>{z(e,C)}:void 0,onRemove:$?()=>z(e,0):void 0,discount:ht&&e.discounted&&e.discountPercentage?n("div",{"data-testid":"item-discount-percent",children:i.discountPercent.replace("{discount}",((p=e.discountPercentage)==null?void 0:p.toString())??"")}):void 0,savings:yt&&e.discounted&&e.savingsAmount?y("div",{children:[n("span",{children:n(O,{...Nt(e)})})," ",i.savingsAmount]}):void 0,footer:Xt(e)},e.uid)}):null,Y=n(w,{name:"EmptyCart",slot:c==null?void 0:c.EmptyCart,context:{},children:n(Mt,{"data-testid":"empty-cart",ctaLinkURL:_==null?void 0:_()})}),H=n(w,{name:"Heading",slot:c==null?void 0:c.Heading,context:{count:a==null?void 0:a.totalQuantity},children:n("div",{"data-testid":"default-cart-heading",children:i.heading.replace("({count})",a!=null&&a.totalQuantity?`(${a==null?void 0:a.totalQuantity.toString()})`:"")})}),jt=H.props.children.props.children,$t=()=>{const t=a==null?void 0:a.items.filter(e=>e.outOfStock);t==null||t.forEach(e=>{z(e,0)})},Zt=R(t=>t.outOfStock||t.insufficientQuantity||!1),D=a!=null&&a.hasOutOfStockItems?n(Tt,{"data-testid":"cart-out-of-stock-message",icon:n(q,{source:dt,size:"16"}),itemList:n(lt,{"data-testid":"out-of-stock-cart-items",children:Zt}),type:"warning",heading:i.outOfStockHeading,description:i.outOfStockDescription,variant:"primary",actionButtonPosition:"bottom",additionalActions:a!=null&&a.hasFullyOutOfStockItems&&$?[{label:i.removeAction,onClick:$t}]:void 0}):void 0,V=R(t=>!t.outOfStock&&!t.insufficientQuantity),tt=Q?Math.max(h||5,5):Math.min((a==null?void 0:a.totalQuantity)||5,5),et=(a==null?void 0:a.totalQuantity)>tt,Bt=et&&!Q&&tt!=h,b=a!=null&&a.totalQuantity&&V?n(w,{name:"Footer",slot:c==null?void 0:c.CartSummaryFooter,context:{displayMaxItems:Q,routeCart:u},"data-testid":"cart-cart-summary-footer-slot",children:n("div",{"data-testid":"cart-cart-summary-footer",children:et?Bt?n(T,{className:"cart-cart-summary-list-footer__action",onClick:St,"data-testid":"view-more-items-button",variant:"tertiary",children:i.viewMore}):u&&n(T,{className:"cart-cart-summary-list-footer__action",href:u(),variant:"tertiary","data-testid":"view-cart-or-less-items-button",children:i.viewAll}):u&&n(T,{className:"cart-cart-summary-list-footer__action",href:u(),variant:"tertiary","data-testid":"view-cart-button",children:i.viewAll})})}):null,nt=a!=null&&a.totalQuantity?n(lt,{"data-testid":"cart-list",children:V==null?void 0:V.slice(0,Q?Math.max(h||(a==null?void 0:a.totalQuantity),5):Math.min(h??5,5))}):null;return ft?n(Ut,{"data-testid":"cart-summary-list-accordion",className:L(["cart-cart-summary-list-accordion",`cart-cart-summary-list__background--${B}`]),iconOpen:ee,iconClose:Dt,children:n(Wt,{title:jt,"data-testid":"cart-summary-list-accordion__section",open:!0,renderContentWhenClosed:!0,children:n(gt,{...K,"aria-expanded":!0,"aria-label":"TEST",className:"cart-cart-summary-list-accordion__list",loading:F,footer:k?void 0:b||(u?b:void 0),emptyCart:Y,products:nt,outOfStockMessage:D,variant:B})})}):n(gt,{...K,heading:U?void 0:H,footer:k?void 0:b||(u?b:void 0),loading:F,emptyCart:Y,products:nt,outOfStockMessage:D,variant:B})};ae.getInitialData=async function(){return Rt()};export{ae as C};
|
|
3
|
+
import{jsx as n,jsxs as y,Fragment as Z}from"@dropins/tools/preact-jsx-runtime.js";import*as o from"@dropins/tools/preact-compat.js";import{useState as N,useCallback as Ft,useEffect as _t}from"@dropins/tools/preact-compat.js";import{classes as E,VComponent as b,Slot as C}from"@dropins/tools/lib.js";import{E as Mt}from"./EmptyCart.js";/* empty css */import{Divider as Et,Skeleton as zt,SkeletonRow as Wt,InLineAlert as qt,Icon as q,CartList as It,Button as U,Accordion as Ut,AccordionSection as Tt,CartItem as Jt,Price as A,Image as Kt}from"@dropins/tools/components.js";import"@dropins/tools/preact-hooks.js";import{g as Yt}from"./persisted-data.js";import{events as Rt}from"@dropins/tools/event-bus.js";import{s as Ht}from"./resetCart.js";import{u as St}from"./updateProductsFromCart.js";import{S as Dt}from"./ChevronDown.js";import{useText as te}from"@dropins/tools/i18n.js";const ee=d=>o.createElement("svg",{id:"Icon_Chevron_right_Base","data-name":"Icon \\u2013 Chevron right \\u2013 Base",xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",...d},o.createElement("g",{id:"Large"},o.createElement("rect",{id:"Placement_area","data-name":"Placement area",width:24,height:24,fill:"#fff",opacity:0}),o.createElement("g",{id:"Chevron_right_icon","data-name":"Chevron right icon"},o.createElement("path",{vectorEffect:"non-scaling-stroke",id:"chevron",d:"M199.75,367.5l4.255,-4.255-4.255,-4.255",transform:"translate(-189.25 -351.0)",fill:"none",stroke:"currentColor"})))),xt=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("g",{clipPath:"url(#clip0_4797_15331)"},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M10.25 20.91L1.5 17.55V6.51996L10.25 9.92996V20.91Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.24023 4.64001L14.9902 8.06001V11.42",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{className:"error-icon",vectorEffect:"non-scaling-stroke",d:"M19 13.31L15.5 19.37H22.5L19 13.31Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{className:"error-icon",vectorEffect:"non-scaling-stroke",d:"M19.0202 17.11H18.9802L18.9502 15.56H19.0502L19.0202 17.11ZM18.9602 18.29V18.06H19.0502V18.29H18.9602Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19 12.16V6.51996L10.25 9.92996V20.91L14.27 19.37L14.4 19.32",stroke:"currentColor",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M1.5 6.51999L10.25 3.04999L19 6.51999L10.25 9.92999L1.5 6.51999Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})),o.createElement("defs",null,o.createElement("clipPath",{id:"clip0_4797_15331"},o.createElement("rect",{width:22,height:18.86,fill:"white",transform:"translate(1 2.54999)"})))),ne=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),Pt=({className:d,children:T,heading:w,footer:v,emptyCart:I,products:u,outOfStockMessage:m,variant:S="primary",loading:h=!0,...c})=>n("div",{...c,className:E(["cart-cart-summary-list",d,`cart-cart-summary-list__background--${S}`]),children:h?n(re,{}):y(Z,{children:[(w||m)&&y("div",{"data-testid":"cart-summary-list-heading-wrapper",className:E(["cart-cart-summary-list__heading",["cart-cart-summary-list__heading--full-width",!u]]),children:[w&&y(Z,{children:[n(b,{node:w,className:"cart-cart-summary-list__heading-text"}),n(Et,{variant:"primary",className:E(["cart-cart-summary-list__heading-divider"])})]}),m&&n(b,{node:m,className:"cart-cart-summary-list__out-of-stock-message"})]}),n("div",{className:E(["cart-cart-summary-list__content",["cart-cart-summary-list__content--empty",!u]]),children:u||n(b,{node:I,className:"cart-cart-summary-list__empty-cart"})}),v&&y(Z,{children:[n(Et,{variant:"primary",className:E(["cart-cart-summary-list__footer-divider"])}),n(b,{node:v,className:"cart-cart-summary-list__footer-text"})]})]})}),re=()=>n(zt,{"data-testid":"cart-summary-list-skeleton",className:"cart-cart-summary-list__skeleton",rowGap:"medium",children:n(Wt,{variant:"row",size:"xlarge",fullWidth:!0,lines:3,multilineGap:"small"})}),ae=({initialData:d=null,hideHeading:T,hideFooter:w,routeProduct:v,routeEmptyCartCTA:I,routeCart:u,onItemUpdate:m,onItemRemove:S,maxItems:h,slots:c,attributesToHide:l=[],enableRemoveItem:O,enableUpdateItemQuantity:B,onItemsErrorsChange:F,accordion:Nt=!1,variant:M="primary",isLoading:At,showMaxItems:J,showDiscount:K,showSavings:Y,quantityType:R,dropdownOptions:H,...D})=>{var kt;const[Q,Ot]=N(!d),[a,Qt]=N(d),[L,Gt]=N(new Set),[G,Vt]=N(new Map),s=(kt=Ht.config)==null?void 0:kt.shoppingCartDisplaySetting,[V,Xt]=N(J?!0:!h&&!J),i=te({file:"Cart.CartItem.file",files:"Cart.CartItem.files",heading:"Cart.Cart.heading",message:"Cart.CartItem.message",recipient:"Cart.CartItem.recipient",regularPrice:"Cart.CartItem.regularPrice",discountedPrice:"Cart.CartItem.discountedPrice",sender:"Cart.CartItem.sender",lowInventory:"Cart.CartItem.lowInventory",insufficientQuantity:"Cart.CartItem.insufficientQuantity",insufficientQuantityGeneral:"Cart.CartItem.insufficientQuantityGeneral",outOfStockHeading:"Cart.OutOfStockMessage.heading",outOfStockDescription:"Cart.OutOfStockMessage.message",outOfStockAlert:"Cart.OutOfStockMessage.alert",removeAction:"Cart.OutOfStockMessage.action",notAvailableMessage:"Cart.CartItem.notAvailableMessage",viewMore:"Cart.Cart.viewMore",viewAll:"Cart.Cart.viewAll",discountPercent:"Cart.CartItem.discountPercentage",savingsAmount:"Cart.CartItem.savingsAmount"}),X=(t,e)=>{Gt(r=>(e?r.add(t):r.delete(t),new Set(r)))},z=(t,e)=>{Vt(r=>(e?r.set(t,e):r.delete(t),new Map(r)))},W=(t,e)=>{X(t.uid,!0),z(t.uid),O&&e===0?St([{uid:t.uid,quantity:e}]).then(()=>{S==null||S({item:t})}).finally(()=>{X(t.uid,!1)}).catch(r=>{console.warn(r)}):B&&St([{uid:t.uid,quantity:e}]).then(()=>{m==null||m({item:t})}).finally(()=>{X(t.uid,!1)}).catch(r=>{console.warn(r),z(t.uid,r.message)})},jt=Ft(()=>{Xt(t=>!t)},[]);_t(()=>{const t=Rt.on("cart/data",e=>{Qt(e),Ot(!!At)},{eager:!0});return()=>{t==null||t.off()}},[]),_t(()=>{F&&F(G)},[G,F]);const tt=(t,e)=>{if(l.includes("image"))return;const r=n(Kt,{"data-testid":"cart-list-item-image",loading:e<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}});return n(C,{name:"Thumbnail",slot:c==null?void 0:c.Thumbnail,context:{item:t},children:v?n("a",{href:v(t),children:r}):r})},et=t=>{if(!l.includes("name"))return n("span",{"data-testid":"cart-list-item-title",children:v?n("a",{href:v(t),children:t.name}):t.name})},nt=t=>{if(l.includes("configurations"))return;const e={...t.bundleOptions,...t.selectedOptions,...t.customizableOptions,...t.recipient?{[i.recipient]:t.recipient}:null,...t.recipientEmail&&t.recipient?{[i.recipient]:`${t.recipient} (${t.recipientEmail})`}:null,...t.sender?{[i.sender]:t.sender}:null,...t.senderEmail&&t.sender?{[i.sender]:`${t.sender} (${t.senderEmail})`}:{},...t.message?{[i.message]:t.message}:null,...t.links&&t.links.count?t.links.count>1?{[i.files.replace("{count}",t.links.count.toString())]:t.links.result}:{[i.file.replace("{count}",t.links.count.toString())]:t.links.result}:null};if(Object.keys(e).length!==0)return e},rt=t=>{var e,r,f,g;return(s==null?void 0:s.price)==="INCLUDING_TAX"?t.discounted?{amount:t.regularPrice.value,currency:t.regularPrice.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}:{amount:(e=t.taxedPrice)==null?void 0:e.value,currency:(r=t.taxedPrice)==null?void 0:r.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}:{amount:(f=t.regularPrice)==null?void 0:f.value,currency:(g=t.regularPrice)==null?void 0:g.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}},at=t=>{var e,r;return{amount:(e=t.savingsAmount)==null?void 0:e.value,currency:(r=t.savingsAmount)==null?void 0:r.currency,style:{font:"inherit"},"data-testid":"item-savings-amount"}},it=t=>(s==null?void 0:s.price)==="INCLUDING_EXCLUDING_TAX"?n(A,{amount:t.rowTotal.value,currency:t.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":i.regularPrice}):void 0,ct=t=>{var f,g,_,p,k,x,P,Ct,wt,Lt;const e={"aria-label":i.regularPrice},r=t.discounted?{}:null;return["INCLUDING_TAX","INCLUDING_EXCLUDING_TAX"].includes(s==null?void 0:s.price)?(e.amount=(f=t.rowTotalIncludingTax)==null?void 0:f.value,e.currency=(g=t.rowTotalIncludingTax)==null?void 0:g.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="including-tax-item-total",r&&(e.amount=(_=t.total)==null?void 0:_.value,e.currency=(p=t.total)==null?void 0:p.currency,r.amount=(k=t.rowTotalIncludingTax)==null?void 0:k.value,r.currency=(x=t.rowTotalIncludingTax)==null?void 0:x.currency,r.sale=!0,r["aria-label"]=i.discountedPrice,r["data-testid"]="discount-total")):(e.amount=(P=t.total)==null?void 0:P.value,e.currency=(Ct=t.total)==null?void 0:Ct.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="regular-item-total",r&&(r.amount=(wt=t.discountedTotal)==null?void 0:wt.value,r.currency=(Lt=t.discountedTotal)==null?void 0:Lt.currency,r.sale=!0,r["aria-label"]=i.regularPrice,r["data-testid"]="discount-total")),{totalProps:e,discountProps:r}},ot=t=>{var k,x,P;if(l.includes("warning"))return;const e=G.get(t.uid),r=(k=G.get(t.uid))==null?void 0:k.includes("The requested qty is not available"),f=L.has(t.uid),g=t.insufficientQuantity&&t.stockLevel?t.stockLevel==="noNumber"?i.insufficientQuantityGeneral:i.insufficientQuantity.replace("{inventory}",(x=t.stockLevel)==null?void 0:x.toString()).replace("{count}",t.quantity.toString()):"",_=t.lowInventory&&t.onlyXLeftInStock&&i.lowInventory.replace("{count}",(P=t.onlyXLeftInStock)==null?void 0:P.toString()),p=!t.outOfStock&&e&&r?i.notAvailableMessage:e;return!f&&(e||t.insufficientQuantity||t.lowInventory)?y("span",{"data-testid":"item-warning",children:[n(q,{source:ne,size:"16"}),p||g||_]}):void 0},st=t=>l!=null&&l.includes("alert")?void 0:!L.has(t.uid)&&t.outOfStock?y("span",{"data-testid":"item-alert",children:[n(q,{source:xt,size:"16"}),i.outOfStockAlert]}):void 0,lt=t=>n(C,{name:"ProductAttributes",slot:c==null?void 0:c.ProductAttributes,context:{item:t}}),ut=t=>{if(!l.includes("sku"))return n("span",{"data-testid":"cart-list-item-sku",children:t.sku})},dt=t=>n(C,{name:"Footer",slot:c==null?void 0:c.Footer,context:{item:t,handleItemsLoading:X,handleItemsError:z,onItemUpdate:m}}),gt=t=>a!=null&&a.totalQuantity?a.items.filter(t).map((e,r)=>{var p;const{totalProps:f,discountProps:g}=ct(e),_=n(Jt,{updating:L==null?void 0:L.has(e.uid),loading:Q,"data-testid":`cart-list-item-entry-${e.uid}`,image:tt(e,r),title:et(e),sku:ut(e),price:l.includes("price")?void 0:n(A,{...rt(e)}),quantity:l.includes("quantity")?void 0:e.quantity,total:y(Z,{children:[l.includes("total")?void 0:n(A,{...f}),l.includes("totalDiscount")?void 0:g&&n(A,{...g})]}),attributes:lt(e),configurations:nt(e),totalExcludingTax:l.includes("totalExcludingTax")?void 0:it(e),taxIncluded:(s==null?void 0:s.price)==="INCLUDING_TAX",taxExcluded:!l.includes("totalExcludingTax")&&(s==null?void 0:s.price)==="INCLUDING_EXCLUDING_TAX",warning:ot(e),alert:st(e),quantityType:R,dropdownOptions:H,onQuantity:B?k=>{W(e,k)}:void 0,onRemove:O?()=>W(e,0):void 0,discount:K&&e.discounted&&e.discountPercentage?n("div",{"data-testid":"item-discount-percent",children:i.discountPercent.replace("{discount}",((p=e.discountPercentage)==null?void 0:p.toString())??"")}):void 0,savings:Y&&e.discounted&&e.savingsAmount?y("div",{children:[n("span",{children:n(A,{...at(e)})})," ",i.savingsAmount]}):void 0,footer:dt(e)},e.uid);return n(C,{name:"CartItem",slot:c==null?void 0:c.CartItem,context:{item:e,index:r,enableUpdateItemQuantity:B,enableRemoveItem:O,itemsLoading:L,loading:Q,attributesToHide:l,cartTaxesConfig:s,quantityType:R,dropdownOptions:H,showDiscount:K,showSavings:Y,dictionary:i,getImage:tt,getTitle:et,getSku:ut,getPriceProps:rt,getTotalPriceProps:ct,getProductAttributes:lt,getConfiguration:nt,getTotalExcludingTax:it,getWarning:ot,getAlert:st,getFooter:dt,getSavingsAmount:at},children:_})}):null,ft=n(C,{name:"EmptyCart",slot:c==null?void 0:c.EmptyCart,context:{},children:n(Mt,{"data-testid":"empty-cart",ctaLinkURL:I==null?void 0:I()})}),mt=n(C,{name:"Heading",slot:c==null?void 0:c.Heading,context:{count:a==null?void 0:a.totalQuantity},children:n("div",{"data-testid":"default-cart-heading",children:i.heading.replace("({count})",a!=null&&a.totalQuantity?`(${a==null?void 0:a.totalQuantity.toString()})`:"")})}),$t=mt.props.children.props.children,bt=()=>{const t=a==null?void 0:a.items.filter(e=>e.outOfStock);t==null||t.forEach(e=>{W(e,0)})},Zt=gt(t=>t.outOfStock||t.insufficientQuantity||!1),ht=a!=null&&a.hasOutOfStockItems?n(qt,{"data-testid":"cart-out-of-stock-message",icon:n(q,{source:xt,size:"16"}),itemList:n(It,{"data-testid":"out-of-stock-cart-items",children:Zt}),type:"warning",heading:i.outOfStockHeading,description:i.outOfStockDescription,variant:"primary",actionButtonPosition:"bottom",additionalActions:a!=null&&a.hasFullyOutOfStockItems&&O?[{label:i.removeAction,onClick:bt}]:void 0}):void 0,j=gt(t=>!t.outOfStock&&!t.insufficientQuantity),yt=V?Math.max(h||5,5):Math.min((a==null?void 0:a.totalQuantity)||5,5),vt=(a==null?void 0:a.totalQuantity)>yt,Bt=vt&&!V&&yt!=h,$=a!=null&&a.totalQuantity&&j?n(C,{name:"Footer",slot:c==null?void 0:c.CartSummaryFooter,context:{displayMaxItems:V,routeCart:u},"data-testid":"cart-cart-summary-footer-slot",children:n("div",{"data-testid":"cart-cart-summary-footer",children:vt?Bt?n(U,{className:"cart-cart-summary-list-footer__action",onClick:jt,"data-testid":"view-more-items-button",variant:"tertiary",children:i.viewMore}):u&&n(U,{className:"cart-cart-summary-list-footer__action",href:u(),variant:"tertiary","data-testid":"view-cart-or-less-items-button",children:i.viewAll}):u&&n(U,{className:"cart-cart-summary-list-footer__action",href:u(),variant:"tertiary","data-testid":"view-cart-button",children:i.viewAll})})}):null,pt=a!=null&&a.totalQuantity?n(It,{"data-testid":"cart-list",children:j==null?void 0:j.slice(0,V?Math.max(h||(a==null?void 0:a.totalQuantity),5):Math.min(h??5,5))}):null;return Nt?n(Ut,{"data-testid":"cart-summary-list-accordion",className:E(["cart-cart-summary-list-accordion",`cart-cart-summary-list__background--${M}`]),iconOpen:ee,iconClose:Dt,children:n(Tt,{title:$t,"data-testid":"cart-summary-list-accordion__section",open:!0,renderContentWhenClosed:!0,children:n(Pt,{...D,"aria-expanded":!0,"aria-label":"TEST",className:"cart-cart-summary-list-accordion__list",loading:Q,footer:w?void 0:$||(u?$:void 0),emptyCart:ft,products:pt,outOfStockMessage:ht,variant:M})})}):n(Pt,{...D,heading:T?void 0:mt,footer:w?void 0:$||(u?$:void 0),loading:Q,emptyCart:ft,products:pt,outOfStockMessage:ht,variant:M})};ae.getInitialData=async function(){return Yt()};export{ae as C};
|
|
@@ -24,6 +24,7 @@ export interface CartSummaryListProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
24
24
|
Thumbnail?: SlotProps;
|
|
25
25
|
ProductAttributes?: SlotProps;
|
|
26
26
|
CartSummaryFooter?: SlotProps;
|
|
27
|
+
CartItem?: SlotProps;
|
|
27
28
|
};
|
|
28
29
|
enableRemoveItem?: boolean;
|
|
29
30
|
enableUpdateItemQuantity?: boolean;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-cart", "version": "1.
|
|
1
|
+
{"name": "@dropins/storefront-cart", "version": "1.3.0-alpha03121610", "@dropins/tools": "~0.41.0", "license": "SEE LICENSE IN LICENSE.md"}
|