@dropins/storefront-cart 0.3.0 → 0.4.0
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/api.js +5 -5
- package/chunks/CartFragment.js +235 -0
- package/chunks/EmptyCart.js +1 -0
- package/chunks/getEstimateShipping.js +48 -0
- package/chunks/getEstimatedTotals.js +4 -51
- package/chunks/getStoreConfig.js +4 -4
- package/chunks/resetCart.js +1 -230
- package/chunks/updateProductsFromCart.js +4 -4
- package/components/Cart/Cart.d.ts +2 -1
- package/components/EstimateShipping/EstimateShipping.d.ts +20 -0
- package/components/EstimateShipping/index.d.ts +2 -0
- package/components/MiniCart/MiniCart.d.ts +1 -0
- package/components/OrderSummary/OrderSummary.d.ts +37 -0
- package/components/OrderSummary/index.d.ts +3 -0
- package/components/index.d.ts +3 -1
- package/containers/Cart/Cart.d.ts +4 -6
- package/containers/Cart.js +1 -1
- package/containers/EstimateShipping/EstimateShipping.d.ts +7 -0
- package/containers/EstimateShipping/index.d.ts +3 -0
- package/containers/EstimateShipping.d.ts +3 -0
- package/containers/EstimateShipping.js +1 -0
- package/containers/MiniCart.js +1 -1
- package/containers/OrderSummary/OrderSummary.d.ts +16 -0
- package/containers/OrderSummary/index.d.ts +3 -0
- package/containers/OrderSummary.d.ts +3 -0
- package/containers/OrderSummary.js +1 -0
- package/containers/index.d.ts +2 -0
- package/data/models/cart-model.d.ts +9 -1
- package/data/models/index.d.ts +1 -0
- package/data/models/shipping-models.d.ts +16 -0
- package/data/transforms/__fixtures__/productTypesData.d.ts +223 -5
- package/data/transforms/transform-shipping.d.ts +5 -0
- package/i18n/en_US.json.d.ts +57 -2
- package/lib/state.d.ts +1 -0
- package/package.json +1 -1
- package/render.js +2 -2
- package/chunks/MiniCart.js +0 -1
package/chunks/resetCart.js
CHANGED
|
@@ -1,230 +1 @@
|
|
|
1
|
-
import{FetchGraphQL as
|
|
2
|
-
customizable_options {
|
|
3
|
-
type
|
|
4
|
-
customizable_option_uid
|
|
5
|
-
label
|
|
6
|
-
is_required
|
|
7
|
-
values {
|
|
8
|
-
label
|
|
9
|
-
value
|
|
10
|
-
price{
|
|
11
|
-
type
|
|
12
|
-
units
|
|
13
|
-
value
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
`,x=`
|
|
18
|
-
price_range {
|
|
19
|
-
minimum_price {
|
|
20
|
-
regular_price {
|
|
21
|
-
value
|
|
22
|
-
currency
|
|
23
|
-
}
|
|
24
|
-
final_price {
|
|
25
|
-
value
|
|
26
|
-
currency
|
|
27
|
-
}
|
|
28
|
-
discount {
|
|
29
|
-
percent_off
|
|
30
|
-
amount_off
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
maximum_price {
|
|
34
|
-
regular_price {
|
|
35
|
-
value
|
|
36
|
-
currency
|
|
37
|
-
}
|
|
38
|
-
final_price {
|
|
39
|
-
value
|
|
40
|
-
currency
|
|
41
|
-
}
|
|
42
|
-
discount {
|
|
43
|
-
percent_off
|
|
44
|
-
amount_off
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
`,Z=`
|
|
49
|
-
fragment CartFragment on Cart {
|
|
50
|
-
id
|
|
51
|
-
total_quantity
|
|
52
|
-
is_virtual
|
|
53
|
-
prices {
|
|
54
|
-
subtotal_with_discount_excluding_tax {
|
|
55
|
-
currency
|
|
56
|
-
value
|
|
57
|
-
}
|
|
58
|
-
subtotal_including_tax {
|
|
59
|
-
currency
|
|
60
|
-
value
|
|
61
|
-
}
|
|
62
|
-
subtotal_excluding_tax {
|
|
63
|
-
currency
|
|
64
|
-
value
|
|
65
|
-
}
|
|
66
|
-
grand_total {
|
|
67
|
-
currency
|
|
68
|
-
value
|
|
69
|
-
}
|
|
70
|
-
grand_total_excluding_tax {
|
|
71
|
-
currency
|
|
72
|
-
value
|
|
73
|
-
}
|
|
74
|
-
applied_taxes {
|
|
75
|
-
label,
|
|
76
|
-
amount {
|
|
77
|
-
value
|
|
78
|
-
currency
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
discounts {
|
|
82
|
-
amount {
|
|
83
|
-
value
|
|
84
|
-
currency
|
|
85
|
-
}
|
|
86
|
-
label
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
itemsV2 (
|
|
90
|
-
pageSize:$pageSize,
|
|
91
|
-
currentPage:$currentPage,
|
|
92
|
-
sort: $itemsSortInput
|
|
93
|
-
) {
|
|
94
|
-
items {
|
|
95
|
-
__typename
|
|
96
|
-
uid
|
|
97
|
-
quantity
|
|
98
|
-
|
|
99
|
-
errors {
|
|
100
|
-
code
|
|
101
|
-
message
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
prices {
|
|
105
|
-
price {
|
|
106
|
-
value
|
|
107
|
-
currency
|
|
108
|
-
}
|
|
109
|
-
total_item_discount {
|
|
110
|
-
value
|
|
111
|
-
currency
|
|
112
|
-
}
|
|
113
|
-
row_total {
|
|
114
|
-
value
|
|
115
|
-
currency
|
|
116
|
-
}
|
|
117
|
-
row_total_including_tax {
|
|
118
|
-
value
|
|
119
|
-
currency
|
|
120
|
-
}
|
|
121
|
-
price_including_tax {
|
|
122
|
-
value
|
|
123
|
-
currency
|
|
124
|
-
}
|
|
125
|
-
fixed_product_taxes {
|
|
126
|
-
amount {
|
|
127
|
-
value
|
|
128
|
-
currency
|
|
129
|
-
}
|
|
130
|
-
label
|
|
131
|
-
}
|
|
132
|
-
original_row_total{
|
|
133
|
-
value
|
|
134
|
-
currency
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
product {
|
|
139
|
-
name
|
|
140
|
-
sku
|
|
141
|
-
thumbnail {
|
|
142
|
-
url
|
|
143
|
-
label
|
|
144
|
-
}
|
|
145
|
-
url_key
|
|
146
|
-
url_suffix
|
|
147
|
-
categories {
|
|
148
|
-
url_path
|
|
149
|
-
url_key
|
|
150
|
-
}
|
|
151
|
-
${x}
|
|
152
|
-
}
|
|
153
|
-
...on SimpleCartItem {
|
|
154
|
-
${o}
|
|
155
|
-
}
|
|
156
|
-
... on ConfigurableCartItem {
|
|
157
|
-
configurable_options {
|
|
158
|
-
configurable_product_option_uid
|
|
159
|
-
option_label
|
|
160
|
-
value_label
|
|
161
|
-
}
|
|
162
|
-
configured_variant {
|
|
163
|
-
uid
|
|
164
|
-
sku
|
|
165
|
-
thumbnail {
|
|
166
|
-
label
|
|
167
|
-
url
|
|
168
|
-
}
|
|
169
|
-
${x}
|
|
170
|
-
}
|
|
171
|
-
${o}
|
|
172
|
-
}
|
|
173
|
-
... on DownloadableCartItem {
|
|
174
|
-
links {
|
|
175
|
-
sort_order
|
|
176
|
-
title
|
|
177
|
-
}
|
|
178
|
-
${o}
|
|
179
|
-
}
|
|
180
|
-
... on BundleCartItem {
|
|
181
|
-
bundle_options {
|
|
182
|
-
uid
|
|
183
|
-
label
|
|
184
|
-
values {
|
|
185
|
-
uid
|
|
186
|
-
label
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
... on GiftCardCartItem {
|
|
191
|
-
message
|
|
192
|
-
recipient_email
|
|
193
|
-
recipient_name
|
|
194
|
-
sender_email
|
|
195
|
-
sender_name
|
|
196
|
-
amount{
|
|
197
|
-
currency
|
|
198
|
-
value
|
|
199
|
-
}
|
|
200
|
-
is_available
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
shipping_addresses {
|
|
205
|
-
country {
|
|
206
|
-
code
|
|
207
|
-
}
|
|
208
|
-
region {
|
|
209
|
-
code
|
|
210
|
-
}
|
|
211
|
-
postcode
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
`,W=`
|
|
215
|
-
$pageSize: Int! = 100,
|
|
216
|
-
$currentPage: Int! = 1,
|
|
217
|
-
$itemsSortInput: QuoteItemsSortInput! = {field: CREATED_AT, order: DESC}
|
|
218
|
-
`,X=`
|
|
219
|
-
customer {
|
|
220
|
-
addresses {
|
|
221
|
-
default_shipping
|
|
222
|
-
country_id
|
|
223
|
-
postcode
|
|
224
|
-
region {
|
|
225
|
-
region
|
|
226
|
-
region_code
|
|
227
|
-
region_id
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}`,$=()=>(a.cartId=null,a.authenticated=!1,Promise.resolve(null));export{W as C,Z as a,B as b,V as c,U as d,$ as e,H as f,J as g,K as h,q as i,X as j,R as k,Q as l,j as r,a as s,L as t};
|
|
1
|
+
import{FetchGraphQL as i}from"@dropins/tools/fetch-graphql.js";import"@dropins/tools/event-bus.js";function c(t){const r=document.cookie.split(";");for(let s=0;s<r.length;s++){const a=r[s].trim();if(a.indexOf(`${t}=`)===0)return a.substring(t.length+1)}return null}function h(t){t?sessionStorage.setItem("DROPIN__CART__CART__DATA",JSON.stringify(t)):sessionStorage.removeItem("DROPIN__CART__CART__DATA")}function _(){const t=sessionStorage.getItem("DROPIN__CART__CART__DATA");return t?JSON.parse(t):null}function I(t){t?sessionStorage.setItem("DROPIN__CART__SHIPPING__DATA",JSON.stringify(t)):sessionStorage.removeItem("DROPIN__CART__SHIPPING__DATA")}const u=(()=>{const t=_();return{cartId:null,authenticated:t?!t.isGuestCart:!1}})(),n=new Proxy(u,{set(t,r,s){var a;if(t[r]=s,r==="cartId"){if(s===n.cartId)return!0;if(s===null)return document.cookie="DROPIN__CART__CART-ID=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/",!0;const e=(a=n.config)==null?void 0:a.cartExpiresInDays;e||console.warn('Missing "expiresInDays" config. Cookie expiration will default to 30 days.');const o=new Date;o.setDate(o.getDate()+(e??30)),document.cookie=`DROPIN__CART__CART-ID=${s}; expires=${o.toUTCString()}; path=/`}return!0},get(t,r){return r==="cartId"?c("DROPIN__CART__CART-ID"):t[r]}}),{setEndpoint:f,setFetchGraphQlHeader:p,removeFetchGraphQlHeader:A,setFetchGraphQlHeaders:C,fetchGraphQl:D,getConfig:R}=new i().getMethods(),T=t=>{const r=t.findIndex(({extensions:e})=>(e==null?void 0:e.category)==="graphql-authorization")>-1,s=t.findIndex(({extensions:e})=>(e==null?void 0:e.category)==="graphql-no-such-entity")>-1,a=t.map(e=>e.message).join(" ");if(r||s)return l(),console.error(a),null;throw Error(a)},l=()=>(n.cartId=null,n.authenticated=!1,Promise.resolve(null));export{f as a,p as b,C as c,l as d,h as e,D as f,R as g,T as h,_ as i,I as j,A as r,n as s};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{s as g,f as R,h as A}from"./resetCart.js";import{C as I,a as v,t as D}from"./CartFragment.js";import{events as m}from"@dropins/tools/event-bus.js";function _(a){const{cart:r,locale:t="en-US"}=a;return{id:r.id,items:E(r.items,t),prices:{subtotalExcludingTax:r.subtotal.excludingTax,subtotalIncludingTax:r.subtotal.includingTax},totalQuantity:r.totalQuantity,possibleOnepageCheckout:void 0,giftMessageSelected:void 0,giftWrappingSelected:void 0,source:void 0}}function E(a,r){return a.map(t=>{var e;return{canApplyMsrp:!1,formattedPrice:h(r,t.price.currency,t.price.value),id:t.uid,prices:{price:t.price},product:{productId:t.uid,name:t.name,sku:t.sku,topLevelSku:void 0,specialToDate:void 0,specialFromDate:void 0,newToDate:void 0,newFromDate:void 0,createdAt:void 0,updatedAt:void 0,manufacturer:void 0,countryOfManufacture:void 0,categories:t.url.categories,productType:void 0,pricing:{regularPrice:t.regularPrice.value,minimalPrice:void 0,maximalPrice:void 0,specialPrice:(e=t.discount)==null?void 0:e.value,tierPricing:void 0,currencyCode:t.regularPrice.currency},canonicalUrl:t.url.urlKey,mainImageUrl:t.image.src,image:{src:t.image.src,alt:t.image.alt}},configurableOptions:void 0,quantity:t.quantity}})}function h(a,r,t){const e=a.replace("_","-");return new Intl.NumberFormat(e,{style:"currency",currency:r}).format(t)}const c={SHOPPING_CART_CONTEXT:"shoppingCartContext",PRODUCT_CONTEXT:"productContext",CHANGED_PRODUCTS_CONTEXT:"changedProductsContext"},u={OPEN_CART:"open-cart",ADD_TO_CART:"add-to-cart",REMOVE_FROM_CART:"remove-from-cart",SHOPPING_CART_VIEW:"shopping-cart-view"};function l(){return window.adobeDataLayer=window.adobeDataLayer||[],window.adobeDataLayer}function s(a,r){const t=l();t.push({[a]:null}),t.push({[a]:r})}function O(a,r){l().push(e=>{const i=e.getState?e.getState():{};e.push({event:a,eventInfo:{...i,...r}})})}function x(a,r,t){const e=_({cart:a,locale:t});s(c.SHOPPING_CART_CONTEXT,{...e}),O(u.OPEN_CART),E(r,t).forEach(o=>{s(c.PRODUCT_CONTEXT,o.product),p(e,[o],u.ADD_TO_CART)})}function M(a,r){const t=_({cart:a,locale:r});s(c.SHOPPING_CART_CONTEXT,{...t}),O(u.SHOPPING_CART_VIEW)}function p(a,r,t){const e={items:r};s(c.SHOPPING_CART_CONTEXT,{...a}),s(c.CHANGED_PRODUCTS_CONTEXT,{...e}),O(t)}function N(a,r,t){const e=_({cart:a,locale:t}),i=e.items,o=l(),C=o.getState?o.getState():{},{shoppingCartContext:{items:P=[]}={}}=C;r.forEach(f=>{const d=P.find(T=>T.id===f.uid),n=i.find(T=>T.id===f.uid);!n&&!d||(!d&&n?(s(c.PRODUCT_CONTEXT,n.product),p(e,[n],u.ADD_TO_CART)):d&&!n?(s(c.PRODUCT_CONTEXT,d.product),p(e,[d],u.REMOVE_FROM_CART)):n.quantity>d.quantity?(s(c.PRODUCT_CONTEXT,n.product),p(e,[n],u.ADD_TO_CART)):(s(c.PRODUCT_CONTEXT,n.product),p(e,[n],u.REMOVE_FROM_CART)))})}const y=`
|
|
2
2
|
mutation UPDATE_PRODUCTS_FROM_CART_MUTATION(
|
|
3
3
|
$cartId: String!,
|
|
4
4
|
$cartItems: [CartItemUpdateInput!]!,
|
|
5
|
-
${
|
|
5
|
+
${I}
|
|
6
6
|
) {
|
|
7
7
|
updateCartItems(
|
|
8
8
|
input: {
|
|
@@ -16,5 +16,5 @@ import{C as P,a as A,s as f,f as I,h as v,t as D}from"./resetCart.js";import{eve
|
|
|
16
16
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
${
|
|
20
|
-
`,
|
|
19
|
+
${v}
|
|
20
|
+
`,w=async a=>{const r=g.cartId;if(!r)throw Error("Cart ID is not set");return R(y,{variables:{cartId:r,cartItems:a.map(({uid:t,quantity:e})=>({cart_item_uid:t,quantity:e}))}}).then(({errors:t,data:e})=>{var C;const i=[...((C=e==null?void 0:e.addProductsToCart)==null?void 0:C.user_errors)??[],...t??[]];if(i.length>0)return A(i);const o=D(e.updateCartItems.cart);return m.emit("cart/updated",o),m.emit("cart/data",o),o&&N(o,a,g.locale??"en-US"),o})};export{N as a,M as b,x as p,w as u};
|
|
@@ -5,7 +5,8 @@ export interface CartProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
5
5
|
emptyCart: VNode;
|
|
6
6
|
heading?: VNode;
|
|
7
7
|
products?: VNode;
|
|
8
|
-
|
|
8
|
+
orderSummary?: VNode<HTMLAttributes<HTMLElement>>;
|
|
9
|
+
outOfStockMessage?: VNode;
|
|
9
10
|
}
|
|
10
11
|
export declare const Cart: FunctionComponent<CartProps>;
|
|
11
12
|
//# sourceMappingURL=Cart.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FunctionComponent, VNode } from 'preact';
|
|
2
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
3
|
+
|
|
4
|
+
export interface EstimateShippingProps extends Omit<HTMLAttributes<HTMLDivElement>, 'loading'> {
|
|
5
|
+
countryField?: VNode<HTMLAttributes<HTMLInputElement>>;
|
|
6
|
+
destinationText?: string;
|
|
7
|
+
estimateButton?: VNode<HTMLAttributes<HTMLButtonElement>>;
|
|
8
|
+
estimated?: boolean;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
onEstimate?: (formData: any) => void;
|
|
11
|
+
price: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
12
|
+
priceExcludingTax?: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
13
|
+
priceIncludingTax?: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
14
|
+
stateField?: VNode<HTMLAttributes<HTMLInputElement>>;
|
|
15
|
+
taxExcluded?: boolean;
|
|
16
|
+
taxIncluded?: boolean;
|
|
17
|
+
zipField?: VNode<HTMLAttributes<HTMLInputElement>>;
|
|
18
|
+
}
|
|
19
|
+
export declare const EstimateShipping: FunctionComponent<EstimateShippingProps>;
|
|
20
|
+
//# sourceMappingURL=EstimateShipping.d.ts.map
|
|
@@ -8,6 +8,7 @@ export interface MiniCartProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
8
8
|
subtotal?: VNode;
|
|
9
9
|
subtotalExcludingTaxes?: VNode;
|
|
10
10
|
ctas?: VNode;
|
|
11
|
+
outOfStockMessage?: VNode;
|
|
11
12
|
}
|
|
12
13
|
export declare const MiniCart: FunctionComponent<MiniCartProps>;
|
|
13
14
|
//# sourceMappingURL=MiniCart.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { FunctionComponent, VNode } from 'preact';
|
|
2
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
3
|
+
|
|
4
|
+
export interface OrderSummaryProps extends Omit<HTMLAttributes<HTMLDivElement>, 'loading'> {
|
|
5
|
+
variant?: 'primary' | 'secondary';
|
|
6
|
+
heading?: VNode<HTMLAttributes<HTMLDivElement>>;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
subTotal?: {
|
|
9
|
+
price: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
10
|
+
priceExcludingTax?: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
11
|
+
taxIncluded?: boolean;
|
|
12
|
+
taxExcluded?: boolean;
|
|
13
|
+
zeroTaxSubtotal?: boolean;
|
|
14
|
+
};
|
|
15
|
+
shipping?: VNode<HTMLAttributes<HTMLDivElement>>;
|
|
16
|
+
discounts?: {
|
|
17
|
+
label: string;
|
|
18
|
+
price: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
19
|
+
caption?: VNode<HTMLAttributes<HTMLDivElement>>;
|
|
20
|
+
}[];
|
|
21
|
+
taxTotal?: {
|
|
22
|
+
price: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
23
|
+
estimated?: boolean;
|
|
24
|
+
};
|
|
25
|
+
taxesApplied?: {
|
|
26
|
+
label: string;
|
|
27
|
+
price: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
28
|
+
}[];
|
|
29
|
+
total?: {
|
|
30
|
+
price: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
31
|
+
estimated?: boolean;
|
|
32
|
+
priceWithoutTax?: VNode<HTMLAttributes<HTMLSpanElement>>;
|
|
33
|
+
};
|
|
34
|
+
primaryAction?: VNode<HTMLAttributes<HTMLButtonElement>>;
|
|
35
|
+
}
|
|
36
|
+
export declare const OrderSummary: FunctionComponent<OrderSummaryProps>;
|
|
37
|
+
//# sourceMappingURL=OrderSummary.d.ts.map
|
package/components/index.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { HTMLAttributes } from 'preact/compat';
|
|
2
|
-
import { Container } from '@dropins/tools/types/elsie/src/lib';
|
|
2
|
+
import { Container, SlotProps } from '@dropins/tools/types/elsie/src/lib';
|
|
3
3
|
import { CartModel } from '../../data/models';
|
|
4
4
|
|
|
5
|
-
interface CheckoutRouteContext {
|
|
6
|
-
cartId: string;
|
|
7
|
-
}
|
|
8
5
|
export interface CartProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
6
|
routeProduct?: (item: CartModel['items'][0]) => string;
|
|
10
7
|
routeEmptyCartCTA?: () => string;
|
|
11
|
-
|
|
8
|
+
slots?: {
|
|
9
|
+
OrderSummary: SlotProps;
|
|
10
|
+
};
|
|
12
11
|
}
|
|
13
12
|
export declare const Cart: Container<CartProps, CartModel | null>;
|
|
14
|
-
export {};
|
|
15
13
|
//# sourceMappingURL=Cart.d.ts.map
|
package/containers/Cart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useState as m,useEffect as Z,useCallback as Te}from"@dropins/tools/preact-compat.js";import{events as ae}from"@dropins/tools/event-bus.js";import{Divider as Ne,PriceSummary as De,Price as c,Picker as ye,Input as xe,Button as ve,CartList as Ee,CartItem as Le,Image as Ie}from"@dropins/tools/components.js";import{E as Pe}from"../chunks/MiniCart.js";import{classes as R,VComponent as ie}from"@dropins/tools/lib.js";import{jsx as r,jsxs as re,Fragment as ne}from"@dropins/tools/preact-jsx-runtime.js";import{l as Se,s as be,k as Ce}from"../chunks/resetCart.js";import{b as fe,u as we}from"../chunks/updateProductsFromCart.js";import{c as Ue,a as Ge,b as ke,g as Xe}from"../chunks/getEstimatedTotals.js";import{useText as Fe}from"@dropins/tools/i18n.js";import"@dropins/tools/fetch-graphql.js";const Ae=({className:F,children:y,emptyCart:b,heading:_,products:v,priceSummary:h,...t})=>r("div",{...t,className:R(["cart-cart",F]),children:re("div",{className:R(["cart-cart__wrapper"]),children:[_&&re("div",{className:R(["cart-cart__heading",["cart-cart__heading--full-width",!v||!h]]),children:[r(ie,{node:_,className:"cart-cart__heading-text"}),r(Ne,{variant:"primary",className:R(["cart-cart__heading-divider"])})]}),r("div",{className:R(["cart-cart__content",["cart-cart__content--empty",!v],["cart-cart__content--full-width",!h]]),children:v||r(ie,{node:b,className:"cart-cart__empty-cart"})}),v&&h&&r(ie,{node:h,className:R(["cart-cart__price-summary"])})]})}),ze=()=>{const[F,y]=m(!1),[b,_]=m();return{handleEstimateTotals:(h,t)=>{y(!0);const{shippingCountry:D,shippingState:O="",shippingZip:E=""}=h,$={countryCode:D,postcode:E,region:{region:O},shipping_method:{carrier_code:(t==null?void 0:t.carrier_code)||"",method_code:(t==null?void 0:t.method_code)||""}};Ue($).then(l=>{var U,S,G,d,A,L,k,I,N,P,z,C,a,x,u,p,o,i,n,Y;l&&_({estimatedTaxTotal:{amount:(U=l.totalTax)==null?void 0:U.value,currency:(S=l.totalTax)==null?void 0:S.currency},estimatedSubTotal:{excludingTax:{amount:(d=(G=l.subtotal)==null?void 0:G.excludingTax)==null?void 0:d.value,currency:(L=(A=l.subtotal)==null?void 0:A.excludingTax)==null?void 0:L.currency},includingTax:{amount:(I=(k=l.subtotal)==null?void 0:k.includingTax)==null?void 0:I.value,currency:(P=(N=l.subtotal)==null?void 0:N.includingTax)==null?void 0:P.currency},includingDiscountOnly:{amount:(C=(z=l.subtotal)==null?void 0:z.includingDiscountOnly)==null?void 0:C.value,currency:(x=(a=l.subtotal)==null?void 0:a.includingDiscountOnly)==null?void 0:x.currency}},estimatedGrandTotalPrice:{includingTax:{amount:(u=l.total)==null?void 0:u.includingTax.value,currency:(p=l.total)==null?void 0:p.includingTax.currency},excludingTax:{amount:(o=l.total)==null?void 0:o.excludingTax.value,currency:(i=l.total)==null?void 0:i.excludingTax.currency}},estimatedAppliedTaxes:{taxes:(n=l.appliedTaxes)==null?void 0:n.map(s=>{var f,w;return{label:s.label,amount:{value:(f=s.amount)==null?void 0:f.value,currency:(w=s.amount)==null?void 0:w.currency}}})},estimatedItems:{items:(Y=l.items)==null?void 0:Y.map(s=>{var f,w,j,Q,V,q,W,H,J,K;return{uid:s.uid,price:{amount:(f=s.price)==null?void 0:f.value,currency:(w=s.price)==null?void 0:w.currency},taxedPrice:{amount:(j=s.taxedPrice)==null?void 0:j.value,currency:(Q=s.taxedPrice)==null?void 0:Q.currency},rowTotal:{amount:(V=s.rowTotal)==null?void 0:V.value,currency:(q=s.rowTotal)==null?void 0:q.currency},rowTotalIncludingTax:{amount:(W=s.rowTotalIncludingTax)==null?void 0:W.value,currency:(H=s.rowTotalIncludingTax)==null?void 0:H.currency},regularPrice:{amount:(J=s.regularPrice)==null?void 0:J.value,currency:(K=s.regularPrice)==null?void 0:K.currency}}})}})}).finally(()=>{y(!1)})},estimatedTotals:b,loading:F}},Be=()=>{const[F,y]=m(!1),[b,_]=m([]),[v,h]=m("US"),[t,D]=m(""),[O,E]=m(""),[$,l]=m([]),[U,S]=m(!1),[G,d]=m(),[A,L]=m(),[k,I]=m(""),[N,P]=m(!1),z=()=>{h("US"),D(""),E(""),d(null),L(null),I(""),P(!1)},C=async x=>{const{shippingCountry:u,shippingState:p="",shippingZip:o=""}=x,i={countryCode:u,postcode:o,region:{region:p}};return y(!0),Xe(i).then(n=>(n&&(d({amount:n.amount.value,currency:n.amount.currency,priceIncludingtax:{amount:n.price_incl_tax.value,currency:n.price_incl_tax.currency},priceExcludingtax:{amount:n.price_excl_tax.value,currency:n.price_excl_tax.currency}}),L({carrier_code:n.carrier_code,method_code:n.method_code}),h(u),D(p),E(o),I(p||o||u),P(!0)),h(u),D(p),E(o),I(p||o||u),n)).finally(()=>{y(!1)})},a=x=>{x.preventDefault(),D(""),E("");const u=x.target.value;h(u)};return Z(()=>{Ge().then(x=>{let u="US";const p=x.map(o=>(o.isDefaultCountry&&(u=o.id),{text:o.label,value:o.id}));_(p),h(u)})},[]),Z(()=>{S(!0),ke(v).then(x=>{const u=x.map(p=>({text:p.name,value:p.code}));l(u)}).finally(()=>{S(!1)})},[v,S]),{loading:F,regionsLoading:U,estimatedDestinationText:k,countries:b,selectedCountry:v,selectedRegion:t,selectedZip:O,regions:$,estimatedShippingPrice:G,estimatedShippingMethod:A,shippingEstimated:N,handleEstimateShipping:C,handleCountrySelected:a,resetValues:z,setPriceSummaryLoading:y}},Re=({children:F,initialData:y=null,routeProduct:b,routeEmptyCartCTA:_,routeCheckout:v,...h})=>{var s,f,w,j,Q,V,q,W,H,J,K,ce,le,ue,oe;const[t,D]=m(y),[O,E]=m(new Set),{loading:$,countries:l,regions:U,selectedCountry:S,estimatedDestinationText:G,estimatedShippingPrice:d,handleCountrySelected:A,handleEstimateShipping:L,regionsLoading:k,selectedRegion:I,selectedZip:N,shippingEstimated:P,resetValues:z}=Be(),{handleEstimateTotals:C,estimatedTotals:a,loading:x}=ze(),u=(e,g)=>{E(T=>(e?T.add(g):T.delete(g),new Set(T)))},p=(e,g)=>{u(!0,e),we([{uid:e,quantity:g}]).finally(()=>{u(!1,e),G&&o({shippingCountry:S,shippingState:I,shippingZip:N})})},o=Te(e=>{L(e).then(g=>{if(g){const{carrier_code:T,method_code:X}=g;C(e,{carrier_code:T,method_code:X})}else C(e)}).then(()=>{Se(e)})},[L,C]),i=Fe({applyButton:"Cart.PriceSummary.estimatedShippingForm.apply.label",checkout:"Cart.PriceSummary.checkout",countryField:"Cart.PriceSummary.estimatedShippingForm.country.placeholder",discountedPrice:"Cart.CartItem.discountedPrice",download:"Cart.CartItem.download",freeShipping:"Cart.PriceSummary.freeShipping",heading:"Cart.Cart.heading",message:"Cart.CartItem.message",orderSummary:"Cart.PriceSummary.orderSummary",regularPrice:"Cart.CartItem.regularPrice",recipient:"Cart.CartItem.recipient",sender:"Cart.CartItem.sender",stateField:"Cart.PriceSummary.estimatedShippingForm.state.placeholder",taxToBeDetermined:"Cart.PriceSummary.taxToBeDetermined",zipField:"Cart.PriceSummary.estimatedShippingForm.zip.placeholder",file:"Cart.CartItem.file",files:"Cart.CartItem.files"});Z(()=>{const e=ae.on("cart/data",g=>{var X,B;D(g);const T=(B=(X=g==null?void 0:g.addresses)==null?void 0:X.shipping)==null?void 0:B[0];if(T){const{countryCode:M,regionCode:ee,zipCode:te}=T;o({shippingCountry:M,shippingState:ee,shippingZip:te})}},{eager:!0});return()=>{e==null||e.off()}},[]),Z(()=>{const e=ae.on("cart/merged",()=>{P&&o({shippingCountry:S,shippingState:I,shippingZip:N})});return()=>{e==null||e.off()}},[P,S,I,N]),Z(()=>{const e=ae.on("cart/reset",()=>{z(),Se(null)});return()=>{e==null||e.off()}},[]),Z(()=>{y&&Object.keys(y).length>0&&fe(y,be.locale||"en-US")},[y]);const n=(s=be.config)==null?void 0:s.shoppingCartDisplaySetting,Y=(t==null?void 0:t.totalQuantity)??0?r(De,{"data-testid":"price-summary",loading:$||x,heading:i.orderSummary,total:{price:a!=null&&a.estimatedGrandTotalPrice?r(c,{...a==null?void 0:a.estimatedGrandTotalPrice.includingTax}):r(c,{amount:t==null?void 0:t.total.includingTax.value,currency:t==null?void 0:t.total.includingTax.currency}),estimated:!0,priceWithoutTax:n!=null&&n.grandTotal?a!=null&&a.estimatedAppliedTaxes?r(c,{...a==null?void 0:a.estimatedGrandTotalPrice.excludingTax}):r(c,{amount:t==null?void 0:t.total.excludingTax.value,currency:t==null?void 0:t.total.excludingTax.currency}):void 0},subTotal:{taxIncluded:(n==null?void 0:n.subtotal)==="INCLUDING_TAX"&&!(n!=null&&n.zeroTax),taxExcluded:(n==null?void 0:n.subtotal)==="INCLUDING_EXCLUDING_TAX",zeroTaxSubtotal:n==null?void 0:n.zeroTax,priceExcludingTax:(f=a==null?void 0:a.estimatedSubTotal)!=null&&f.excludingTax?r(c,{"data-testid":"subtotal",...(w=a==null?void 0:a.estimatedSubTotal)==null?void 0:w.excludingTax}):r(c,{"data-testid":"subtotal",amount:(j=t==null?void 0:t.subtotal.excludingTax)==null?void 0:j.value,currency:(Q=t==null?void 0:t.subtotal.excludingTax)==null?void 0:Q.currency}),price:!(n!=null&&n.zeroTax)&&(n==null?void 0:n.subtotal)==="INCLUDING_TAX"||!(n!=null&&n.zeroTax)&&(n==null?void 0:n.subtotal)==="INCLUDING_EXCLUDING_TAX"?(V=a==null?void 0:a.estimatedSubTotal)!=null&&V.includingTax?r(c,{"data-testid":"subtotal",...(q=a==null?void 0:a.estimatedSubTotal)==null?void 0:q.includingTax}):r(c,{"data-testid":"subtotal",amount:(W=t==null?void 0:t.subtotal.includingTax)==null?void 0:W.value,currency:(H=t==null?void 0:t.subtotal.includingTax)==null?void 0:H.currency}):r(c,{"data-testid":"subtotal",amount:(J=t==null?void 0:t.subtotal.excludingTax)==null?void 0:J.value,currency:(K=t==null?void 0:t.subtotal.excludingTax)==null?void 0:K.currency})},shipping:t!=null&&t.isVirtual?void 0:{taxIncluded:(n==null?void 0:n.shipping)==="INCLUDING_TAX",taxExcluded:(n==null?void 0:n.shipping)==="INCLUDING_EXCLUDING_TAX",price:(d==null?void 0:d.amount)==0?r("span",{"data-testId":"free-shipping",children:i.freeShipping}):(n==null?void 0:n.shipping)==="INCLUDING_TAX"&&d?r(c,{"data-testid":"shipping",...d.priceIncludingtax}):d?r(c,{...d}):r("span",{children:i.taxToBeDetermined}),estimated:!0,priceExcludingTax:d!=null&&d.priceExcludingtax?r(c,{"data-testid":"shipping-excluding-tax",...d.priceExcludingtax}):r("span",{children:i.taxToBeDetermined}),countryField:r(ye,{name:"shippingCountry",placeholder:i.countryField,value:S,variant:"primary",options:l,handleSelect:A,"data-testid":"estimate-shipping-country-selector"}),stateField:U.length>0?r(ye,{name:"shippingState",placeholder:i.stateField,variant:"primary",options:U,value:I,"data-testid":"estimate-shipping-state-selector",disabled:k}):r(xe,{"aria-label":i.stateField,name:"shippingState",placeholder:i.stateField,variant:"primary",value:I,disabled:k,"data-testid":"estimate-shipping-state-input",maxLength:50}),zipField:r(xe,{"aria-label":i.zipField,name:"shippingZip",placeholder:i.zipField,variant:"primary","data-testid":"estimate-shipping-zip-input",value:N,maxLength:12}),estimateButton:r(ve,{variant:"secondary","data-testid":"estimate-shipping-apply-button","aria-label":i.applyButton,children:i.applyButton}),destinationText:G||i.taxToBeDetermined,onEstimate:o},taxTotal:t!=null&&t.isVirtual?{price:r("span",{"data-testid":"tax-total",children:i.taxToBeDetermined})}:{price:a!=null&&a.estimatedTaxTotal?r(c,{"data-testid":"tax-total",...a==null?void 0:a.estimatedTaxTotal}):t!=null&&t.totalTax?r(c,{"data-testid":"tax-total",amount:(ce=t==null?void 0:t.totalTax)==null?void 0:ce.value,currency:(le=t==null?void 0:t.totalTax)==null?void 0:le.currency}):r("span",{"data-testid":"tax-total",children:i.taxToBeDetermined}),estimated:!0},taxesApplied:t!=null&&t.isVirtual?void 0:n!=null&&n.fullSummary&&(a!=null&&a.estimatedAppliedTaxes)?(oe=(ue=a==null?void 0:a.estimatedAppliedTaxes)==null?void 0:ue.taxes)==null?void 0:oe.map(e=>({label:e.label,price:r(c,{"data-testid":"applied-taxes",amount:e.amount.value,currency:e.amount.currency})})):n!=null&&n.fullSummary?t==null?void 0:t.appliedTaxes.map(e=>({label:e.label,price:r(c,{"data-testid":"applied-taxes",amount:e.amount.value,currency:e.amount.currency})})):void 0,primaryAction:v?r(ve,{"data-testid":"checkout-button",variant:"primary",href:v({cartId:t.id}),children:i.checkout}):void 0,discounts:t==null?void 0:t.appliedDiscounts.map(e=>({label:e.label,price:r(c,{"data-testid":"summary-discount-total",amount:-e.amount.value,currency:e.amount.currency,sale:!0})}))}):void 0;return r(Ae,{...h,heading:r("div",{children:i.heading}),emptyCart:r(Pe,{ctaLinkURL:_==null?void 0:_()}),priceSummary:Y,products:(t==null?void 0:t.totalQuantity)??0?r(Ee,{children:t==null?void 0:t.items.map((e,g)=>{var B,M,ee,te,se,de,pe,ge,me,he;const T=O.has(e.uid),X={...e.bundleOptions??{},...e.selectedOptions??{},...e.customizableOptions,...e.recipient?{[i.recipient]:e.recipient}:{},...e.recipientEmail&&e.recipient?{[i.recipient]:`${e.recipient} (${e.recipientEmail})`}:{},...e.sender?{[i.sender]:e.sender}:{},...e.senderEmail&&e.sender?{[i.sender]:`${e.sender} (${e.senderEmail})`}:{},...e.message?{[i.message]:e.message}:{},...e.links&&e.links.count?e.links.count>1?{[i.files.replace("{count}",e.links.count.toString())]:e.links.result}:{[i.file.replace("{count}",e.links.count.toString())]:e.links.result}:{}};return r(Le,{ariaLabel:e.name,updating:T,"data-testid":"cart-item",taxIncluded:(n==null?void 0:n.price)==="INCLUDING_TAX",taxExcluded:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX",image:b?r("a",{href:b(e),children:r(Ie,{loading:g<4?"eager":"lazy",src:e.image.src,alt:e.image.alt,width:"300",height:"300",params:{width:300}})}):r(Ie,{loading:g<4?"eager":"lazy",src:e.image.src,alt:e.image.alt,width:"300",height:"300",params:{width:300}}),title:r("span",{children:b?r("a",{href:b(e),children:e.name}):r(ne,{children:e.name})}),sku:r("span",{children:e.sku}),configurations:Object.keys(X).length>0?X:void 0,quantity:e.quantity,price:(n==null?void 0:n.price)==="INCLUDING_TAX"?r(c,{amount:e.discounted?(B=e.regularPrice)==null?void 0:B.value:(M=e.taxedPrice)==null?void 0:M.value,currency:e.discounted?(ee=e.regularPrice)==null?void 0:ee.currency:(te=e.taxedPrice)==null?void 0:te.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}):r(c,{amount:(se=e.regularPrice)==null?void 0:se.value,currency:(de=e.regularPrice)==null?void 0:de.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}),total:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX"||(n==null?void 0:n.price)==="INCLUDING_TAX"?r(ne,{children:e.discounted?re(ne,{children:[r(c,{amount:e.total.value,currency:e.total.currency,variant:e.discounted?"strikethrough":"default","data-testid":"including-tax-row-total","aria-label":i.regularPrice}),r(c,{amount:(pe=e.rowTotalIncludingTax)==null?void 0:pe.value,currency:(ge=e.rowTotalIncludingTax)==null?void 0:ge.currency,sale:e.discounted,"data-testid":"discount-total","aria-label":i.discountedPrice})]}):r(c,{amount:e.rowTotalIncludingTax.value,currency:e.rowTotalIncludingTax.currency,"data-testid":"including-tax-row-total","aria-label":i.regularPrice})}):re(ne,{children:[r(c,{amount:e.total.value,currency:e.total.currency,variant:e.discounted?"strikethrough":"default","data-testid":"regular-total","aria-label":i.regularPrice}),e.discounted&&r(c,{amount:(me=e.discountedTotal)==null?void 0:me.value,currency:(he=e.discountedTotal)==null?void 0:he.currency,sale:e.discounted,"data-testid":"discount-total","aria-label":i.discountedPrice})]}),totalExcludingTax:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX"?r(c,{amount:e.rowTotal.value,currency:e.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":i.regularPrice}):void 0,onQuantity:_e=>{p(e.uid,_e)},onRemove:()=>{p(e.uid,0)}},e.uid)})}):void 0})};Re.getInitialData=async function(){return Ce()};export{Re as Cart,Re as default};
|
|
1
|
+
import{jsx as e,jsxs as o,Fragment as d}from"@dropins/tools/preact-jsx-runtime.js";import{useState as j,useEffect as M}from"@dropins/tools/preact-compat.js";import{classes as p,VComponent as D,Slot as K}from"@dropins/tools/lib.js";import{events as Y}from"@dropins/tools/event-bus.js";import{Divider as Z,InLineAlert as m,Icon as X,CartList as R,CartItem as F,Image as Q,Price as c}from"@dropins/tools/components.js";/* empty css */import{S as rr,a as U,E as er}from"../chunks/EmptyCart.js";import{s as H,i as tr}from"../chunks/resetCart.js";import{b as nr,u as ar}from"../chunks/updateProductsFromCart.js";import{useText as cr}from"@dropins/tools/i18n.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/CartFragment.js";const ir=({className:x,children:h,emptyCart:g,heading:l,products:s,orderSummary:y,outOfStockMessage:a,...E})=>e("div",{...E,className:p(["cart-cart",x]),children:o("div",{className:p(["cart-cart__wrapper"]),children:[l&&o("div",{className:p(["cart-cart__heading",["cart-cart__heading--full-width",!s||!y]]),children:[e(D,{node:l,className:"cart-cart__heading-text"}),e(Z,{variant:"primary",className:p(["cart-cart__heading-divider"])}),a&&e(D,{node:a,className:"cart-cart__out-of-stock-message"})]}),e("div",{className:p(["cart-cart__content",["cart-cart__content--empty",!s],["cart-cart__content--full-width",!y]]),children:s||e(D,{node:g,className:"cart-cart__empty-cart"})}),s&&y&&e(D,{node:y,className:p(["cart-cart__order-summary"])})]})}),lr=({children:x,slots:h,initialData:g=null,routeProduct:l,routeEmptyCartCTA:s,...y})=>{var q;const[a,E]=j(g),[T,V]=j(new Set),z=(r,i)=>{V(u=>(i?u.add(r):u.delete(r),new Set(u)))},f=(r,i)=>{z(r,!0),ar([{uid:r,quantity:i}]).catch(u=>{console.warn(u)}).finally(()=>{z(r,!1)})},t=cr({discountedPrice:"Cart.CartItem.discountedPrice",heading:"Cart.Cart.heading",message:"Cart.CartItem.message",orderSummary:"Cart.PriceSummary.orderSummary",regularPrice:"Cart.CartItem.regularPrice",recipient:"Cart.CartItem.recipient",sender:"Cart.CartItem.sender",file:"Cart.CartItem.file",files:"Cart.CartItem.files",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"});M(()=>{const r=Y.on("cart/data",i=>{E(i)},{eager:!0});return()=>{r==null||r.off()}},[]),M(()=>{g&&Object.keys(g).length>0&&nr(g,H.locale??"en-US")},[g]);const n=(q=H.config)==null?void 0:q.shoppingCartDisplaySetting,W=h!=null&&h.OrderSummary?e(K,{name:"OrderSummary",slot:h.OrderSummary}):void 0,$=a!=null&&a.totalQuantity?a.totalQuantity.toString():"",B=()=>{const r=a==null?void 0:a.items.filter(i=>i.outOfStock);r==null||r.forEach(i=>{f(i.uid,0)})},J=e(m,{"data-testid":"out-of-stock-message",icon:e(X,{source:rr,size:"16"}),itemList:(a==null?void 0:a.totalQuantity)??0?e(R,{children:a==null?void 0:a.items.filter(r=>r.outOfStock||r.insufficientQuantity).map((r,i)=>{var v,k,S,w,N,O,L,_,C,b,P,G;const u=T.has(r.uid),I={...r.bundleOptions??{},...r.selectedOptions??{},...r.customizableOptions,...r.recipient?{[t.recipient]:r.recipient}:{},...r.recipientEmail&&r.recipient?{[t.recipient]:`${r.recipient} (${r.recipientEmail})`}:{},...r.sender?{[t.sender]:r.sender}:{},...r.senderEmail&&r.sender?{[t.sender]:`${r.sender} (${r.senderEmail})`}:{},...r.message?{[t.message]:r.message}:{},...r.links&&r.links.count?r.links.count>1?{[t.files.replace("{count}",r.links.count.toString())]:r.links.result}:{[t.file.replace("{count}",r.links.count.toString())]:r.links.result}:{}};return e(F,{"data-testid":"cart-item",ariaLabel:r.name,updating:u,taxIncluded:(n==null?void 0:n.price)==="INCLUDING_TAX",taxExcluded:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX",warning:!r.outOfStock&&(r.insufficientQuantity||r.lowInventory)?o("span",{"data-testid":"inline-warning",children:[e(X,{source:U,size:"16"}),r.insufficientQuantity&&r.stockLevel&&(r.stockLevel==="noNumber"?t.insufficientQuantityGeneral:t.insufficientQuantity.replace("{inventory}",(v=r.stockLevel)==null?void 0:v.toString()).replace("{count}",r.quantity.toString()))||r.lowInventory&&r.onlyXLeftInStock&&t.lowInventory.replace("{count}",(k=r.onlyXLeftInStock)==null?void 0:k.toString())]}):void 0,alert:r.outOfStock?o("span",{children:[e(X,{source:U,size:"16"}),t.outOfStockAlert]}):void 0,image:l?e("a",{href:l(r),children:e(Q,{loading:i<4?"eager":"lazy",src:r.image.src,alt:r.image.alt,width:"300",height:"300",params:{width:300}})}):e(Q,{loading:i<4?"eager":"lazy",src:r.image.src,alt:r.image.alt,width:"300",height:"300",params:{width:300}}),title:e("span",{children:l?e("a",{href:l(r),children:r.name}):e(d,{children:r.name})}),sku:e("span",{children:r.sku}),configurations:Object.keys(I).length>0?I:void 0,quantity:r.quantity,price:(n==null?void 0:n.price)==="INCLUDING_TAX"?e(c,{amount:r.discounted?(S=r.regularPrice)==null?void 0:S.value:(w=r.taxedPrice)==null?void 0:w.value,currency:r.discounted?(N=r.regularPrice)==null?void 0:N.currency:(O=r.taxedPrice)==null?void 0:O.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}):e(c,{amount:(L=r.regularPrice)==null?void 0:L.value,currency:(_=r.regularPrice)==null?void 0:_.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}),total:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX"||(n==null?void 0:n.price)==="INCLUDING_TAX"?e(d,{children:r.discounted?o(d,{children:[e(c,{amount:r.total.value,currency:r.total.currency,variant:r.discounted?"strikethrough":"default","data-testid":"including-tax-row-total","aria-label":t.regularPrice}),e(c,{amount:(C=r.rowTotalIncludingTax)==null?void 0:C.value,currency:(b=r.rowTotalIncludingTax)==null?void 0:b.currency,sale:r.discounted,"data-testid":"discount-total","aria-label":t.discountedPrice})]}):e(c,{amount:r.rowTotalIncludingTax.value,currency:r.rowTotalIncludingTax.currency,"data-testid":"including-tax-row-total","aria-label":t.regularPrice})}):o(d,{children:[e(c,{amount:r.total.value,currency:r.total.currency,variant:r.discounted?"strikethrough":"default","data-testid":"regular-total","aria-label":t.regularPrice}),r.discounted&&e(c,{amount:(P=r.discountedTotal)==null?void 0:P.value,currency:(G=r.discountedTotal)==null?void 0:G.currency,sale:r.discounted,"data-testid":"discount-total","aria-label":t.discountedPrice})]}),totalExcludingTax:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX"?e(c,{amount:r.rowTotal.value,currency:r.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":t.regularPrice}):void 0,onQuantity:A=>{f(r.uid,A)},onRemove:()=>{f(r.uid,0)}},r.uid)})}):void 0,type:"warning",heading:t.outOfStockHeading,description:t.outOfStockDescription,variant:"primary",actionButtonPosition:"bottom",additionalActions:a!=null&&a.hasFullyOutOfStockItems?[{label:t.removeAction,onClick:B}]:void 0});return e(ir,{...y,heading:e("div",{children:t.heading.replace("({count})",$?`(${$})`:"")}),emptyCart:e(er,{ctaLinkURL:s==null?void 0:s()}),orderSummary:W,outOfStockMessage:a!=null&&a.hasOutOfStockItems?J:void 0,products:(a==null?void 0:a.totalQuantity)??0?e(R,{children:a==null?void 0:a.items.filter(r=>!r.outOfStock&&!r.insufficientQuantity).map((r,i)=>{var v,k,S,w,N,O,L,_,C,b,P,G;const u=T.has(r.uid),I={...r.bundleOptions??{},...r.selectedOptions??{},...r.customizableOptions,...r.recipient?{[t.recipient]:r.recipient}:{},...r.recipientEmail&&r.recipient?{[t.recipient]:`${r.recipient} (${r.recipientEmail})`}:{},...r.sender?{[t.sender]:r.sender}:{},...r.senderEmail&&r.sender?{[t.sender]:`${r.sender} (${r.senderEmail})`}:{},...r.message?{[t.message]:r.message}:{},...r.links&&r.links.count?r.links.count>1?{[t.files.replace("{count}",r.links.count.toString())]:r.links.result}:{[t.file.replace("{count}",r.links.count.toString())]:r.links.result}:{}};return e(F,{ariaLabel:r.name,updating:u,"data-testid":"cart-item",taxIncluded:(n==null?void 0:n.price)==="INCLUDING_TAX",taxExcluded:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX",warning:!r.outOfStock&&(r.insufficientQuantity||r.lowInventory)?o("span",{children:[e(X,{source:U,size:"16"}),r.insufficientQuantity&&r.stockLevel&&(r.stockLevel==="noNumber"?t.insufficientQuantityGeneral:t.insufficientQuantity.replace("{inventory}",(v=r.stockLevel)==null?void 0:v.toString()).replace("{count}",r.quantity.toString()))||r.lowInventory&&r.onlyXLeftInStock&&t.lowInventory.replace("{count}",(k=r.onlyXLeftInStock)==null?void 0:k.toString())]}):void 0,alert:r.outOfStock?o("span",{children:[e(X,{source:U,size:"16"}),t.outOfStockAlert]}):void 0,image:l?e("a",{href:l(r),children:e(Q,{loading:i<4?"eager":"lazy",src:r.image.src,alt:r.image.alt,width:"300",height:"300",params:{width:300}})}):e(Q,{loading:i<4?"eager":"lazy",src:r.image.src,alt:r.image.alt,width:"300",height:"300",params:{width:300}}),title:e("span",{children:l?e("a",{href:l(r),children:r.name}):e(d,{children:r.name})}),sku:e("span",{children:r.sku}),configurations:Object.keys(I).length>0?I:void 0,quantity:r.quantity,price:(n==null?void 0:n.price)==="INCLUDING_TAX"?e(c,{amount:r.discounted?(S=r.regularPrice)==null?void 0:S.value:(w=r.taxedPrice)==null?void 0:w.value,currency:r.discounted?(N=r.regularPrice)==null?void 0:N.currency:(O=r.taxedPrice)==null?void 0:O.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}):e(c,{amount:(L=r.regularPrice)==null?void 0:L.value,currency:(_=r.regularPrice)==null?void 0:_.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}),total:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX"||(n==null?void 0:n.price)==="INCLUDING_TAX"?e(d,{children:r.discounted?o(d,{children:[e(c,{amount:r.total.value,currency:r.total.currency,variant:r.discounted?"strikethrough":"default","data-testid":"including-tax-row-total","aria-label":t.regularPrice}),e(c,{amount:(C=r.rowTotalIncludingTax)==null?void 0:C.value,currency:(b=r.rowTotalIncludingTax)==null?void 0:b.currency,sale:r.discounted,"data-testid":"discount-total","aria-label":t.discountedPrice})]}):e(c,{amount:r.rowTotalIncludingTax.value,currency:r.rowTotalIncludingTax.currency,"data-testid":"including-tax-row-total","aria-label":t.regularPrice})}):o(d,{children:[e(c,{amount:r.total.value,currency:r.total.currency,variant:r.discounted?"strikethrough":"default","data-testid":"regular-total","aria-label":t.regularPrice}),r.discounted&&e(c,{amount:(P=r.discountedTotal)==null?void 0:P.value,currency:(G=r.discountedTotal)==null?void 0:G.currency,sale:r.discounted,"data-testid":"discount-total","aria-label":t.discountedPrice})]}),totalExcludingTax:(n==null?void 0:n.price)==="INCLUDING_EXCLUDING_TAX"?e(c,{amount:r.rowTotal.value,currency:r.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":t.regularPrice}):void 0,onQuantity:A=>{f(r.uid,A)},onRemove:()=>{f(r.uid,0)}},r.uid)})}):void 0})};lr.getInitialData=async function(){return tr()};export{lr as Cart,lr as default};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Container } from '@dropins/tools/types/elsie/src/lib';
|
|
2
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
3
|
+
|
|
4
|
+
export interface EstimateShippingProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
}
|
|
6
|
+
export declare const EstimateShipping: Container<EstimateShippingProps>;
|
|
7
|
+
//# sourceMappingURL=EstimateShipping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsxs as I,jsx as e,Fragment as V}from"@dropins/tools/preact-jsx-runtime.js";import{classes as x,VComponent as Z,getFormValues as K}from"@dropins/tools/lib.js";import{Price as U,Picker as w,Input as G,Button as $}from"@dropins/tools/components.js";/* empty css */import{useState as p,useEffect as T,useRef as q,useCallback as H}from"@dropins/tools/preact-compat.js";import{useText as j,Text as F}from"@dropins/tools/i18n.js";import{j as X,s as J}from"../chunks/resetCart.js";import{events as B}from"@dropins/tools/event-bus.js";import{a as O,b as Q,g as W}from"../chunks/getEstimateShipping.js";import"@dropins/tools/fetch-graphql.js";const Y=()=>{const[b,E]=p(!1),[L,N]=p([]),[_,a]=p("US"),[A,i]=p(""),[P,c]=p(""),[v,m]=p([]),[h,C]=p(!1),[k,l]=p(),[n,r]=p(),[z,t]=p(""),[u,D]=p(!1),o=()=>{a("US"),i(""),c(""),l(null),r(null),t(""),D(!1)},y=async d=>{const{shippingCountry:s,shippingState:g="",shippingZip:S=""}=d,M={countryCode:s,postcode:S,region:{region:g}};return E(!0),W(M).then(f=>(f&&(l({amount:f.amount.value,currency:f.amount.currency,priceIncludingtax:{amount:f.price_incl_tax.value,currency:f.price_incl_tax.currency},priceExcludingtax:{amount:f.price_excl_tax.value,currency:f.price_excl_tax.currency}}),r({carrier_code:f.carrier_code,method_code:f.method_code}),a(s),i(g),c(S),t(g||S||s),D(!0)),a(s),i(g),c(S),t(g||S||s),f)).finally(()=>{E(!1)})},R=d=>{d.preventDefault(),i(""),c("");const s=d.target.value;a(s)};return T(()=>{O().then(d=>{let s="US";const g=d.map(S=>(S.isDefaultCountry&&(s=S.id),{text:S.label,value:S.id}));N(g),a(s)})},[]),T(()=>{C(!0),Q(_).then(d=>{const s=d.map(g=>({text:g.name,value:g.code}));m(s)}).finally(()=>{C(!1)})},[_,C]),{loading:b,regionsLoading:h,estimatedDestinationText:z,countries:L,selectedCountry:_,selectedRegion:A,selectedZip:P,regions:v,estimatedShippingPrice:k,estimatedShippingMethod:n,shippingEstimated:u,handleEstimateShipping:y,handleCountrySelected:R,resetValues:o,setPriceSummaryLoading:E}},ee=({countryField:b,destinationText:E,estimateButton:L,estimated:N,loading:_,onEstimate:a,price:A,priceExcludingTax:i,priceIncludingTax:P,stateField:c,taxExcluded:v,taxIncluded:m,zipField:h})=>{const C=q(null),[k,l]=p(!0),[n,r]=p("zip"),z=j({editZipAction:"Cart.EstimateShipping.editZipAction",destinationLinkAriaLabel:"Cart.EstimateShipping.destinationLinkAriaLabel",shippingLabel:"Cart.EstimateShipping.label",zipPlaceholder:"Cart.EstimateShipping.zipPlaceholder"}),t=o=>{o.preventDefault(),l(y=>!y)},u=o=>{o.preventDefault(),l(!0),r(y=>y==="zip"?"state":"zip")},D=o=>{o.preventDefault(),l(!1);const y=K(C.current);a==null||a(y)};return I("div",{"data-testid":"estimate-shipping",className:x(["cart-estimate-shipping",["cart-estimate-shipping--loading",_]]),children:[e("span",{className:"cart-estimate-shipping__label",children:N?E?I(V,{children:[e(F,{id:"Cart.EstimateShipping.estimatedDestination"}),e("a",{className:"cart-estimate-shippingLink",role:"button",href:"",onClick:t,onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&t(o)},tabIndex:0,"aria-label":z.destinationLinkAriaLabel,"data-testid":"shipping-destination-link",children:E})]}):e(F,{id:"Cart.EstimateShipping.estimated"}):e(F,{id:"Cart.EstimateShipping.label"})}),e(Z,{node:A,className:"cart-estimate-shipping__price"}),N&&I(V,{children:[e("div",{className:x(["cart-estimate-shipping__caption"]),children:e("a",{href:"#",className:"cart-estimate-shipping__link",onClick:u,"data-testid":"shipping-alternate-field-link",children:n==="zip"?e(F,{id:"Cart.EstimateShipping.alternateField.state"}):e(F,{id:"Cart.EstimateShipping.alternateField.zip"})})}),I("form",{className:x(["cart-estimate-shipping--edit",["cart-estimate-shipping--hide",!k]]),ref:C,"data-testid":"shipping-estimate-form",children:[b&&e(Z,{node:b,className:x(["cart-estimate-shipping--country"])}),n==="state"?c&&e(Z,{node:c,className:x(["cart-estimate-shipping--state"])}):h&&e(Z,{node:h,className:x(["cart-estimate-shipping--zip"])}),L&&e(Z,{node:L,className:x(["cart-estimate-shipping--action"]),onClick:D,type:"submit"})]})]}),m&&e("div",{"data-testid":"shipping-tax-included",className:x(["cart-estimate-shipping__caption"]),children:I("span",{children:[P," ",e(F,{id:"Cart.EstimateShipping.withTaxes"})]})}),v?e("div",{"data-testid":"shipping-tax-included-excluded",className:x(["cart-estimate-shipping__caption"]),children:I("span",{children:[i," ",e(F,{id:"Cart.EstimateShipping.withoutTaxes"})]})}):void 0]})},de=()=>{var z;const[b,E]=p(!1),{loading:L,countries:N,regions:_,selectedCountry:a,estimatedDestinationText:A,estimatedShippingPrice:i,handleCountrySelected:P,handleEstimateShipping:c,regionsLoading:v,selectedRegion:m,selectedZip:h,shippingEstimated:C,resetValues:k}=Y(),l=H(t=>{c(t).then(()=>{X(t)})},[c]);T(()=>{const t=B.on("cart/data",u=>{var d,s;E((u==null?void 0:u.isVirtual)||!1);const D=(s=(d=u==null?void 0:u.addresses)==null?void 0:d.shipping)==null?void 0:s[0];if(!D)return;const{countryCode:o,regionCode:y,zipCode:R}=D;l({shippingCountry:o,shippingState:y,shippingZip:R})},{eager:!0});return()=>{t==null||t.off()}},[]),T(()=>{const t=B.on("cart/updated",()=>{c({shippingCountry:a,shippingState:m,shippingZip:h})});return()=>{t==null||t.off()}},[a,m,h]),T(()=>{const t=B.on("cart/reset",()=>{k(),X(null)});return()=>{t==null||t.off()}},[k]),T(()=>{const t=B.on("cart/merged",()=>{C&&l({shippingCountry:a,shippingState:m,shippingZip:h})});return()=>{t==null||t.off()}},[C,a,m,h,l]);const n=j({applyButton:"Cart.PriceSummary.estimatedShippingForm.apply.label",countryField:"Cart.PriceSummary.estimatedShippingForm.country.placeholder",freeShipping:"Cart.PriceSummary.freeShipping",stateField:"Cart.PriceSummary.estimatedShippingForm.state.placeholder",taxToBeDetermined:"Cart.PriceSummary.taxToBeDetermined",zipField:"Cart.PriceSummary.estimatedShippingForm.zip.placeholder"});if(b)return null;const r=(z=J.config)==null?void 0:z.shoppingCartDisplaySetting;return e(ee,{loading:L,taxIncluded:(r==null?void 0:r.shipping)==="INCLUDING_TAX",taxExcluded:(r==null?void 0:r.shipping)==="INCLUDING_EXCLUDING_TAX",price:(i==null?void 0:i.amount)==0?e("span",{"data-testId":"free-shipping",children:n.freeShipping}):(r==null?void 0:r.shipping)==="INCLUDING_TAX"&&i?e(U,{"data-testid":"shipping",...i.priceIncludingtax}):i?e(U,{...i}):e("span",{children:n.taxToBeDetermined}),estimated:!0,priceExcludingTax:i!=null&&i.priceExcludingtax?e(U,{"data-testid":"shipping-excluding-tax",...i.priceExcludingtax}):e("span",{children:n.taxToBeDetermined}),countryField:e(w,{name:"shippingCountry",placeholder:n.countryField,value:a,variant:"primary",options:N,handleSelect:P,"data-testid":"estimate-shipping-country-selector"}),stateField:_.length>0?e(w,{name:"shippingState",placeholder:n.stateField,variant:"primary",options:_,value:m,"data-testid":"estimate-shipping-state-selector",disabled:v}):e(G,{"aria-label":n.stateField,name:"shippingState",placeholder:n.stateField,variant:"primary",value:m,disabled:v,"data-testid":"estimate-shipping-state-input",maxLength:50}),zipField:e(G,{"aria-label":n.zipField,name:"shippingZip",placeholder:n.zipField,variant:"primary","data-testid":"estimate-shipping-zip-input",value:h,maxLength:12}),estimateButton:e($,{variant:"secondary","data-testid":"estimate-shipping-apply-button","aria-label":n.applyButton,children:n.applyButton}),destinationText:A||n.taxToBeDetermined,onEstimate:l})};export{de as EstimateShipping,de as default};
|
package/containers/MiniCart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useState as T,useEffect as S}from"@dropins/tools/preact-compat.js";import{s as M,k as q}from"../chunks/resetCart.js";import{events as F}from"@dropins/tools/event-bus.js";import{E as R}from"../chunks/MiniCart.js";import{classes as A,VComponent as p}from"@dropins/tools/lib.js";import{Divider as V,Price as i,Button as O,CartList as B,CartItem as H,Image as $}from"@dropins/tools/components.js";import{jsxs as l,jsx as e,Fragment as _}from"@dropins/tools/preact-jsx-runtime.js";import{useText as j}from"@dropins/tools/i18n.js";import{b as J,u as K}from"../chunks/updateProductsFromCart.js";import"@dropins/tools/fetch-graphql.js";const W=({className:N,children:s,emptyCart:u,heading:g,products:o,subtotal:d,subtotalExcludingTaxes:y,ctas:t,...m})=>{const I=j({subtotal:"Cart.MiniCart.subtotal",subtotalExcludingTaxes:"Cart.MiniCart.subtotalExcludingTaxes"});return l("div",{...m,className:A(["cart-mini-cart",N]),children:[o&&g&&l("div",{className:"cart-mini-cart__heading",children:[e(p,{node:g,className:"cart-mini-cart__heading-text"}),e(V,{variant:"primary",className:"cart-mini-cart__heading-divider"})]}),o?l(_,{children:[e("div",{className:"cart-mini-cart__products",children:o}),l("div",{className:"cart-mini-cart__footer",children:[d&&l("div",{className:"cart-mini-cart__footer__estimated-total",children:[I.subtotal,e(p,{node:d})]}),y&&l("div",{className:"cart-mini-cart__footer__estimated-total-excluding-taxes",children:[I.subtotalExcludingTaxes,e(p,{node:y,className:A(["dropin-price-summary__price","dropin-price-summary__price--muted"])})]}),t&&e(p,{node:t,className:"cart-mini-cart__footer__ctas"})]})]}):e(p,{node:u,className:"cart-mini-cart__empty-cart"})]})},Y=({children:N,initialData:s=null,routeProduct:u,routeCart:g,routeCheckout:o,routeEmptyCartCTA:d,...y})=>{var v,x;const[t,m]=T(s),[I,z]=T(new Set),a=(v=M.config)==null?void 0:v.shoppingCartDisplaySetting,b=(r,c)=>{z(h=>(r?h.add(c):h.delete(c),new Set(h)))};S(()=>{const r=F.on("cart/data",c=>{m(c)},{eager:!0});return()=>{r==null||r.off()}},[]);const n=j({cartLink:"Cart.MiniCart.cartLink",checkoutLink:"Cart.MiniCart.checkoutLink",discountedPrice:"Cart.CartItem.discountedPrice",heading:"Cart.MiniCart.heading",message:"Cart.CartItem.message",recipient:"Cart.CartItem.recipient",regularPrice:"Cart.CartItem.regularPrice",sender:"Cart.CartItem.sender",file:"Cart.CartItem.file",files:"Cart.CartItem.files"}),Q=(r,c)=>{b(!0,r),K([{uid:r,quantity:c}]).finally(()=>{b(!1,r)})};return S(()=>{s&&Object.keys(s).length>0&&J(s,M.locale||"en-US")},[s]),e(W,{...y,heading:e("div",{children:n.heading.replace("{count}",((t==null?void 0:t.totalQuantity)??0).toString())}),emptyCart:e(R,{ctaLinkURL:d==null?void 0:d()}),subtotal:(t==null?void 0:t.subtotal)&&((a==null?void 0:a.subtotal)==="INCLUDING_TAX"||(a==null?void 0:a.subtotal)==="INCLUDING_EXCLUDING_TAX"?e(i,{amount:t==null?void 0:t.subtotal.includingTax.value,currency:t==null?void 0:t.subtotal.includingTax.currency,"data-testid":"subtotal-including-tax",style:{font:"inherit"}}):e(i,{amount:t==null?void 0:t.subtotal.excludingTax.value,currency:t==null?void 0:t.subtotal.excludingTax.currency,"data-testid":"subtotal-excluding-tax",style:{font:"inherit"}})),subtotalExcludingTaxes:(t==null?void 0:t.subtotal)&&((a==null?void 0:a.subtotal)==="INCLUDING_EXCLUDING_TAX"?e(i,{amount:t==null?void 0:t.subtotal.excludingTax.value,currency:t==null?void 0:t.subtotal.excludingTax.currency,"data-testid":"subtotal-including-excluding-tax",style:{font:"inherit"}}):void 0),ctas:l("div",{children:[o&&e(O,{variant:"primary",href:o(),children:n.checkoutLink}),g&&e(O,{variant:"tertiary",href:g(),children:n.cartLink})]}),products:(t==null?void 0:t.totalQuantity)??0?e(B,{children:(x=t==null?void 0:t.miniCartMaxItems)==null?void 0:x.map((r,c)=>{var f,k,C,U,P,w,D,E,G,X;const h=I.has(r.uid),L={...r.bundleOptions??{},...r.selectedOptions??{},...r.customizableOptions,...r.recipient?{[n.recipient]:r.recipient}:{},...r.recipientEmail&&r.recipient?{[n.recipient]:`${r.recipient} (${r.recipientEmail})`}:{},...r.sender?{[n.sender]:r.sender}:{},...r.senderEmail&&r.sender?{[n.sender]:`${r.sender} (${r.senderEmail})`}:{},...r.message?{[n.message]:r.message}:{},...r.links&&r.links.count?r.links.count>1?{[n.files.replace("{count}",r.links.count.toString())]:r.links.result}:{[n.file.replace("{count}",r.links.count.toString())]:r.links.result}:{}};return e(H,{"data-testid":"cart-item",updating:h,taxIncluded:(a==null?void 0:a.price)==="INCLUDING_TAX",taxExcluded:(a==null?void 0:a.price)==="INCLUDING_EXCLUDING_TAX",image:u?e("a",{href:u(r),children:e($,{loading:c<4?"eager":"lazy",src:r.image.src,alt:r.image.alt,width:"300",height:"300",params:{width:300}})}):e($,{loading:c<4?"eager":"lazy",src:r.image.src,alt:r.image.alt,width:"300",height:"300",params:{width:300}}),title:e("span",{children:u?e("a",{href:u(r),children:r.name}):r.name}),sku:e("span",{children:r.sku}),configurations:Object.keys(L).length>0?L:void 0,quantity:r.quantity,price:(a==null?void 0:a.price)==="INCLUDING_TAX"?e(i,{amount:r.discounted?(f=r.regularPrice)==null?void 0:f.value:(k=r.taxedPrice)==null?void 0:k.value,currency:r.discounted?(C=r.regularPrice)==null?void 0:C.currency:(U=r.taxedPrice)==null?void 0:U.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}):e(i,{amount:(P=r.regularPrice)==null?void 0:P.value,currency:(w=r.regularPrice)==null?void 0:w.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}),total:(a==null?void 0:a.price)==="INCLUDING_EXCLUDING_TAX"||(a==null?void 0:a.price)==="INCLUDING_TAX"?e(_,{children:r.discounted?l(_,{children:[e(i,{amount:r.total.value,currency:r.total.currency,variant:"strikethrough","data-testid":"including-tax-row-total","aria-label":n.regularPrice}),e(i,{amount:(D=r.rowTotalIncludingTax)==null?void 0:D.value,currency:(E=r.rowTotalIncludingTax)==null?void 0:E.currency,sale:r.discounted,"data-testid":"discount-total","aria-label":n.discountedPrice})]}):e(i,{amount:r.rowTotalIncludingTax.value,currency:r.rowTotalIncludingTax.currency,"data-testid":"including-tax-row-total","aria-label":n.regularPrice})}):l(_,{children:[e(i,{amount:r.total.value,currency:r.total.currency,variant:r.discounted?"strikethrough":"default","data-testid":"regular-total","aria-label":n.regularPrice}),r.discounted&&e(i,{amount:(G=r.discountedTotal)==null?void 0:G.value,currency:(X=r.discountedTotal)==null?void 0:X.currency,sale:r.discounted,"data-testid":"discount-total","aria-label":n.discountedPrice})]}),totalExcludingTax:(a==null?void 0:a.price)==="INCLUDING_EXCLUDING_TAX"?e(i,{amount:r.rowTotal.value,currency:r.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":n.regularPrice}):void 0,onRemove:()=>{Q(r.uid,0)}},r.uid)})}):void 0})};Y.getInitialData=async function(){return q()};export{Y as MiniCart,Y as default};
|
|
1
|
+
import{jsxs as l,jsx as e,Fragment as u}from"@dropins/tools/preact-jsx-runtime.js";import{useState as m,useEffect as q}from"@dropins/tools/preact-compat.js";import{s as j,i as K}from"../chunks/resetCart.js";import{events as Y}from"@dropins/tools/event-bus.js";import{classes as R,VComponent as p}from"@dropins/tools/lib.js";import{Divider as Z,InLineAlert as tt,Icon as G,CartList as F,CartItem as B,Image as P,Price as c,Button as H}from"@dropins/tools/components.js";/* empty css */import{S as nt,a as A,E as et}from"../chunks/EmptyCart.js";import{useText as V}from"@dropins/tools/i18n.js";import{b as rt,u as at}from"../chunks/updateProductsFromCart.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/CartFragment.js";const ct=({className:T,children:d,emptyCart:o,heading:h,products:g,subtotal:y,subtotalExcludingTaxes:X,ctas:n,outOfStockMessage:D,...U})=>{const E=V({subtotal:"Cart.MiniCart.subtotal",subtotalExcludingTaxes:"Cart.MiniCart.subtotalExcludingTaxes"});return l("div",{...U,className:R(["cart-mini-cart",T]),children:[g&&h&&l("div",{className:"cart-mini-cart__heading",children:[e(p,{node:h,className:"cart-mini-cart__heading-text"}),e(Z,{variant:"primary",className:"cart-mini-cart__heading-divider"}),D&&e(p,{node:D,className:"cart-mini-cart__outOfStockMessage"})]}),g?l(u,{children:[e("div",{className:"cart-mini-cart__products",children:g}),l("div",{className:"cart-mini-cart__footer",children:[y&&l("div",{className:"cart-mini-cart__footer__estimated-total",children:[E.subtotal,e(p,{node:y})]}),X&&l("div",{className:"cart-mini-cart__footer__estimated-total-excluding-taxes",children:[E.subtotalExcludingTaxes,e(p,{node:X,className:R(["dropin-price-summary__price","dropin-price-summary__price--muted"])})]}),n&&e(p,{node:n,className:"cart-mini-cart__footer__ctas"})]})]}):e(p,{node:o,className:"cart-mini-cart__empty-cart"})]})},it=({children:T,initialData:d=null,routeProduct:o,routeCart:h,routeCheckout:g,routeEmptyCartCTA:y,...X})=>{var z,$;const[n,D]=m(d),[U,E]=m(new Set),r=(z=j.config)==null?void 0:z.shoppingCartDisplaySetting,M=(t,i)=>{E(s=>(t?s.add(i):s.delete(i),new Set(s)))};q(()=>{const t=Y.on("cart/data",i=>{D(i)},{eager:!0});return()=>{t==null||t.off()}},[]);const a=V({cartLink:"Cart.MiniCart.cartLink",checkoutLink:"Cart.MiniCart.checkoutLink",discountedPrice:"Cart.CartItem.discountedPrice",heading:"Cart.MiniCart.heading",message:"Cart.CartItem.message",recipient:"Cart.CartItem.recipient",regularPrice:"Cart.CartItem.regularPrice",sender:"Cart.CartItem.sender",file:"Cart.CartItem.file",files:"Cart.CartItem.files",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"}),Q=(t,i)=>{M(!0,t),at([{uid:t,quantity:i}]).finally(()=>{M(!1,t)})};q(()=>{d&&Object.keys(d).length>0&&rt(d,j.locale||"en-US")},[d]);const W=()=>{const t=n==null?void 0:n.items.filter(i=>i.outOfStock);t==null||t.forEach(i=>{Q(i.uid,0)})},J=e(tt,{"data-testid":"out-of-stock-message",icon:e(G,{source:nt,size:"16"}),itemList:(n==null?void 0:n.totalQuantity)??0?e(F,{children:n==null?void 0:n.items.filter(t=>t.outOfStock||t.insufficientQuantity).map((t,i)=>{var f,v,k,_,N,L,b,S,O,w,C,x;const s=U.has(t.uid),I={...t.bundleOptions??{},...t.selectedOptions??{},...t.customizableOptions,...t.recipient?{[a.recipient]:t.recipient}:{},...t.recipientEmail&&t.recipient?{[a.recipient]:`${t.recipient} (${t.recipientEmail})`}:{},...t.sender?{[a.sender]:t.sender}:{},...t.senderEmail&&t.sender?{[a.sender]:`${t.sender} (${t.senderEmail})`}:{},...t.message?{[a.message]:t.message}:{},...t.links&&t.links.count?t.links.count>1?{[a.files.replace("{count}",t.links.count.toString())]:t.links.result}:{[a.file.replace("{count}",t.links.count.toString())]:t.links.result}:{}};return e(B,{"data-testid":"cart-item",ariaLabel:t.name,updating:s,taxIncluded:(r==null?void 0:r.price)==="INCLUDING_TAX",taxExcluded:(r==null?void 0:r.price)==="INCLUDING_EXCLUDING_TAX",warning:!t.outOfStock&&(t.insufficientQuantity||t.lowInventory)?l("span",{"data-testid":"inline-warning",children:[e(G,{source:A,size:"16"}),t.insufficientQuantity&&t.stockLevel&&(t.stockLevel==="noNumber"?a.insufficientQuantityGeneral:a.insufficientQuantity.replace("{inventory}",(f=t.stockLevel)==null?void 0:f.toString()).replace("{count}",t.quantity.toString()))||t.lowInventory&&t.onlyXLeftInStock&&a.lowInventory.replace("{count}",(v=t.onlyXLeftInStock)==null?void 0:v.toString())]}):void 0,alert:t.outOfStock?l("span",{children:[e(G,{source:A,size:"16"}),a.outOfStockAlert]}):void 0,image:o?e("a",{href:o(t),children:e(P,{loading:i<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}})}):e(P,{loading:i<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}}),title:e("span",{children:o?e("a",{href:o(t),children:t.name}):t.name}),sku:e("span",{children:t.sku}),configurations:Object.keys(I).length>0?I:void 0,quantity:t.quantity,price:(r==null?void 0:r.price)==="INCLUDING_TAX"?e(c,{amount:t.discounted?(k=t.regularPrice)==null?void 0:k.value:(_=t.taxedPrice)==null?void 0:_.value,currency:t.discounted?(N=t.regularPrice)==null?void 0:N.currency:(L=t.taxedPrice)==null?void 0:L.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}):e(c,{amount:(b=t.regularPrice)==null?void 0:b.value,currency:(S=t.regularPrice)==null?void 0:S.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}),total:(r==null?void 0:r.price)==="INCLUDING_EXCLUDING_TAX"||(r==null?void 0:r.price)==="INCLUDING_TAX"?e(u,{children:t.discounted?l(u,{children:[e(c,{amount:t.total.value,currency:t.total.currency,variant:"strikethrough","data-testid":"including-tax-row-total","aria-label":a.regularPrice}),e(c,{amount:(O=t.rowTotalIncludingTax)==null?void 0:O.value,currency:(w=t.rowTotalIncludingTax)==null?void 0:w.currency,sale:t.discounted,"data-testid":"discount-total","aria-label":a.discountedPrice})]}):e(c,{amount:t.rowTotalIncludingTax.value,currency:t.rowTotalIncludingTax.currency,"data-testid":"including-tax-row-total","aria-label":a.regularPrice})}):l(u,{children:[e(c,{amount:t.total.value,currency:t.total.currency,variant:t.discounted?"strikethrough":"default","data-testid":"regular-total","aria-label":a.regularPrice}),t.discounted&&e(c,{amount:(C=t.discountedTotal)==null?void 0:C.value,currency:(x=t.discountedTotal)==null?void 0:x.currency,sale:t.discounted,"data-testid":"discount-total","aria-label":a.discountedPrice})]}),totalExcludingTax:(r==null?void 0:r.price)==="INCLUDING_EXCLUDING_TAX"?e(c,{amount:t.rowTotal.value,currency:t.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":a.regularPrice}):void 0,onRemove:()=>{Q(t.uid,0)}},t.uid)})}):void 0,type:"warning",heading:a.outOfStockHeading,description:a.outOfStockDescription,variant:"primary",actionButtonPosition:"bottom",additionalActions:n!=null&&n.hasFullyOutOfStockItems?[{label:a.removeAction,onClick:W}]:void 0});return e(ct,{...X,heading:e("div",{children:a.heading.replace("{count}",((n==null?void 0:n.totalQuantity)??0).toString())}),emptyCart:e(et,{ctaLinkURL:y==null?void 0:y()}),subtotal:(n==null?void 0:n.subtotal)&&((r==null?void 0:r.subtotal)==="INCLUDING_TAX"||(r==null?void 0:r.subtotal)==="INCLUDING_EXCLUDING_TAX"?e(c,{amount:n==null?void 0:n.subtotal.includingTax.value,currency:n==null?void 0:n.subtotal.includingTax.currency,"data-testid":"subtotal-including-tax",style:{font:"inherit"}}):e(c,{amount:n==null?void 0:n.subtotal.excludingTax.value,currency:n==null?void 0:n.subtotal.excludingTax.currency,"data-testid":"subtotal-excluding-tax",style:{font:"inherit"}})),subtotalExcludingTaxes:(n==null?void 0:n.subtotal)&&((r==null?void 0:r.subtotal)==="INCLUDING_EXCLUDING_TAX"?e(c,{amount:n==null?void 0:n.subtotal.excludingTax.value,currency:n==null?void 0:n.subtotal.excludingTax.currency,"data-testid":"subtotal-including-excluding-tax",style:{font:"inherit"}}):void 0),ctas:l("div",{children:[g&&e(H,{variant:"primary",href:n!=null&&n.hasOutOfStockItems?void 0:g(),disabled:n==null?void 0:n.hasOutOfStockItems,"aria-disabled":n==null?void 0:n.hasOutOfStockItems,children:a.checkoutLink}),h&&e(H,{variant:"tertiary",href:h(),children:a.cartLink})]}),outOfStockMessage:n!=null&&n.hasOutOfStockItems?J:void 0,products:(n==null?void 0:n.totalQuantity)??0?e(F,{children:($=n==null?void 0:n.miniCartMaxItems)==null?void 0:$.filter(t=>!t.outOfStock&&!t.insufficientQuantity).map((t,i)=>{var f,v,k,_,N,L,b,S,O,w,C,x;const s=U.has(t.uid),I={...t.bundleOptions??{},...t.selectedOptions??{},...t.customizableOptions,...t.recipient?{[a.recipient]:t.recipient}:{},...t.recipientEmail&&t.recipient?{[a.recipient]:`${t.recipient} (${t.recipientEmail})`}:{},...t.sender?{[a.sender]:t.sender}:{},...t.senderEmail&&t.sender?{[a.sender]:`${t.sender} (${t.senderEmail})`}:{},...t.message?{[a.message]:t.message}:{},...t.links&&t.links.count?t.links.count>1?{[a.files.replace("{count}",t.links.count.toString())]:t.links.result}:{[a.file.replace("{count}",t.links.count.toString())]:t.links.result}:{}};return e(B,{"data-testid":"cart-item",ariaLabel:t.name,updating:s,taxIncluded:(r==null?void 0:r.price)==="INCLUDING_TAX",taxExcluded:(r==null?void 0:r.price)==="INCLUDING_EXCLUDING_TAX",warning:!t.outOfStock&&(t.insufficientQuantity||t.lowInventory)?l("span",{children:[e(G,{source:A,size:"16"}),t.insufficientQuantity&&t.stockLevel&&(t.stockLevel==="noNumber"?a.insufficientQuantityGeneral:a.insufficientQuantity.replace("{inventory}",(f=t.stockLevel)==null?void 0:f.toString()).replace("{count}",t.quantity.toString()))||t.lowInventory&&t.onlyXLeftInStock&&a.lowInventory.replace("{count}",(v=t.onlyXLeftInStock)==null?void 0:v.toString())]}):void 0,alert:t.outOfStock?l("span",{children:[e(G,{source:A,size:"16"}),a.outOfStockAlert]}):void 0,image:o?e("a",{href:o(t),children:e(P,{loading:i<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}})}):e(P,{loading:i<4?"eager":"lazy",src:t.image.src,alt:t.image.alt,width:"300",height:"300",params:{width:300}}),title:e("span",{children:o?e("a",{href:o(t),children:t.name}):t.name}),sku:e("span",{children:t.sku}),configurations:Object.keys(I).length>0?I:void 0,quantity:t.quantity,price:(r==null?void 0:r.price)==="INCLUDING_TAX"?e(c,{amount:t.discounted?(k=t.regularPrice)==null?void 0:k.value:(_=t.taxedPrice)==null?void 0:_.value,currency:t.discounted?(N=t.regularPrice)==null?void 0:N.currency:(L=t.taxedPrice)==null?void 0:L.currency,style:{font:"inherit"},"data-testid":"including-tax-item-price"}):e(c,{amount:(b=t.regularPrice)==null?void 0:b.value,currency:(S=t.regularPrice)==null?void 0:S.currency,style:{font:"inherit"},"data-testid":"regular-item-price"}),total:(r==null?void 0:r.price)==="INCLUDING_EXCLUDING_TAX"||(r==null?void 0:r.price)==="INCLUDING_TAX"?e(u,{children:t.discounted?l(u,{children:[e(c,{amount:t.total.value,currency:t.total.currency,variant:"strikethrough","data-testid":"including-tax-row-total","aria-label":a.regularPrice}),e(c,{amount:(O=t.rowTotalIncludingTax)==null?void 0:O.value,currency:(w=t.rowTotalIncludingTax)==null?void 0:w.currency,sale:t.discounted,"data-testid":"discount-total","aria-label":a.discountedPrice})]}):e(c,{amount:t.rowTotalIncludingTax.value,currency:t.rowTotalIncludingTax.currency,"data-testid":"including-tax-row-total","aria-label":a.regularPrice})}):l(u,{children:[e(c,{amount:t.total.value,currency:t.total.currency,variant:t.discounted?"strikethrough":"default","data-testid":"regular-total","aria-label":a.regularPrice}),t.discounted&&e(c,{amount:(C=t.discountedTotal)==null?void 0:C.value,currency:(x=t.discountedTotal)==null?void 0:x.currency,sale:t.discounted,"data-testid":"discount-total","aria-label":a.discountedPrice})]}),totalExcludingTax:(r==null?void 0:r.price)==="INCLUDING_EXCLUDING_TAX"?e(c,{amount:t.rowTotal.value,currency:t.rowTotal.currency,"data-testid":"excluding-tax-total","aria-label":a.regularPrice}):void 0,onRemove:()=>{Q(t.uid,0)}},t.uid)})}):void 0})};it.getInitialData=async function(){return K()};export{it as MiniCart,it as default};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
2
|
+
import { Container, SlotProps } from '@dropins/tools/types/elsie/src/lib';
|
|
3
|
+
import { CartModel } from '../../data/models';
|
|
4
|
+
|
|
5
|
+
interface CheckoutRouteContext {
|
|
6
|
+
cartId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface OrderSummaryProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
routeCheckout?: (context: CheckoutRouteContext) => string;
|
|
10
|
+
slots?: {
|
|
11
|
+
EstimateShipping?: SlotProps;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare const OrderSummary: Container<OrderSummaryProps, CartModel | null>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=OrderSummary.d.ts.map
|