@dropins/storefront-cart 0.3.0 → 0.4.0-alpha128
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/getEstimatedTotals/getEstimatedTotals.d.ts +0 -1
- package/api/index.d.ts +1 -0
- package/api/initializeCart/initializeCart.d.ts +2 -0
- package/api/refreshCart/index.d.ts +2 -0
- package/api/refreshCart/refreshCart.d.ts +4 -0
- package/api.js +5 -5
- package/chunks/CartFragment.js +235 -0
- package/chunks/CartSummaryList.js +1 -0
- package/chunks/MiniCart.js +1 -1
- package/chunks/OrderSummary.js +1 -0
- package/chunks/getEstimateShipping.js +48 -0
- package/chunks/getEstimatedTotals.js +3 -50
- package/chunks/getStoreConfig.js +4 -4
- package/chunks/resetCart.js +1 -230
- package/chunks/state.js +1 -0
- package/chunks/updateProductsFromCart.js +3 -3
- package/components/Cart/Cart.d.ts +3 -3
- package/components/CartSummaryList/CartSummaryList.d.ts +12 -0
- package/components/CartSummaryList/index.d.ts +3 -0
- package/components/EstimateShipping/EstimateShipping.d.ts +20 -0
- package/components/EstimateShipping/index.d.ts +2 -0
- package/components/MiniCart/MiniCart.d.ts +0 -2
- package/components/OrderSummary/OrderSummary.d.ts +37 -0
- package/components/OrderSummary/index.d.ts +3 -0
- package/components/index.d.ts +4 -1
- package/containers/Cart/Cart.d.ts +6 -7
- package/containers/Cart.js +1 -1
- package/containers/CartSummaryList/CartSummaryList.d.ts +20 -0
- package/containers/CartSummaryList/index.d.ts +3 -0
- package/containers/CartSummaryList.d.ts +3 -0
- package/containers/CartSummaryList.js +1 -0
- 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/MiniCart.d.ts +4 -1
- 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 +3 -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__/cartModel.d.ts +1 -0
- package/data/transforms/__fixtures__/productTypesData.d.ts +223 -5
- package/data/transforms/__fixtures__/storeConfig.d.ts +4 -0
- package/data/transforms/transform-shipping.d.ts +5 -0
- package/hooks/useEstimatedTotals.d.ts +2 -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/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 c}from"@dropins/tools/fetch-graphql.js";import{s as e}from"./state.js";import"@dropins/tools/event-bus.js";const{setEndpoint:n,setFetchGraphQlHeader:g,removeFetchGraphQlHeader:m,setFetchGraphQlHeaders:u,fetchGraphQl:f,getConfig:i}=new c().getMethods(),F=a=>{const o=a.findIndex(({extensions:r})=>(r==null?void 0:r.category)==="graphql-authorization")>-1,h=a.findIndex(({extensions:r})=>(r==null?void 0:r.category)==="graphql-no-such-entity")>-1,t=a.map(r=>r.message).join(" ");if(o||h)return s(),console.error(t),null;throw Error(t)},s=()=>(e.cartId=null,e.authenticated=!1,Promise.resolve(null));export{g as a,u as b,s as c,f,i as g,F as h,m as r,n as s};
|
package/chunks/state.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function _(t){const e=document.cookie.split(";");for(let s=0;s<e.length;s++){const n=e[s].trim();if(n.indexOf(`${t}=`)===0)return n.substring(t.length+1)}return null}function u(t){t?sessionStorage.setItem("DROPIN__CART__CART__DATA",JSON.stringify(t)):sessionStorage.removeItem("DROPIN__CART__CART__DATA")}function a(){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 c=(()=>{const t=a();return{cartId:null,authenticated:t?!t.isGuestCart:!1}})(),o=new Proxy(c,{set(t,e,s){var n;if(t[e]=s,e==="cartId"){if(s===o.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 r=(n=o.config)==null?void 0:n.cartExpiresInDays;r||console.warn('Missing "expiresInDays" config. Cookie expiration will default to 30 days.');const i=new Date;i.setDate(i.getDate()+(r??30)),document.cookie=`DROPIN__CART__CART-ID=${s}; expires=${i.toUTCString()}; path=/`}return!0},get(t,e){return e==="cartId"?_("DROPIN__CART__CART-ID"):t[e]}});export{I as a,u as b,a as g,o as s};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{s as m}from"./state.js";import{C as R,a as A,t as I}from"./CartFragment.js";import{events as g}from"@dropins/tools/event-bus.js";import{f as v,h as D}from"./resetCart.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 i(a,r){const t=l();t.push({[a]:null}),t.push({[a]:r})}function O(a,r){l().push(e=>{const s=e.getState?e.getState():{};e.push({event:a,eventInfo:{...s,...r}})})}function M(a,r,t){const e=_({cart:a,locale:t});i(c.SHOPPING_CART_CONTEXT,{...e}),O(u.OPEN_CART),E(r,t).forEach(o=>{i(c.PRODUCT_CONTEXT,o.product),p(e,[o],u.ADD_TO_CART)})}function w(a,r){const t=_({cart:a,locale:r});i(c.SHOPPING_CART_CONTEXT,{...t}),O(u.SHOPPING_CART_VIEW)}function p(a,r,t){const e={items:r};i(c.SHOPPING_CART_CONTEXT,{...a}),i(c.CHANGED_PRODUCTS_CONTEXT,{...e}),O(t)}function N(a,r,t){const e=_({cart:a,locale:t}),s=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=s.find(T=>T.id===f.uid);!n&&!d||(!d&&n?(i(c.PRODUCT_CONTEXT,n.product),p(e,[n],u.ADD_TO_CART)):d&&!n?(i(c.PRODUCT_CONTEXT,d.product),p(e,[d],u.REMOVE_FROM_CART)):n.quantity>d.quantity?(i(c.PRODUCT_CONTEXT,n.product),p(e,[n],u.ADD_TO_CART)):(i(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
|
+
${R}
|
|
6
6
|
) {
|
|
7
7
|
updateCartItems(
|
|
8
8
|
input: {
|
|
@@ -17,4 +17,4 @@ import{C as P,a as A,s as f,f as I,h as v,t as D}from"./resetCart.js";import{eve
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
${A}
|
|
20
|
-
`,
|
|
20
|
+
`,F=async a=>{const r=m.cartId;if(!r)throw Error("Cart ID is not set");return v(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 s=[...((C=e==null?void 0:e.addProductsToCart)==null?void 0:C.user_errors)??[],...t??[]];if(s.length>0)return D(s);const o=I(e.updateCartItems.cart);return g.emit("cart/updated",o),g.emit("cart/data",o),o&&N(o,a,m.locale??"en-US"),o})};export{M as a,N as b,w as p,F as u};
|
|
@@ -2,10 +2,10 @@ import { FunctionComponent, VNode } from 'preact';
|
|
|
2
2
|
import { HTMLAttributes } from 'preact/compat';
|
|
3
3
|
|
|
4
4
|
export interface CartProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
-
|
|
6
|
-
heading?: VNode;
|
|
5
|
+
empty?: boolean;
|
|
7
6
|
products?: VNode;
|
|
8
|
-
|
|
7
|
+
orderSummary?: VNode<HTMLAttributes<HTMLElement>>;
|
|
8
|
+
outOfStockMessage?: VNode;
|
|
9
9
|
}
|
|
10
10
|
export declare const Cart: FunctionComponent<CartProps>;
|
|
11
11
|
//# sourceMappingURL=Cart.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FunctionComponent, VNode } from 'preact';
|
|
2
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
3
|
+
|
|
4
|
+
export interface CartSummaryListProps extends Omit<HTMLAttributes<HTMLDivElement>, 'loading'> {
|
|
5
|
+
heading?: VNode | null;
|
|
6
|
+
emptyCart: VNode;
|
|
7
|
+
products?: VNode | null;
|
|
8
|
+
outOfStockMessage?: VNode | null;
|
|
9
|
+
loading?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const CartSummaryList: FunctionComponent<CartSummaryListProps>;
|
|
12
|
+
//# sourceMappingURL=CartSummaryList.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
|
|
@@ -2,8 +2,6 @@ import { FunctionComponent, VNode } from 'preact';
|
|
|
2
2
|
import { HTMLAttributes } from 'preact/compat';
|
|
3
3
|
|
|
4
4
|
export interface MiniCartProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
-
emptyCart: VNode;
|
|
6
|
-
heading?: VNode;
|
|
7
5
|
products?: VNode;
|
|
8
6
|
subtotal?: VNode;
|
|
9
7
|
subtotalExcludingTaxes?: VNode;
|
|
@@ -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,14 @@
|
|
|
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
|
-
routeProduct?: (item: CartModel['items'][0]) => string;
|
|
10
6
|
routeEmptyCartCTA?: () => string;
|
|
11
|
-
|
|
7
|
+
routeProduct?: (item: CartModel['items'][0]) => string;
|
|
8
|
+
slots?: {
|
|
9
|
+
OrderSummary?: SlotProps;
|
|
10
|
+
ProductList?: SlotProps;
|
|
11
|
+
};
|
|
12
12
|
}
|
|
13
13
|
export declare const Cart: Container<CartProps, CartModel | null>;
|
|
14
|
-
export {};
|
|
15
14
|
//# 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{C as g,C as h}from"../chunks/MiniCart.js";import"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/preact-compat.js";import"@dropins/tools/lib.js";import"../chunks/state.js";import"@dropins/tools/event-bus.js";/* empty css */import"@dropins/tools/components.js";import"@dropins/tools/i18n.js";import"../chunks/updateProductsFromCart.js";import"../chunks/CartFragment.js";import"../chunks/resetCart.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/CartSummaryList.js";import"../chunks/OrderSummary.js";import"../chunks/getEstimatedTotals.js";export{g as Cart,h as default};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
2
|
+
import { Container, SlotProps } from '@dropins/tools/types/elsie/src/lib';
|
|
3
|
+
import { CartModel } from '../../data/models/cart-model';
|
|
4
|
+
|
|
5
|
+
export interface CartSummaryListProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
hideHeading?: boolean;
|
|
7
|
+
routeProduct?: (item: CartModel['items'][0]) => string;
|
|
8
|
+
routeEmptyCartCTA?: () => string;
|
|
9
|
+
onItemQuantityUpdate?: (uid: string, quantity: number) => Promise<CartModel | null>;
|
|
10
|
+
onItemRemove?: (uid: string) => Promise<CartModel | null>;
|
|
11
|
+
maxItems?: number;
|
|
12
|
+
attributesToHide?: SwitchableAttributes[];
|
|
13
|
+
slots?: {
|
|
14
|
+
Heading?: SlotProps;
|
|
15
|
+
EmptyCart?: SlotProps;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export type SwitchableAttributes = 'name' | 'image' | 'configurations' | 'warning' | 'alert';
|
|
19
|
+
export declare const CartSummaryList: Container<CartSummaryListProps, CartModel | null>;
|
|
20
|
+
//# sourceMappingURL=CartSummaryList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as f,C as u}from"../chunks/CartSummaryList.js";import"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/preact-compat.js";import"@dropins/tools/lib.js";/* empty css */import"@dropins/tools/components.js";import"@dropins/tools/i18n.js";import"../chunks/state.js";import"@dropins/tools/event-bus.js";export{f as CartSummaryList,u 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";/* empty css */import{Price as U,Picker as w,Input as G,Button as $}from"@dropins/tools/components.js";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{a as X,s as J}from"../chunks/state.js";import{events as B}from"@dropins/tools/event-bus.js";import{g as O,a as Q,b as W}from"../chunks/getEstimateShipping.js";import"../chunks/resetCart.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]})},me=()=>{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{me as EstimateShipping,me as default};
|
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
export interface MiniCartProps extends HTMLAttributes<HTMLDivElement> {
|
|
@@ -7,6 +7,9 @@ export interface MiniCartProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
7
7
|
routeCart?: () => string;
|
|
8
8
|
routeCheckout?: () => string;
|
|
9
9
|
routeEmptyCartCTA?: () => string;
|
|
10
|
+
slots?: {
|
|
11
|
+
ProductList?: SlotProps;
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
14
|
export declare const MiniCart: Container<MiniCartProps, CartModel | null>;
|
|
12
15
|
//# sourceMappingURL=MiniCart.d.ts.map
|
package/containers/MiniCart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{M as b,M as c}from"../chunks/MiniCart.js";import"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/preact-compat.js";import"@dropins/tools/lib.js";import"../chunks/state.js";import"@dropins/tools/event-bus.js";/* empty css */import"@dropins/tools/components.js";import"@dropins/tools/i18n.js";import"../chunks/updateProductsFromCart.js";import"../chunks/CartFragment.js";import"../chunks/resetCart.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/CartSummaryList.js";import"../chunks/OrderSummary.js";import"../chunks/getEstimatedTotals.js";export{b as MiniCart,c 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{O as x,O as y}from"../chunks/OrderSummary.js";import"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/preact-compat.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import"../chunks/state.js";import"../chunks/getEstimatedTotals.js";import"../chunks/CartFragment.js";import"../chunks/resetCart.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/components.js";/* empty css */import"@dropins/tools/i18n.js";export{x as OrderSummary,y as default};
|