@dropins/storefront-checkout 0.1.0-alpha39 → 0.1.0-alpha40
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/errors/errors.d.ts +1 -1
- package/api/fetch-graphql/fetch-graphql.d.ts +1 -0
- package/api/fetchAddressFormFields/fetchAddressFormFields.d.ts +1 -3
- package/api/initializeCheckout/initializeCheckout.d.ts +1 -1
- package/api/placeOrder/graphql/placeOrder.graphql.d.ts +1 -1
- package/api/utils/dispatchApiCall.d.ts +5 -1
- package/api/utils/filterControlledErrors.d.ts +1 -1
- package/api.js +1 -1
- package/chunks/BillToShippingAddress2.js +1 -1
- package/chunks/BillingForm.js +1 -1
- package/chunks/ErrorBanner.js +1 -1
- package/chunks/LoginForm.js +1 -1
- package/chunks/MergedCartBanner.js +1 -1
- package/chunks/OutOfStock.js +1 -0
- package/chunks/PlaceOrder.js +1 -1
- package/chunks/ShippingForm.js +1 -1
- package/chunks/ShippingMethods.js +1 -1
- package/chunks/ToggleButton.js +1 -1
- package/chunks/ToggleButton2.js +1 -1
- package/chunks/fixtures.js +2 -31
- package/chunks/getMultilineValues.js +1 -1
- package/chunks/placeOrder2.js +2 -7
- package/chunks/resetCustomer.js +31 -2
- package/chunks/setGuestEmailOnCart.js +4 -4
- package/chunks/setShippingMethods.js +2 -2
- package/components/AddressForm/AddressForm.d.ts +1 -0
- package/components/AddressForm/useAddressForm.d.ts +4 -3
- package/components/Checkout/Checkout.d.ts +8 -1
- package/components/OutOfStock/OutOfStock.d.ts +6 -4
- package/components/PlaceOrder/PlaceOrder.d.ts +1 -1
- package/containers/BillToShippingAddress/BillToShippingAddress.d.ts +3 -3
- package/containers/BillToShippingAddress.js +1 -1
- package/containers/BillingForm.js +1 -1
- package/containers/Checkout/Checkout.d.ts +6 -2
- package/containers/Checkout.js +1 -1
- package/containers/ErrorBanner.js +1 -1
- package/containers/EstimateShipping.js +1 -1
- package/containers/LoginForm.js +1 -1
- package/containers/MergedCartBanner.js +1 -1
- package/containers/OutOfStock/OutOfStock.d.ts +13 -0
- package/containers/OutOfStock/index.d.ts +3 -0
- package/containers/OutOfStock.d.ts +3 -0
- package/containers/OutOfStock.js +1 -0
- package/containers/PaymentMethods.js +1 -1
- package/containers/PlaceOrder/PlaceOrder.d.ts +1 -1
- package/containers/PlaceOrder.js +1 -1
- package/containers/ShippingForm/ShippingForm.d.ts +1 -0
- package/containers/ShippingForm.js +1 -1
- package/containers/ShippingMethods/ShippingMethods.d.ts +1 -0
- package/containers/ShippingMethods.js +1 -1
- package/containers/index.d.ts +2 -1
- package/hooks/index.d.ts +4 -0
- package/hooks/useBreakpoint/index.d.ts +2 -0
- package/hooks/useBreakpoint/useBreakpoint.d.ts +2 -0
- package/i18n/en_US.json.d.ts +7 -4
- package/package.json +1 -1
- package/render/Provider.d.ts +0 -2
- package/render.js +3 -3
- package/signals/AddressFormFieldsSignal.d.ts +7 -0
- package/signals/index.d.ts +1 -0
- package/tests/integration/utils/setup.d.ts +2 -1
- package/chunks/address-form-fields.js +0 -1
- package/context/address-form-fields.d.ts +0 -13
- package/context/index.d.ts +0 -2
- package/tests/index.d.ts +0 -2
- package/tests/render.d.ts +0 -4
package/api/errors/errors.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export declare const setEndpoint: (endpoint: string) => void, setFetchGraphQlHea
|
|
|
5
5
|
endpoint: string | undefined;
|
|
6
6
|
fetchGraphQlHeaders: import('@adobe/fetch-graphql').Header | undefined;
|
|
7
7
|
};
|
|
8
|
+
export type { FetchOptions, FetchQueryError } from '@adobe/fetch-graphql';
|
|
8
9
|
//# sourceMappingURL=fetch-graphql.d.ts.map
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const fetchAddressFormFields: () => Promise<AddressFormField[]>;
|
|
1
|
+
export declare const fetchAddressFormFields: () => Promise<import('../../data/models/address-form-fields').AddressFormField[] | undefined>;
|
|
4
2
|
//# sourceMappingURL=fetchAddressFormFields.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const initializeCheckout: () => Promise<[import('../../data/models/store-config').StoreConfig | undefined, import('../../data/models/country').Country[] | undefined]>;
|
|
1
|
+
export declare const initializeCheckout: () => Promise<[import('../../data/models/store-config').StoreConfig | undefined, import('../../data/models/country').Country[] | undefined, import('../../data/models/address-form-fields').AddressFormField[] | undefined]>;
|
|
2
2
|
//# sourceMappingURL=initializeCheckout.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const placeOrderMutation = "\n mutation placeOrder($cartId: String!) {\n placeOrder(input: { cart_id: $cartId }) {\n orderV2 {\n number\n status\n token\n is_virtual\n applied_coupons {\n code\n }\n email\n id\n total {\n grand_total {\n currency\n value\n }\n subtotal {\n currency\n value\n }\n total_shipping {\n currency\n value\n }\n total_tax {\n currency\n value\n }\n }\n shipping_method\n payment_methods {\n name\n type\n }\n billing_address {\n firstname\n middlename\n lastname\n street\n city\n postcode\n telephone\n country_code\n region\n region_id\n company\n custom_attributesV2 {\n code\n ... on AttributeValue {\n value\n }\n }\n }\n shipping_address {\n firstname\n middlename\n lastname\n street\n city\n postcode\n telephone\n country_code\n region\n region_id\n company\n custom_attributesV2 {\n code\n ... on AttributeValue {\n value\n }\n }\n }\n items {\n __typename\n id\n discounts {\n amount {\n value\n }\n }\n product {\n __typename\n canonical_url\n image {\n url\n }\n thumbnail {\n label\n url\n }\n name\n sku\n uid\n price_range {\n maximum_price {\n regular_price {\n currency\n value\n }\n }\n }\n }\n selected_options {\n label\n value\n }\n product_sale_price {\n value\n currency\n }\n
|
|
1
|
+
export declare const placeOrderMutation = "\n mutation placeOrder($cartId: String!) {\n placeOrder(input: { cart_id: $cartId }) {\n orderV2 {\n number\n status\n token\n is_virtual\n applied_coupons {\n code\n }\n email\n id\n total {\n grand_total {\n currency\n value\n }\n subtotal {\n currency\n value\n }\n total_shipping {\n currency\n value\n }\n total_tax {\n currency\n value\n }\n }\n shipping_method\n payment_methods {\n name\n type\n }\n billing_address {\n firstname\n middlename\n lastname\n street\n city\n postcode\n telephone\n country_code\n region\n region_id\n company\n custom_attributesV2 {\n code\n ... on AttributeValue {\n value\n }\n }\n }\n shipping_address {\n firstname\n middlename\n lastname\n street\n city\n postcode\n telephone\n country_code\n region\n region_id\n company\n custom_attributesV2 {\n code\n ... on AttributeValue {\n value\n }\n }\n }\n items {\n __typename\n id\n discounts {\n amount {\n value\n }\n }\n product {\n __typename\n canonical_url\n image {\n url\n }\n thumbnail {\n label\n url\n }\n name\n sku\n uid\n price_range {\n maximum_price {\n regular_price {\n currency\n value\n }\n }\n }\n }\n selected_options {\n label\n value\n }\n product_sale_price {\n value\n currency\n }\n quantity_ordered\n ... on GiftCardOrderItem {\n gift_card {\n recipient_name\n recipient_email\n sender_name\n sender_email\n message\n }\n }\n }\n }\n }\n }\n";
|
|
2
2
|
//# sourceMappingURL=placeOrder.graphql.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FetchOptions } from '
|
|
1
|
+
import { FetchOptions } from '..';
|
|
2
2
|
|
|
3
3
|
declare const signalTypes: {
|
|
4
4
|
cart: import('@preact/signals-core').Signal<{
|
|
@@ -29,6 +29,10 @@ declare const signalTypes: {
|
|
|
29
29
|
data?: import('../../data/models/country').Country[] | undefined;
|
|
30
30
|
pending: boolean;
|
|
31
31
|
}>;
|
|
32
|
+
addressFormFields: import('@preact/signals-core').Signal<{
|
|
33
|
+
data?: import('../../data/models/address-form-fields').AddressFormField[] | undefined;
|
|
34
|
+
pending: boolean;
|
|
35
|
+
}>;
|
|
32
36
|
};
|
|
33
37
|
type SignalTypesType = typeof signalTypes;
|
|
34
38
|
type SignalTypesKeys = keyof SignalTypesType;
|
package/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as g,F as h,I as l,c,M as
|
|
1
|
+
import{D as g,F as h,I as l,c as f,M as c,d as C,a as x,b as A,S as F,U as u,i as E,g as M,h as S,j as T,r as D,s as G,e as O,f as U}from"./chunks/fixtures.js";import{e as b,g as I}from"./chunks/getMultilineValues.js";import{c as _,f as k,g as v,i as y,a as B,r as H,b as N}from"./chunks/resetCustomer.js";import{g as z,a as L,b as P}from"./chunks/getCustomer.js";import{i as Y,s as q}from"./chunks/setGuestEmailOnCart.js";import{p as K}from"./chunks/placeOrder2.js";import{s as W}from"./chunks/setBillingAddress.js";import{s as Z}from"./chunks/setPaymentMethod.js";import{S as ss,p as es,s as as}from"./chunks/setShippingAddress.js";import{s as rs}from"./chunks/setShippingMethods.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/preact.js";import"@dropins/tools/preact-hooks.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";import"./chunks/getCart.graphql.js";const n=e=>{var s;(s=window==null?void 0:window.location)==null||s.assign(e)};export{g as DEFAULT_COUNTRY,h as FetchError,l as InvalidArgument,f as MissingBillingAddress,c as MissingCart,C as MissingCountry,x as MissingEmail,A as MissingPaymentMethod,ss as STANDARD_ATTRIBUTES,F as STORE_CONFIG_DEFAULTS,u as UnexpectedError,_ as config,E as defaultFormFields,b as estimateShippingMethods,k as fetchAddressFormFields,M as fetchGraphQl,z as getCart,L as getCheckoutData,S as getConfig,v as getCountries,P as getCustomer,I as getRegions,T as getStoreConfig,y as initialize,B as initializeCheckout,Y as isEmailAvailable,K as placeOrder,es as prepareAddress,n as redirect,D as removeFetchGraphQlHeader,H as resetCheckout,N as resetCustomer,W as setBillingAddress,G as setEndpoint,O as setFetchGraphQlHeader,U as setFetchGraphQlHeaders,q as setGuestEmailOnCart,Z as setPaymentMethod,as as setShippingAddress,rs as setShippingMethodsOnCart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@dropins/tools/event-bus.js";import{
|
|
1
|
+
import{jsx as o}from"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/event-bus.js";import{k as p,n as f,l as k}from"./fixtures.js";import{s as b}from"./setBillingAddress.js";import{classes as S}from"@dropins/tools/lib.js";import{Checkbox as _,Skeleton as v,SkeletonRow as A}from"@dropins/tools/components.js";/* empty css */import{useText as B}from"@dropins/tools/i18n.js";import{useState as I,useEffect as g}from"@dropins/tools/preact-compat.js";const x=({className:r,isInitialized:s=!0,checked:i=!0,...t})=>{const e=B({title:"Checkout.BillToShippingAddress.title"});return s?o("div",{className:S(["checkout-bill-to-shipping-address",r]),children:o(_,{"data-testid":"bill-to-shipping-checkbox",className:"checkout-bill-to-shipping-address__checkbox",checked:i,name:"checkout-bill-to-shipping-address__checkbox",label:e.title,...t})}):o(C,{})},C=()=>o(v,{className:"bill-to-shipping-address__skeleton",children:o(A,{variant:"row",size:"small"})}),m="is_bill_to_shipping_address";function y(r,s,i){const t=r[i],e=s[i];return t===void 0&&e===void 0||t===null&&e===null?!0:typeof t=="object"&&typeof e=="object"?JSON.stringify(t)===JSON.stringify(e):t===e}function N(r,s,i){return!s&&!i?!0:!s||!i?!1:r.every(t=>{const e=t.code;return y(s,i,e)})}const T=({isBillToShipping:r})=>{var d;const[s,i]=I(!1),t=k.value.data,e=f.value.data,h=(e==null?void 0:e.id)||"",l=!!e,a=e==null?void 0:e.billingAddress,n=(d=e==null?void 0:e.shippingAddresses)==null?void 0:d[0],c=!!n;return g(()=>{if(s)return;const u=localStorage.getItem(m);u&&(i(!0),r.value={checked:u==="true",setByUser:!1})},[s,r]),g(()=>{if(s||!t||!l)return;i(!0);const u=N(t,a,n);r.value={checked:a?u:r.value.checked,setByUser:!1}},[a,t,l,r,s,n]),{cartId:h,isInitialized:s,hasShippingAddress:c}},L=({children:r,...s})=>{const i=p.value.checked,{hasShippingAddress:t,isInitialized:e}=T({isBillToShipping:p});return o(x,{...s,checked:i,isInitialized:e,onChange:l=>{const n=l.target.checked;if(p.value={checked:n,setByUser:!0},localStorage.setItem(m,n.toString()),!e||!n||!t)return;const c=new AbortController;return b({signal:c.signal,input:{same_as_shipping:!0}}).catch(d=>{console.error(d)}),()=>{c.abort()}},disabled:f.value.pending})};export{L as B,m as a,N as c};
|
package/chunks/BillingForm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@dropins/tools/event-bus.js";import{
|
|
1
|
+
import{jsx as c}from"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/event-bus.js";import{l as A,m as B,n as F,k as b}from"./fixtures.js";import{A as h}from"./getMultilineValues.js";import{s as v}from"./setBillingAddress.js";import{p as S}from"./setShippingAddress.js";import{A as k}from"./ToggleButton.js";import"@dropins/tools/preact-hooks.js";import"@dropins/tools/lib.js";import{c as y}from"./BillToShippingAddress2.js";import{useRef as I,useMemo as L,useCallback as _,useEffect as C}from"@dropins/tools/preact-compat.js";import{B as M}from"./constants2.js";const q=f=>{var p;const d=I(null),i=A.value.data,o=B.value.data,a=o==null?void 0:o.defaultBillingAddress,s=F.value.data,t=s==null?void 0:s.billingAddress,n=(p=s==null?void 0:s.shippingAddresses)==null?void 0:p[0],{checked:r,setByUser:m}=b.value,l=!r,u=L(()=>!i||!l?!1:t?!y(i,t,n):!!a,[l,i,t,n,a]),g=_(e=>v({signal:e.signal,input:{address:r?void 0:S(e.address),same_as_shipping:r}}),[r]);return C(()=>{if(!m)return;const e=new AbortController;return r||d.current.triggerSaveAddress(e.signal),()=>{e.abort()}},[r,m]),c(k,{...f,addressType:h.BILLING,autoFill:u,"data-testid":"billing-form",headingId:"Checkout.BillingAddress.title",name:M,ref:d,saveAddressHandler:g,style:{display:l?"block":"none"}})};export{q as B};
|
package/chunks/ErrorBanner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as c from"@dropins/tools/preact-compat.js";import{useState as m,useEffect as f}from"@dropins/tools/preact-compat.js";import{events as a}from"@dropins/tools/event-bus.js";import{AlertBanner as u,Icon as g}from"@dropins/tools/components.js";import{
|
|
1
|
+
import{jsx as o}from"@dropins/tools/preact-jsx-runtime.js";import*as c from"@dropins/tools/preact-compat.js";import{useState as m,useEffect as f}from"@dropins/tools/preact-compat.js";import{events as a}from"@dropins/tools/event-bus.js";import{AlertBanner as u,Icon as g}from"@dropins/tools/components.js";import{useText as p}from"@dropins/tools/i18n.js";const h=r=>c.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},c.createElement("path",{vectorEffect:"non-scaling-stroke",fillRule:"evenodd",clipRule:"evenodd",d:"M1 20.8953L12.1922 1.5L23.395 20.8953H1ZM13.0278 13.9638L13.25 10.0377V9H11.25V10.0377L11.4722 13.9638H13.0278ZM11.2994 16V17.7509H13.2253V16H11.2994Z",fill:"currentColor"})),x=r=>{const[i,s]=m(!1),t=p({message:"Checkout.ErrorBanner.genericMessage"});f(()=>{const n=a.on("error",e=>{(e==null?void 0:e.source)==="checkout"&&(e==null?void 0:e.type)==="network"&&s(!0)});return()=>{n==null||n.off()}},[]);const l=()=>{s(!1)};return i?o(u,{...r,className:"checkout__banner","data-testid":"error-banner",icon:o(g,{source:h}),message:o("span",{children:t.message}),"aria-label":t.message,onDismiss:l,variant:"warning"}):null};export{x as E};
|
package/chunks/LoginForm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@dropins/tools/event-bus.js";import{n as
|
|
1
|
+
import{jsx as e,jsxs as c,Fragment as T}from"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/event-bus.js";import{n as B,m as z,o as V}from"./fixtures.js";import{i as $,s as j}from"./setGuestEmailOnCart.js";import{H as q,p as G}from"./ToggleButton.js";import{useState as F,useEffect as O}from"@dropins/tools/preact-hooks.js";import{classes as x}from"@dropins/tools/lib.js";import{Field as P,Input as w,Divider as D}from"@dropins/tools/components.js";/* empty css */import{useText as b,Text as L}from"@dropins/tools/i18n.js";import{L as R}from"./constants3.js";const U=({value:o,error:l,hint:t,onChange:u,onBlur:d,onInvalid:s})=>{const i=b({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return e(P,{size:"medium",error:l,hint:t,children:e(w,{id:"customer-email",name:"customer-email",type:"email",value:o,autocomplete:"email",placeholder:i.LoginFormPlaceholder,floatingLabel:i.LoginFormFloatingLabel,onChange:u,onBlur:d,onInvalid:s,required:!0,"aria-label":i.LoginFormLabel,"aria-required":!0})})},J=({onSignInClick:o,email:l})=>c("div",{className:"checkout-login-form__sign-in",children:[e(L,{id:"Checkout.LoginForm.account"}),e("a",{"data-testid":"sign-in-link",className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:t=>{t.preventDefault(),o==null||o(l)},children:e(L,{id:"Checkout.LoginForm.signIn"})})]}),K=({name:o,className:l,currentEmail:t,hint:u,error:d=null,onEmailChange:s,onEmailBlur:i,onEmailInvalid:v,onSignInClick:p,onSignOutClick:g,customer:a,..._})=>{const n=b({Title:"Checkout.LoginForm.title"}),h=!!a;return c("div",{..._,className:x(["checkout-login-form",l]),"data-testid":"checkout-login-form",children:[c("div",{className:"checkout-login-form__heading",children:[e(q,{level:2,className:"checkout-login-form__title",children:n.Title}),h?e(Q,{onSignOutClick:g}):e(J,{onSignInClick:p,email:t})]}),a?c("div",{className:"checkout-login-form__customer-details",children:[e("div",{className:"checkout-login-form__customer-name",children:`${a==null?void 0:a.firstName} ${a==null?void 0:a.lastName}`}),e("div",{className:"checkout-login-form__customer-email",children:a==null?void 0:a.email})]}):e("div",{className:"checkout-login-form__content",children:c("form",{className:x(["dropin-login-form__form",l]),name:o,noValidate:!0,children:[e("button",{type:"submit",disabled:!0,style:"display: none","aria-hidden":"true"}),e(U,{value:t||void 0,error:d||"",hint:u,onChange:s,onBlur:i,onInvalid:v})]})}),e(D,{variant:"primary"})]})},Q=({onSignOutClick:o})=>c("p",{className:"checkout-login-form__sign-out",children:[e(L,{id:"Checkout.LoginForm.switch"}),e("a",{className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:l=>{l.preventDefault(),o==null||o()},children:e(L,{id:"Checkout.LoginForm.signOut"})})]}),W=o=>G.email.test(o),X=1e3,me=({className:o,email:l=null,onSignInClick:t,onSignOutClick:u,...d})=>{const s=b({LoginFormInvalidEmailError:"Checkout.LoginForm.invalidEmailError",LoginFormMissingEmailError:"Checkout.LoginForm.missingEmailError",LoginFormEmailExistsAlreadyHaveAccount:"Checkout.LoginForm.emailExists.alreadyHaveAccount",LoginFormEmailExistsSignInButton:"Checkout.LoginForm.emailExists.signInButton",LoginFormEmailExistsForFasterCheckout:"Checkout.LoginForm.emailExists.forFasterCheckout"}),{data:i}=B.value,v=(i==null?void 0:i.id)||"",p=!!i,g=(i==null?void 0:i.email)||"",[a,_]=F(!1),[n,h]=F(l),[E,f]=F(null),[C,k]=F(!0),N=r=>r.valid?null:r.valueMissing?s.LoginFormMissingEmailError:s.LoginFormInvalidEmailError,y=z.value.data,A=r=>{const{value:m}=r.target;h(m),f(null),k(!0)},I=r=>{const{validity:m}=r.target;f(N(m))},H=r=>{const{validity:m}=r.target;f(N(m))};!a&&p&&(_(!0),h((i==null?void 0:i.email)||l)),O(()=>{if(E!==null&&E!==""||n===null||n===""||V.authenticated)return;const r=setTimeout(()=>{$(n).then(m=>{k(m),g!==n&&j(n).catch(console.error)}).catch(m=>{console.log(m),f(s.LoginFormInvalidEmailError),k(!0)})},X);return()=>{r&&clearTimeout(r)}},[g,v,n,E,s.LoginFormInvalidEmailError]);const M=C?"":c(T,{children:[s.LoginFormEmailExistsAlreadyHaveAccount," ",e("a",{href:"#",onClick:r=>{r.preventDefault(),t==null||t(n)},children:s.LoginFormEmailExistsSignInButton})," ",s.LoginFormEmailExistsForFasterCheckout]});return e(K,{className:o,currentEmail:n,error:E,hint:M,name:R,onEmailBlur:I,onEmailChange:A,onEmailInvalid:H,onSignInClick:r=>{const m=n?W(n):!1;t==null||t(m?r:null)},onSignOutClick:u,customer:y,...d})};export{me as L};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AlertBanner as f,Icon as u}from"@dropins/tools/components.js";import{events as g}from"@dropins/tools/event-bus.js";import*as i from"@dropins/tools/preact-compat.js";import{useState as p,useEffect as I}from"@dropins/tools/preact-compat.js";import{
|
|
1
|
+
import{jsx as e}from"@dropins/tools/preact-jsx-runtime.js";import{AlertBanner as f,Icon as u}from"@dropins/tools/components.js";import{events as g}from"@dropins/tools/event-bus.js";import*as i from"@dropins/tools/preact-compat.js";import{useState as p,useEffect as I}from"@dropins/tools/preact-compat.js";import{useText as h,Text as v}from"@dropins/tools/i18n.js";const M=t=>i.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},i.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M0 12C0 5.37931 5.37931 0 12 0C18.6207 0 24 5.37931 24 12C24 18.6207 18.6207 24 12 24C5.37931 24 0 18.6207 0 12ZM11.8885 5.06101C11.1405 5.06101 10.5357 5.66579 10.5357 6.4138V6.57295C10.5835 7.27321 11.1882 7.81433 11.8885 7.76658H12.0795C12.7797 7.70292 13.289 7.09815 13.2413 6.4138C13.2413 5.66579 12.6365 5.06101 11.8885 5.06101ZM13.1935 16.8223H14.1007C14.2599 16.8223 14.4031 16.9655 14.4031 17.1247V17.7294C14.4031 17.9045 14.2599 18.0318 14.1007 18.0318H9.8832C9.70813 18.0318 9.58081 17.8886 9.58081 17.7294V17.1247C9.58081 16.9496 9.72405 16.8223 9.8832 16.8223H10.7904V10.7905H9.8832C9.70813 10.7905 9.58081 10.6472 9.58081 10.4881V9.88329C9.58081 9.70823 9.72405 9.58091 9.8832 9.58091H12.5888C12.923 9.58091 13.1935 9.85146 13.1935 10.1857V16.8223Z",fill:"currentColor"})),E=t=>{const[r,s]=p(0),a=h({mergedCartBannerItems:e(v,{id:"Checkout.MergedCartBanner.items",fields:{count:r},plural:r})});I(()=>{const n=g.on("cart/merged",o=>{var m;const l=(m=o==null?void 0:o.oldCartItems)==null?void 0:m.reduce((C,d)=>C+d.quantity,0);l>0&&s(l)});return()=>{n==null||n.off()}},[]);const c=()=>{s(0)};return r?e(f,{...t,className:"checkout__banner","data-testid":"merged-cart-banner",icon:e(u,{source:M}),message:e("span",{children:a.mergedCartBannerItems}),"aria-label":a.mergedCartBannerItems,onDismiss:c,variant:"neutral"}):null};export{E as M};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as c,jsxs as k}from"@dropins/tools/preact-jsx-runtime.js";import"./ToggleButton.js";import{events as f}from"@dropins/tools/event-bus.js";import"@dropins/tools/preact-hooks.js";import"./fixtures.js";import{classes as h}from"@dropins/tools/lib.js";import{Card as d,Icon as p,Image as O}from"@dropins/tools/components.js";/* empty css */import{useText as g}from"@dropins/tools/i18n.js";import*as t from"@dropins/tools/preact-compat.js";import{useState as L,useCallback as v,useEffect as E}from"@dropins/tools/preact-compat.js";const _=r=>t.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},t.createElement("g",{clipPath:"url(#clip0_4797_15331)"},t.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M10.25 20.91L1.5 17.55V6.51996L10.25 9.92996V20.91Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),t.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.24023 4.64001L14.9902 8.06001V11.42",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),t.createElement("path",{className:"error-icon",vectorEffect:"non-scaling-stroke",d:"M19 13.31L15.5 19.37H22.5L19 13.31Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),t.createElement("path",{className:"error-icon",vectorEffect:"non-scaling-stroke",d:"M19.0202 17.11H18.9802L18.9502 15.56H19.0502L19.0202 17.11ZM18.9602 18.29V18.06H19.0502V18.29H18.9602Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),t.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19 12.16V6.51996L10.25 9.92996V20.91L14.27 19.37L14.4 19.32",stroke:"currentColor",strokeLinejoin:"round"}),t.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M1.5 6.51999L10.25 3.04999L19 6.51999L10.25 9.92999L1.5 6.51999Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})),t.createElement("defs",null,t.createElement("clipPath",{id:"clip0_4797_15331"},t.createElement("rect",{width:22,height:18.86,fill:"white",transform:"translate(1 2.54999)"})))),b=({onCartProductsUpdate:r,routeCart:i})=>{const[o,u]=L([]),l=e=>e.outOfStock||e.insufficientQuantity,n=v(()=>{if(!r)return;const e=o.filter(s=>s.outOfStock).map(s=>({uid:s.uid,quantity:0}));r(e)},[o,r]);if(E(()=>{const e=f.on("cart/data",s=>{const m=(s==null?void 0:s.items)||[];u(m.filter(l))},{eager:!0});return()=>{e==null||e.off()}},[]),o.length===0)return null;const a=!o.some(e=>e.insufficientQuantity);return c(S,{items:o,onRemoveOutOfStock:a?n:void 0,routeCart:i==null?void 0:i()})},S=({className:r,items:i,onRemoveOutOfStock:o,routeCart:u,...l})=>{const n=g({title:"Checkout.OutOfStock.title",message:"Checkout.OutOfStock.message",reviewCart:"Checkout.OutOfStock.actions.reviewCart",removeOutOfStock:"Checkout.OutOfStock.actions.removeOutOfStock"});return k(d,{className:h(["checkout-out-of-stock",r]),"data-testid":"checkout-out-of-stock",variant:"secondary",...l,children:[k("h4",{className:"checkout-out-of-stock__title",children:[c(p,{source:_,size:"16",stroke:"1"}),n.title]}),c("p",{className:"checkout-out-of-stock__message",children:n.message}),c("ol",{className:"checkout-out-of-stock__items",children:i.map(a=>c("li",{"data-testid":"out-of-stock-item",className:"checkout-out-of-stock__item",children:c(O,{loading:"eager",src:a.image.src,alt:a.image.alt,width:"100",height:"100",params:{width:100}})},a.sku))}),k("div",{className:"checkout-out-of-stock__actions",children:[u&&c("a",{"data-testid":"review-cart",className:"checkout-out-of-stock__action",href:u,children:n.reviewCart}),o&&c("button",{className:"checkout-out-of-stock__action","data-testid":"remove-out-of-stock",type:"button",onClick:o,children:n.removeOutOfStock})]})]})};export{b as O,_ as S};
|
package/chunks/PlaceOrder.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import{classes as l}from"@dropins/tools/lib.js";import"./ToggleButton.js";import{Button as u}from"@dropins/tools/components.js";import{Text as d}from"@dropins/tools/i18n.js";import{events as p}from"@dropins/tools/event-bus.js";import{n as O}from"./fixtures.js";import"@dropins/tools/preact-hooks.js";/* empty css */import{useState as h,useEffect as P}from"@dropins/tools/preact-compat.js";import{B as v}from"./constants2.js";import{L as I}from"./constants3.js";import{S as F}from"./constants.js";const S=({className:e,onClick:r=()=>{},disabled:o=!1})=>n("div",{className:l(["checkout-place-order",e]),children:n(u,{className:l(["checkout-place-order__button",e]),"data-testid":"place-order-button",disabled:o,onClick:r,size:"medium",type:"submit",variant:"primary",children:n(d,{id:"Checkout.PlaceOrder.button"})},"placeOrder")}),_=[I,F,v],k=e=>{const r=e.querySelector(":invalid");r&&(r.scrollIntoView({behavior:"smooth"}),r.focus())},y=()=>{const r=(Array.from(document.forms)||[]).filter(t=>_.includes(t.name)).filter(t=>t.offsetParent!==null).filter(t=>!t.checkValidity()),o=r.length===0;if(!o){const t=r[0];k(t)}return o},w=({onClick:e,handleServerError:r})=>{const[o,t]=h(!1),a=O.value.pending,m=async()=>{if(y())try{await e()}catch(i){r(i)}};return P(()=>{const i=p.on("cart/initialized",c=>{const f=(c==null?void 0:c.items)||[];t(f.some(s=>s.outOfStock||s.insufficientQuantity))},{eager:!0});return()=>{i==null||i.off()}},[]),n(S,{onClick:m,disabled:a||o})};export{w as P};
|
package/chunks/ShippingForm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@dropins/tools/event-bus.js";import{
|
|
1
|
+
import{jsx as t}from"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/event-bus.js";import{k as a}from"./fixtures.js";import{A as d}from"./getMultilineValues.js";import{s as m}from"./setBillingAddress.js";import{s as n,p as l}from"./setShippingAddress.js";import{A as g}from"./ToggleButton.js";import"@dropins/tools/preact-hooks.js";import"@dropins/tools/lib.js";import{useCallback as h}from"@dropins/tools/preact-compat.js";import{S as A}from"./constants.js";const H=({onCheckoutDataUpdate:i,preselectedFields:e,...p})=>{const s=a.value.checked,o=h(r=>n({signal:r.signal,address:l(r.address)}).then(()=>{if(s)return m({input:{same_as_shipping:!0}})}),[s]);return t(g,{...p,addressType:d.SHIPPING,headingId:"Checkout.ShippingAddress.title",name:A,onCheckoutDataUpdate:i,preselectedFields:e,saveAddressHandler:o})};export{H as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{jsx as n,jsxs as j,Fragment as B}from"@dropins/tools/preact-jsx-runtime.js";import{e as O}from"./getMultilineValues.js";import{events as T}from"@dropins/tools/event-bus.js";import{w as P,x as L,n as w,q,y as V}from"./fixtures.js";import{s as Z}from"./setShippingMethods.js";import{classes as W}from"@dropins/tools/lib.js";import{H as $}from"./ToggleButton.js";import{IllustratedMessage as F,Icon as G,ProgressSpinner as J,RadioButton as K,Price as Q,Divider as X,Skeleton as Y,SkeletonRow as y}from"@dropins/tools/components.js";import{useState as I,useEffect as x}from"@dropins/tools/preact-hooks.js";/* empty css */import*as a from"@dropins/tools/preact-compat.js";import{useCallback as D,useMemo as U,useEffect as A}from"@dropins/tools/preact-compat.js";import{useText as ee}from"@dropins/tools/i18n.js";const v=P(void 0),te=e=>({countryCode:e.country_id,postCode:e.postcode||"",...e.region_id?{regionId:Number(e.region_id)}:{...e.region?{region:e.region}:{}}}),ne=e=>({carrierCode:e.carrier.code||"",methodCode:e.code||"",amount:e.amount,amountExclTax:e.amountExclTax,amountInclTax:e.amountInclTax}),oe=e=>a.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.47266 4.90002H15.1851V10.9645H21.2495L23 12.715V17.6124H20.073",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76151 16.7898C9.76151 18.0525 8.72845 19.076 7.46582 19.076C6.20318 19.076 5.17969 18.0429 5.17969 16.7803C5.17969 15.5176 6.20318 14.4941 7.46582 14.4941C8.72845 14.4941 9.75195 15.5176 9.76151 16.7803C9.76151 16.7803 9.76151 16.7803 9.76151 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8726 16.7898C19.8726 18.062 18.8491 19.0855 17.5769 19.0855C16.3047 19.0855 15.2812 18.062 15.2812 16.7898C15.2812 15.5176 16.3047 14.4941 17.5769 14.4941C18.8491 14.4941 19.8726 15.5176 19.8726 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),ie=({className:e,isLoading:t=!1,onSelectionChange:r=()=>{},options:s,selection:o,...m})=>{const u=ee({Title:"Checkout.ShippingMethods.title",EmptyState:"Checkout.ShippingMethods.emptyState"});return s===void 0?n(re,{}):j("div",{...m,className:W(["checkout-shipping-methods",e]),children:[n($,{level:3,className:"checkout-shipping-methods__title",children:u.Title}),!t&&s.length===0&&n(F,{icon:n(G,{source:oe}),message:n("p",{children:u.EmptyState})}),j("div",{className:W(["checkout-shipping-methods__content"]),children:[t&&n(J,{className:"checkout-shipping-methods__spinner"}),n("div",{className:W(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",t]]),children:s.map(i=>n(K,{"data-testid":"shipping-method-radiobutton","aria-busy":t,id:i.value,name:"shipping-method",className:"checkout-shipping-methods__method",label:j(B,{children:[n(Q,{amount:i.amount.value,currency:i.amount.currency})," ",n("span",{children:i.carrier.title})]}),description:i.title,value:i.value,checked:(o==null?void 0:o.value)===i.value,onChange:()=>r(i)},i.value))})]}),n(X,{variant:"primary"})]})},re=()=>j(Y,{"data-testid":"shipping-methods-skeleton",children:[n(y,{variant:"heading",size:"small"}),n(y,{variant:"empty",size:"small"}),n(y,{size:"medium",fullWidth:!0}),n(y,{size:"medium",fullWidth:!0})]});function se(){var c;const[e,t]=I(),[r,s]=I();x(()=>{T.on("checkout/address",({address:M,type:S})=>{S==="shipping"&&t(M)})},[]),x(()=>{s(v.value)},[v.value]),x(()=>{L.value.pending?s(void 0):s(v.value)},[L.value.pending]);const{country_id:o,region_id:m,region:u,postcode:i}=e||{},p=!!e,f=w.value.data,k=!!((c=f==null?void 0:f.shippingAddresses)!=null&&c[0]);x(()=>{k||!r||!p||T.emit("shipping/estimate",{address:te({country_id:o,region_id:m,region:u,postcode:i}),shippingMethod:ne(r)})},[r,o,m,u,i,p,k])}const b=(e,t)=>e.code===t.code&&e.carrier.code===t.carrier.code;function ce({onCheckoutDataUpdate:e,preSelectedMethod:t}){const r=q.value.data,s=!r,o=w.value.data,m=w.value.pending,u=L.value.data,i=L.value.pending,p=v.value,f=o==null?void 0:o.id,k=o==null?void 0:o.shippingAddresses,c=k==null?void 0:k[0],M=!!c,S=c==null?void 0:c.availableShippingMethods,E=c==null?void 0:c.selectedShippingMethod,d=S||u,N=D(l=>{if(!M)return;const g={method_code:l.code,carrier_code:l.carrier.code};Z([g]).then(()=>{e==null||e()}).catch(_=>{console.error("setting shipping methods on cart failed:",_)})},[M,e]),R=l=>{v.value=l},h=U(()=>{if(!(d!=null&&d.length))return;const l=d[0],g=p||E;return g?d.some(C=>b(C,g))?g:l:d.find(H=>H.carrier.code===(t==null?void 0:t.carrierCode)&&H.code===(t==null?void 0:t.methodCode))||l},[p,E,d,t]);return A(()=>{h&&((!p||!b(h,p))&&(v.value=h),(!E||!b(h,E))&&N(h))},[h,p,E,N]),A(()=>{if(!f||S)return;const{country:l,selectedRegion:g,selectedRegionId:_}=V.value,C=l||(r==null?void 0:r.defaultCountry);C&&O({criteria:{country_code:C,region_name:g,region_id:_}}).catch(z=>{L.value={pending:!1,data:[]},console.error("shipping methods estimation failed:",z)})},[f,S,r]),{isLoading:m||s||i,options:d,selection:h,onSelectionChange:R}}const Ee=e=>{const{isLoading:t,options:r,selection:s,onSelectionChange:o}=ce(e);return se(),n(ie,{...e,className:"checkout-shipping-methods",isLoading:t,onSelectionChange:o,options:r,selection:s})};export{Ee as S};
|
package/chunks/ToggleButton.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{events as re}from"@dropins/tools/event-bus.js";import{A as P,z as L,n as ne,V as w,B as ge,q as fe,m as he}from"./fixtures.js";import{b as Y,a as F,A as R,e as pe,D as U,g as Fe,M as Q,c as ee}from"./getMultilineValues.js";import{useState as q,useCallback as O,useEffect as z,useRef as ve,useMemo as Ie}from"@dropins/tools/preact-hooks.js";import{classes as V,getFormErrors as Ee,VComponent as _}from"@dropins/tools/lib.js";import{Text as oe,useText as Ae}from"@dropins/tools/i18n.js";import{Field as Z,Input as ae,Picker as Ce,Skeleton as Se,SkeletonRow as k,ProgressSpinner as ke}from"@dropins/tools/components.js";/* empty css */import{jsx as s,Fragment as se,jsxs as B}from"@dropins/tools/preact-jsx-runtime.js";import{forwardRef as be,useRef as Me,useImperativeHandle as $e,useState as j,useEffect as W}from"@dropins/tools/preact-compat.js";import{u as Re}from"./address-form-fields.js";import{E as Le}from"./ErrorBanner.js";import{M as we}from"./MergedCartBanner.js";const X={firstname:"given-name",lastname:"family-name",company:"organization",country:"country",region:"address-level1",city:"address-level2",postcode:"postal-code",telephone:"tel",street:"address-line1",email:"email",middlename:"additional-name",prefix:"honorific-prefix",suffix:"honorific-suffix"};function ie(e){return Object.keys(e).length===0&&e.constructor===Object}const ye=e=>e.map(t=>{var n;const r=((n=t==null?void 0:t.id)==null?void 0:n.toString())||t.code;return{text:t.name,value:r}}),Ne=e=>e?e.map(t=>({text:t.label,value:t.value})):[];function De({address:e,addressType:t,availableCountries:r,availableRegions:n,config:a,dismissError:i,errors:o,fields:d,onBlur:g,onChange:v,onInvalid:c,onSelection:h,setAddress:E}){const p=()=>{E(l=>({...l,[F.Region]:"",[F.RegionId]:""})),i(F.Region)},A=l=>{E(S=>({...S,[F.RegionId]:l}))};return d.map(l=>{var I;let S,m=l.frontendInput,C=h,y=v,N=l.isDisabled,D=l.isRequired,b=[],u;return m===P.Multiline?(u=Y(l.code,e),S=Y(l.code,o)):(u=e[l.code],S=o[l.code]||""),l.code===F.Country&&(b=Ne(r),t===R.SHIPPING&&(L.value.country=u,C=f=>{const M=f.target,{value:$}=M;$&&H({country_code:$}),h(f),p()})),l.code===F.RegionId&&t===R.SHIPPING&&(L.value.selectedRegionId=u),l.code===F.Region&&(t===L.value.addressType&&(N=L.value.pending),D=a.countriesWithRequiredRegion.includes(e==null?void 0:e.country_id),b=ye(n),!D&&!a.displayStateIfOptional&&(m=P.Undefined),m=b.length>0?P.Select:P.Text,m===P.Select?t===R.SHIPPING?(L.value.selectedRegion=u,C=f=>{const $=f.target.value;H({country_code:L.value.country,region_id:$}),h(f),A($)}):C=f=>{h(f);const $=f.target.value;A($)}:m===P.Text&&t===R.SHIPPING&&(L.value.selectedRegion=u,y=f=>{const M=f.target,{value:$}=M;L.value.country&&H({country_code:L.value.country,region_name:$}),v(f)}),u=b.length>0?((I=b.find(f=>f.value===u))==null?void 0:I.value)||"":u),l.code===F.PostCode&&(D=!a.countriesWithOptionalZipCode.includes(e==null?void 0:e.country_id)),{...l,error:S,frontendInput:m,handleSelect:C,isDisabled:N,isRequired:D,onBlur:g,onChange:y,onInvalid:c,options:b,value:u}})}let te;function H(e){var i;const t=ne.value.data,r=!!t,n=(i=t==null?void 0:t.shippingAddresses)==null?void 0:i[0],a=n==null?void 0:n.availableShippingMethods;r&&!a&&(clearTimeout(te),te=setTimeout(()=>{pe({criteria:e})},U))}const G=({addressType:e,code:t,index:r})=>r?`${e}-${t}-${r}`:`${e}-${t}`,T=e=>`checkout-address-form__${e}`,_e=({addressType:e,element:t})=>{const{code:r,value:n,defaultValue:a}=t;return s("input",{className:T(r),id:G({addressType:e,code:r}),name:r,type:"hidden",value:n||a},r)},xe=({addressType:e,element:t})=>{const{code:r,error:n,isDisabled:a,label:i,onBlur:o,onChange:d,onInvalid:g,validateRules:v,value:c}=t,h=ce(v);return s(Z,{disabled:a,error:n,children:s(ae,{"aria-label":i,autocomplete:X[r]||"off",className:T(r),floatingLabel:`${i} ${t.isRequired?"*":""}`,id:G({addressType:e,code:r}),onBlur:o,onChange:d,onInvalid:g,placeholder:i,required:t.isRequired||!1,type:"text",name:r,value:c??void 0,...h})})},ze=({addressType:e,element:t})=>{const{code:r,error:n,isDisabled:a,isRequired:i,label:o,multilineCount:d,onBlur:g,onChange:v,onInvalid:c,validateRules:h,value:E}=t,p=d??0,A=ce(h);return s(se,{children:Array.from(Array(p).keys()).map(l=>s(Z,{disabled:a,error:(n==null?void 0:n[l])||"",className:"dropin-field--multiline",children:s(ae,{id:G({addressType:e,code:r,index:l}),className:T(r),floatingLabel:`${o} ${l!=0?l:""} ${i&&l===0?"*":""}`,autocomplete:l===0?X[r]:"off","aria-label":o,placeholder:`${o} ${l!=0?l:""}`,type:"text",required:i&&l===0,onChange:v,onBlur:g,onInvalid:c,name:`${r}-${l}`,value:(E==null?void 0:E[l])||void 0,...A})},`${r}-${l}`))})},Pe=({addressType:e,element:t})=>{const{code:r,error:n,handleSelect:a,isDisabled:i,isRequired:o,label:d,onBlur:g,onInvalid:v,options:c,value:h}=t,E=a?{handleSelect:a}:{};return s(Z,{disabled:i,error:n,children:s(Ce,{id:G({addressType:e,code:r}),className:T(r),name:r,floatingLabel:`${d} ${o?"*":""}`,required:o,placeholder:d,"aria-label":d,options:c,value:h,autocomplete:X[r]||"off",onBlur:g,onInvalid:v,...E},r)})},Oe=({addressType:e,element:t})=>{switch(t.frontendInput){case"BOOLEAN":case"DATE":case"DATETIME":case"FILE":case"GALLERY":case"IMAGE":case"MEDIA_IMAGE":case"MULTISELECT":case"PRICE":case"TEXTAREA":case"UNDEFINED":case"WEIGHT":return null;case"HIDDEN":return _e({addressType:e,element:t});case"TEXT":return xe({addressType:e,element:t});case"MULTILINE":return ze({addressType:e,element:t});case"SELECT":return Pe({addressType:e,element:t});default:return null}},ce=e=>e?e.reduce((t,r)=>{switch(r.name){case w.DateRangeMax:return{...t,max:r.value};case w.DateRangeMin:return{...t,min:r.value};case w.FileExtensions:return{...t,accept:r.value};case w.InputValidation:return{...t,pattern:Be(r.value)};case w.MaxFileSize:case w.MaxImageHeight:case w.MaxImageWidth:return t;case w.MaxTextLength:return{...t,maxLength:r.value};case w.MinTextLength:return{...t,minLength:r.value};default:throw new Error(`Unknown rule: ${r.name}`)}},{}):{},x={alpha:/^[a-zA-Z]+$/,alphanumeric:/^[a-zA-Z0-9]+$/,"alphanumeric-w-space":/^[a-zA-Z0-9 ]+$/,"alphanum-with-spaces":/^[a-zA-Z0-9 ]+$/,email:/^([a-z0-9,!#$%&'*+/=?^_`{|}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!#$%&'*+/=?^_`{|}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i,numeric:/^[0-9]+$/,url:/^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)$/},Be=e=>{switch(e){case"alpha":return x.alpha.source;case"alphanumeric":return x.alphanumeric.source;case"alphanumeric-w-space":return x["alphanumeric-w-space"].source;case"alphanum-with-spaces":return x["alphanum-with-spaces"].source;case"url":return x.url.source;case"numeric":return x.numeric.source;case"email":return x.email.source;default:throw new Error(`Unknown validation type: ${e}`)}},Ve=e=>B(Se,{...e,children:[s(k,{variant:"heading",size:"medium"}),s(k,{variant:"empty",size:"medium"}),s(k,{size:"large"}),s(k,{size:"large"}),s(k,{size:"large",fullWidth:!0}),s(k,{size:"large",fullWidth:!0,lines:3}),s(k,{size:"large"}),s(k,{size:"large"}),s(k,{size:"large"}),s(k,{size:"large"}),s(k,{size:"large"}),s(k,{size:"large"}),s(k,{size:"large"})]}),Ue=({addressType:e,className:t,fields:r,formRef:n,headingId:a,name:i,...o})=>B("div",{...o,className:V(["checkout-fields-form",t]),children:[s(le,{level:2,children:s(oe,{id:a}),className:"checkout-fields-form__title"}),s("form",{name:i,ref:n,className:V(["checkout-fields-form__form",t]),noValidate:!0,children:r.sort((d,g)=>!d.sortOrder||!g.sortOrder?d.code<g.code?-1:1:d.sortOrder-g.sortOrder).map(d=>Oe({element:d,addressType:e}))})]}),Ge=e=>{const t=new FormData(e),r=Object.fromEntries(t);return Object.entries(r).reduce((a,[i])=>{const o=e.elements[i];return o!=null&&o.validationMessage?{...a,[i]:o.validationMessage}:{...a}},{})};function Te(e){const[t,r]=j({});return W(()=>{e&&r(n=>({...n,country_id:e}))},[e]),{defaultValues:t}}function He({country:e,addressType:t}){const[r,n]=j([]);return W(()=>{if(!e){n([]);return}Fe(e,t).then(a=>{n(a||[])}).catch(a=>{console.error(a)})},[n,e,t]),{availableRegions:r}}function qe({autoFill:e,addressType:t,dismissError:r,loadAutoFill:n}){const[a,i]=j(!1),o=he.value.data,d=!!o,g=ne.value.data,v=!!g;W(()=>{var S;if(!e||!v||a)return;let c,h=!1;c=it({addressType:t,cart:g}),!c&&d&&(c=st({addressType:t,customer:o}),h=!0);const E=m=>m?m.split(ee).length>1:!1;if(!c)return;i(!0);const p={[F.City]:c.city,[F.Company]:c.company||"",[F.Country]:c.country.value,[F.FirstName]:c.firstName,[F.LastName]:c.lastName,[F.PostCode]:c.postCode||"",[F.Telephone]:c.telephone||"",[F.Vat]:c.vatId||""},A=c.region;if(A){const m=(S=A==null?void 0:A.id)==null?void 0:S.toString();m?(p[F.Region]=m,p[F.RegionId]=m):p[F.Region]=A.code}c!=null&&c.street&&c.street.length>0&&c.street.forEach((m,C)=>{p[`${F.Street}${Q}${C}`]=m}),((c==null?void 0:c.customAttributes)||[]).forEach(m=>{E(m.code)?m.value.split(ee).forEach((y,N)=>{p[`${m.code}${Q}${N}`]=y}):p[m.code]=m.value}),n({values:p,triggerAutoSave:h})},[t,e,g,o,a,v,d,n,r])}const $t=be(({addressType:e,autoFill:t=!0,children:r,headingId:n,name:a,preselectedFields:i,saveAddressHandler:o,...d},g)=>{const{fields:v}=Re(),c=ge.value.data,h=c===void 0,E=v===void 0,p=fe.value.data,A=p===void 0,{defaultValues:l}=Te(p==null?void 0:p.defaultCountry),S=at({fields:v,preselectedFields:i}),m=Me(null),{address:C,errors:y,loadAutoFill:N,onBlur:D,dismissError:b,onChange:u,onInvalid:I,onSelection:f,setAddress:M}=nt({formRef:m,type:e,defaultValues:l,preselection:S,saveAddressHandler:o}),{availableRegions:$}=He({country:C.country_id,addressType:e});if($e(g,()=>({triggerSaveAddress:de=>{if(!m.current)return;const me=Ge(m.current);if(ie(me))return o({signal:de,address:C})}})),qe({addressType:e,autoFill:t,loadAutoFill:N,dismissError:b}),E||h||A)return s(Ve,{"data-testid":`${e}-skeleton`});const ue=De({address:C,addressType:e,availableCountries:c,availableRegions:$,config:p,dismissError:b,errors:y,fields:v,onBlur:D,onChange:u,onInvalid:I,onSelection:f,setAddress:M}),K={[R.SHIPPING]:"shipping",[R.BILLING]:"billing"};return s(Ue,{...d,name:a,addressType:e,className:`checkout-${K[e]}-form`,"data-testid":`${K[e]}-form`,fields:ue,formRef:m,headingId:n})}),Ze="DROPIN__CHECKOUT",J=e=>`${Ze}__${e.toUpperCase()}`,je=(e,t)=>{window.localStorage.setItem(J(e),JSON.stringify(t))},We=e=>{const t=window.localStorage.getItem(J(e));return t?JSON.parse(t):null},Xe=e=>{window.localStorage.removeItem(J(e))};function Je(e){const[t,r]=q(null),n=O(i=>setTimeout(()=>{je(e,i)},U),[e]),a=O(()=>{Xe(e)},[e]);return z(()=>{const i=We(e);i&&r(i)},[e]),z(()=>{const i=re.on("checkout/order",()=>{a()});return()=>{i==null||i.off()}},[a]),{addressBackup:t,backupAddress:n,removeAddressBackup:a}}const Ke={[R.BILLING]:"billing",[R.SHIPPING]:"shipping"};function Ye({address:e,type:t}){z(()=>{const r=setTimeout(()=>{re.emit("checkout/address",{type:Ke[t],address:e})},U);return()=>{clearTimeout(r)}},[e,t])}const Qe={badInput:"aria-label",patternMismatch:"aria-label",rangeOverflow:"max",rangeUnderflow:"min",tooLong:"maxlength",tooShort:"minlength",typeMismatch:"aria-label",valueMissing:"aria-label"},et=["badInput","patternMismatch","rangeOverflow","rangeUnderflow","tooLong","tooShort","typeMismatch","valueMissing"],tt=e=>{const[t,r]=q({}),n=O(o=>{const{name:d,validity:g,validationMessage:v}=o;let c=g.valid?"":v;et.forEach(h=>{if(!g[h])return;const E=e[h];if(!E)return;const p=Qe[h];c=E.replace("{field}",o.getAttribute(p)||"")}),r(h=>({...h,[d]:c}))},[e]);return{errors:t,dismissError:o=>{t[o]&&r(d=>{const{[o]:g,...v}=d;return v})},validateFormElement:n,resetErrors:()=>{r({})}}},rt=e=>{const t=e.current;if(!t)return!1;const r=Ee(t);return ie(r)},nt=({formRef:e,type:t,defaultValues:r={},preselection:n={},saveAddressHandler:a})=>{const i=Ae({badInput:"Checkout.AddressForm.Validity.badInput",patternMismatch:"Checkout.AddressForm.Validity.patternMismatch",rangeUnderflow:"Checkout.AddressForm.Validity.rangeUnderflow",tooLong:"Checkout.AddressForm.Validity.tooLong",tooShort:"Checkout.AddressForm.Validity.tooShort",typeMismatch:"Checkout.AddressForm.Validity.typeMismatch",valueMissing:"Checkout.AddressForm.Validity.valueMissing"}),o=ve(!1),[d,g]=q({});Ye({address:d,type:t});const{addressBackup:v,backupAddress:c,removeAddressBackup:h}=Je(t),{errors:E,validateFormElement:p,dismissError:A,resetErrors:l}=tt(i),S=O(u=>{o.current=!1,a(u).then(()=>{h()}).catch(I=>{o.current=!0,console.error("Saving address form failed:",I)})},[h,a]),m=(u,I)=>{g(f=>({...f,[u]:I})),o.current=!0},C=({values:u,triggerAutoSave:I=!1})=>{l(),g(f=>({...f,...u})),I&&(o.current=!0)},y=u=>{const I=u.target,{name:f,value:M}=I;m(f,M),p(I)},N=u=>{const I=u.target;p(I)},D=u=>{const I=u.target,{name:f,value:M}=I;m(f,M),p(I)},b=u=>{u.target.checkValidity()};return z(()=>{g(u=>({...r,...n,...v,...u}))},[r,n,v]),z(()=>{if(!o.current)return;const u=c(d);return()=>{clearTimeout(u)}},[d,c]),z(()=>{if(!o.current||!rt(e))return;const u=new AbortController,I=u.signal,f=setTimeout(()=>{S({signal:I,address:d})},U);return()=>{clearTimeout(f),u.abort()}},[d,e,S]),{address:d,errors:E,loadAutoFill:C,dismissError:A,onChange:y,onSelection:D,onBlur:b,onInvalid:N,setAddress:g}},ot={countryCode:F.Country,region:F.Region,postCode:F.PostCode};function at({fields:e,preselectedFields:t}){return Ie(()=>!(!!e&&e.length>0)||!!!t?{}:Object.keys(t).reduce((a,i)=>{const o=ot[i];return!o||!e.some(g=>g.code===o)?a:{...a,[o]:t[i]}},{}),[e,t])}const st=({addressType:e,customer:t})=>e===R.BILLING?t.defaultBillingAddress:t.defaultShippingAddress,it=({addressType:e,cart:t})=>{if(e===R.BILLING)return t.billingAddress;const r=t.shippingAddresses;if(!(!r||r.length===0))return r[0]},ct=({billingAddress:e,billToShippingAddress:t,login:r,paymentMethods:n,placeOrder:a,shippingAddress:i,shippingMethods:o})=>B(se,{children:[s(_,{node:r}),i&&s(_,{node:i}),t&&s(_,{node:t}),o&&s(_,{node:o}),s(_,{node:n}),s(_,{node:e}),s(_,{node:a})]}),lt=({sections:e})=>B("div",{className:"checkout__content",children:[s(le,{level:1,className:"checkout-title",children:s(oe,{id:"Checkout.title"})}),e&&s(ct,{...e})]}),ut=({children:e,className:t,isLoading:r=!1,...n})=>B("div",{"data-testid":"checkout",className:V(["checkout",t]),...n,children:[r&&s(mt,{}),s(Le,{}),s(we,{}),e]});ut.Main=lt;const le=({className:e,children:t,level:r=2})=>{const n=r>=1&&r<=6?`h${r}`:"h2";return s(n,{className:e,children:t})},dt=()=>{const e=O(()=>{document.body.style.overflow="hidden"},[]),t=O(()=>{document.body.style.overflow=""},[]);return{lockScroll:e,unlockScroll:t}},mt=({className:e})=>{const{lockScroll:t,unlockScroll:r}=dt();return z(()=>(t(),r),[t,r]),s("div",{"data-testid":"checkout-overlay-loader",className:V(["checkout-overlay-loader",e]),children:s(ke,{})})};export{$t as A,ut as C,le as H,x as p};
|
|
1
|
+
import{jsx as o,Fragment as T,jsxs as B}from"@dropins/tools/preact-jsx-runtime.js";import{events as ne}from"@dropins/tools/event-bus.js";import{A as P,y as N,n as oe,V as _,l as Fe,z as Ie,q as Ee,m as Ae}from"./fixtures.js";import{b as Q,a as p,A as L,e as Ce,D as G,g as ke,M as ee,c as te}from"./getMultilineValues.js";import{useState as H,useCallback as O,useEffect as x,useRef as Se,useMemo as be}from"@dropins/tools/preact-hooks.js";import{classes as V,getFormErrors as we,VComponent as y}from"@dropins/tools/lib.js";import{Text as ae,useText as Me}from"@dropins/tools/i18n.js";import{Field as Z,Input as se,Picker as Re,Skeleton as $e,SkeletonRow as b,Divider as ye,ProgressSpinner as Le}from"@dropins/tools/components.js";/* empty css */import{forwardRef as Ne,useRef as _e,useImperativeHandle as De,useState as j,useEffect as X}from"@dropins/tools/preact-compat.js";import{E as xe}from"./ErrorBanner.js";import{M as ze}from"./MergedCartBanner.js";const J={firstname:"given-name",lastname:"family-name",company:"organization",country:"country",region:"address-level1",city:"address-level2",postcode:"postal-code",telephone:"tel",street:"address-line1",email:"email",middlename:"additional-name",prefix:"honorific-prefix",suffix:"honorific-suffix"};function ie(e){return Object.keys(e).length===0&&e.constructor===Object}const Pe=e=>e.map(t=>{var n;const r=((n=t==null?void 0:t.id)==null?void 0:n.toString())||t.code;return{text:t.name,value:r}}),Be=e=>e?e.map(t=>({text:t.label,value:t.value})):[];function Oe({address:e,addressType:t,availableCountries:r,availableRegions:n,config:a,dismissError:s,errors:i,fields:u,onBlur:d,onChange:v,onInvalid:c,onSelection:h,setAddress:F}){const I=()=>{F(l=>({...l,[p.Region]:"",[p.RegionId]:""})),s(p.Region)},A=l=>{F(w=>({...w,[p.RegionId]:l}))};return u.map(l=>{var f;let w,g=l.frontendInput,S=h,M=v,R=l.isDisabled,D=l.isRequired,$=[],k;return g===P.Multiline?(k=Q(l.code,e),w=Q(l.code,i)):(k=e[l.code],w=i[l.code]||""),l.code===p.Country&&($=Be(r),t===L.SHIPPING&&(N.value.country=k,S=m=>{const E=m.target,{value:C}=E;C&&W({country_code:C}),h(m),I()})),l.code===p.RegionId&&t===L.SHIPPING&&(N.value.selectedRegionId=k),l.code===p.Region&&(t===N.value.addressType&&(R=N.value.pending),D=a.countriesWithRequiredRegion.includes(e==null?void 0:e.country_id),$=Pe(n),!D&&!a.displayStateIfOptional&&(g=P.Undefined),g=$.length>0?P.Select:P.Text,g===P.Select?t===L.SHIPPING?(N.value.selectedRegion=k,S=m=>{const C=m.target.value;W({country_code:N.value.country,region_id:C}),h(m),A(C)}):S=m=>{h(m);const C=m.target.value;A(C)}:g===P.Text&&t===L.SHIPPING&&(N.value.selectedRegion=k,M=m=>{const E=m.target,{value:C}=E;N.value.country&&W({country_code:N.value.country,region_name:C}),v(m)}),k=$.length>0?((f=$.find(m=>m.value===k))==null?void 0:f.value)||"":k),l.code===p.PostCode&&(D=!a.countriesWithOptionalZipCode.includes(e==null?void 0:e.country_id)),{...l,error:w,frontendInput:g,handleSelect:S,isDisabled:R,isRequired:D,onBlur:d,onChange:M,onInvalid:c,options:$,value:k}})}let re;function W(e){var s;const t=oe.value.data,r=!!t,n=(s=t==null?void 0:t.shippingAddresses)==null?void 0:s[0],a=n==null?void 0:n.availableShippingMethods;r&&!a&&(clearTimeout(re),re=setTimeout(()=>{Ce({criteria:e})},G))}const U=({addressType:e,code:t,index:r})=>r?`${e}-${t}-${r}`:`${e}-${t}`,q=e=>`checkout-address-form__${e}`,Ve=({addressType:e,element:t})=>{const{code:r,value:n,defaultValue:a}=t;return o("input",{className:q(r),id:U({addressType:e,code:r}),name:r,type:"hidden",value:n||a},r)},Te=({addressType:e,element:t})=>{const{code:r,error:n,isDisabled:a,label:s,onBlur:i,onChange:u,onInvalid:d,validateRules:v,value:c}=t,h=ce(v);return o(Z,{disabled:a,error:n,children:o(se,{"aria-label":s,autocomplete:J[r]||"off",className:q(r),floatingLabel:`${s} ${t.isRequired?"*":""}`,id:U({addressType:e,code:r}),onBlur:i,onChange:u,onInvalid:d,placeholder:s,required:t.isRequired||!1,type:"text",name:r,value:c??void 0,...h})})},Ge=({addressType:e,element:t})=>{const{code:r,error:n,isDisabled:a,isRequired:s,label:i,multilineCount:u,onBlur:d,onChange:v,onInvalid:c,validateRules:h,value:F}=t,I=u??0,A=ce(h);return o(T,{children:Array.from(Array(I).keys()).map(l=>o(Z,{disabled:a,error:(n==null?void 0:n[l])||"",className:"dropin-field--multiline",children:o(se,{id:U({addressType:e,code:r,index:l}),className:q(r),floatingLabel:`${i} ${l!=0?l:""} ${s&&l===0?"*":""}`,autocomplete:l===0?J[r]:"off","aria-label":i,placeholder:`${i} ${l!=0?l:""}`,type:"text",required:s&&l===0,onChange:v,onBlur:d,onInvalid:c,name:`${r}-${l}`,value:(F==null?void 0:F[l])||void 0,...A})},`${r}-${l}`))})},He=({addressType:e,element:t})=>{const{code:r,error:n,handleSelect:a,isDisabled:s,isRequired:i,label:u,onBlur:d,onInvalid:v,options:c,value:h}=t,F=a?{handleSelect:a}:{};return o(Z,{disabled:s,error:n,children:o(Re,{id:U({addressType:e,code:r}),className:q(r),name:r,floatingLabel:`${u} ${i?"*":""}`,required:i,placeholder:u,"aria-label":u,options:c,value:h,autocomplete:J[r]||"off",onBlur:d,onInvalid:v,...F},r)})},Ue=({addressType:e,element:t})=>{switch(t.frontendInput){case"BOOLEAN":case"DATE":case"DATETIME":case"FILE":case"GALLERY":case"IMAGE":case"MEDIA_IMAGE":case"MULTISELECT":case"PRICE":case"TEXTAREA":case"UNDEFINED":case"WEIGHT":return null;case"HIDDEN":return Ve({addressType:e,element:t});case"TEXT":return Te({addressType:e,element:t});case"MULTILINE":return Ge({addressType:e,element:t});case"SELECT":return He({addressType:e,element:t});default:return null}},ce=e=>e?e.reduce((t,r)=>{switch(r.name){case _.DateRangeMax:return{...t,max:r.value};case _.DateRangeMin:return{...t,min:r.value};case _.FileExtensions:return{...t,accept:r.value};case _.InputValidation:return{...t,pattern:qe(r.value)};case _.MaxFileSize:case _.MaxImageHeight:case _.MaxImageWidth:return t;case _.MaxTextLength:return{...t,maxLength:r.value};case _.MinTextLength:return{...t,minLength:r.value};default:throw new Error(`Unknown rule: ${r.name}`)}},{}):{},z={alpha:/^[a-zA-Z]+$/,alphanumeric:/^[a-zA-Z0-9]+$/,"alphanumeric-w-space":/^[a-zA-Z0-9 ]+$/,"alphanum-with-spaces":/^[a-zA-Z0-9 ]+$/,email:/^([a-z0-9,!#$%&'*+/=?^_`{|}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!#$%&'*+/=?^_`{|}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i,numeric:/^[0-9]+$/,url:/^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)$/},qe=e=>{switch(e){case"alpha":return z.alpha.source;case"alphanumeric":return z.alphanumeric.source;case"alphanumeric-w-space":return z["alphanumeric-w-space"].source;case"alphanum-with-spaces":return z["alphanum-with-spaces"].source;case"url":return z.url.source;case"numeric":return z.numeric.source;case"email":return z.email.source;default:throw new Error(`Unknown validation type: ${e}`)}},We=e=>B($e,{...e,children:[o(b,{variant:"heading",size:"medium"}),o(b,{variant:"empty",size:"medium"}),o(b,{size:"large"}),o(b,{size:"large"}),o(b,{size:"large",fullWidth:!0}),o(b,{size:"large",fullWidth:!0,lines:3}),o(b,{size:"large"}),o(b,{size:"large"}),o(b,{size:"large"}),o(b,{size:"large"}),o(b,{size:"large"}),o(b,{size:"large"}),o(b,{size:"large"})]}),Ze=({addressType:e,className:t,fields:r,formRef:n,headingId:a,name:s,...i})=>B("div",{...i,className:V(["checkout-fields-form",t]),children:[o(me,{level:2,children:o(ae,{id:a}),className:"checkout-fields-form__title"}),o("form",{name:s,ref:n,className:V(["checkout-fields-form__form",t]),noValidate:!0,children:r.sort((u,d)=>!u.sortOrder||!d.sortOrder?u.code<d.code?-1:1:u.sortOrder-d.sortOrder).map(u=>Ue({element:u,addressType:e}))})]}),je=e=>{const t=new FormData(e),r=Object.fromEntries(t);return Object.entries(r).reduce((a,[s])=>{const i=e.elements[s];return i!=null&&i.validationMessage?{...a,[s]:i.validationMessage}:{...a}},{})};function Xe(e){const[t,r]=j({});return X(()=>{e&&r(n=>({...n,country_id:e}))},[e]),{defaultValues:t}}function Je({country:e,addressType:t}){const[r,n]=j([]);return X(()=>{if(!e){n([]);return}ke(e,t).then(a=>{n(a||[])}).catch(a=>{console.error(a)})},[n,e,t]),{availableRegions:r}}function Ke({autoFill:e,addressType:t,dismissError:r,loadAutoFill:n}){const[a,s]=j(!1),i=Ae.value.data,u=!!i,d=oe.value.data,v=!!d;X(()=>{var w;if(!e||!v||a)return;let c,h=!1;c=gt({addressType:t,cart:d}),!c&&u&&(c=mt({addressType:t,customer:i}),h=!0);const F=g=>g?g.split(te).length>1:!1;if(!c)return;s(!0);const I={[p.City]:c.city,[p.Company]:c.company||"",[p.Country]:c.country.value,[p.FirstName]:c.firstName,[p.LastName]:c.lastName,[p.PostCode]:c.postCode||"",[p.Telephone]:c.telephone||"",[p.Vat]:c.vatId||""},A=c.region;if(A){const g=(w=A==null?void 0:A.id)==null?void 0:w.toString();g?(I[p.Region]=g,I[p.RegionId]=g):I[p.Region]=A.code}c!=null&&c.street&&c.street.length>0&&c.street.forEach((g,S)=>{I[`${p.Street}${ee}${S}`]=g}),((c==null?void 0:c.customAttributes)||[]).forEach(g=>{F(g.code)?g.value.split(te).forEach((M,R)=>{I[`${g.code}${ee}${R}`]=M}):I[g.code]=g.value}),n({values:I,triggerAutoSave:h})},[t,e,d,i,a,v,u,n,r])}const Nt=Ne(({addressType:e,autoFill:t=!0,children:r,headingId:n,name:a,preselectedFields:s,saveAddressHandler:i,onCheckoutDataUpdate:u,...d},v)=>{const{data:c,pending:h}=Fe.value,F=Ie.value.data,I=F===void 0,A=c===void 0||h,l=Ee.value.data,w=l===void 0,{defaultValues:g}=Xe(l==null?void 0:l.defaultCountry),S=dt({fields:c,preselectedFields:s}),M=_e(null),{address:R,errors:D,loadAutoFill:$,onBlur:k,dismissError:f,onChange:m,onInvalid:E,onSelection:C,setAddress:ge}=lt({defaultValues:g,formRef:M,onCheckoutDataUpdate:u,preselection:S,saveAddressHandler:i,type:e}),{availableRegions:fe}=Je({country:R.country_id,addressType:e});if(De(v,()=>({triggerSaveAddress:pe=>{if(!M.current)return;const ve=je(M.current);if(ie(ve))return i({signal:pe,address:R})}})),Ke({addressType:e,autoFill:t,loadAutoFill:$,dismissError:f}),A||I||w)return o(We,{"data-testid":`${e}-skeleton`});const he=Oe({address:R,addressType:e,availableCountries:F,availableRegions:fe,config:l,dismissError:f,errors:D,fields:c,onBlur:k,onChange:m,onInvalid:E,onSelection:C,setAddress:ge}),Y={[L.SHIPPING]:"shipping",[L.BILLING]:"billing"};return o(Ze,{...d,name:a,addressType:e,className:`checkout-${Y[e]}-form`,"data-testid":`${Y[e]}-form`,fields:he,formRef:M,headingId:n})}),Ye="DROPIN__CHECKOUT",K=e=>`${Ye}__${e.toUpperCase()}`,Qe=(e,t)=>{window.localStorage.setItem(K(e),JSON.stringify(t))},et=e=>{const t=window.localStorage.getItem(K(e));return t?JSON.parse(t):null},tt=e=>{window.localStorage.removeItem(K(e))};function rt(e){const[t,r]=H(null),n=O(s=>setTimeout(()=>{Qe(e,s)},G),[e]),a=O(()=>{tt(e)},[e]);return x(()=>{const s=et(e);s&&r(s)},[e]),x(()=>{const s=ne.on("checkout/order",()=>{a()});return()=>{s==null||s.off()}},[a]),{addressBackup:t,backupAddress:n,removeAddressBackup:a}}const nt={[L.BILLING]:"billing",[L.SHIPPING]:"shipping"};function ot({address:e,type:t}){x(()=>{const r=setTimeout(()=>{ne.emit("checkout/address",{type:nt[t],address:e})},G);return()=>{clearTimeout(r)}},[e,t])}const at={badInput:"aria-label",patternMismatch:"aria-label",rangeOverflow:"max",rangeUnderflow:"min",tooLong:"maxlength",tooShort:"minlength",typeMismatch:"aria-label",valueMissing:"aria-label"},st=["badInput","patternMismatch","rangeOverflow","rangeUnderflow","tooLong","tooShort","typeMismatch","valueMissing"],it=e=>{const[t,r]=H({}),n=O(i=>{const{name:u,validity:d,validationMessage:v}=i;let c=d.valid?"":v;st.forEach(h=>{if(!d[h])return;const F=e[h];if(!F)return;const I=at[h];c=F.replace("{field}",i.getAttribute(I)||"")}),r(h=>({...h,[u]:c}))},[e]);return{errors:t,dismissError:i=>{t[i]&&r(u=>{const{[i]:d,...v}=u;return v})},validateFormElement:n,resetErrors:()=>{r({})}}},ct=e=>{const t=e.current;if(!t)return!1;const r=we(t);return ie(r)},lt=({defaultValues:e={},formRef:t,onCheckoutDataUpdate:r,preselection:n={},saveAddressHandler:a,type:s})=>{const i=Me({badInput:"Checkout.AddressForm.Validity.badInput",patternMismatch:"Checkout.AddressForm.Validity.patternMismatch",rangeUnderflow:"Checkout.AddressForm.Validity.rangeUnderflow",tooLong:"Checkout.AddressForm.Validity.tooLong",tooShort:"Checkout.AddressForm.Validity.tooShort",typeMismatch:"Checkout.AddressForm.Validity.typeMismatch",valueMissing:"Checkout.AddressForm.Validity.valueMissing"}),u=Se(!1),[d,v]=H({});ot({address:d,type:s});const{addressBackup:c,backupAddress:h,removeAddressBackup:F}=rt(s),{errors:I,validateFormElement:A,dismissError:l,resetErrors:w}=it(i),g=O(f=>{u.current=!1,a(f).then(()=>{F(),r==null||r()}).catch(m=>{u.current=!0,console.error("Saving address form failed:",m)})},[F,a,r]),S=(f,m)=>{v(E=>({...E,[f]:m})),u.current=!0},M=({values:f,triggerAutoSave:m=!1})=>{w(),v(E=>({...E,...f})),m&&(u.current=!0)},R=f=>{const m=f.target,{name:E,value:C}=m;S(E,C),A(m)},D=f=>{const m=f.target;A(m)},$=f=>{const m=f.target,{name:E,value:C}=m;S(E,C),A(m)},k=f=>{f.target.checkValidity()};return x(()=>{v(f=>({...e,...n,...c,...f}))},[e,n,c]),x(()=>{if(!u.current)return;const f=h(d);return()=>{clearTimeout(f)}},[d,h]),x(()=>{if(!u.current||!ct(t))return;const f=new AbortController,m=f.signal,E=setTimeout(()=>{g({signal:m,address:d})},G);return()=>{clearTimeout(E),f.abort()}},[d,t,g]),{address:d,errors:I,loadAutoFill:M,dismissError:l,onChange:R,onSelection:$,onBlur:k,onInvalid:D,setAddress:v}},ut={countryCode:p.Country,region:p.Region,postCode:p.PostCode};function dt({fields:e,preselectedFields:t}){return be(()=>!(!!e&&e.length>0)||!!!t?{}:Object.keys(t).reduce((a,s)=>{const i=ut[s];return!i||!e.some(d=>d.code===i)?a:{...a,[i]:t[s]}},{}),[e,t])}const mt=({addressType:e,customer:t})=>e===L.BILLING?t.defaultBillingAddress:t.defaultShippingAddress,gt=({addressType:e,cart:t})=>{if(e===L.BILLING)return t.billingAddress;const r=t.shippingAddresses;if(!(!r||r.length===0))return r[0]},le=()=>{const e=()=>window.innerWidth>=1920?"xxlarge":window.innerWidth>=1366?"xlarge":window.innerWidth>=1024?"large":window.innerWidth>=768?"medium":"small",[t,r]=H(e());return x(()=>{let n;const a=()=>{n&&clearTimeout(n),n=setTimeout(()=>r(e()),50)};return window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a),n&&clearTimeout(n)}},[]),t},ft=()=>{const e=O(()=>{document.body.style.overflow="hidden"},[]),t=O(()=>{document.body.style.overflow=""},[]);return{lockScroll:e,unlockScroll:t}},ue=({children:e,className:t})=>le()==="small"?o(T,{children:e}):o("div",{className:t,children:e}),ht=({sections:e})=>o(ue,{className:"checkout__aside",children:e.orderSummary&&o(y,{node:e.orderSummary})}),pt=({billingAddress:e,billToShippingAddress:t,login:r,outOfStock:n,paymentMethods:a,placeOrder:s,shippingAddress:i,shippingMethods:u})=>{const d=le();return B(T,{children:[o(y,{node:n}),o(y,{node:r}),i&&o(y,{node:i}),t&&o(y,{node:t}),u&&o(y,{node:u}),o(y,{node:a}),o(y,{node:e}),o(y,{node:s}),d==="small"&&o(y,{node:n})]})},vt=({sections:e})=>o(ue,{className:"checkout__main",children:B(T,{children:[B("div",{className:"checkout-heading",children:[o(me,{level:1,className:"checkout-heading__title",children:o(ae,{id:"Checkout.title"})}),o(ye,{variant:"primary",className:"checkout-heading__divider-primary"})]}),e&&o(pt,{...e})]})}),de=({children:e,className:t,isLoading:r=!1,...n})=>B("div",{"data-testid":"checkout",className:V(["checkout",t]),...n,children:[r&&o(Ft,{}),o(xe,{}),o(ze,{}),o("div",{className:"checkout__content",children:e})]});de.Main=vt;de.Aside=ht;const me=({className:e,children:t,level:r=2})=>{const n=r>=1&&r<=6?`h${r}`:"h2";return o(n,{className:e,children:t})},Ft=({className:e})=>{const{lockScroll:t,unlockScroll:r}=ft();return x(()=>(t(),r),[t,r]),o("div",{"data-testid":"checkout-overlay-loader",className:V(["checkout-overlay-loader",e]),children:o(Le,{})})};export{Nt as A,de as C,me as H,z as p};
|
package/chunks/ToggleButton2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@dropins/tools/event-bus.js";import{n as L}from"./fixtures.js";import{s as
|
|
1
|
+
import{jsxs as y,jsx as e,Fragment as z}from"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/event-bus.js";import{n as L}from"./fixtures.js";import{s as O}from"./setPaymentMethod.js";import{H as U}from"./ToggleButton.js";import"@dropins/tools/preact-hooks.js";import{classes as f,Slot as E}from"@dropins/tools/lib.js";import{Skeleton as $,SkeletonRow as v,IllustratedMessage as q,Icon as Z,ProgressSpinner as F,Divider as G,RadioButton as J}from"@dropins/tools/components.js";/* empty css */import*as M from"@dropins/tools/preact-compat.js";import{useState as P,useCallback as x,useEffect as N}from"@dropins/tools/preact-compat.js";import{useText as K}from"@dropins/tools/i18n.js";const Q=t=>M.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},M.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),M.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),M.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),X=()=>y($,{"data-testid":"payment-methods-skeleton",children:[e(v,{variant:"heading",size:"medium"}),e(v,{variant:"empty",size:"medium"}),e(v,{size:"xlarge",fullWidth:!0}),e(v,{size:"xlarge",fullWidth:!0})]}),Y=({code:t,isLoading:n,isSelected:d,onChange:s,title:o})=>e(te,{className:"checkout-payment-methods__method",label:o,name:"payment-method",value:t,selected:d,onChange:s,radioButtonProps:{"aria-busy":n}}),D=({className:t,paymentMethodContent:n,isLoading:d,onChange:s=()=>{},options:o,selection:u})=>{const l=K({Title:"Checkout.PaymentMethods.title",EmptyState:"Checkout.PaymentMethods.emptyState"});return o===void 0?e(X,{}):y("div",{className:f(["checkout-payment-methods",t]),children:[e(U,{level:2,className:"checkout-payment-methods__title",children:l.Title}),!d&&o.length===0&&e(q,{icon:e(Z,{source:Q}),message:e("p",{children:l.EmptyState})}),y("div",{className:f(["checkout-payment-methods__wrapper"]),children:[d&&e(F,{className:"checkout-payment-methods__spinner"}),e("div",{className:f(["checkout-payment-methods__methods",["checkout-payment-methods--loading",d],["checkout-payment-methods--full-width",o.length%2!==0]]),children:o==null?void 0:o.map(m=>e(Y,{code:m.code,onChange:s,isSelected:m.code===u,title:m.title},m.code))}),n&&e("div",{className:"checkout-payment-methods__content",children:n})]}),e(G,{variant:"primary"})]})},T={free:{render:t=>{const n=document.createElement("div");n.innerText="",t.replaceHTML(n)}},checkmo:{render:t=>{const n=document.createElement("div");n.innerText="",t.replaceHTML(n)}}};function ee(t){var w;const{onPlaceOrder:n,handleServerError:d,paymentMethodsSlot:s,isShippingInfoRequired:o}=t,[u,l]=P(),[m,g]=P(),[h,_]=P(T),[C,I]=P(!0),{data:a}=L.value,W=(a==null?void 0:a.id)??"",H=!!a,b=!!((w=a==null?void 0:a.shippingAddresses)!=null&&w[0]),i=a==null?void 0:a.availablePaymentMethods,c=a==null?void 0:a.selectedPaymentMethod,k=x(async r=>{try{if(l(r),!b&&o||r===(c==null?void 0:c.code))return;await O(r)}catch(p){console.error("setting payment method failed:",p)}},[b,o,c]);N(()=>{H&&(c!=null&&c.code?(i==null?void 0:i.some(p=>p.code===c.code))?l(c.code):i!=null&&i.length?k(i[0].code):l(void 0):i[0]&&k(m||i[0].code))},[i,H,c,k,m]);const B=async r=>{await k(r),c!=null&&c.code||g(r)},V=x((r,p)=>{if(!r){console.warn("Payment method handler is ignored because it has no code");return}if(!p){console.warn("Payment method handler is ignored because it is empty");return}_(R=>({...R,[r]:p}))},[]),j=s?e(E,{name:"PaymentMethods",slot:s,context:{addPaymentMethodHandler:V,replaceHTML(r){this.replaceWith(r),I(!1)}}}):null,S=u?h[u]:null,A=S?e(E,{name:"PaymentMethodContent",slot:S.render,context:{cartId:W,onPlaceOrder:n,handleServerError:d,replaceHTML(r){this.replaceWith(r)}}},S):void 0;return N(()=>{!C&&h!=T&&console.warn("Payment method handlers you have added are ignored because the default content has been replaced")},[C,h]),{availablePaymentMethods:i,selectedPaymentMethod:u,onPaymentMethodChange:B,paymentMethodContent:A,mainSlotContent:j,isDefaultContentUsed:C}}const ue=t=>{const{onPlaceOrder:n,handleServerError:d,paymentMethodsSlot:s,isShippingInfoRequired:o=!0}=t,{availablePaymentMethods:u,selectedPaymentMethod:l,onPaymentMethodChange:m,paymentMethodContent:g,mainSlotContent:h,isDefaultContentUsed:_}=ee({onPlaceOrder:n,handleServerError:d,paymentMethodsSlot:s,isShippingInfoRequired:o});return y(z,{children:[h&&e(h.type,{ref:h.ref,...h.props}),_&&e(D,{options:u,selection:l,onChange:m,paymentMethodContent:g,isLoading:L.value.pending})]})},te=({label:t,name:n,value:d,icon:s,selected:o,onChange:u,className:l,children:m,radioButtonProps:g,...h})=>e("div",{className:f(["checkout-toggle-button",l,["checkout-toggle-button__selected",o]]),...h,children:y("label",{className:"checkout-toggle-button__actionButton",children:[e(J,{...g,label:"",name:n,value:d,checked:o,onChange:()=>u(d),"aria-label":t,className:f([l,"checkout-toggle-button__radioButton"])}),y("div",{className:"checkout-toggle-button__content",children:[s&&e(s.type,{...s==null?void 0:s.props,className:"checkout-toggle-button__icon"}),t]})]})});export{ue as P};
|
package/chunks/fixtures.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{events as A}from"@dropins/tools/event-bus.js";import{Component as Z,options as X,isValidElement as z}from"@dropins/tools/preact.js";import{useMemo as F}from"@dropins/tools/preact-hooks.js";import{FetchGraphQL as Y}from"@dropins/tools/fetch-graphql.js";class J extends Error{constructor(t){super(t.map(i=>i.message).join(" ")),this.name="FetchError"}}class C extends Error{constructor(t){super(t),this.name="InvalidArgument"}}class we extends Error{constructor(t){super(t),this.name="UnexpectedError"}}class Ge extends C{constructor(){super("Cart ID is required")}}class Le extends C{constructor(){super("Email is required")}}class Re extends C{constructor(){super("Payment method code is required")}}class qe extends C{constructor(){super("Billing address is required")}}class Xe extends C{constructor(){super("Country Code is required")}}const U=e=>{throw e instanceof DOMException&&e.name==="AbortError"||A.emit("error",{source:"checkout",type:"network",error:e}),e};var K=Symbol.for("preact-signals");function G(){if(y>1)y--;else{for(var e,t=!1;T!==void 0;){var i=T;for(T=void 0,O++;i!==void 0;){var r=i.o;if(i.o=void 0,i.f&=-3,!(8&i.f)&&P(i))try{i.c()}catch(o){t||(e=o,t=!0)}i=r}}if(O=0,y--,t)throw e}}var n=void 0,T=void 0,y=0,O=0,I=0;function $(e){if(n!==void 0){var t=e.n;if(t===void 0||t.t!==n)return t={i:0,S:e,p:n.s,n:void 0,t:n,e:void 0,x:void 0,r:t},n.s!==void 0&&(n.s.n=t),n.s=t,e.n=t,32&n.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=n.s,t.n=void 0,n.s.n=t,n.s=t),t}}function l(e){this.v=e,this.i=0,this.n=void 0,this.t=void 0}l.prototype.brand=K;l.prototype.h=function(){return!0};l.prototype.S=function(e){this.t!==e&&e.e===void 0&&(e.x=this.t,this.t!==void 0&&(this.t.e=e),this.t=e)};l.prototype.U=function(e){if(this.t!==void 0){var t=e.e,i=e.x;t!==void 0&&(t.x=i,e.e=void 0),i!==void 0&&(i.e=t,e.x=void 0),e===this.t&&(this.t=i)}};l.prototype.subscribe=function(e){var t=this;return x(function(){var i=t.value,r=n;n=void 0;try{e(i)}finally{n=r}})};l.prototype.valueOf=function(){return this.value};l.prototype.toString=function(){return this.value+""};l.prototype.toJSON=function(){return this.value};l.prototype.peek=function(){var e=n;n=void 0;try{return this.value}finally{n=e}};Object.defineProperty(l.prototype,"value",{get:function(){var e=$(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(O>100)throw new Error("Cycle detected");this.v=e,this.i++,I++,y++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{G()}}}});function d(e){return new l(e)}function P(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function H(e){for(var t=e.s;t!==void 0;t=t.n){var i=t.S.n;if(i!==void 0&&(t.r=i),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function B(e){for(var t=e.s,i=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):i=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=i}function m(e){l.call(this,void 0),this.x=e,this.s=void 0,this.g=I-1,this.f=4}(m.prototype=new l).h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===I))return!0;if(this.g=I,this.f|=1,this.i>0&&!P(this))return this.f&=-2,!0;var e=n;try{H(this),n=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(i){this.v=i,this.f|=16,this.i++}return n=e,B(this),this.f&=-2,!0};m.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}l.prototype.S.call(this,e)};m.prototype.U=function(e){if(this.t!==void 0&&(l.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};m.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(m.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=$(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function ee(e){return new m(e)}function W(e){var t=e.u;if(e.u=void 0,typeof t=="function"){y++;var i=n;n=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,L(e),r}finally{n=i,G()}}}function L(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,W(e)}function te(e){if(n!==this)throw new Error("Out-of-order effect");B(this),n=e,this.f&=-2,8&this.f&&L(this),G()}function b(e){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}b.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{e()}};b.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,W(this),H(this),y++;var e=n;return n=this,te.bind(this,e)};b.prototype.N=function(){2&this.f||(this.f|=2,this.o=T,T=this)};b.prototype.d=function(){this.f|=8,1&this.f||L(this)};function x(e){var t=new b(e);try{t.c()}catch(i){throw t.d(),i}return t.d.bind(t)}var D;function S(e,t){X[e]=t.bind(null,X[e]||function(){})}function N(e){D&&D(),D=e&&e.S()}function Q(e){var t=this,i=e.data,r=re(i);r.value=i;var o=F(function(){for(var s=t.__v;s=s.__;)if(s.__c){s.__c.__$f|=4;break}return t.__$u.c=function(){var a;!z(o.peek())&&((a=t.base)==null?void 0:a.nodeType)===3?t.base.data=o.peek():(t.__$f|=1,t.setState({}))},ee(function(){var a=r.value.value;return a===0?0:a===!0?"":a||""})},[]);return o.value}Q.displayName="_st";Object.defineProperties(l.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Q},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});S("__b",function(e,t){if(typeof t.type=="string"){var i,r=t.props;for(var o in r)if(o!=="children"){var s=r[o];s instanceof l&&(i||(t.__np=i={}),i[o]=s,r[o]=s.peek())}}e(t)});S("__r",function(e,t){N();var i,r=t.__c;r&&(r.__$f&=-2,(i=r.__$u)===void 0&&(r.__$u=i=function(o){var s;return x(function(){s=this}),s.c=function(){r.__$f|=1,r.setState({})},s}())),N(i),e(t)});S("__e",function(e,t,i,r){N(),e(t,i,r)});S("diffed",function(e,t){N();var i;if(typeof t.type=="string"&&(i=t.__e)){var r=t.__np,o=t.props;if(r){var s=i.U;if(s)for(var a in s){var f=s[a];f!==void 0&&!(a in r)&&(f.d(),s[a]=void 0)}else i.U=s={};for(var u in r){var v=s[u],p=r[u];v===void 0?(v=ie(i,u,p,o),s[u]=v):v.o(p,o)}}}e(t)});function ie(e,t,i,r){var o=t in e&&e.ownerSVGElement===void 0,s=d(i);return{o:function(a,f){s.value=a,r=f},d:x(function(){var a=s.value.value;r[t]!==a&&(r[t]=a,o?e[t]=a:a?e.setAttribute(t,a):e.removeAttribute(t))})}}S("unmount",function(e,t){if(typeof t.type=="string"){var i=t.__e;if(i){var r=i.U;if(r){i.U=void 0;for(var o in r){var s=r[o];s&&s.d()}}}}else{var a=t.__c;if(a){var f=a.__$u;f&&(a.__$u=void 0,f.d())}}e(t)});S("__h",function(e,t,i,r){(r<3||r===9)&&(t.__$f|=2),e(t,i,r)});Z.prototype.shouldComponentUpdate=function(e,t){var i=this.__$u;if(!(i&&i.s!==void 0||4&this.__$f)||3&this.__$f)return!0;for(var r in t)return!0;for(var o in e)if(o!=="__source"&&e[o]!==this.props[o])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function re(e){return F(function(){return d(e)},[])}const se=d({checked:!0,setByUser:!1}),_=d({pending:!1,data:void 0});x(()=>{var e;(e=_.value.data)!=null&&e.isVirtual&&(se.value={checked:!1,setByUser:!1})});x(()=>{_.value.pending||(A.emit("checkout/data",_.value.data||null),_.value.data&&A.emit("cart/updated",_.value.data.id))});const oe=d({data:void 0,pending:!1}),ne=d({pending:!1,data:void 0}),ae=d({pending:!1,data:void 0}),le=d({pending:!1,data:void 0}),ue=d({data:void 0,pending:!1}),M=[];function fe(e){return new Promise((t,i)=>{M.push(e);const r=()=>{M[0]===e?e().then(t).catch(i).finally(()=>M.shift()):setTimeout(r,100)};r()})}const ce=["sender_email","recipient_email"];function de(e){return e.filter(t=>!t.path||!ce.some(i=>{var r;return((r=t.path)==null?void 0:r.at(-1))===i}))}const he={cart:_,customer:ne,estimateShippingMethods:ae,regions:le,storeConfig:ue,countryList:oe};function ve(e,t){return t.split(".").reduce((i,r)=>i&&i[r]!==void 0?i[r]:void 0,e)}const k={cart:null,customer:null,estimateShippingMethods:null,regions:null,storeConfig:null,countryList:null};async function pe(e){const{defaultValueOnFail:t,query:i,options:r,path:o,signalType:s,type:a,transformer:f}=e,u=he[s],v=Symbol();k[s]=v,u.value={...u.value,pending:!0};try{const{data:p,errors:R}=await(a==="mutation"?fe(()=>w(i,r).catch(U)):w(i,{method:"GET",cache:"no-cache",...r}).catch(U));if(R){const q=de(R);if(q.length>0)throw new J(q)}let E=ve(p,o);if(E===void 0)throw new Error(`No data found at path: ${o}`);return f&&(E=f(E)),u.value={...u.value,data:E},setTimeout(()=>{u.value={...u.value,pending:k[s]===v?!1:u.value.pending}},0),E}catch(p){if(t)return u.value={pending:!1,data:t},t;if(p.name==="AbortError")return;throw u.value={...u.value,pending:!1},p}}const _e={cartId:null,authenticated:!1},ke=new Proxy(_e,{set(e,t,i){return e[t]=i,!0},get(e,t){return e[t]}}),ge=e=>e?e.filter(Boolean).filter(i=>(i==null?void 0:i.label)&&(i==null?void 0:i.value)).map(i=>({text:i.label,value:i.value})):[],ye=e=>e?e.filter(Boolean).filter(t=>(t==null?void 0:t.name)&&(t==null?void 0:t.value)):[],me=e=>e?e.filter(Boolean).map(i=>({code:i.code,defaultValue:i.default_value||void 0,frontendInput:i.frontend_input||void 0,isDisabled:!1,isRequired:i.is_required,label:i.label||void 0,multilineCount:i.multiline_count||void 0,options:ge(i.options),sortOrder:i.sort_order||void 0,validateRules:ye(i.validate_rules)})):[],Se=e=>e==null,Ee=(e,t)=>e.amount.value-t.amount.value,j=e=>!(!e||!e.method_code||!e.method_title||Se(e.amount.value)||!e.amount.currency),V=e=>({amount:{value:e.amount.value,currency:e.amount.currency},title:e.method_title,code:e.method_code,carrier:{code:e.carrier_code,title:e.carrier_title},value:`${e.carrier_code} - ${e.method_code}`,...e.price_excl_tax&&{amountExclTax:{value:e.price_excl_tax.value,currency:e.price_excl_tax.currency}},...e.price_incl_tax&&{amountInclTax:{value:e.price_incl_tax.value,currency:e.price_incl_tax.currency}}}),Fe=e=>{if(j(e))return V(e)},$e=e=>{if(e)return e.filter(j).map(t=>V(t)).sort(Ee)},Te=`
|
|
1
|
+
import{events as k}from"@dropins/tools/event-bus.js";import{Component as V,options as O,isValidElement as z}from"@dropins/tools/preact.js";import{useMemo as $}from"@dropins/tools/preact-hooks.js";import{FetchGraphQL as Y}from"@dropins/tools/fetch-graphql.js";class J extends Error{constructor(i){super(i.map(t=>t.message).join(" ")),this.name="FetchError"}}class m extends Error{constructor(i){super(i),this.name="InvalidArgument"}}class Me extends Error{constructor(i){super(i),this.name="UnexpectedError"}}class Ue extends m{constructor(){super("Cart ID is required")}}class we extends m{constructor(){super("Email is required")}}class Ge extends m{constructor(){super("Payment method code is required")}}class Le extends m{constructor(){super("Billing address is required")}}class Ae extends m{constructor(){super("Country Code is required")}}const D=[];function K(e){return new Promise((i,t)=>{D.push(e);const r=()=>{D[0]===e?e().then(i).catch(t).finally(()=>D.shift()):setTimeout(r,100)};r()})}const ee=["sender_email","recipient_email"];function ie(e){return e.filter(i=>!i.path||!ee.some(t=>{var r;return((r=i.path)==null?void 0:r.at(-1))===t}))}const R=e=>{throw e instanceof DOMException&&e.name==="AbortError"||k.emit("error",{source:"checkout",type:"network",error:e}),e};var te=Symbol.for("preact-signals");function w(){if(g>1)g--;else{for(var e,i=!1;E!==void 0;){var t=E;for(E=void 0,U++;t!==void 0;){var r=t.o;if(t.o=void 0,t.f&=-3,!(8&t.f)&&F(t))try{t.c()}catch(o){i||(e=o,i=!0)}t=r}}if(U=0,g--,i)throw e}}var n=void 0,E=void 0,g=0,U=0,I=0;function P(e){if(n!==void 0){var i=e.n;if(i===void 0||i.t!==n)return i={i:0,S:e,p:n.s,n:void 0,t:n,e:void 0,x:void 0,r:i},n.s!==void 0&&(n.s.n=i),n.s=i,e.n=i,32&n.f&&e.S(i),i;if(i.i===-1)return i.i=0,i.n!==void 0&&(i.n.p=i.p,i.p!==void 0&&(i.p.n=i.n),i.p=n.s,i.n=void 0,n.s.n=i,n.s=i),i}}function l(e){this.v=e,this.i=0,this.n=void 0,this.t=void 0}l.prototype.brand=te;l.prototype.h=function(){return!0};l.prototype.S=function(e){this.t!==e&&e.e===void 0&&(e.x=this.t,this.t!==void 0&&(this.t.e=e),this.t=e)};l.prototype.U=function(e){if(this.t!==void 0){var i=e.e,t=e.x;i!==void 0&&(i.x=t,e.e=void 0),t!==void 0&&(t.e=i,e.x=void 0),e===this.t&&(this.t=t)}};l.prototype.subscribe=function(e){var i=this;return x(function(){var t=i.value,r=n;n=void 0;try{e(t)}finally{n=r}})};l.prototype.valueOf=function(){return this.value};l.prototype.toString=function(){return this.value+""};l.prototype.toJSON=function(){return this.value};l.prototype.peek=function(){var e=n;n=void 0;try{return this.value}finally{n=e}};Object.defineProperty(l.prototype,"value",{get:function(){var e=P(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(U>100)throw new Error("Cycle detected");this.v=e,this.i++,I++,g++;try{for(var i=this.t;i!==void 0;i=i.x)i.t.N()}finally{w()}}}});function d(e){return new l(e)}function F(e){for(var i=e.s;i!==void 0;i=i.n)if(i.S.i!==i.i||!i.S.h()||i.S.i!==i.i)return!0;return!1}function H(e){for(var i=e.s;i!==void 0;i=i.n){var t=i.S.n;if(t!==void 0&&(i.r=t),i.S.n=i,i.i=-1,i.n===void 0){e.s=i;break}}}function W(e){for(var i=e.s,t=void 0;i!==void 0;){var r=i.p;i.i===-1?(i.S.U(i),r!==void 0&&(r.n=i.n),i.n!==void 0&&(i.n.p=r)):t=i,i.S.n=i.r,i.r!==void 0&&(i.r=void 0),i=r}e.s=t}function y(e){l.call(this,void 0),this.x=e,this.s=void 0,this.g=I-1,this.f=4}(y.prototype=new l).h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===I))return!0;if(this.g=I,this.f|=1,this.i>0&&!F(this))return this.f&=-2,!0;var e=n;try{H(this),n=this;var i=this.x();(16&this.f||this.v!==i||this.i===0)&&(this.v=i,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return n=e,W(this),this.f&=-2,!0};y.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var i=this.s;i!==void 0;i=i.n)i.S.S(i)}l.prototype.S.call(this,e)};y.prototype.U=function(e){if(this.t!==void 0&&(l.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var i=this.s;i!==void 0;i=i.n)i.S.U(i)}};y.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(y.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=P(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function re(e){return new y(e)}function B(e){var i=e.u;if(e.u=void 0,typeof i=="function"){g++;var t=n;n=void 0;try{i()}catch(r){throw e.f&=-2,e.f|=8,G(e),r}finally{n=t,w()}}}function G(e){for(var i=e.s;i!==void 0;i=i.n)i.S.U(i);e.x=void 0,e.s=void 0,B(e)}function se(e){if(n!==this)throw new Error("Out-of-order effect");W(this),n=e,this.f&=-2,8&this.f&&G(this),w()}function C(e){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}C.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var i=this.x();typeof i=="function"&&(this.u=i)}finally{e()}};C.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,B(this),H(this),g++;var e=n;return n=this,se.bind(this,e)};C.prototype.N=function(){2&this.f||(this.f|=2,this.o=E,E=this)};C.prototype.d=function(){this.f|=8,1&this.f||G(this)};function x(e){var i=new C(e);try{i.c()}catch(t){throw i.d(),t}return i.d.bind(i)}var M;function S(e,i){O[e]=i.bind(null,O[e]||function(){})}function N(e){M&&M(),M=e&&e.S()}function Q(e){var i=this,t=e.data,r=ne(t);r.value=t;var o=$(function(){for(var s=i.__v;s=s.__;)if(s.__c){s.__c.__$f|=4;break}return i.__$u.c=function(){var a;!z(o.peek())&&((a=i.base)==null?void 0:a.nodeType)===3?i.base.data=o.peek():(i.__$f|=1,i.setState({}))},re(function(){var a=r.value.value;return a===0?0:a===!0?"":a||""})},[]);return o.value}Q.displayName="_st";Object.defineProperties(l.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Q},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});S("__b",function(e,i){if(typeof i.type=="string"){var t,r=i.props;for(var o in r)if(o!=="children"){var s=r[o];s instanceof l&&(t||(i.__np=t={}),t[o]=s,r[o]=s.peek())}}e(i)});S("__r",function(e,i){N();var t,r=i.__c;r&&(r.__$f&=-2,(t=r.__$u)===void 0&&(r.__$u=t=function(o){var s;return x(function(){s=this}),s.c=function(){r.__$f|=1,r.setState({})},s}())),N(t),e(i)});S("__e",function(e,i,t,r){N(),e(i,t,r)});S("diffed",function(e,i){N();var t;if(typeof i.type=="string"&&(t=i.__e)){var r=i.__np,o=i.props;if(r){var s=t.U;if(s)for(var a in s){var u=s[a];u!==void 0&&!(a in r)&&(u.d(),s[a]=void 0)}else t.U=s={};for(var f in r){var p=s[f],v=r[f];p===void 0?(p=oe(t,f,v,o),s[f]=p):p.o(v,o)}}}e(i)});function oe(e,i,t,r){var o=i in e&&e.ownerSVGElement===void 0,s=d(t);return{o:function(a,u){s.value=a,r=u},d:x(function(){var a=s.value.value;r[i]!==a&&(r[i]=a,o?e[i]=a:a?e.setAttribute(i,a):e.removeAttribute(i))})}}S("unmount",function(e,i){if(typeof i.type=="string"){var t=i.__e;if(t){var r=t.U;if(r){t.U=void 0;for(var o in r){var s=r[o];s&&s.d()}}}}else{var a=i.__c;if(a){var u=a.__$u;u&&(a.__$u=void 0,u.d())}}e(i)});S("__h",function(e,i,t,r){(r<3||r===9)&&(i.__$f|=2),e(i,t,r)});V.prototype.shouldComponentUpdate=function(e,i){var t=this.__$u;if(!(t&&t.s!==void 0||4&this.__$f)||3&this.__$f)return!0;for(var r in i)return!0;for(var o in e)if(o!=="__source"&&e[o]!==this.props[o])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function ne(e){return $(function(){return d(e)},[])}const ae=d({data:void 0,pending:!1}),le=d({checked:!0,setByUser:!1}),b=d({pending:!1,data:void 0});x(()=>{var e;(e=b.value.data)!=null&&e.isVirtual&&(le.value={checked:!1,setByUser:!1})});x(()=>{b.value.pending||k.emit("checkout/data",b.value.data||null)});const fe=d({data:void 0,pending:!1}),ue=d({pending:!1,data:void 0}),ce=d({pending:!1,data:void 0}),de=d({pending:!1,data:void 0}),he=d({data:void 0,pending:!1}),pe={cart:b,customer:ue,estimateShippingMethods:ce,regions:de,storeConfig:he,countryList:fe,addressFormFields:ae};function ve(e,i){return i.split(".").reduce((t,r)=>t&&t[r]!==void 0?t[r]:void 0,e)}const X={cart:null,customer:null,estimateShippingMethods:null,regions:null,storeConfig:null,countryList:null,addressFormFields:null};async function _e(e){const{defaultValueOnFail:i,query:t,options:r,path:o,signalType:s,type:a,transformer:u}=e,f=pe[s],p=Symbol();X[s]=p,f.value={...f.value,pending:!0};try{const{data:v,errors:L}=await(a==="mutation"?K(()=>q(t,r).catch(R)):q(t,{method:"GET",cache:"no-cache",...r}).catch(R));if(L){const A=ie(L);if(A.length>0)throw new J(A)}let T=ve(v,o);if(T===void 0)throw new Error(`No data found at path: ${o}`);return u&&(T=u(T)),f.value={...f.value,data:T},setTimeout(()=>{f.value={...f.value,pending:X[s]===p?!1:f.value.pending}},0),T}catch(v){if(i)return f.value={pending:!1,data:i},i;if(v.name==="AbortError")return;throw f.value={...f.value,pending:!1},v}}const ge={cartId:null,authenticated:!1},Oe=new Proxy(ge,{set(e,i,t){return e[i]=t,!0},get(e,i){return e[i]}}),ye=e=>e==null,Se=(e,i)=>e.amount.value-i.amount.value,j=e=>!(!e||!e.method_code||!e.method_title||ye(e.amount.value)||!e.amount.currency),Z=e=>({amount:{value:e.amount.value,currency:e.amount.currency},title:e.method_title,code:e.method_code,carrier:{code:e.carrier_code,title:e.carrier_title},value:`${e.carrier_code} - ${e.method_code}`,...e.price_excl_tax&&{amountExclTax:{value:e.price_excl_tax.value,currency:e.price_excl_tax.currency}},...e.price_incl_tax&&{amountInclTax:{value:e.price_incl_tax.value,currency:e.price_incl_tax.currency}}}),Re=e=>{if(j(e))return Z(e)},Xe=e=>{if(e)return e.filter(j).map(i=>Z(i)).sort(Se)},Te=`
|
|
2
2
|
query getStoreConfig {
|
|
3
3
|
storeConfig {
|
|
4
4
|
countries_with_required_region
|
|
@@ -12,33 +12,4 @@ import{events as A}from"@dropins/tools/event-bus.js";import{Component as Z,optio
|
|
|
12
12
|
store_code
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
`;var
|
|
16
|
-
query fetchAddressFormFields {
|
|
17
|
-
attributesForm(formCode: "customer_register_address") {
|
|
18
|
-
items {
|
|
19
|
-
frontend_input
|
|
20
|
-
code
|
|
21
|
-
label
|
|
22
|
-
default_value
|
|
23
|
-
is_required
|
|
24
|
-
options {
|
|
25
|
-
label
|
|
26
|
-
value
|
|
27
|
-
is_default
|
|
28
|
-
}
|
|
29
|
-
... on CustomerAttributeMetadata {
|
|
30
|
-
multiline_count
|
|
31
|
-
sort_order
|
|
32
|
-
validate_rules {
|
|
33
|
-
name
|
|
34
|
-
value
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
errors {
|
|
39
|
-
message
|
|
40
|
-
type
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`,Ne=e=>{if(!(!e||e.length===0))throw Error(e.map(t=>t.message).join(" "))},Ve=async()=>w(Ie,{method:"GET",cache:"no-cache"}).then(({data:e,errors:t})=>(Ne(t),me(e.attributesForm.items))).catch(U);var c=(e=>(e.Boolean="BOOLEAN",e.Date="DATE",e.Datetime="DATETIME",e.File="FILE",e.Gallery="GALLERY",e.Hidden="HIDDEN",e.Image="IMAGE",e.MediaImage="MEDIA_IMAGE",e.Multiline="MULTILINE",e.Multiselect="MULTISELECT",e.Price="PRICE",e.Select="SELECT",e.Text="TEXT",e.Textarea="TEXTAREA",e.Undefined="UNDEFINED",e.Weight="WEIGHT",e))(c||{}),De=(e=>(e.DateRangeMax="DATE_RANGE_MAX",e.DateRangeMin="DATE_RANGE_MIN",e.FileExtensions="FILE_EXTENSIONS",e.InputValidation="INPUT_VALIDATION",e.MaxFileSize="MAX_FILE_SIZE",e.MaxImageHeight="MAX_IMAGE_HEIGHT",e.MaxImageWidth="MAX_IMAGE_WIDTH",e.MaxTextLength="MAX_TEXT_LENGTH",e.MinTextLength="MIN_TEXT_LENGTH",e))(De||{});const Ze=[{frontendInput:c.Text,code:"firstname",label:"First Name",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:10},{frontendInput:c.Text,code:"lastname",label:"Last Name",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:20},{frontendInput:c.Text,code:"company",label:"Company",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:30},{frontendInput:c.Multiline,code:"street",label:"Street Address",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:40},{frontendInput:c.Text,code:"city",label:"City",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:50},{frontendInput:c.Select,code:"country_id",label:"Country",isRequired:!0,isDisabled:!1,options:[{text:"United States",value:"US"},{text:"Spain",value:"ES"},{text:"France",value:"FR"}],validateRules:[],sortOrder:60},{frontendInput:c.Text,code:"region",label:"State/Province",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:70},{frontendInput:c.Hidden,code:"region_id",label:"State/Province",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:80},{frontendInput:c.Text,code:"postcode",label:"Zip/Postal Code",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:90},{frontendInput:c.Text,code:"telephone",label:"Phone Number",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:100},{frontendInput:c.Text,code:"vat_id",label:"VAT Number",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:110}];export{c as A,oe as B,Ce as D,J as F,C as I,Ge as M,h as S,g as T,we as U,De as V,Le as a,Re as b,qe as c,Xe as d,Be as e,Qe as f,w as g,je as h,Ve as i,Ze as j,Pe as k,se as l,ne as m,_ as n,ke as o,pe as p,ue as q,We as r,He as s,$e as t,Fe as u,U as v,Ne as w,d as x,ae as y,le as z};
|
|
15
|
+
`;var _=(e=>(e.EXCLUDING_TAX="EXCLUDING_TAX",e.INCLUDING_EXCLUDING_TAX="INCLUDING_AND_EXCLUDING_TAX",e.INCLUDING_TAX="INCLUDING_TAX",e))(_||{});const Ee="US",h={defaultCountry:Ee,countriesWithRequiredRegion:[],displayStateIfOptional:!1,countriesWithOptionalZipCode:[],isGuestCheckoutEnabled:!1,isOnePageCheckoutEnabled:!1,shoppingCartDisplaySetting:{shipping:_.EXCLUDING_TAX}},qe=async()=>await _e({type:"query",query:Te,options:{method:"GET",cache:"no-cache"},path:"storeConfig",signalType:"storeConfig",transformer:Ce,defaultValueOnFail:h});function me(e){switch(e){case 1:return _.EXCLUDING_TAX;case 2:return _.INCLUDING_TAX;case 3:return _.INCLUDING_EXCLUDING_TAX;default:return _.EXCLUDING_TAX}}function Ce(e){if(!e)return h;const{default_country:i,countries_with_required_region:t,display_state_if_optional:r,optional_zip_countries:o,is_guest_checkout_enabled:s,is_one_page_checkout_enabled:a,shopping_cart_display_shipping:u}=e;return{defaultCountry:i||h.defaultCountry,countriesWithRequiredRegion:(t==null?void 0:t.split(","))||h.countriesWithRequiredRegion,displayStateIfOptional:r||h.displayStateIfOptional,countriesWithOptionalZipCode:(o==null?void 0:o.split(","))||h.countriesWithOptionalZipCode,isGuestCheckoutEnabled:s||h.isGuestCheckoutEnabled,isOnePageCheckoutEnabled:a||h.isOnePageCheckoutEnabled,shoppingCartDisplaySetting:{shipping:me(u)}}}const{setEndpoint:ke,setFetchGraphQlHeader:$e,removeFetchGraphQlHeader:Pe,setFetchGraphQlHeaders:Fe,fetchGraphQl:q,getConfig:He}=new Y().getMethods();var c=(e=>(e.Boolean="BOOLEAN",e.Date="DATE",e.Datetime="DATETIME",e.File="FILE",e.Gallery="GALLERY",e.Hidden="HIDDEN",e.Image="IMAGE",e.MediaImage="MEDIA_IMAGE",e.Multiline="MULTILINE",e.Multiselect="MULTISELECT",e.Price="PRICE",e.Select="SELECT",e.Text="TEXT",e.Textarea="TEXTAREA",e.Undefined="UNDEFINED",e.Weight="WEIGHT",e))(c||{}),xe=(e=>(e.DateRangeMax="DATE_RANGE_MAX",e.DateRangeMin="DATE_RANGE_MIN",e.FileExtensions="FILE_EXTENSIONS",e.InputValidation="INPUT_VALIDATION",e.MaxFileSize="MAX_FILE_SIZE",e.MaxImageHeight="MAX_IMAGE_HEIGHT",e.MaxImageWidth="MAX_IMAGE_WIDTH",e.MaxTextLength="MAX_TEXT_LENGTH",e.MinTextLength="MIN_TEXT_LENGTH",e))(xe||{});const We=[{frontendInput:c.Text,code:"firstname",label:"First Name",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:10},{frontendInput:c.Text,code:"lastname",label:"Last Name",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:20},{frontendInput:c.Text,code:"company",label:"Company",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:30},{frontendInput:c.Multiline,code:"street",label:"Street Address",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:40},{frontendInput:c.Text,code:"city",label:"City",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:50},{frontendInput:c.Select,code:"country_id",label:"Country",isRequired:!0,isDisabled:!1,options:[{text:"United States",value:"US"},{text:"Spain",value:"ES"},{text:"France",value:"FR"}],validateRules:[],sortOrder:60},{frontendInput:c.Text,code:"region",label:"State/Province",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:70},{frontendInput:c.Hidden,code:"region_id",label:"State/Province",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:80},{frontendInput:c.Text,code:"postcode",label:"Zip/Postal Code",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:90},{frontendInput:c.Text,code:"telephone",label:"Phone Number",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:100},{frontendInput:c.Text,code:"vat_id",label:"VAT Number",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:110}];export{c as A,Ee as D,J as F,m as I,Ue as M,h as S,_ as T,Me as U,xe as V,we as a,Ge as b,Le as c,Ae as d,$e as e,Fe as f,q as g,He as h,We as i,qe as j,le as k,ae as l,ue as m,b as n,Oe as o,_e as p,he as q,Pe as r,ke as s,Xe as t,Re as u,R as v,d as w,ce as x,de as y,fe as z};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as _,M as y,d as h,p as g,t as l,
|
|
1
|
+
import{o as _,M as y,d as h,p as g,t as l,y as I}from"./fixtures.js";import"@dropins/tools/event-bus.js";const m=`
|
|
2
2
|
mutation estimateShippingMethods(
|
|
3
3
|
$cartId: String!
|
|
4
4
|
$address: EstimateAddressInput!
|
package/chunks/placeOrder2.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as
|
|
1
|
+
import{o as T,M as w,g as A,v as k,n as D,F as L,U as R}from"./fixtures.js";import{events as f}from"@dropins/tools/event-bus.js";const V=n=>({id:T.cartId,totalQuantity:n.totalQuantity,possibleOnepageCheckout:!0,items:n.items.map(a=>{var t;return{canApplyMsrp:!0,formattedPrice:"",id:a.id,quantity:a.totalQuantity,product:{canonicalUrl:a.product.canonicalUrl||"",mainImageUrl:a.product.image||"",name:a.product.name,productId:0,productType:a.product.productType,sku:a.product.sku},prices:{price:{value:a.price.value,currency:a.price.currency}},configurableOptions:((t=a.selectedOptions)==null?void 0:t.map(i=>({optionLabel:i.label,valueLabel:i.value})))||[]}})}),q=n=>{var i,c,l;const a=n.coupons[0],t=(i=n.payments)==null?void 0:i[0];return{appliedCouponCode:(a==null?void 0:a.code)||"",email:n.email,grandTotal:n.total,orderId:n.number,orderType:"checkout",otherTax:0,salesTax:n.totalTax,shipping:{shippingMethod:((c=n.shipping)==null?void 0:c.code)||"",shippingAmount:((l=n.shipping)==null?void 0:l.amount)||0},subtotalExcludingTax:n.subtotal,subtotalIncludingTax:0,payments:t?[{paymentMethodCode:(t==null?void 0:t.code)||"",paymentMethodName:(t==null?void 0:t.name)||"",total:n.total}]:[]}},Q=n=>n||0,S=n=>{var a;return{canonicalUrl:(n==null?void 0:n.canonical_url)||"",id:(n==null?void 0:n.uid)||"",name:(n==null?void 0:n.name)||"",sku:(n==null?void 0:n.sku)||"",image:((a=n==null?void 0:n.image)==null?void 0:a.url)||"",productType:(n==null?void 0:n.__typename)||""}};function M(n){if(!n||!("selected_options"in n))return;const a={};for(const t of n.selected_options)a[t.label]=t.value;return a}const P=n=>n?n.map(a=>{var t,i,c,l,u,s,e,p,_,o,y,g,h,v;return{type:a==null?void 0:a.__typename,id:a==null?void 0:a.id,discounted:(a==null?void 0:a.product.price_range.maximum_price.regular_price.value)*(a==null?void 0:a.quantity_ordered)!==(a==null?void 0:a.product_sale_price.value)*(a==null?void 0:a.quantity_ordered),total:{value:(a==null?void 0:a.product_sale_price.value)*(a==null?void 0:a.quantity_ordered),currency:a==null?void 0:a.product_sale_price.currency},totalInclTax:{value:(a==null?void 0:a.product_sale_price.value)*(a==null?void 0:a.quantity_ordered),currency:a==null?void 0:a.product_sale_price.currency},price:{value:a==null?void 0:a.product_sale_price.value,currency:a==null?void 0:a.product_sale_price.currency},priceInclTax:{value:a==null?void 0:a.product_sale_price.value,currency:a==null?void 0:a.product_sale_price.currency},totalQuantity:Q(a==null?void 0:a.quantity_ordered),regularPrice:{value:(c=(i=(t=a==null?void 0:a.product)==null?void 0:t.price_range)==null?void 0:i.maximum_price)==null?void 0:c.regular_price.value,currency:(s=(u=(l=a==null?void 0:a.product)==null?void 0:l.price_range)==null?void 0:u.maximum_price)==null?void 0:s.regular_price.currency},product:S(a==null?void 0:a.product),thumbnail:{label:((p=(e=a==null?void 0:a.product)==null?void 0:e.thumbnail)==null?void 0:p.label)||"",url:((o=(_=a==null?void 0:a.product)==null?void 0:_.thumbnail)==null?void 0:o.url)||""},giftCard:(a==null?void 0:a.__typename)==="GiftCardOrderItem"?{senderName:((y=a.gift_card)==null?void 0:y.sender_name)||"",senderEmail:((g=a.gift_card)==null?void 0:g.sender_email)||"",recipientEmail:((h=a.gift_card)==null?void 0:h.recipient_email)||"",recipientName:((v=a.gift_card)==null?void 0:v.recipient_name)||""}:void 0,configurableOptions:M(a)}}):[];function U(n){return n!==null&&n.value!==void 0}const C=n=>n?{city:n.city,company:n.company||"",country:n.country_code||"",firstName:n.firstname,middleName:n.middlename||"",lastName:n.lastname,postCode:n.postcode||"",regionId:n.region_id||"",region:n.region||"",street:n.street.filter(a=>a!==null),telephone:n.telephone||"",customAttributes:n.custom_attributesV2.filter(U).map(a=>({code:a.code,value:a.value}))}:null,G=n=>{var u,s,e,p,_,o,y,g,h,v;const a=(u=n.payment_methods)==null?void 0:u[0],t=(a==null?void 0:a.type)??"",i=(a==null?void 0:a.name)??"",c=P(n.items),l=c.reduce((b,N)=>b+N.totalQuantity,0);return{status:n.status,isVirtual:n.is_virtual,coupons:((s=n==null?void 0:n.applied_coupons)==null?void 0:s.map(b=>({code:(b==null?void 0:b.code)??""})))||[],email:n.email??"",items:c,number:n.number,token:n.token,grandTotal:{value:((e=n.total)==null?void 0:e.grand_total.value)??0,currency:((p=n.total)==null?void 0:p.grand_total.currency)||""},totalQuantity:l,totalTax:{value:((_=n.total)==null?void 0:_.total_tax.value)??0,currency:((o=n.total)==null?void 0:o.total_tax.currency)||""},subtotal:{value:((y=n.total)==null?void 0:y.subtotal.value)??0,currency:((g=n.total)==null?void 0:g.subtotal.currency)||""},shipping:{amount:((h=n.total)==null?void 0:h.total_shipping.value)??0,currency:((v=n.total)==null?void 0:v.total_shipping.currency)||"",code:n.shipping_method??""},payments:[{code:t,name:i}],shippingAddress:C(n.shipping_address),billingAddress:C(n.billing_address)}},F=`
|
|
2
2
|
mutation placeOrder($cartId: String!) {
|
|
3
3
|
placeOrder(input: { cart_id: $cartId }) {
|
|
4
4
|
orderV2 {
|
|
@@ -110,12 +110,7 @@ import{o as E,M as w,g as A,v as k,n as D,F as L,U as R}from"./fixtures.js";impo
|
|
|
110
110
|
value
|
|
111
111
|
currency
|
|
112
112
|
}
|
|
113
|
-
quantity_canceled
|
|
114
|
-
quantity_invoiced
|
|
115
113
|
quantity_ordered
|
|
116
|
-
quantity_refunded
|
|
117
|
-
quantity_returned
|
|
118
|
-
quantity_shipped
|
|
119
114
|
... on GiftCardOrderItem {
|
|
120
115
|
gift_card {
|
|
121
116
|
recipient_name
|
|
@@ -129,4 +124,4 @@ import{o as E,M as w,g as A,v as k,n as D,F as L,U as R}from"./fixtures.js";impo
|
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
126
|
}
|
|
132
|
-
`,
|
|
127
|
+
`,x={SHOPPING_CART_CONTEXT:"shoppingCartContext",ORDER_CONTEXT:"orderContext"},X={PLACE_ORDER:"place-order"};function E(){return window.adobeDataLayer=window.adobeDataLayer||[],window.adobeDataLayer}function O(n,a){const t=E();t.push({[n]:null}),t.push({[n]:a})}function $(n,a){E().push(i=>{const c=i.getState?i.getState():{};i.push({event:n,eventInfo:{...c,...a}})})}function H(n){const a=V(n),t=q(n);console.debug({shoppingCartContext:a,orderContext:t}),O(x.SHOPPING_CART_CONTEXT,{...a}),O(x.ORDER_CONTEXT,{...t}),$(X.PLACE_ORDER)}function j(n){throw n.every(t=>{var i;return(i=t.extensions)==null?void 0:i.category})?new L(n):new R(n[0].message)}const J=async()=>{const n=T.cartId;if(!n)throw new w;const{data:a,errors:t}=await A(F,{variables:{cartId:n}}).catch(k);t&&j(t);const i=G(a.placeOrder.orderV2);return H(i),f.emit("checkout/order",i),D.value={pending:!1,data:null},f.emit("cart/reset",void 0),i};export{J as p};
|