@dropins/storefront-cart 1.3.0-beta2 → 1.3.0-beta3
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 M}from"@dropins/tools/preact-jsx-runtime.js";import*as o from"@dropins/tools/preact-compat.js";import{useState as N,useCallback as Bt,useEffect as It}from"@dropins/tools/preact-compat.js";import{classes as I,VComponent as b,Slot as C}from"@dropins/tools/lib.js";import{E as Ft}from"./EmptyCart.js";/* empty css */import{Divider as Et,Skeleton as zt,SkeletonRow as Wt,InLineAlert as qt,CartList as St,Icon as W,Button as q,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 Pt}from"./updateProductsFromCart.js";import{S as Dt}from"./ChevronDown.js";import{useText as te}from"@dropins/tools/i18n.js";const ee=g=>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",...g},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=g=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},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=g=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},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"})),Nt=({className:g,children:U,heading:w,footer:v,emptyCart:E,products:d,outOfStockMessage:m,variant:S="primary",loading:h=!0,...c})=>n("div",{...c,className:I(["cart-cart-summary-list",g,`cart-cart-summary-list__background--${S}`]),children:h?n(re,{}):y(M,{children:[(w||m)&&y("div",{"data-testid":"cart-summary-list-heading-wrapper",className:I(["cart-cart-summary-list__heading",["cart-cart-summary-list__heading--full-width",!d]]),children:[w&&y(M,{children:[n(b,{node:w,className:"cart-cart-summary-list__heading-text"}),n(Et,{variant:"primary",className:I(["cart-cart-summary-list__heading-divider"])})]}),m&&n(b,{node:m,className:"cart-cart-summary-list__out-of-stock-message"})]}),n("div",{className:I(["cart-cart-summary-list__content",["cart-cart-summary-list__content--empty",!d]]),children:d||n(b,{node:E,className:"cart-cart-summary-list__empty-cart"})}),v&&y(M,{children:[n(Et,{variant:"primary",className:I(["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:g=null,hideHeading:U,hideFooter:w,routeProduct:v,routeEmptyCartCTA:E,routeCart:d,onItemUpdate:m,onItemRemove:S,maxItems:h,slots:c,attributesToHide:l=[],enableRemoveItem:O,enableUpdateItemQuantity:Z,onItemsErrorsChange:B,accordion:At=!1,variant:F="primary",isLoading:Ot,showMaxItems:T,showDiscount:J,showSavings:K,quantityType:Y,dropdownOptions:R,...H})=>{var Ct;const[Q,Qt]=N(!g),[a,Gt]=N(g),[L,Vt]=N(new Set),[G,D]=N(new Map),s=(Ct=Ht.config)==null?void 0:Ct.shoppingCartDisplaySetting,[V,Xt]=N(T?!0:!h&&!T),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)=>{Vt(r=>(e?r.add(t):r.delete(t),new Set(r)))},tt=(t,e)=>{D(r=>(e?r.set(t,e):r.delete(t),new Map(r)))},z=(t,e)=>{X(t.uid,!0),D(new Map),O&&e===0?Pt([{uid:t.uid,quantity:e}]).then(()=>{S==null||S({item:t})}).finally(()=>{X(t.uid,!1)}).catch(r=>{console.warn(r)}):Z&&Pt([{uid:t.uid,quantity:e}]).then(()=>{m==null||m({item:t})}).finally(()=>{X(t.uid,!1)}).catch(r=>{tt(t.uid,r.message)})},jt=Bt(()=>{Xt(t=>!t)},[]);It(()=>{const t=Rt.on("cart/data",e=>{Gt(e),Qt(!!Ot)},{eager:!0});return()=>{t==null||t.off()}},[]),It(()=>{B&&B(G)},[G,B]);const et=(t,e)=>{if(l.includes("image"))return;const r={loading:e<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}},u=n(Kt,{"data-testid":"cart-list-item-image",...r});return n(C,{name:"Thumbnail",slot:c==null?void 0:c.Thumbnail,context:{item:t,defaultImageProps:r},children:v?n("a",{href:v(t),children:u}):u})},nt=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})},rt=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},at=t=>{var e,r,u,f;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:(u=t.regularPrice)==null?void 0:u.value,currency:(f=t.regularPrice)==null?void 0:f.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}},it=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"}},ct=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,ot=t=>{var u,f,_,p,k,P,x,wt,Lt,_t;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=(u=t.rowTotalIncludingTax)==null?void 0:u.value,e.currency=(f=t.rowTotalIncludingTax)==null?void 0:f.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=(P=t.rowTotalIncludingTax)==null?void 0:P.currency,r.sale=!0,r["aria-label"]=i.discountedPrice,r["data-testid"]="discount-total")):(e.amount=(x=t.total)==null?void 0:x.value,e.currency=(wt=t.total)==null?void 0:wt.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="regular-item-total",r&&(r.amount=(Lt=t.discountedTotal)==null?void 0:Lt.value,r.currency=(_t=t.discountedTotal)==null?void 0:_t.currency,r.sale=!0,r["aria-label"]=i.regularPrice,r["data-testid"]="discount-total")),{totalProps:e,discountProps:r}},st=t=>{var k,P,x;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"),u=L.has(t.uid),f=t.insufficientQuantity&&t.stockLevel?t.stockLevel==="noNumber"?i.insufficientQuantityGeneral:i.insufficientQuantity.replace("{inventory}",(P=t.stockLevel)==null?void 0:P.toString()).replace("{count}",t.quantity.toString()):"",_=t.lowInventory&&t.onlyXLeftInStock&&i.lowInventory.replace("{count}",(x=t.onlyXLeftInStock)==null?void 0:x.toString()),p=!t.outOfStock&&e&&r?i.notAvailableMessage:e;return!u&&(e||t.insufficientQuantity||t.lowInventory)?y("span",{"data-testid":"item-warning",children:[n(W,{source:ne,size:"16"}),p||f||_]}):void 0},lt=t=>l!=null&&l.includes("alert")?void 0:!L.has(t.uid)&&t.outOfStock?y("span",{"data-testid":"item-alert",children:[n(W,{source:xt,size:"16"}),i.outOfStockAlert]}):void 0,ut=t=>n(C,{name:"ProductAttributes",slot:c==null?void 0:c.ProductAttributes,context:{item:t}}),dt=t=>{if(!l.includes("sku"))return n("span",{"data-testid":"cart-list-item-sku",children:t.sku})},gt=t=>n(C,{name:"Footer",slot:c==null?void 0:c.Footer,context:{item:t,handleItemsLoading:X,handleItemsError:tt,onItemUpdate:m}}),ft=t=>a!=null&&a.totalQuantity?a.items.filter(t).map((e,r)=>{var p;const{totalProps:u,discountProps:f}=ot(e),_=n(Jt,{updating:L==null?void 0:L.has(e.uid),loading:Q,"data-testid":`cart-list-item-entry-${e.uid}`,image:et(e,r),title:nt(e),sku:dt(e),price:l.includes("price")?void 0:n(A,{...at(e)}),quantity:l.includes("quantity")?void 0:e.quantity,total:y(M,{children:[l.includes("total")?void 0:n(A,{...u}),l.includes("totalDiscount")?void 0:f&&n(A,{...f})]}),attributes:ut(e),configurations:rt(e),totalExcludingTax:l.includes("totalExcludingTax")?void 0:ct(e),taxIncluded:(s==null?void 0:s.price)==="INCLUDING_TAX",taxExcluded:!l.includes("totalExcludingTax")&&(s==null?void 0:s.price)==="INCLUDING_EXCLUDING_TAX",warning:st(e),alert:lt(e),quantityType:Y,dropdownOptions:R,onQuantity:Z?k=>{z(e,k)}:void 0,onRemove:O?()=>z(e,0):void 0,discount:J&&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:K&&e.discounted&&e.savingsAmount?y("div",{children:[n("span",{children:n(A,{...it(e)})})," ",i.savingsAmount]}):void 0,footer:gt(e)},e.uid);return n(C,{name:"CartItem",slot:c==null?void 0:c.CartItem,context:{item:e,index:r,enableUpdateItemQuantity:Z,enableRemoveItem:O,itemsLoading:L,loading:Q,attributesToHide:l,cartTaxesConfig:s,quantityType:Y,dropdownOptions:R,showDiscount:J,showSavings:K,dictionary:i,getImage:et,getTitle:nt,getSku:dt,getPriceProps:at,getTotalPriceProps:ot,getProductAttributes:ut,getConfiguration:rt,getTotalExcludingTax:ct,getWarning:st,getAlert:lt,getFooter:gt,getSavingsAmount:it},children:_},e.uid)}):null,mt=n(C,{name:"EmptyCart",slot:c==null?void 0:c.EmptyCart,context:{},children:n(Ft,{"data-testid":"empty-cart",ctaLinkURL:E==null?void 0:E()})}),ht=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=ht.props.children.props.children,bt=()=>{const t=a==null?void 0:a.items.filter(e=>e.outOfStock);t==null||t.forEach(e=>{z(e,0)})},Mt=ft(t=>t.outOfStock||t.insufficientQuantity||!1),yt=a!=null&&a.hasOutOfStockItems?n(qt,{"data-testid":"cart-out-of-stock-message",icon:n(W,{source:xt,size:"16"}),itemList:n(St,{"data-testid":"out-of-stock-cart-items",children:Mt}),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=ft(t=>!t.outOfStock&&!t.insufficientQuantity),vt=V?Math.max(h||5,5):Math.min((a==null?void 0:a.totalQuantity)||5,5),pt=(a==null?void 0:a.totalQuantity)>vt,Zt=pt&&!V&&vt!=h,$=a!=null&&a.totalQuantity&&j?n(C,{name:"Footer",slot:c==null?void 0:c.CartSummaryFooter,context:{displayMaxItems:V,routeCart:d},"data-testid":"cart-cart-summary-footer-slot",children:n("div",{"data-testid":"cart-cart-summary-footer",children:pt?Zt?n(q,{className:"cart-cart-summary-list-footer__action",onClick:jt,"data-testid":"view-more-items-button",variant:"tertiary",children:i.viewMore}):d&&n(q,{className:"cart-cart-summary-list-footer__action",href:d(),variant:"tertiary","data-testid":"view-cart-or-less-items-button",children:i.viewAll}):d&&n(q,{className:"cart-cart-summary-list-footer__action",href:d(),variant:"tertiary","data-testid":"view-cart-button",children:i.viewAll})})}):null,kt=a!=null&&a.totalQuantity?n(St,{"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 At?n(Ut,{"data-testid":"cart-summary-list-accordion",className:I(["cart-cart-summary-list-accordion",`cart-cart-summary-list__background--${F}`]),iconOpen:ee,iconClose:Dt,children:n(Tt,{title:$t,"data-testid":"cart-summary-list-accordion__section",open:!0,renderContentWhenClosed:!0,children:n(Nt,{...H,"aria-expanded":!0,"aria-label":"TEST",className:"cart-cart-summary-list-accordion__list",loading:Q,footer:w?void 0:$||(d?$:void 0),emptyCart:mt,products:kt,outOfStockMessage:yt,variant:F})})}):n(Nt,{...H,heading:U?void 0:ht,footer:w?void 0:$||(d?$:void 0),loading:Q,emptyCart:mt,products:kt,outOfStockMessage:yt,variant:F})};ae.getInitialData=async function(){return Yt()};export{ae as C};
|
|
3
|
+
import{jsx as n,jsxs as y,Fragment as M}from"@dropins/tools/preact-jsx-runtime.js";import*as o from"@dropins/tools/preact-compat.js";import{useState as N,useCallback as Bt,useEffect as It}from"@dropins/tools/preact-compat.js";import{classes as I,VComponent as b,Slot as C}from"@dropins/tools/lib.js";import{E as Ft}from"./EmptyCart.js";/* empty css */import{Divider as Et,Skeleton as zt,SkeletonRow as Wt,InLineAlert as qt,CartList as St,Icon as W,Button as q,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 Pt}from"./updateProductsFromCart.js";import{S as Dt}from"./ChevronDown.js";import{useText as te}from"@dropins/tools/i18n.js";const ee=g=>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",...g},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=g=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},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=g=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},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"})),Nt=({className:g,children:U,heading:w,footer:v,emptyCart:E,products:d,outOfStockMessage:m,variant:S="primary",loading:h=!0,...c})=>n("div",{...c,className:I(["cart-cart-summary-list",g,`cart-cart-summary-list__background--${S}`]),children:h?n(re,{}):y(M,{children:[(w||m)&&y("div",{"data-testid":"cart-summary-list-heading-wrapper",className:I(["cart-cart-summary-list__heading",["cart-cart-summary-list__heading--full-width",!d]]),children:[w&&y(M,{children:[n(b,{node:w,className:"cart-cart-summary-list__heading-text"}),n(Et,{variant:"primary",className:I(["cart-cart-summary-list__heading-divider"])})]}),m&&n(b,{node:m,className:"cart-cart-summary-list__out-of-stock-message"})]}),n("div",{className:I(["cart-cart-summary-list__content",["cart-cart-summary-list__content--empty",!d]]),children:d||n(b,{node:E,className:"cart-cart-summary-list__empty-cart"})}),v&&y(M,{children:[n(Et,{variant:"primary",className:I(["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:g=null,hideHeading:U,hideFooter:w,routeProduct:v,routeEmptyCartCTA:E,routeCart:d,onItemUpdate:m,onItemRemove:S,maxItems:h,slots:c,attributesToHide:l=[],enableRemoveItem:O,enableUpdateItemQuantity:Z,onItemsErrorsChange:B,accordion:At=!1,variant:F="primary",isLoading:Ot,showMaxItems:T,showDiscount:J,showSavings:K,quantityType:Y,dropdownOptions:R,...H})=>{var Ct;const[Q,Qt]=N(!g),[a,Gt]=N(g),[L,Vt]=N(new Set),[G,D]=N(new Map),s=(Ct=Ht.config)==null?void 0:Ct.shoppingCartDisplaySetting,[V,Xt]=N(T?!0:!h&&!T),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)=>{Vt(r=>(e?r.add(t):r.delete(t),new Set(r)))},tt=(t,e)=>{D(r=>(e?r.set(t,e):r.delete(t),new Map(r)))},z=(t,e)=>{X(t.uid,!0),D(new Map),O&&e===0?Pt([{uid:t.uid,quantity:e}]).then(()=>{S==null||S({item:t})}).finally(()=>{X(t.uid,!1)}).catch(r=>{console.warn(r)}):Z&&Pt([{uid:t.uid,quantity:e}]).then(()=>{m==null||m({item:t})}).finally(()=>{X(t.uid,!1)}).catch(r=>{tt(t.uid,r.message)})},jt=Bt(()=>{Xt(t=>!t)},[]);It(()=>{const t=Rt.on("cart/data",e=>{Gt(e),Qt(!!Ot)},{eager:!0});return()=>{t==null||t.off()}},[]),It(()=>{B&&B(G)},[G,B]);const et=(t,e)=>{if(l.includes("image"))return;const r={loading:e<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}},u=n(Kt,{"data-testid":"cart-list-item-image",...r});return n(C,{name:"Thumbnail",slot:c==null?void 0:c.Thumbnail,context:{item:t,defaultImageProps:r},children:v?n("a",{href:v(t),children:u}):u})},nt=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})},rt=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},at=t=>{var e,r,u,f;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:(u=t.regularPrice)==null?void 0:u.value,currency:(f=t.regularPrice)==null?void 0:f.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}},it=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"}},ct=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,ot=t=>{var u,f,_,p,k,P,x,wt,Lt,_t;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=(u=t.rowTotalIncludingTax)==null?void 0:u.value,e.currency=(f=t.rowTotalIncludingTax)==null?void 0:f.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=(P=t.rowTotalIncludingTax)==null?void 0:P.currency,r.sale=!0,r["aria-label"]=i.discountedPrice,r["data-testid"]="discount-total")):(e.amount=(x=t.total)==null?void 0:x.value,e.currency=(wt=t.total)==null?void 0:wt.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="regular-item-total",r&&(r.amount=(Lt=t.discountedTotal)==null?void 0:Lt.value,r.currency=(_t=t.discountedTotal)==null?void 0:_t.currency,r.sale=!0,r["aria-label"]=i.regularPrice,r["data-testid"]="discount-total")),{totalProps:e,discountProps:r}},st=t=>{var k,P,x;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"),u=L.has(t.uid),f=t.insufficientQuantity&&t.stockLevel?t.stockLevel==="noNumber"?i.insufficientQuantityGeneral:i.insufficientQuantity.replace("{inventory}",(P=t.stockLevel)==null?void 0:P.toString()).replace("{count}",t.quantity.toString()):"",_=t.lowInventory&&t.onlyXLeftInStock&&i.lowInventory.replace("{count}",(x=t.onlyXLeftInStock)==null?void 0:x.toString()),p=!t.outOfStock&&e&&r?i.notAvailableMessage:e;return!u&&(e||t.insufficientQuantity||t.lowInventory)?y("span",{"data-testid":"item-warning",children:[n(W,{source:ne,size:"16"}),p||f||_]}):void 0},lt=t=>l!=null&&l.includes("alert")?void 0:!L.has(t.uid)&&t.outOfStock?y("span",{"data-testid":"item-alert",children:[n(W,{source:xt,size:"16"}),i.outOfStockAlert]}):void 0,ut=t=>n(C,{name:"ProductAttributes",slot:c==null?void 0:c.ProductAttributes,context:{item:t}}),dt=t=>{if(!l.includes("sku"))return n("span",{"data-testid":"cart-list-item-sku",children:t.sku})},gt=t=>n(C,{name:"Footer",slot:c==null?void 0:c.Footer,context:{item:t,handleItemsLoading:X,handleItemsError:tt,onItemUpdate:m}}),ft=t=>a!=null&&a.totalQuantity?a.items.filter(t).map((e,r)=>{var p;const{totalProps:u,discountProps:f}=ot(e),_=n(Jt,{updating:L==null?void 0:L.has(e.uid),loading:Q,"data-testid":`cart-list-item-entry-${e.uid}`,image:et(e,r),title:nt(e),sku:dt(e),price:l.includes("price")?void 0:n(A,{...at(e)}),quantity:l.includes("quantity")?void 0:e.quantity,total:y(M,{children:[l.includes("total")?void 0:n(A,{...u}),l.includes("totalDiscount")?void 0:f&&n(A,{...f})]}),attributes:ut(e),configurations:rt(e),totalExcludingTax:l.includes("totalExcludingTax")?void 0:ct(e),taxIncluded:(s==null?void 0:s.price)==="INCLUDING_TAX",taxExcluded:!l.includes("totalExcludingTax")&&(s==null?void 0:s.price)==="INCLUDING_EXCLUDING_TAX",warning:st(e),alert:lt(e),quantityType:Y,dropdownOptions:R,onQuantity:Z?k=>{z(e,k)}:void 0,onRemove:O?()=>z(e,0):void 0,discount:J&&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:K&&e.discounted&&e.savingsAmount?y("div",{children:[n("span",{children:n(A,{...it(e)})})," ",i.savingsAmount]}):void 0,footer:gt(e)},e.uid);return n(C,{name:"CartItem",slot:c==null?void 0:c.CartItem,context:{item:e,index:r,enableUpdateItemQuantity:Z,enableRemoveItem:O,itemsLoading:L,loading:Q,attributesToHide:l,cartTaxesConfig:s,quantityType:Y,dropdownOptions:R,showDiscount:J,showSavings:K,dictionary:i,getImage:et,getTitle:nt,getSku:dt,getPriceProps:at,getTotalPriceProps:ot,getProductAttributes:ut,getConfiguration:rt,getTotalExcludingTax:ct,getWarning:st,getAlert:lt,getFooter:gt,getSavingsAmount:it},children:_},e.uid)}):null,mt=n(C,{name:"EmptyCart",slot:c==null?void 0:c.EmptyCart,context:{},children:n(Ft,{"data-testid":"empty-cart",ctaLinkURL:E==null?void 0:E()})}),ht=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=ht.props.children.props.children,bt=()=>{const t=a==null?void 0:a.items.filter(e=>e.outOfStock);t==null||t.forEach(e=>{z(e,0)})},Mt=ft(t=>t.outOfStock||t.insufficientQuantity||!1),yt=a!=null&&a.hasOutOfStockItems?n(qt,{"data-testid":"cart-out-of-stock-message",icon:n(W,{source:xt,size:"16"}),itemList:n(St,{"data-testid":"out-of-stock-cart-items",children:Mt}),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=ft(t=>!t.outOfStock&&!t.insufficientQuantity),vt=V?Math.max(h||5,5):Math.min((a==null?void 0:a.totalQuantity)||5,5),pt=(a==null?void 0:a.totalQuantity)>vt,Zt=pt&&!V&&vt!=h,$=a!=null&&a.totalQuantity&&j?n(C,{name:"Footer",slot:c==null?void 0:c.CartSummaryFooter,context:{displayMaxItems:V,routeCart:d},"data-testid":"cart-cart-summary-footer-slot",className:"cart-cart-summary-footer",children:pt?Zt?n(q,{className:"cart-cart-summary-list-footer__action",onClick:jt,"data-testid":"view-more-items-button",variant:"tertiary",children:i.viewMore}):d&&n(q,{className:"cart-cart-summary-list-footer__action",href:d(),variant:"tertiary","data-testid":"view-cart-or-less-items-button",children:i.viewAll}):d&&n(q,{className:"cart-cart-summary-list-footer__action",href:d(),variant:"tertiary","data-testid":"view-cart-button",children:i.viewAll})}):null,kt=a!=null&&a.totalQuantity?n(St,{"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 At?n(Ut,{"data-testid":"cart-summary-list-accordion",className:I(["cart-cart-summary-list-accordion",`cart-cart-summary-list__background--${F}`]),iconOpen:ee,iconClose:Dt,children:n(Tt,{title:$t,"data-testid":"cart-summary-list-accordion__section",open:!0,renderContentWhenClosed:!0,children:n(Nt,{...H,"aria-expanded":!0,"aria-label":"TEST",className:"cart-cart-summary-list-accordion__list",loading:Q,footer:w?void 0:$||(d?$:void 0),emptyCart:mt,products:kt,outOfStockMessage:yt,variant:F})})}):n(Nt,{...H,heading:U?void 0:ht,footer:w?void 0:$||(d?$:void 0),loading:Q,emptyCart:mt,products:kt,outOfStockMessage:yt,variant:F})};ae.getInitialData=async function(){return Yt()};export{ae as C};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-cart", "version": "1.3.0-
|
|
1
|
+
{"name": "@dropins/storefront-cart", "version": "1.3.0-beta3", "@dropins/tools": "~1.2.0", "license": "SEE LICENSE IN LICENSE.md"}
|