@dropins/storefront-cart 0.7.0-alpha015 → 0.7.0-alpha017
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.
package/chunks/CartFragment.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{s}from"./resetCart.js";function R(r){var u,
|
|
1
|
+
import{s}from"./resetCart.js";function R(r){var n,u,e,l,c,t,a;return r?{id:r.id,totalQuantity:z(r),errors:S(r==null?void 0:r.itemsV2),items:h(r==null?void 0:r.itemsV2),miniCartMaxItems:h(r==null?void 0:r.itemsV2).slice(0,((n=s.config)==null?void 0:n.miniCartMaxItemsDisplay)??10),total:{includingTax:{value:r.prices.grand_total.value,currency:r.prices.grand_total.currency},excludingTax:{value:r.prices.grand_total_excluding_tax.value,currency:r.prices.grand_total_excluding_tax.currency}},subtotal:{excludingTax:{value:(u=r.prices.subtotal_excluding_tax)==null?void 0:u.value,currency:(e=r.prices.subtotal_excluding_tax)==null?void 0:e.currency},includingTax:{value:(l=r.prices.subtotal_including_tax)==null?void 0:l.value,currency:(c=r.prices.subtotal_including_tax)==null?void 0:c.currency},includingDiscountOnly:{value:(t=r.prices.subtotal_with_discount_excluding_tax)==null?void 0:t.value,currency:(a=r.prices.subtotal_with_discount_excluding_tax)==null?void 0:a.currency}},appliedTaxes:I(r.prices.applied_taxes),totalTax:k(r.prices.applied_taxes,r.prices.grand_total.currency),appliedDiscounts:I(r.prices.discounts),isVirtual:r.is_virtual,addresses:{shipping:r.shipping_addresses&&N(r)},isGuestCart:!s.authenticated,hasOutOfStockItems:$(r),hasFullyOutOfStockItems:P(r)}:null}function k(r,n){return r!=null&&r.length?r.reduce((u,e)=>({value:u.value+e.amount.value,currency:e.amount.currency}),{value:0,currency:n}):{value:0,currency:n}}function h(r){var u;if(!((u=r==null?void 0:r.items)!=null&&u.length))return[];const n=s.config;return r.items.map(e=>{var l,c,t,a,_,o,i,g,y,m,f,b,d,v,C,x;return{itemType:e.__typename,uid:e.uid,url:{urlKey:e.product.url_key,categories:e.product.categories.map(O=>O.url_key)},quantity:e.quantity,sku:e.product.sku,name:e.product.name,image:{src:n!=null&&n.useConfigurableParentThumbnail?e.product.thumbnail.url:((c=(l=e.configured_variant)==null?void 0:l.thumbnail)==null?void 0:c.url)||e.product.thumbnail.url,alt:n!=null&&n.useConfigurableParentThumbnail?e.product.thumbnail.label:((a=(t=e.configured_variant)==null?void 0:t.thumbnail)==null?void 0:a.label)||e.product.thumbnail.label},price:{value:e.prices.price.value,currency:e.prices.price.currency},taxedPrice:{value:e.prices.price_including_tax.value,currency:e.prices.price_including_tax.currency},rowTotal:{value:e.prices.row_total.value,currency:e.prices.row_total.currency},rowTotalIncludingTax:{value:e.prices.row_total_including_tax.value,currency:e.prices.row_total_including_tax.currency},links:G(e.links),total:e.__typename==="SimpleCartItem"&&e.customizable_options.length!==0||e.__typename==="BundleCartItem"?{value:e.prices.row_total.value,currency:e.prices.row_total.currency}:{value:(_=e.prices.original_row_total)==null?void 0:_.value,currency:(o=e.prices.original_row_total)==null?void 0:o.currency},discount:{value:e.prices.total_item_discount.value,currency:e.prices.total_item_discount.currency},regularPrice:e.__typename==="ConfigurableCartItem"?{value:(g=(i=e.configured_variant)==null?void 0:i.price_range)==null?void 0:g.maximum_price.regular_price.value,currency:(m=(y=e.configured_variant)==null?void 0:y.price_range)==null?void 0:m.maximum_price.regular_price.currency}:e.__typename==="GiftCardCartItem"||e.__typename==="SimpleCartItem"&&e.customizable_options.length!==0||e.__typename==="BundleCartItem"?{value:e.prices.price.value,currency:e.prices.price.currency}:{value:(f=e.product.price_range)==null?void 0:f.maximum_price.regular_price.value,currency:(b=e.product.price_range)==null?void 0:b.maximum_price.regular_price.currency},discounted:e.__typename==="BundleCartItem"||e.__typename==="SimpleCartItem"&&e.customizable_options.length!==0?!1:e.__typename==="ConfigurableCartItem"?((v=(d=e.configured_variant)==null?void 0:d.price_range)==null?void 0:v.maximum_price.discount.amount_off)>0:((C=e.product.price_range)==null?void 0:C.maximum_price.discount.amount_off)>0,bundleOptions:e.__typename==="BundleCartItem"?w(e.bundle_options):null,selectedOptions:E(e.configurable_options),customizableOptions:A(e.customizable_options),sender:e.__typename==="GiftCardCartItem"?e.sender_name:null,senderEmail:e.__typename==="GiftCardCartItem"?e.sender_email:null,recipient:e.__typename==="GiftCardCartItem"?e.recipient_name:null,recipientEmail:e.__typename==="GiftCardCartItem"?e.recipient_email:null,message:e.__typename==="GiftCardCartItem"?e.message:null,discountedTotal:{value:e.prices.row_total.value,currency:e.prices.row_total.currency},onlyXLeftInStock:e.__typename==="ConfigurableCartItem"?(x=e.configured_variant)==null?void 0:x.only_x_left_in_stock:e.product.only_x_left_in_stock,lowInventory:e.is_available&&e.product.only_x_left_in_stock!==null,insufficientQuantity:(e.__typename==="ConfigurableCartItem"?e.configured_variant:e.product).stock_status==="IN_STOCK"&&!e.is_available,outOfStock:e.product.stock_status==="OUT_OF_STOCK",stockLevel:M(e)}})}function S(r){var u;const n=(u=r==null?void 0:r.items)==null?void 0:u.reduce((e,l)=>{var c;return(c=l.errors)==null||c.forEach(t=>{e.push({uid:l.uid,text:t.message})}),e},[]);return n!=null&&n.length?n:null}function I(r){return r!=null&&r.length?r.map(n=>({amount:{value:n.amount.value,currency:n.amount.currency},label:n.label})):[]}function w(r){const n=r==null?void 0:r.map(e=>({uid:e.uid,label:e.label,value:e.values.map(l=>l.label).join(", ")})),u={};return n==null||n.forEach(e=>{u[e.label]=e.value}),Object.keys(u).length>0?u:null}function E(r){const n=r==null?void 0:r.map(e=>({uid:e.configurable_product_option_uid,label:e.option_label,value:e.value_label})),u={};return n==null||n.forEach(e=>{u[e.label]=e.value}),Object.keys(u).length>0?u:null}function A(r){const n=r==null?void 0:r.map(e=>({uid:e.customizable_option_uid,label:e.label,type:e.type,values:e.values.map(l=>({uid:l.customizable_option_value_uid,label:l.label,value:l.value}))})),u={};return n==null||n.forEach(e=>{var l;switch(e.type){case"field":case"area":case"date_time":u[e.label]=e.values[0].value;break;case"radio":case"drop_down":u[e.label]=e.values[0].label;break;case"multiple":case"checkbox":u[e.label]=e.values.reduce((o,i)=>o?`${o}, ${i.label}`:i.label,"");break;case"file":const c=new DOMParser,t=e.values[0].value,_=((l=c.parseFromString(t,"text/html").querySelector("a"))==null?void 0:l.textContent)||"";u[e.label]=_;break}}),u}function z(r){var n,u;return((n=s.config)==null?void 0:n.cartSummaryDisplayTotal)===0?r.itemsV2.items.length:((u=s.config)==null?void 0:u.cartSummaryDisplayTotal)===1?r.total_quantity:r.itemsV2.items.length}function G(r){return(r==null?void 0:r.length)>0?{count:r.length,result:r.map(n=>n.title).join(", ")}:null}function N(r){var n,u,e,l;return(n=r.shipping_addresses)!=null&&n.length?(u=r.shipping_addresses)==null?void 0:u.map(c=>({countryCode:c.country.code,zipCode:c.postcode,regionCode:c.region.code})):(e=r.addresses)!=null&&e.length?(l=r.addresses)==null?void 0:l.filter(c=>c.default_shipping).map(c=>{var t;return c.default_shipping&&{countryCode:c.country_id,zipCode:c.postcode,regionCode:(t=c.region)==null?void 0:t.region_code}}):null}function $(r){var n,u;return(u=(n=r==null?void 0:r.itemsV2)==null?void 0:n.items)==null?void 0:u.some(e=>{var l;return((l=e==null?void 0:e.product)==null?void 0:l.stock_status)==="OUT_OF_STOCK"||e.product.stock_status==="IN_STOCK"&&!e.is_available})}function M(r){if(!r.not_available_message)return null;const n=r.not_available_message.match(/-?\d+/);return n?parseInt(n[0]):"noNumber"}function P(r){var n,u;return(u=(n=r==null?void 0:r.itemsV2)==null?void 0:n.items)==null?void 0:u.some(e=>{var l;return((l=e==null?void 0:e.product)==null?void 0:l.stock_status)==="OUT_OF_STOCK"})}const p=`
|
|
2
2
|
customizable_options {
|
|
3
3
|
type
|
|
4
4
|
customizable_option_uid
|
|
@@ -149,21 +149,6 @@ fragment CartFragment on Cart {
|
|
|
149
149
|
url_path
|
|
150
150
|
url_key
|
|
151
151
|
}
|
|
152
|
-
custom_attributesV2(filters: {is_visible_on_front: true}){
|
|
153
|
-
items{
|
|
154
|
-
code
|
|
155
|
-
...on AttributeValue{
|
|
156
|
-
value
|
|
157
|
-
}
|
|
158
|
-
...on AttributeSelectedOptions{
|
|
159
|
-
selected_options {
|
|
160
|
-
value
|
|
161
|
-
label
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
152
|
only_x_left_in_stock
|
|
168
153
|
stock_status
|
|
169
154
|
${T}
|
|
@@ -231,7 +216,7 @@ fragment CartFragment on Cart {
|
|
|
231
216
|
postcode
|
|
232
217
|
}
|
|
233
218
|
}
|
|
234
|
-
`,
|
|
219
|
+
`,V=`
|
|
235
220
|
$pageSize: Int! = 100,
|
|
236
221
|
$currentPage: Int! = 1,
|
|
237
222
|
$itemsSortInput: QuoteItemsSortInput! = {field: CREATED_AT, order: DESC}
|
|
@@ -247,4 +232,4 @@ customer {
|
|
|
247
232
|
region_id
|
|
248
233
|
}
|
|
249
234
|
}
|
|
250
|
-
}`;export{
|
|
235
|
+
}`;export{V as C,D as a,q as b,R as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as r,jsxs as k,Fragment as Z}from"@dropins/tools/preact-jsx-runtime.js";import*as s from"@dropins/tools/preact-compat.js";import{useState as _,useEffect as T}from"@dropins/tools/preact-compat.js";import{classes as x,VComponent as V,Slot as X}from"@dropins/tools/lib.js";/* empty css */import{E as mt}from"./EmptyCart.js";import{Divider as vt,Skeleton as Lt,SkeletonRow as Ct,InLineAlert as wt,Icon as j,CartList as b,CartItem as It,Price as O,Image as Et}from"@dropins/tools/components.js";import{g as St}from"./persisted-data.js";import{events as _t}from"@dropins/tools/event-bus.js";import{s as xt}from"./resetCart.js";import{u as D}from"./updateProductsFromCart.js";import{useText as Ot}from"@dropins/tools/i18n.js";const J=g=>s.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},s.createElement("g",{clipPath:"url(#clip0_4797_15331)"},s.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"}),s.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.24023 4.64001L14.9902 8.06001V11.42",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),s.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"}),s.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"}),s.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"}),s.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"})),s.createElement("defs",null,s.createElement("clipPath",{id:"clip0_4797_15331"},s.createElement("rect",{width:22,height:18.86,fill:"white",transform:"translate(1 2.54999)"})))),Pt=g=>s.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},s.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"}),s.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:$,heading:f,emptyCart:m,products:p,outOfStockMessage:h,loading:P=!0,...l})=>r("div",{...l,className:x(["cart-cart-summary-list",g]),children:P?r(Qt,{}):k(Z,{children:[(f||h)&&k("div",{"data-testid":"cart-summary-list-heading-wrapper",className:x(["cart-cart-summary-list__heading",["cart-cart-summary-list__heading--full-width",!p]]),children:[f&&k(Z,{children:[r(V,{node:f,className:"cart-cart-summary-list__heading-text"}),r(vt,{variant:"primary",className:x(["cart-cart-summary-list__heading-divider"])})]}),h&&r(V,{node:h,className:"cart-cart-summary-list__out-of-stock-message"})]}),r("div",{className:x(["cart-cart-summary-list__content",["cart-cart-summary-list__content--empty",!p]]),children:p||r(V,{node:m,className:"cart-cart-summary-list__empty-cart"})})]})}),Qt=()=>r(Lt,{"data-testid":"cart-summary-list-skeleton",className:"cart-cart-summary-list__skeleton",rowGap:"medium",children:r(Ct,{variant:"row",size:"xlarge",fullWidth:!0,lines:3,multilineGap:"small"})}),At=({initialData:g=null,hideHeading:$,routeProduct:f,routeEmptyCartCTA:m,onItemUpdate:p,onItemRemove:h,maxItems:P,slots:l,attributesToHide:o=[],enableRemoveItem:N,enableUpdateItemQuantity:z,onItemsErrorsChange:Q,...K})=>{var M;const[Y,R]=_(!g),[a,H]=_(g),[v,tt]=_(new Set),[I,et]=_(new Map),c=(M=xt.config)==null?void 0:M.shoppingCartDisplaySetting,i=Ot({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"}),A=(t,e)=>{tt(n=>(e?n.add(t):n.delete(t),new Set(n)))},U=(t,e)=>{et(n=>(e?n.set(t,e):n.delete(t),new Map(n)))},G=(t,e)=>{A(t.uid,!0),U(t.uid),N&&e===0?D([{uid:t.uid,quantity:e}]).then(()=>{h==null||h({item:t})}).finally(()=>{A(t.uid,!1)}).catch(n=>{console.warn(n)}):z&&D([{uid:t.uid,quantity:e}]).then(()=>{p==null||p({item:t})}).finally(()=>{A(t.uid,!1)}).catch(n=>{console.warn(n),U(t.uid,n.message)})};T(()=>{const t=_t.on("cart/data",e=>{H(e),R(!1)},{eager:!0});return()=>{t==null||t.off()}},[]),T(()=>{Q&&Q(I)},[I,Q]);const nt=(t,e)=>{if(o.includes("image"))return;const n=r(Et,{"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 f?r("a",{href:f(t),children:n}):n},rt=t=>{if(!o.includes("name"))return r("span",{"data-testid":"cart-list-item-title",children:f?r("a",{href:f(t),children:t.name}):t.name})},at=t=>{if(!o.includes("configurations"))return{...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}},it=t=>{var e,n,d,u;return(c==null?void 0:c.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:(n=t.taxedPrice)==null?void 0:n.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}:{amount:(d=t.regularPrice)==null?void 0:d.value,currency:(u=t.regularPrice)==null?void 0:u.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}},ct=t=>(c==null?void 0:c.price)==="INCLUDING_EXCLUDING_TAX"?r(O,{amount:t.rowTotal.value,currency:t.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":i.regularPrice}):void 0,ot=t=>{var d,u,y,S,L,C,w,W,B,F;const e={"aria-label":i.regularPrice},n=t.discounted?{}:null;return["INCLUDING_TAX","INCLUDING_EXCLUDING_TAX"].includes(c==null?void 0:c.price)?(e.amount=(d=t.rowTotalIncludingTax)==null?void 0:d.value,e.currency=(u=t.rowTotalIncludingTax)==null?void 0:u.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="including-tax-item-total",n&&(e.amount=(y=t.total)==null?void 0:y.value,e.currency=(S=t.total)==null?void 0:S.currency,n.amount=(L=t.rowTotalIncludingTax)==null?void 0:L.value,n.currency=(C=t.rowTotalIncludingTax)==null?void 0:C.currency,n.sale=!0,n["aria-label"]=i.discountedPrice,n["data-testid"]="discount-total")):(e.amount=(w=t.total)==null?void 0:w.value,e.currency=(W=t.total)==null?void 0:W.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="regular-item-total",n&&(n.amount=(B=t.discountedTotal)==null?void 0:B.value,n.currency=(F=t.discountedTotal)==null?void 0:F.currency,n.sale=!0,n["aria-label"]=i.regularPrice,n["data-testid"]="discount-total")),{totalProps:e,discountProps:n}},st=t=>{var L,C,w;if(o.includes("warning"))return;const e=I.get(t.uid),n=(L=I.get(t.uid))==null?void 0:L.includes("The requested qty is not available"),d=v.has(t.uid),u=t.insufficientQuantity&&t.stockLevel?t.stockLevel==="noNumber"?i.insufficientQuantityGeneral:i.insufficientQuantity.replace("{inventory}",(C=t.stockLevel)==null?void 0:C.toString()).replace("{count}",t.quantity.toString()):"",y=t.lowInventory&&t.onlyXLeftInStock&&i.lowInventory.replace("{count}",(w=t.onlyXLeftInStock)==null?void 0:w.toString()),S=!t.outOfStock&&e&&n?i.notAvailableMessage:e;return!d&&(e||t.insufficientQuantity||t.lowInventory)?k("span",{"data-testid":"item-warning",children:[r(j,{source:Pt,size:"16"}),S||u||y]}):void 0},lt=t=>o!=null&&o.includes("alert")?void 0:!v.has(t.uid)&&t.outOfStock?k("span",{"data-testid":"item-alert",children:[r(j,{source:J,size:"16"}),i.outOfStockAlert]}):void 0,ut=t=>r(X,{name:"ProductAttributes",slot:l==null?void 0:l.ProductAttributes,context:{item:t}}),dt=t=>{if(!o.includes("sku"))return r("span",{"data-testid":"cart-list-item-sku",children:t.sku})},q=t=>a!=null&&a.totalQuantity?a.items.filter(t).map((e,n)=>{const{totalProps:d,discountProps:u}=ot(e);return r(It,{updating:v==null?void 0:v.has(e.uid),"data-testid":`cart-list-item-entry-${e.uid}`,image:nt(e,n),title:rt(e),sku:dt(e),price:o.includes("price")?void 0:r(O,{...it(e)}),quantity:o.includes("quantity")?void 0:e.quantity,total:k(Z,{children:[o.includes("total")?void 0:r(O,{...d}),o.includes("totalDiscount")?void 0:u&&r(O,{...u})]}),attributes:ut(e),configurations:at(e),totalExcludingTax:o.includes("totalExcludingTax")?void 0:ct(e),taxIncluded:(c==null?void 0:c.price)==="INCLUDING_TAX",taxExcluded:!o.includes("totalExcludingTax")&&(c==null?void 0:c.price)==="INCLUDING_EXCLUDING_TAX",warning:st(e),alert:lt(e),onQuantity:z?y=>{G(e,y)}:void 0,onRemove:N?()=>G(e,0):void 0},e.uid)}):null,gt=r(X,{name:"EmptyCart",slot:l==null?void 0:l.EmptyCart,context:{},children:r(mt,{"data-testid":"empty-cart",ctaLinkURL:m==null?void 0:m()})}),ft=r(X,{name:"Heading",slot:l==null?void 0:l.Heading,context:{count:a==null?void 0:a.totalQuantity},children:r("div",{"data-testid":"default-cart-heading",children:i.heading.replace("({count})",a!=null&&a.totalQuantity?`(${a==null?void 0:a.totalQuantity.toString()})`:"")})}),pt=()=>{const t=a==null?void 0:a.items.filter(e=>e.outOfStock);t==null||t.forEach(e=>{G(e,0)})},ht=q(t=>t.outOfStock||t.insufficientQuantity||!1),yt=a!=null&&a.hasOutOfStockItems?r(wt,{"data-testid":"cart-out-of-stock-message",icon:r(j,{source:J,size:"16"}),itemList:r(b,{"data-testid":"out-of-stock-cart-items",children:ht}),type:"warning",heading:i.outOfStockHeading,description:i.outOfStockDescription,variant:"primary",actionButtonPosition:"bottom",additionalActions:a!=null&&a.hasFullyOutOfStockItems&&N?[{label:i.removeAction,onClick:pt}]:void 0}):void 0,E=q(t=>!t.outOfStock&&!t.insufficientQuantity),kt=a!=null&&a.totalQuantity?r(b,{"data-testid":"cart-list",children:E==null?void 0:E.slice(0,P??E.length)}):null;return r(Nt,{...K,heading:$?void 0:ft,loading:Y,emptyCart:gt,products:kt,outOfStockMessage:yt})};At.getInitialData=async function(){return St()};export{At as C};
|
|
1
|
+
import{jsx as r,jsxs as k,Fragment as Z}from"@dropins/tools/preact-jsx-runtime.js";import*as s from"@dropins/tools/preact-compat.js";import{useState as _,useEffect as T}from"@dropins/tools/preact-compat.js";import{classes as x,VComponent as V,Slot as X}from"@dropins/tools/lib.js";/* empty css */import{E as kt}from"./EmptyCart.js";import{Divider as mt,Skeleton as vt,SkeletonRow as Lt,InLineAlert as Ct,Icon as j,CartList as D,CartItem as wt,Price as O,Image as It}from"@dropins/tools/components.js";import{g as Et}from"./persisted-data.js";import{events as St}from"@dropins/tools/event-bus.js";import{s as _t}from"./resetCart.js";import{u as J}from"./updateProductsFromCart.js";import{useText as xt}from"@dropins/tools/i18n.js";const K=g=>s.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},s.createElement("g",{clipPath:"url(#clip0_4797_15331)"},s.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"}),s.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.24023 4.64001L14.9902 8.06001V11.42",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),s.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"}),s.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"}),s.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"}),s.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"})),s.createElement("defs",null,s.createElement("clipPath",{id:"clip0_4797_15331"},s.createElement("rect",{width:22,height:18.86,fill:"white",transform:"translate(1 2.54999)"})))),Ot=g=>s.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...g},s.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"}),s.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:$,heading:f,emptyCart:m,products:p,outOfStockMessage:h,loading:N=!0,...l})=>r("div",{...l,className:x(["cart-cart-summary-list",g]),children:N?r(Pt,{}):k(Z,{children:[(f||h)&&k("div",{"data-testid":"cart-summary-list-heading-wrapper",className:x(["cart-cart-summary-list__heading",["cart-cart-summary-list__heading--full-width",!p]]),children:[f&&k(Z,{children:[r(V,{node:f,className:"cart-cart-summary-list__heading-text"}),r(mt,{variant:"primary",className:x(["cart-cart-summary-list__heading-divider"])})]}),h&&r(V,{node:h,className:"cart-cart-summary-list__out-of-stock-message"})]}),r("div",{className:x(["cart-cart-summary-list__content",["cart-cart-summary-list__content--empty",!p]]),children:p||r(V,{node:m,className:"cart-cart-summary-list__empty-cart"})})]})}),Pt=()=>r(vt,{"data-testid":"cart-summary-list-skeleton",className:"cart-cart-summary-list__skeleton",rowGap:"medium",children:r(Lt,{variant:"row",size:"xlarge",fullWidth:!0,lines:3,multilineGap:"small"})}),Qt=({initialData:g=null,hideHeading:$,routeProduct:f,routeEmptyCartCTA:m,onItemUpdate:p,onItemRemove:h,maxItems:N,slots:l,attributesToHide:o=[],enableRemoveItem:P,enableUpdateItemQuantity:z,onItemsErrorsChange:Q,...Y})=>{var M;const[R,b]=_(!g),[a,H]=_(g),[v,tt]=_(new Set),[I,et]=_(new Map),c=(M=_t.config)==null?void 0:M.shoppingCartDisplaySetting,i=xt({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"}),G=(t,e)=>{tt(n=>(e?n.add(t):n.delete(t),new Set(n)))},U=(t,e)=>{et(n=>(e?n.set(t,e):n.delete(t),new Map(n)))},A=(t,e)=>{G(t.uid,!0),U(t.uid),P&&e===0?J([{uid:t.uid,quantity:e}]).then(()=>{h==null||h({item:t})}).finally(()=>{G(t.uid,!1)}).catch(n=>{console.warn(n)}):z&&J([{uid:t.uid,quantity:e}]).then(()=>{p==null||p({item:t})}).finally(()=>{G(t.uid,!1)}).catch(n=>{console.warn(n),U(t.uid,n.message)})};T(()=>{const t=St.on("cart/data",e=>{H(e),b(!1)},{eager:!0});return()=>{t==null||t.off()}},[]),T(()=>{Q&&Q(I)},[I,Q]);const nt=(t,e)=>{if(o.includes("image"))return;const n=r(It,{"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 r(X,{name:"Thumbnail",slot:l==null?void 0:l.Thumbnail,context:{item:t},children:f?r("a",{href:f(t),children:n}):n})},rt=t=>{if(!o.includes("name"))return r("span",{"data-testid":"cart-list-item-title",children:f?r("a",{href:f(t),children:t.name}):t.name})},at=t=>{if(!o.includes("configurations"))return{...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}},it=t=>{var e,n,d,u;return(c==null?void 0:c.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:(n=t.taxedPrice)==null?void 0:n.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}:{amount:(d=t.regularPrice)==null?void 0:d.value,currency:(u=t.regularPrice)==null?void 0:u.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}},ct=t=>(c==null?void 0:c.price)==="INCLUDING_EXCLUDING_TAX"?r(O,{amount:t.rowTotal.value,currency:t.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":i.regularPrice}):void 0,ot=t=>{var d,u,y,S,L,C,w,W,B,F;const e={"aria-label":i.regularPrice},n=t.discounted?{}:null;return["INCLUDING_TAX","INCLUDING_EXCLUDING_TAX"].includes(c==null?void 0:c.price)?(e.amount=(d=t.rowTotalIncludingTax)==null?void 0:d.value,e.currency=(u=t.rowTotalIncludingTax)==null?void 0:u.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="including-tax-item-total",n&&(e.amount=(y=t.total)==null?void 0:y.value,e.currency=(S=t.total)==null?void 0:S.currency,n.amount=(L=t.rowTotalIncludingTax)==null?void 0:L.value,n.currency=(C=t.rowTotalIncludingTax)==null?void 0:C.currency,n.sale=!0,n["aria-label"]=i.discountedPrice,n["data-testid"]="discount-total")):(e.amount=(w=t.total)==null?void 0:w.value,e.currency=(W=t.total)==null?void 0:W.currency,e.variant=t.discounted?"strikethrough":"default",e["data-testid"]="regular-item-total",n&&(n.amount=(B=t.discountedTotal)==null?void 0:B.value,n.currency=(F=t.discountedTotal)==null?void 0:F.currency,n.sale=!0,n["aria-label"]=i.regularPrice,n["data-testid"]="discount-total")),{totalProps:e,discountProps:n}},st=t=>{var L,C,w;if(o.includes("warning"))return;const e=I.get(t.uid),n=(L=I.get(t.uid))==null?void 0:L.includes("The requested qty is not available"),d=v.has(t.uid),u=t.insufficientQuantity&&t.stockLevel?t.stockLevel==="noNumber"?i.insufficientQuantityGeneral:i.insufficientQuantity.replace("{inventory}",(C=t.stockLevel)==null?void 0:C.toString()).replace("{count}",t.quantity.toString()):"",y=t.lowInventory&&t.onlyXLeftInStock&&i.lowInventory.replace("{count}",(w=t.onlyXLeftInStock)==null?void 0:w.toString()),S=!t.outOfStock&&e&&n?i.notAvailableMessage:e;return!d&&(e||t.insufficientQuantity||t.lowInventory)?k("span",{"data-testid":"item-warning",children:[r(j,{source:Ot,size:"16"}),S||u||y]}):void 0},lt=t=>o!=null&&o.includes("alert")?void 0:!v.has(t.uid)&&t.outOfStock?k("span",{"data-testid":"item-alert",children:[r(j,{source:K,size:"16"}),i.outOfStockAlert]}):void 0,ut=t=>{if(!o.includes("sku"))return r("span",{"data-testid":"cart-list-item-sku",children:t.sku})},q=t=>a!=null&&a.totalQuantity?a.items.filter(t).map((e,n)=>{const{totalProps:d,discountProps:u}=ot(e);return r(wt,{updating:v==null?void 0:v.has(e.uid),"data-testid":`cart-list-item-entry-${e.uid}`,image:nt(e,n),title:rt(e),sku:ut(e),price:o.includes("price")?void 0:r(O,{...it(e)}),quantity:o.includes("quantity")?void 0:e.quantity,total:k(Z,{children:[o.includes("total")?void 0:r(O,{...d}),o.includes("totalDiscount")?void 0:u&&r(O,{...u})]}),configurations:at(e),totalExcludingTax:o.includes("totalExcludingTax")?void 0:ct(e),taxIncluded:(c==null?void 0:c.price)==="INCLUDING_TAX",taxExcluded:!o.includes("totalExcludingTax")&&(c==null?void 0:c.price)==="INCLUDING_EXCLUDING_TAX",warning:st(e),alert:lt(e),onQuantity:z?y=>{A(e,y)}:void 0,onRemove:P?()=>A(e,0):void 0},e.uid)}):null,dt=r(X,{name:"EmptyCart",slot:l==null?void 0:l.EmptyCart,context:{},children:r(kt,{"data-testid":"empty-cart",ctaLinkURL:m==null?void 0:m()})}),gt=r(X,{name:"Heading",slot:l==null?void 0:l.Heading,context:{count:a==null?void 0:a.totalQuantity},children:r("div",{"data-testid":"default-cart-heading",children:i.heading.replace("({count})",a!=null&&a.totalQuantity?`(${a==null?void 0:a.totalQuantity.toString()})`:"")})}),ft=()=>{const t=a==null?void 0:a.items.filter(e=>e.outOfStock);t==null||t.forEach(e=>{A(e,0)})},pt=q(t=>t.outOfStock||t.insufficientQuantity||!1),ht=a!=null&&a.hasOutOfStockItems?r(Ct,{"data-testid":"cart-out-of-stock-message",icon:r(j,{source:K,size:"16"}),itemList:r(D,{"data-testid":"out-of-stock-cart-items",children:pt}),type:"warning",heading:i.outOfStockHeading,description:i.outOfStockDescription,variant:"primary",actionButtonPosition:"bottom",additionalActions:a!=null&&a.hasFullyOutOfStockItems&&P?[{label:i.removeAction,onClick:ft}]:void 0}):void 0,E=q(t=>!t.outOfStock&&!t.insufficientQuantity),yt=a!=null&&a.totalQuantity?r(D,{"data-testid":"cart-list",children:E==null?void 0:E.slice(0,N??E.length)}):null;return r(Nt,{...Y,heading:$?void 0:gt,loading:R,emptyCart:dt,products:yt,outOfStockMessage:ht})};Qt.getInitialData=async function(){return Et()};export{Qt as C};
|
|
@@ -17,7 +17,7 @@ export interface CartSummaryListProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
17
17
|
slots?: {
|
|
18
18
|
Heading?: SlotProps;
|
|
19
19
|
EmptyCart?: SlotProps;
|
|
20
|
-
|
|
20
|
+
Thumbnail?: SlotProps;
|
|
21
21
|
};
|
|
22
22
|
enableRemoveItem?: boolean;
|
|
23
23
|
enableUpdateItemQuantity?: boolean;
|
|
@@ -88,7 +88,6 @@ export interface Item {
|
|
|
88
88
|
outOfStock?: boolean;
|
|
89
89
|
notAvailableMessage?: string;
|
|
90
90
|
stockLevel?: String;
|
|
91
|
-
productAttributes?: Attribute[];
|
|
92
91
|
}
|
|
93
92
|
interface ItemError {
|
|
94
93
|
id: string;
|
|
@@ -110,14 +109,5 @@ interface ItemLinks {
|
|
|
110
109
|
count: number;
|
|
111
110
|
result: string;
|
|
112
111
|
}
|
|
113
|
-
interface AttributeOption {
|
|
114
|
-
value: string;
|
|
115
|
-
label: string;
|
|
116
|
-
}
|
|
117
|
-
interface Attribute {
|
|
118
|
-
code: string;
|
|
119
|
-
value?: string;
|
|
120
|
-
selected_options?: AttributeOption[];
|
|
121
|
-
}
|
|
122
112
|
export {};
|
|
123
113
|
//# sourceMappingURL=cart-model.d.ts.map
|
|
@@ -940,84 +940,5 @@ declare const complexInsufficientQuantityGeneralMessage: {
|
|
|
940
940
|
};
|
|
941
941
|
};
|
|
942
942
|
};
|
|
943
|
-
|
|
944
|
-
product: {
|
|
945
|
-
custom_attributesV2: {
|
|
946
|
-
items: ({
|
|
947
|
-
code: string;
|
|
948
|
-
value: string;
|
|
949
|
-
selected_options?: undefined;
|
|
950
|
-
} | {
|
|
951
|
-
code: string;
|
|
952
|
-
selected_options: {
|
|
953
|
-
value: string;
|
|
954
|
-
label: string;
|
|
955
|
-
}[];
|
|
956
|
-
value?: undefined;
|
|
957
|
-
})[];
|
|
958
|
-
};
|
|
959
|
-
name: string;
|
|
960
|
-
sku: string;
|
|
961
|
-
thumbnail: {
|
|
962
|
-
url: string;
|
|
963
|
-
label: string;
|
|
964
|
-
};
|
|
965
|
-
url_key: string;
|
|
966
|
-
url_suffix: string;
|
|
967
|
-
categories: {
|
|
968
|
-
url_path: string;
|
|
969
|
-
url_key: string;
|
|
970
|
-
}[];
|
|
971
|
-
price_range: {
|
|
972
|
-
maximum_price: {
|
|
973
|
-
regular_price: {
|
|
974
|
-
value: number;
|
|
975
|
-
currency: string;
|
|
976
|
-
};
|
|
977
|
-
final_price: {
|
|
978
|
-
value: number;
|
|
979
|
-
currency: string;
|
|
980
|
-
};
|
|
981
|
-
discount: {
|
|
982
|
-
amount_off: number;
|
|
983
|
-
percent_off: number;
|
|
984
|
-
};
|
|
985
|
-
};
|
|
986
|
-
};
|
|
987
|
-
};
|
|
988
|
-
__typename: string;
|
|
989
|
-
links: {
|
|
990
|
-
title: string;
|
|
991
|
-
url: string;
|
|
992
|
-
}[];
|
|
993
|
-
uid: string;
|
|
994
|
-
quantity: number;
|
|
995
|
-
errors: null;
|
|
996
|
-
prices: {
|
|
997
|
-
price: {
|
|
998
|
-
value: number;
|
|
999
|
-
currency: string;
|
|
1000
|
-
};
|
|
1001
|
-
total_item_discount: {
|
|
1002
|
-
value: number;
|
|
1003
|
-
currency: string;
|
|
1004
|
-
};
|
|
1005
|
-
row_total: {
|
|
1006
|
-
value: number;
|
|
1007
|
-
currency: string;
|
|
1008
|
-
};
|
|
1009
|
-
price_including_tax: {
|
|
1010
|
-
value: number;
|
|
1011
|
-
currency: string;
|
|
1012
|
-
};
|
|
1013
|
-
row_total_including_tax: {
|
|
1014
|
-
value: number;
|
|
1015
|
-
};
|
|
1016
|
-
original_row_total: {
|
|
1017
|
-
value: number;
|
|
1018
|
-
currency: string;
|
|
1019
|
-
};
|
|
1020
|
-
};
|
|
1021
|
-
};
|
|
1022
|
-
export { bundleOptions, bundleOptionsEmpty, giftCardPhysical, giftCardVirtual, simple, simpleCustomizable, configurable, configurableCustomizable, giftCard, downloadbleWithMultipleLinks, simpleLowInventory, complexInsufficientQuantity, complexInsufficientQuantityGeneralMessage, complexWithProductAttributes, };
|
|
943
|
+
export { bundleOptions, bundleOptionsEmpty, giftCardPhysical, giftCardVirtual, simple, simpleCustomizable, configurable, configurableCustomizable, giftCard, downloadbleWithMultipleLinks, simpleLowInventory, complexInsufficientQuantity, complexInsufficientQuantityGeneralMessage, };
|
|
1023
944
|
//# sourceMappingURL=productTypesData.d.ts.map
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-cart", "version": "0.7.0-
|
|
1
|
+
{"name": "@dropins/storefront-cart", "version": "0.7.0-alpha017", "@dropins/tools": "~0.32.0"}
|