@dropins/storefront-checkout 2.0.0-beta2 → 2.0.0-beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{t as S,a as f,b as E}from"./chunks/synchronizeCheckout.js";import{d as j,c as Y,g as J,i as W,e as X,r as Z,s as tt}from"./chunks/synchronizeCheckout.js";import{s as p,M as l,c as I,d as c,Q as A,a as M,e as T}from"./chunks/errors.js";import{D as st,F as it,I as rt,p as at,n as nt,o as ot,S as dt,U as pt,k as ct,l as gt,m as ht,g as mt,r as _t,f as ut,i as lt,j as At}from"./chunks/errors.js";import"@dropins/tools/lib.js";import{a as y}from"./chunks/setShippingMethods.js";import{s as St}from"./chunks/setShippingMethods.js";import"@dropins/tools/event-bus.js";import{A as O}from"./chunks/checkout.js";import{g as Et,i as It,s as Mt}from"./chunks/setGuestEmailOnCart.js";import{s as yt}from"./chunks/setBillingAddress.js";import{s as xt}from"./chunks/setPaymentMethod.js";import{CHECKOUT_DATA_FRAGMENT as C}from"./fragments.js";import{g as x}from"./chunks/values.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const G=`
3
+ import{t as y,a as O,b as x}from"./chunks/synchronizeCheckout.js";import{d as et,c as st,g as it,i as rt,e as nt,r as at,s as ot}from"./chunks/synchronizeCheckout.js";import{s as g,M as S,b as G,d as m,Q as C,c as N}from"./chunks/errors.js";import{D as pt,F as ct,I as ht,o as gt,m as mt,n as _t,S as lt,U as ut,j as At,k as ft,l as St,g as Ct,r as Mt,e as Et,f as It,i as Tt}from"./chunks/errors.js";import"@dropins/tools/lib.js";import{t as $,a as v}from"./chunks/setShippingMethods.js";import{s as Ot}from"./chunks/setShippingMethods.js";import{g as M}from"./chunks/values.js";import{events as U}from"@dropins/tools/event-bus.js";import{A as F}from"./chunks/checkout.js";import{g as Gt,i as Nt,s as $t}from"./chunks/setGuestEmailOnCart.js";import{s as Ut}from"./chunks/setBillingAddress.js";import{s as bt}from"./chunks/setPaymentMethod.js";import{CHECKOUT_DATA_FRAGMENT as E}from"./fragments.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const b=`
4
4
  mutation estimateShippingMethods(
5
5
  $cartId: String!
6
6
  $address: EstimateAddressInput!
@@ -26,7 +26,7 @@ import{t as S,a as f,b as E}from"./chunks/synchronizeCheckout.js";import{d as j,
26
26
  error_message
27
27
  }
28
28
  }
29
- `,N=e=>e?e.filter(t=>!!t).map(t=>({id:t.agreement_id,name:t.name,mode:O[t.mode],text:t.checkbox_text,content:{value:t.content,html:t.is_html,height:t.content_height??null}})):[],K=async e=>{var h,m,_,u;const t=p.cartId,r=((h=e==null?void 0:e.criteria)==null?void 0:h.country_code)??((m=p.config)==null?void 0:m.defaultCountry);if(!t)throw new l;if(!r)throw new I;const{region_id:s,region_name:o,zip:a}=(e==null?void 0:e.criteria)??{},i=s||o?{region_id:typeof s=="string"?parseInt(s,10):s,region_code:o}:void 0,n={country_code:r,...a&&{postcode:a},...i&&{region:{...i.region_id&&{region_id:i.region_id},...i.region_code&&{region_code:i.region_code}}}},d={country_id:r,region:(_=n.region)==null?void 0:_.region_code,region_id:(u=n.region)==null?void 0:u.region_id,postcode:a},g=await c({options:{variables:{cartId:t,address:n}},path:"estimateShippingMethods",query:G,queueName:A.ShippingEstimate,transformer:S,type:"mutation"});return M.value={address:y(d),options:g},g},$=`
29
+ `,w=e=>e?e.filter(t=>!!t).map(t=>({id:t.agreement_id,name:t.name,mode:F[t.mode],text:t.checkbox_text,content:{value:t.content,html:t.is_html,height:t.content_height??null}})):[],J=async e=>{var _,l,u,A;const t=g.cartId,r=((_=e==null?void 0:e.criteria)==null?void 0:_.country_code)??((l=g.config)==null?void 0:l.defaultCountry);if(!t)throw new S;if(!r)throw new G;const{region_id:s,region_name:p,zip:n}=(e==null?void 0:e.criteria)??{},i=s||p?{region_id:typeof s=="string"?parseInt(s,10):s,region_code:p}:void 0,o={country_code:r,...n&&{postcode:n},...i&&{region:{...i.region_id&&{region_id:i.region_id},...i.region_code&&{region_code:i.region_code}}}},c={country_id:r,region:(u=o.region)==null?void 0:u.region_code,region_id:(A=o.region)==null?void 0:A.region_id,postcode:n},d=await m({options:{variables:{cartId:t,address:o}},path:"estimateShippingMethods",query:b,queueName:C.ShippingEstimate,transformer:y,type:"mutation"}),I=d.length>0,T=v(c);let h=null;if(I){const a=M("selectedShippingMethod");h=d.find(f=>f.code===(a==null?void 0:a.code)&&f.carrier.code===(a==null?void 0:a.carrier.code))??d[0]}return U.emit("shipping/estimate",{address:T,shippingMethod:h?$(h):null,availableShippingMethods:d}),d},k=`
30
30
  query GET_CHECKOUT_AGREEMENTS {
31
31
  checkoutAgreements {
32
32
  agreement_id
@@ -38,7 +38,7 @@ import{t as S,a as f,b as E}from"./chunks/synchronizeCheckout.js";import{d as j,
38
38
  name
39
39
  }
40
40
  }
41
- `,P=async()=>await c({defaultValueOnFail:[],options:{method:"GET",cache:"no-cache"},path:"checkoutAgreements",query:$,transformer:N,type:"query"}),U=`
41
+ `,W=async()=>await m({defaultValueOnFail:[],options:{method:"GET",cache:"no-cache"},path:"checkoutAgreements",query:k,transformer:w,type:"query"}),D=`
42
42
  mutation setShippingAddress(
43
43
  $cartId: String!
44
44
  $shippingAddressInput: ShippingAddressInput!
@@ -52,8 +52,8 @@ import{t as S,a as f,b as E}from"./chunks/synchronizeCheckout.js";import{d as j,
52
52
  }
53
53
  }
54
54
 
55
- ${C}
56
- `,v=`
55
+ ${E}
56
+ `,H=`
57
57
  mutation SET_SHIPPING_ADDRESS_ON_CART_AND_USE_AS_BILLING_MUTATION(
58
58
  $cartId: String!
59
59
  $shippingAddressInput: ShippingAddressInput!
@@ -75,5 +75,5 @@ import{t as S,a as f,b as E}from"./chunks/synchronizeCheckout.js";import{d as j,
75
75
  }
76
76
  }
77
77
 
78
- ${C}
79
- `,z=async({address:e,customerAddressId:t,pickupLocationCode:r})=>{const s=p.cartId;if(!s)throw new l;const o=()=>{if(t)return{customer_address_id:t};if(r)return{pickup_location_code:r};if(!e)throw new T;return{address:f(e)}},a=x("isBillToShipping"),i=a?v:U,n=a?"setBillingAddressOnCart.cart":"setShippingAddressesOnCart.cart",d={cartId:s,shippingAddressInput:o()};return await c({type:"mutation",query:i,options:{variables:d},path:n,queueName:A.CartUpdate,transformer:E})};export{st as DEFAULT_COUNTRY,it as FetchError,rt as InvalidArgument,at as MissingBillingAddress,l as MissingCart,I as MissingCountry,nt as MissingEmail,ot as MissingPaymentMethod,T as MissingShippinghAddress,dt as STORE_CONFIG_DEFAULTS,pt as UnexpectedError,j as authenticateCustomer,Y as config,K as estimateShippingMethods,ct as fetchGraphQl,J as getCart,P as getCheckoutAgreements,gt as getConfig,Et as getCustomer,ht as getStoreConfig,mt as getStoreConfigCache,W as initialize,X as initializeCheckout,It as isEmailAvailable,_t as removeFetchGraphQlHeader,Z as resetCheckout,yt as setBillingAddress,ut as setEndpoint,lt as setFetchGraphQlHeader,At as setFetchGraphQlHeaders,Mt as setGuestEmailOnCart,xt as setPaymentMethod,z as setShippingAddress,St as setShippingMethodsOnCart,tt as synchronizeCheckout};
78
+ ${E}
79
+ `,X=async({address:e,customerAddressId:t,pickupLocationCode:r})=>{const s=g.cartId;if(!s)throw new S;const p=()=>{if(t)return{customer_address_id:t};if(r)return{pickup_location_code:r};if(!e)throw new N;return{address:O(e)}},n=M("isBillToShipping"),i=n?H:D,o=n?"setBillingAddressOnCart.cart":"setShippingAddressesOnCart.cart",c={cartId:s,shippingAddressInput:p()};return await m({type:"mutation",query:i,options:{variables:c},path:o,queueName:C.CartUpdate,transformer:x})};export{pt as DEFAULT_COUNTRY,ct as FetchError,ht as InvalidArgument,gt as MissingBillingAddress,S as MissingCart,G as MissingCountry,mt as MissingEmail,_t as MissingPaymentMethod,N as MissingShippinghAddress,lt as STORE_CONFIG_DEFAULTS,ut as UnexpectedError,et as authenticateCustomer,st as config,J as estimateShippingMethods,At as fetchGraphQl,it as getCart,W as getCheckoutAgreements,ft as getConfig,Gt as getCustomer,St as getStoreConfig,Ct as getStoreConfigCache,rt as initialize,nt as initializeCheckout,Nt as isEmailAvailable,Mt as removeFetchGraphQlHeader,at as resetCheckout,Ut as setBillingAddress,Et as setEndpoint,It as setFetchGraphQlHeader,Tt as setFetchGraphQlHeaders,$t as setGuestEmailOnCart,bt as setPaymentMethod,X as setShippingAddress,Ot as setShippingMethodsOnCart,ot as synchronizeCheckout};
package/chunks/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import"@dropins/tools/lib.js";import{events as C}from"@dropins/tools/event-bus.js";import{signal as E,computed as I}from"@dropins/tools/signals.js";import{FetchGraphQL as w}from"@dropins/tools/fetch-graphql.js";const A={authenticated:!1,cartId:null,initialized:!1,config:null},N=new Proxy(A,{set(e,t,s){return e[t]=s,!0},get(e,t){return e[t]}}),V=()=>N.config;var i=(e=>(e.EXCLUDING_TAX="EXCLUDING_TAX",e.INCLUDING_EXCLUDING_TAX="INCLUDING_AND_EXCLUDING_TAX",e.INCLUDING_TAX="INCLUDING_TAX",e))(i||{}),S=(e=>(e.CartUpdate="cartUpdate",e.Default="default",e.ShippingEstimate="shippingEstimate",e))(S||{});const d=new Map,g=new Map,c=E(new Set),U=new Map;U.set("cartUpdate",e=>{C.emit("checkout/updated",e)});async function D(e){g.set(e,!0);const t=d.get(e);let s;for(;t.length>0;){const o=t.shift();try{const n=await o.requestFn();o.resolve(n),s=n}catch(n){o.reject(n)}}g.set(e,!1);const r=new Set(c.value);r.delete(e),c.value=r;const a=U.get(e);a&&s&&a(s)}function G(e,t="default"){d.has(t)||d.set(t,[]);const s=d.get(t),r=new Promise((o,n)=>{s.push({requestFn:e,resolve:o,reject:n})}),a=new Set(c.value);return a.add(t),c.value=a,g.get(t)||D(t),r}const B=I(()=>c.value.has("cartUpdate")),z=I(()=>c.value.has("shippingEstimate")),q=["sender_email","recipient_email"];function X(e){return e.filter(t=>!t.path||!q.some(s=>{var r;return((r=t.path)==null?void 0:r.at(-1))===s}))}const v=e=>{throw e instanceof DOMException&&e.name==="AbortError"||C.emit("error",{source:"checkout",type:"network",error:e}),e};function T(e,t){return t.split(".").reduce((s,r)=>s&&s[r]!==void 0?s[r]:void 0,e)}async function L(e){const{defaultValueOnFail:t,options:s,path:r,query:a,queueName:o,transformer:n,type:p}=e;try{const l=async()=>{const{data:y,errors:_}=await k(a,{method:p==="query"?"GET":"POST",cache:p==="query"?"no-cache":void 0,...s}).catch(v);if(_){const m=X(_);if(m.length>0)throw new P(m)}let h=T(y,r);if(h===void 0)throw new Error(`No data found at path: ${r}`);return n?n(h):h};return p==="mutation"?await G(l,o):await l()}catch(l){if(t!==void 0)return t;throw l}}const x=`
3
+ import"@dropins/tools/lib.js";import{events as m}from"@dropins/tools/event-bus.js";import{signal as y,computed as E}from"@dropins/tools/signals.js";import{FetchGraphQL as w}from"@dropins/tools/fetch-graphql.js";const A={authenticated:!1,cartId:null,initialized:!1,config:null},N=new Proxy(A,{set(e,t,r){return e[t]=r,!0},get(e,t){return e[t]}}),V=()=>N.config;var i=(e=>(e.EXCLUDING_TAX="EXCLUDING_TAX",e.INCLUDING_EXCLUDING_TAX="INCLUDING_AND_EXCLUDING_TAX",e.INCLUDING_TAX="INCLUDING_TAX",e))(i||{}),D=(e=>(e.CartUpdate="cartUpdate",e.Default="default",e.ShippingEstimate="shippingEstimate",e))(D||{});const d=new Map,g=new Map,c=y(new Set),I=new Map;I.set("cartUpdate",e=>{m.emit("checkout/updated",e)});async function G(e){g.set(e,!0);const t=d.get(e);let r;for(;t.length>0;){const o=t.shift();try{const n=await o.requestFn();o.resolve(n),r=n}catch(n){o.reject(n)}}g.set(e,!1);const s=new Set(c.value);s.delete(e),c.value=s;const a=I.get(e);a&&r&&a(r)}function S(e,t="default"){d.has(t)||d.set(t,[]);const r=d.get(t),s=new Promise((o,n)=>{r.push({requestFn:e,resolve:o,reject:n})}),a=new Set(c.value);return a.add(t),c.value=a,g.get(t)||G(t),s}const B=E(()=>c.value.has("cartUpdate")),z=E(()=>c.value.has("shippingEstimate")),q=["sender_email","recipient_email"];function X(e){return e.filter(t=>!t.path||!q.some(r=>{var s;return((s=t.path)==null?void 0:s.at(-1))===r}))}const v=e=>{throw e instanceof DOMException&&e.name==="AbortError"||m.emit("error",{source:"checkout",type:"network",error:e}),e};function T(e,t){return t.split(".").reduce((r,s)=>r&&r[s]!==void 0?r[s]:void 0,e)}async function L(e){const{defaultValueOnFail:t,options:r,path:s,query:a,queueName:o,transformer:n,type:p}=e;try{const l=async()=>{const{data:U,errors:_}=await k(a,{method:p==="query"?"GET":"POST",cache:p==="query"?"no-cache":void 0,...r}).catch(v);if(_){const C=X(_);if(C.length>0)throw new P(C)}let h=T(U,s);if(h===void 0)throw new Error(`No data found at path: ${s}`);return n?n(h):h};return p==="mutation"?await S(l,o):await l()}catch(l){if(t!==void 0)return t;throw l}}const x=`
4
4
  query getStoreConfig {
5
5
  storeConfig {
6
6
  default_country
@@ -10,4 +10,4 @@ import"@dropins/tools/lib.js";import{events as C}from"@dropins/tools/event-bus.j
10
10
  shopping_cart_display_shipping
11
11
  }
12
12
  }
13
- `,F="US",f={defaultCountry:F,agreementsEnabled:!0,shoppingCartDisplaySetting:{shipping:i.EXCLUDING_TAX}},Y=async()=>await L({defaultValueOnFail:f,options:{method:"GET",cache:"no-cache"},path:"storeConfig",query:x,transformer:b,type:"query"});function M(e){switch(e){case 1:return i.EXCLUDING_TAX;case 2:return i.INCLUDING_TAX;case 3:return i.INCLUDING_EXCLUDING_TAX;default:return i.EXCLUDING_TAX}}function b(e){if(!e)return f;const{default_country:t,is_checkout_agreements_enabled:s,shopping_cart_display_shipping:r}=e;return{defaultCountry:t||f.defaultCountry,agreementsEnabled:s,shoppingCartDisplaySetting:{shipping:M(r)}}}const $=E(),{setEndpoint:J,setFetchGraphQlHeader:K,removeFetchGraphQlHeader:W,setFetchGraphQlHeaders:Z,fetchGraphQl:k,getConfig:ee}=new w().getMethods();class P extends Error{constructor(t){super(t.map(s=>s.message).join(" ")),this.name="FetchError"}}class u extends Error{constructor(t){super(t),this.name="InvalidArgument"}}class te extends Error{constructor(t){super(t),this.name="UnexpectedError"}}class se extends u{constructor(){super("Cart ID is required")}}class re extends u{constructor(){super("Email is required")}}class ne extends u{constructor(){super("Payment method code is required")}}class ae extends u{constructor(){super("Shipping address is required")}}class oe extends u{constructor(){super("Billing address is required")}}class ie extends u{constructor(){super("Country Code is required")}}export{F as D,P as F,u as I,se as M,S as Q,f as S,i as T,te as U,$ as a,z as b,ie as c,L as d,ae as e,J as f,V as g,B as h,K as i,Z as j,k,ee as l,Y as m,re as n,ne as o,oe as p,W as r,N as s};
13
+ `,F="US",f={defaultCountry:F,agreementsEnabled:!0,shoppingCartDisplaySetting:{shipping:i.EXCLUDING_TAX}},Y=async()=>await L({defaultValueOnFail:f,options:{method:"GET",cache:"no-cache"},path:"storeConfig",query:x,transformer:b,type:"query"});function M(e){switch(e){case 1:return i.EXCLUDING_TAX;case 2:return i.INCLUDING_TAX;case 3:return i.INCLUDING_EXCLUDING_TAX;default:return i.EXCLUDING_TAX}}function b(e){if(!e)return f;const{default_country:t,is_checkout_agreements_enabled:r,shopping_cart_display_shipping:s}=e;return{defaultCountry:t||f.defaultCountry,agreementsEnabled:r,shoppingCartDisplaySetting:{shipping:M(s)}}}const{setEndpoint:$,setFetchGraphQlHeader:J,removeFetchGraphQlHeader:K,setFetchGraphQlHeaders:W,fetchGraphQl:k,getConfig:Z}=new w().getMethods();class P extends Error{constructor(t){super(t.map(r=>r.message).join(" ")),this.name="FetchError"}}class u extends Error{constructor(t){super(t),this.name="InvalidArgument"}}class ee extends Error{constructor(t){super(t),this.name="UnexpectedError"}}class te extends u{constructor(){super("Cart ID is required")}}class re extends u{constructor(){super("Email is required")}}class se extends u{constructor(){super("Payment method code is required")}}class ne extends u{constructor(){super("Shipping address is required")}}class ae extends u{constructor(){super("Billing address is required")}}class oe extends u{constructor(){super("Country Code is required")}}export{F as D,P as F,u as I,te as M,D as Q,f as S,i as T,ee as U,z as a,oe as b,ne as c,L as d,$ as e,J as f,V as g,B as h,W as i,k as j,Z as k,Y as l,re as m,se as n,ae as o,K as r,N as s};
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{CHECKOUT_DATA_FRAGMENT as e}from"../fragments.js";import{a as d,b as l}from"./synchronizeCheckout.js";import{s as o,M as p,p as u,d as _,Q as f}from"./errors.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const m=`
3
+ import{CHECKOUT_DATA_FRAGMENT as e}from"../fragments.js";import{a as d,b as l}from"./synchronizeCheckout.js";import{s as o,M as p,o as u,d as _,Q as f}from"./errors.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const m=`
4
4
  mutation setBillingAddress($input: SetBillingAddressOnCartInput!) {
5
5
  setBillingAddressOnCart(input: $input) {
6
6
  cart {
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{CUSTOMER_FRAGMENT as o,CHECKOUT_DATA_FRAGMENT as n}from"../fragments.js";import{s as m,d as r,n as l,M as u,Q as c}from"./errors.js";import"@dropins/tools/event-bus.js";import{merge as E}from"@dropins/tools/lib.js";import{c as f,b as p}from"./synchronizeCheckout.js";const C=t=>{var i,e,s;if(!t)return null;const a={firstName:t.firstname||"",lastName:t.lastname||"",email:t.email||""};return E(a,(s=(e=(i=f.getConfig().models)==null?void 0:i.CustomerModel)==null?void 0:e.transformer)==null?void 0:s.call(e,t))},y=t=>!!(t!=null&&t.is_email_available),A=`
3
+ import{CUSTOMER_FRAGMENT as o,CHECKOUT_DATA_FRAGMENT as n}from"../fragments.js";import{s as m,d as r,m as l,M as u,Q as c}from"./errors.js";import"@dropins/tools/event-bus.js";import{merge as E}from"@dropins/tools/lib.js";import{c as f,b as p}from"./synchronizeCheckout.js";const C=t=>{var i,e,s;if(!t)return null;const a={firstName:t.firstname||"",lastName:t.lastname||"",email:t.email||""};return E(a,(s=(e=(i=f.getConfig().models)==null?void 0:i.CustomerModel)==null?void 0:e.transformer)==null?void 0:s.call(e,t))},y=t=>!!(t!=null&&t.is_email_available),A=`
4
4
  query getCustomer {
5
5
  customer {
6
6
  ...CUSTOMER_FRAGMENT
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{CHECKOUT_DATA_FRAGMENT as e}from"../fragments.js";import{b as r}from"./synchronizeCheckout.js";import{s as o,M as n,o as s,d as m,Q as i}from"./errors.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const d=`
3
+ import{CHECKOUT_DATA_FRAGMENT as e}from"../fragments.js";import{b as r}from"./synchronizeCheckout.js";import{s as n,M as o,n as s,d as m,Q as i}from"./errors.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";const d=`
4
4
  mutation setPaymentMethod(
5
5
  $cartId: String!
6
6
  $paymentMethod: PaymentMethodInput!
@@ -15,4 +15,4 @@ import{CHECKOUT_DATA_FRAGMENT as e}from"../fragments.js";import{b as r}from"./sy
15
15
  }
16
16
 
17
17
  ${e}
18
- `,u=async t=>{const a=o.cartId;if(!a)throw new n;if(!t)throw new s;return await m({options:{variables:{cartId:a,paymentMethod:t}},path:"setPaymentMethodOnCart.cart",query:d,queueName:i.CartUpdate,transformer:r,type:"mutation"})};export{u as s};
18
+ `,u=async t=>{const a=n.cartId;if(!a)throw new o;if(!t)throw new s;return await m({options:{variables:{cartId:a,paymentMethod:t}},path:"setPaymentMethodOnCart.cart",query:d,queueName:i.CartUpdate,transformer:r,type:"mutation"})};export{u as s};
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{s as r,M as h,d as g,m as y}from"./errors.js";import{merge as v,Initializer as C}from"@dropins/tools/lib.js";import{events as o}from"@dropins/tools/event-bus.js";import{CHECKOUT_DATA_FRAGMENT as c}from"../fragments.js";const A=async(e=!1)=>{r.authenticated=e},x=(e,t)=>e.amount.value-t.amount.value,b=e=>e==null,l=e=>!(!e||!e.method_code||!e.method_title||b(e.amount.value)||!e.amount.currency),u=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}}}),I=e=>{if(l(e))return u(e)},M=e=>e?e.filter(l).map(t=>u(t)).sort(x):[],T=e=>e?!!e.code&&!!e.label:!1,S=e=>{if(!T(e))return;const{code:t,label:i,region_id:n}=e;return n?{code:t,name:i,id:n}:{code:t,name:i}},N=e=>{const{code:t,label:i}=e;return{value:t,label:i}},k=e=>e?"code"in e&&"value"in e:!1,z=e=>e.filter(k).map(t=>{const{code:i,value:n}=t;return{code:i,value:n}}),a=e=>{const t=e.street.filter(Boolean);return{id:(e==null?void 0:e.id)||void 0,city:e.city,company:e.company||void 0,country:N(e.country),customAttributes:z(e.custom_attributes),firstName:e.firstname,lastName:e.lastname,postCode:e.postcode||void 0,region:S(e.region),street:t,telephone:e.telephone||void 0,vatId:e.vat_id||void 0,prefix:e.prefix||void 0,suffix:e.suffix||void 0,middleName:e.middlename||void 0,fax:e.fax||void 0}},E=e=>{if(e)return a(e)},w=e=>e.filter(t=>!!t).map(t=>{const{available_shipping_methods:i,selected_shipping_method:n,same_as_billing:s,..._}=t;return{...a(_),availableShippingMethods:M(i),selectedShippingMethod:I(n),sameAsBilling:s}}),U=e=>({city:e.city,company:e.company,country_code:e.countryCode,custom_attributes:e.customAttributes.map(t=>({attribute_code:t.code,value:t.value})),firstname:e.firstName,lastname:e.lastName,postcode:e.postcode,region:e.region,region_id:e.regionId,save_in_address_book:e.saveInAddressBook??!0,street:e.street,telephone:e.telephone,vat_id:e.vatId,prefix:e.prefix,suffix:e.suffix,middlename:e.middleName,fax:e.fax}),P=e=>{if(e)return{code:e.code,title:e.title}},$=e=>{if(e)return e.filter(t=>!!t).map(t=>{const{code:i,title:n}=t;return{code:i,title:n}})},q=e=>{var i,n,s;if(!e)return;const t={availablePaymentMethods:$(e.available_payment_methods),billingAddress:E(e.billing_address),email:e.email??void 0,id:e.id,isEmpty:e.total_quantity===0,isVirtual:e.is_virtual,selectedPaymentMethod:P(e.selected_payment_method),shippingAddresses:w(e.shipping_addresses),isGuest:!r.authenticated};return v(t,(s=(n=(i=R.getConfig().models)==null?void 0:i.CartModel)==null?void 0:n.transformer)==null?void 0:s.call(n,e))},B=`
3
+ import{s as r,M as h,d as g,l as y}from"./errors.js";import{merge as v,Initializer as C}from"@dropins/tools/lib.js";import{events as o}from"@dropins/tools/event-bus.js";import{CHECKOUT_DATA_FRAGMENT as c}from"../fragments.js";const A=async(e=!1)=>{r.authenticated=e},x=(e,t)=>e.amount.value-t.amount.value,b=e=>e==null,l=e=>!(!e||!e.method_code||!e.method_title||b(e.amount.value)||!e.amount.currency),u=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}}}),I=e=>{if(l(e))return u(e)},M=e=>e?e.filter(l).map(t=>u(t)).sort(x):[],T=e=>e?!!e.code&&!!e.label:!1,S=e=>{if(!T(e))return;const{code:t,label:i,region_id:n}=e;return n?{code:t,name:i,id:n}:{code:t,name:i}},N=e=>{const{code:t,label:i}=e;return{value:t,label:i}},k=e=>e?"code"in e&&"value"in e:!1,z=e=>e.filter(k).map(t=>{const{code:i,value:n}=t;return{code:i,value:n}}),a=e=>{const t=e.street.filter(Boolean);return{id:(e==null?void 0:e.id)||void 0,city:e.city,company:e.company||void 0,country:N(e.country),customAttributes:z(e.custom_attributes),firstName:e.firstname,lastName:e.lastname,postCode:e.postcode||void 0,region:S(e.region),street:t,telephone:e.telephone||void 0,vatId:e.vat_id||void 0,prefix:e.prefix||void 0,suffix:e.suffix||void 0,middleName:e.middlename||void 0,fax:e.fax||void 0}},E=e=>{if(e)return a(e)},w=e=>e.filter(t=>!!t).map(t=>{const{available_shipping_methods:i,selected_shipping_method:n,same_as_billing:s,..._}=t;return{...a(_),availableShippingMethods:M(i),selectedShippingMethod:I(n),sameAsBilling:s}}),U=e=>({city:e.city,company:e.company,country_code:e.countryCode,custom_attributes:e.customAttributes.map(t=>({attribute_code:t.code,value:t.value})),firstname:e.firstName,lastname:e.lastName,postcode:e.postcode,region:e.region,region_id:e.regionId,save_in_address_book:e.saveInAddressBook??!0,street:e.street,telephone:e.telephone,vat_id:e.vatId,prefix:e.prefix,suffix:e.suffix,middlename:e.middleName,fax:e.fax}),P=e=>{if(e)return{code:e.code,title:e.title}},$=e=>{if(e)return e.filter(t=>!!t).map(t=>{const{code:i,title:n}=t;return{code:i,title:n}})},q=e=>{var i,n,s;if(!e)return;const t={availablePaymentMethods:$(e.available_payment_methods),billingAddress:E(e.billing_address),email:e.email??void 0,id:e.id,isEmpty:e.total_quantity===0,isVirtual:e.is_virtual,selectedPaymentMethod:P(e.selected_payment_method),shippingAddresses:w(e.shipping_addresses),isGuest:!r.authenticated};return v(t,(s=(n=(i=R.getConfig().models)==null?void 0:i.CartModel)==null?void 0:n.transformer)==null?void 0:s.call(n,e))},B=`
4
4
  query getCart($cartId: String!) {
5
5
  cart(cart_id: $cartId) {
6
6
  ...CHECKOUT_DATA_FRAGMENT
@@ -1,9 +1,10 @@
1
1
  import { Container } from '@dropins/tools/types/elsie/src/lib';
2
2
 
3
3
  export interface BillToShippingAddressProps {
4
- onChange?: (checked: boolean) => void;
5
4
  active?: boolean;
6
5
  autoSync?: boolean;
6
+ onChange?: (checked: boolean) => void;
7
+ onError?: (error: unknown) => void;
7
8
  }
8
9
  export declare const BillToShippingAddress: Container<BillToShippingAddressProps>;
9
10
  //# sourceMappingURL=BillToShippingAddress.d.ts.map
@@ -1,3 +1,3 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsx as p}from"@dropins/tools/preact-jsx-runtime.js";import{h as x}from"../chunks/errors.js";import"@dropins/tools/lib.js";import{events as f}from"@dropins/tools/event-bus.js";import{W as _,h as z,g as I}from"../chunks/ConditionalWrapper.js";import{n as h}from"../chunks/values.js";import{s as V}from"../chunks/setBillingAddress.js";/* empty css */import{Skeleton as E,SkeletonRow as N,Checkbox as U}from"@dropins/tools/components.js";import{c as w}from"../chunks/classes.js";import{useText as y}from"@dropins/tools/i18n.js";import{useState as m,useRef as D,useCallback as g,useEffect as k}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const P=()=>p(E,{className:"bill-to-shipping-address__skeleton","data-testid":"bill-to-shipping-skeleton",children:p(N,{size:"small",variant:"row"})}),R=({className:s,checked:e,disabled:r,onChange:c})=>{const l=y({title:"Checkout.BillToShippingAddress.title"});return p("div",{className:"checkout-bill-to-shipping-address",children:p(U,{checked:e,className:w(["checkout-bill-to-shipping-address__checkbox",s]),"data-testid":"bill-to-shipping-checkbox",disabled:r,label:l.title,name:"checkout-bill-to-shipping-address__checkbox",onChange:c})})},W=_(R,P);function j(s){var l;const e=(l=s.shippingAddresses)==null?void 0:l[0],r=!!s.billingAddress;return(e==null?void 0:e.sameAsBilling)??!r}const ii=({onChange:s,active:e=!0,autoSync:r=!0})=>{const[c,l]=m(!1),[B,S]=m(!1),[b,a]=m(!0),d=D(!1),A=x.value,T=g(i=>{const t=i.target.checked;a(t),s==null||s(t),h({isBillToShipping:t}),r&&t&&z()&&V({sameAsShipping:!0}).catch(console.error)},[r,s]),n=g(i=>{const o=!i||(i==null?void 0:i.isEmpty),t=!!(i!=null&&i.isVirtual);if(o||t){S(t),a(!1),h({isBillToShipping:!1}),d.current=!1;return}if(!d.current){const u=j(i);a(u),d.current=!0,s==null||s(u),h({isBillToShipping:u})}},[s]);return k(()=>{if(!e)return;const i=I();if(i){l(!0),n(i);return}const o=f.on("checkout/initialized",t=>{l(!0),n(t)},{eager:!0});return()=>{o==null||o.off()}},[e,n]),k(()=>{if(!e)return;const i=f.on("checkout/updated",n,{eager:!1});return()=>{i==null||i.off()}},[e,n]),p(W,{checked:b,disabled:A,initialized:c,visible:e&&!B,onChange:T})};export{ii as BillToShippingAddress,ii as default};
3
+ import{jsx as a}from"@dropins/tools/preact-jsx-runtime.js";import{h as C}from"../chunks/errors.js";import"@dropins/tools/lib.js";import{events as f}from"@dropins/tools/event-bus.js";import{n as _}from"../chunks/values.js";import{W as z,h as I,g as V}from"../chunks/ConditionalWrapper.js";import{s as N}from"../chunks/setBillingAddress.js";/* empty css */import{Skeleton as U,SkeletonRow as w,Checkbox as y}from"@dropins/tools/components.js";import{c as D}from"../chunks/classes.js";import{useText as P}from"@dropins/tools/i18n.js";import{useState as h,useRef as R,useCallback as u,useEffect as g}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const W=()=>a(U,{className:"bill-to-shipping-address__skeleton","data-testid":"bill-to-shipping-skeleton",children:a(w,{size:"small",variant:"row"})}),j=({className:i,checked:t,disabled:l,onChange:n})=>{const r=P({title:"Checkout.BillToShippingAddress.title"});return a("div",{className:"checkout-bill-to-shipping-address",children:a(y,{checked:t,className:D(["checkout-bill-to-shipping-address__checkbox",i]),"data-testid":"bill-to-shipping-checkbox",disabled:l,label:r.title,name:"checkout-bill-to-shipping-address__checkbox",onChange:n})})},L=z(j,W);function $(i){var r;const t=(r=i.shippingAddresses)==null?void 0:r[0],l=!!i.billingAddress;return(t==null?void 0:t.sameAsBilling)??!l}const es=({active:i=!0,autoSync:t=!0,onChange:l,onError:n})=>{const[r,m]=h(!1),[k,b]=h(!1),[B,A]=h(!0),d=R(!1),S=C.value,c=u(s=>{A(e=>e===s?e:(l==null||l(s),s)),_({isBillToShipping:s})},[l]),T=u(s=>{const o=s.target.checked;c(o),!(!t||!o||!I())&&N({sameAsShipping:!0}).catch(x=>{c(!1),n==null||n(x)})},[t,n,c]),p=u(s=>{const e=!s||(s==null?void 0:s.isEmpty),o=!!(s!=null&&s.isVirtual);if(e||o){b(o),c(!1),d.current=!1;return}d.current||(c($(s)),d.current=!0)},[c]);return g(()=>{if(!i)return;const s=V();if(s){m(!0),p(s);return}const e=f.on("checkout/initialized",o=>{m(!0),p(o)},{eager:!0});return()=>{e==null||e.off()}},[i,p]),g(()=>{if(!i)return;const s=f.on("checkout/updated",p,{eager:!1});return()=>{s==null||s.off()}},[i,p]),a(L,{checked:B,disabled:S,initialized:r,visible:i&&!k,onChange:T})};export{es as BillToShippingAddress,es as default};
@@ -1,3 +1,3 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsx as i,jsxs as k}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Skeleton as B,SkeletonRow as U,Price as h}from"@dropins/tools/components.js";import{W as z,g as G}from"../chunks/ConditionalWrapper.js";import"../chunks/TermsAndConditions.js";import{VComponent as C,classes as I}from"@dropins/tools/lib.js";import{useText as _}from"@dropins/tools/i18n.js";/* empty css *//* empty css *//* empty css */import{s as P,T as D}from"../chunks/errors.js";import{events as d}from"@dropins/tools/event-bus.js";import{useState as V,useCallback as b,useEffect as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const X=()=>i(B,{"data-testid":"estimate-shipping-skeleton",children:i(U,{size:"xsmall"})}),j=({label:n,price:t,priceExclTax:a,taxExcluded:o=!1,taxIncluded:c=!1})=>{const l=_({withTaxes:"Checkout.EstimateShipping.withTaxes",withoutTaxes:"Checkout.EstimateShipping.withoutTaxes"});return k("div",{className:"checkout-estimate-shipping","data-testid":"estimate-shipping",children:[i(C,{className:"checkout-estimate-shipping__label",node:n}),i(C,{className:"checkout-estimate-shipping__price",node:t}),c&&i("span",{className:I(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included",children:l.withTaxes}),o&&k("span",{className:I(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included-excluded",children:[a," ",l.withoutTaxes]})]})},v=z(j,X),nt=({active:n=!0})=>{var T;const[t,a]=V(),o=(t==null?void 0:t.amount.value)===0,c=(T=P.config)==null?void 0:T.shoppingCartDisplaySetting.shipping,l=c===D.INCLUDING_EXCLUDING_TAX,g=c===D.INCLUDING_TAX,u=_({freeShipping:"Checkout.EstimateShipping.freeShipping",taxToBeDetermined:"Checkout.EstimateShipping.taxToBeDetermined",label:"Checkout.EstimateShipping.label",estimated:"Checkout.EstimateShipping.estimated"}),r=b(e=>{var S;const s=!e||e.isEmpty,p=!!(e!=null&&e.isVirtual);if(s||p){a(null);return}const m=(S=e.shippingAddresses)==null?void 0:S[0];if(!m)return;const E=m==null?void 0:m.selectedShippingMethod;if(!E){a(null);return}const{amount:w,amountExclTax:L,amountInclTax:M}=E;a({estimated:!1,amount:w,amountExclTax:L,amountInclTax:M})},[]),f=b(e=>{let s=null;if(e.shippingMethod){const p=e.shippingMethod;s={estimated:!0,amount:p.amount,amountExclTax:p.amountExclTax,amountInclTax:p.amountInclTax}}a(s)},[]);x(()=>{if(!n)return;const e=d.on("shipping/estimate",f,{eager:!0});return()=>{e==null||e.off()}},[n,f]),x(()=>{if(!n)return;const e=G();if(e){r(e);return}const s=d.on("checkout/initialized",r,{eager:!0});return()=>{s==null||s.off()}},[n,r]),x(()=>{if(!n)return;const e=d.on("checkout/updated",r,{eager:!1});return()=>{e==null||e.off()}},[n,r]);const y=()=>o?i("span",{"data-testId":"free-shipping",children:u.freeShipping}):g&&(t!=null&&t.amountInclTax)?i(h,{amount:t.amountInclTax.value,currency:t.amountInclTax.currency,"data-testid":"shipping"}):i(h,{amount:t==null?void 0:t.amount.value,currency:t==null?void 0:t.amount.currency,"data-testid":"shipping"}),N=()=>t!=null&&t.amountExclTax?i(h,{amount:t.amountExclTax.value,currency:t.amountExclTax.currency,"data-testid":"shipping-excluding-tax"}):i("span",{children:u.taxToBeDetermined});return i(v,{initialized:t!==void 0,label:(()=>{const e=t!=null&&t.estimated?u.estimated:u.label;return i("span",{"data-testid":"estimate-shipping-label",children:e})})(),price:y(),priceExclTax:N(),taxExcluded:l&&!o,taxIncluded:g&&!o,visible:n&&t!==null})};export{nt as EstimateShipping,nt as default};
3
+ import{jsx as i,jsxs as k}from"@dropins/tools/preact-jsx-runtime.js";/* empty css */import{Skeleton as B,SkeletonRow as U,Price as h}from"@dropins/tools/components.js";import{W as z,g as G}from"../chunks/ConditionalWrapper.js";import"../chunks/TermsAndConditions.js";import{VComponent as C,classes as D}from"@dropins/tools/lib.js";import{useText as _}from"@dropins/tools/i18n.js";/* empty css *//* empty css *//* empty css */import{s as P,T as I}from"../chunks/errors.js";import{events as d}from"@dropins/tools/event-bus.js";import{useState as V,useCallback as b,useEffect as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const X=()=>i(B,{"data-testid":"estimate-shipping-skeleton",children:i(U,{size:"xsmall"})}),j=({label:n,price:t,priceExclTax:a,taxExcluded:o=!1,taxIncluded:c=!1})=>{const l=_({withTaxes:"Checkout.EstimateShipping.withTaxes",withoutTaxes:"Checkout.EstimateShipping.withoutTaxes"});return k("div",{className:"checkout-estimate-shipping","data-testid":"estimate-shipping",children:[i(C,{className:"checkout-estimate-shipping__label",node:n}),i(C,{className:"checkout-estimate-shipping__price",node:t}),c&&i("span",{className:D(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included",children:l.withTaxes}),o&&k("span",{className:D(["checkout-estimate-shipping__caption"]),"data-testid":"shipping-tax-included-excluded",children:[a," ",l.withoutTaxes]})]})},v=z(j,X),nt=({active:n=!0})=>{var T;const[t,a]=V(),o=(t==null?void 0:t.amount.value)===0,c=(T=P.config)==null?void 0:T.shoppingCartDisplaySetting.shipping,l=c===I.INCLUDING_EXCLUDING_TAX,g=c===I.INCLUDING_TAX,u=_({freeShipping:"Checkout.EstimateShipping.freeShipping",taxToBeDetermined:"Checkout.EstimateShipping.taxToBeDetermined",label:"Checkout.EstimateShipping.label",estimated:"Checkout.EstimateShipping.estimated"}),r=b(e=>{var S;const s=!e||e.isEmpty,p=!!(e!=null&&e.isVirtual);if(s||p){a(null);return}const m=(S=e.shippingAddresses)==null?void 0:S[0];if(!m)return;const E=m==null?void 0:m.selectedShippingMethod;if(!E){a(null);return}const{amount:w,amountExclTax:L,amountInclTax:M}=E;a({estimated:!1,amount:w,amountExclTax:L,amountInclTax:M})},[]),f=b(e=>{let s=null;if(e.shippingMethod){const p=e.shippingMethod;s={estimated:!0,amount:p.amount,amountExclTax:p.amountExclTax,amountInclTax:p.amountInclTax}}a(s)},[]);x(()=>{if(!n)return;const e=d.on("shipping/estimate",f,{eager:!0});return()=>{e==null||e.off()}},[n,f]),x(()=>{if(!n)return;const e=G();if(e){r(e);return}const s=d.on("checkout/initialized",r,{eager:!0});return()=>{s==null||s.off()}},[n,r]),x(()=>{if(!n)return;const e=d.on("checkout/updated",r,{eager:!1});return()=>{e==null||e.off()}},[n,r]);const y=()=>o?i("span",{"data-testid":"free-shipping",children:u.freeShipping}):g&&(t!=null&&t.amountInclTax)?i(h,{amount:t.amountInclTax.value,currency:t.amountInclTax.currency,"data-testid":"shipping"}):i(h,{amount:t==null?void 0:t.amount.value,currency:t==null?void 0:t.amount.currency,"data-testid":"shipping"}),N=()=>t!=null&&t.amountExclTax?i(h,{amount:t.amountExclTax.value,currency:t.amountExclTax.currency,"data-testid":"shipping-excluding-tax"}):i("span",{children:u.taxToBeDetermined});return i(v,{initialized:t!==void 0,label:(()=>{const e=t!=null&&t.estimated?u.estimated:u.label;return i("span",{"data-testid":"estimate-shipping-label",children:e})})(),price:y(),priceExclTax:N(),taxExcluded:l&&!o,taxIncluded:g&&!o,visible:n&&t!==null})};export{nt as EstimateShipping,nt as default};
@@ -1,3 +1,3 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsx as r,jsxs as d,Fragment as Y}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/errors.js";import{VComponent as W,classes as Z,Slot as P}from"@dropins/tools/lib.js";import{events as H}from"@dropins/tools/event-bus.js";import{W as ee,a as te,g as re}from"../chunks/ConditionalWrapper.js";import{n as z,g as j}from"../chunks/values.js";import{i as ie,s as oe,g as ne}from"../chunks/setGuestEmailOnCart.js";import{Field as ae,Input as le,Skeleton as se,SkeletonRow as q}from"@dropins/tools/components.js";import{useText as I}from"@dropins/tools/i18n.js";/* empty css */import"../chunks/TermsAndConditions.js";/* empty css *//* empty css *//* empty css */import{useState as f,useRef as ce,useCallback as g,useEffect as T,useMemo as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const me={EMAIL:/^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i},V=a=>me.EMAIL.test(a),ue=({value:a,error:n,hint:c,onChange:u,onBlur:m,onInvalid:s})=>{const l=I({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return r(ae,{error:n,hint:c,children:r(le,{"aria-label":l.LoginFormLabel,"aria-required":!0,autocomplete:"email",floatingLabel:l.LoginFormFloatingLabel,id:"customer-email",name:"customer-email",placeholder:l.LoginFormPlaceholder,required:!0,type:"email",value:a,onBlur:m,onChange:u,onInvalid:s})})},de=({onClick:a})=>{const n=I({account:"Checkout.LoginForm.account",signIn:"Checkout.LoginForm.signIn"});return d("div",{className:"checkout-login-form__sign-in",children:[n.account,r("a",{className:"checkout-login-form__link","data-testid":"sign-in-link",href:"#",rel:"noreferrer",target:"_blank",onClick:c=>{c.preventDefault(),a(c)},children:n.signIn})]})},he=()=>d(se,{"data-testid":"login-form-skeleton",children:[r(q,{fullWidth:!0,variant:"heading"}),r(q,{fullWidth:!0,size:"medium"})]}),ge=({className:a,customer:n,email:c,error:u,headingContent:m,hint:s,name:l,onEmailBlur:k,onEmailChange:N,onEmailInvalid:A,title:L,...y})=>d("div",{className:"checkout-login-form","data-testid":"checkout-login-form",children:[d("div",{className:"checkout-login-form__heading",children:[L&&r(W,{className:"checkout-login-form__title",node:L}),m&&r(W,{className:"checkout-login-form__heading-label",node:m})]}),n?d("div",{className:"checkout-login-form__customer-details",children:[r("div",{className:"checkout-login-form__customer-name",children:`${n.firstName} ${n.lastName}`}),r("div",{className:"checkout-login-form__customer-email",children:n.email})]}):r("div",{className:"checkout-login-form__content",children:d("form",{...y,noValidate:!0,className:Z(["dropin-login-form__form",a]),name:l,children:[r("button",{disabled:!0,"aria-hidden":"true",style:"display: none",type:"submit"}),r(ue,{error:u,hint:s,value:c,onBlur:k,onChange:N,onInvalid:A})]})})]}),fe=ee(ge,he),Ee=({onClick:a})=>{const n=I({switch:"Checkout.LoginForm.switch",signOut:"Checkout.LoginForm.signOut"});return d("p",{className:"checkout-login-form__sign-out",children:[n.switch,r("a",{className:"checkout-login-form__link",href:"#",rel:"noreferrer",target:"_blank",onClick:c=>{c.preventDefault(),a==null||a(c)},children:n.signOut})]})},ke=1e3,De=({displayHeadingContent:a=!0,displayTitle:n=!0,initialData:c,onSignInClick:u,onSignOutClick:m,slots:s,active:l=!0,autoSync:k=!0,...N})=>{const[A,L]=f(null),[y,$]=f(""),[O,p]=f(""),[M,R]=f(!1),[B,v]=f(!0),[U,D]=f(!1),h=ce(null),o=I({AlreadyHaveAccountHint:"Checkout.LoginForm.emailExists.alreadyHaveAccount",FasterCheckoutHint:"Checkout.LoginForm.emailExists.forFasterCheckout",InvalidEmailError:"Checkout.LoginForm.invalidEmailError",MissingEmailError:"Checkout.LoginForm.missingEmailError",SignInLabel:"Checkout.LoginForm.emailExists.signInButton",Title:"Checkout.LoginForm.title"}),F=g(e=>{!V(e)||e===te()||(ie(e).then(t=>{v(t)}).catch(t=>{console.error(t),v(!0)}),k&&oe(e).catch(t=>{console.error("Error setting guest email on cart:",t)}))},[k]),G=g(e=>{const i=e.target.value;$(i),v(!0),p(""),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{F(i),z({email:i}),h.current=null},ke)},[F]),S=g(e=>{const t=e.target,i=t.value.trim(),b=V(i);let C="";i===""?C=o.MissingEmailError:b||(C=o.InvalidEmailError),p(C),t.setCustomValidity(C),b&&h.current&&(clearTimeout(h.current),h.current=null,F(i),z({email:i}))},[o.InvalidEmailError,o.MissingEmailError,F]),J=g(e=>{const b=e.target.validity.valueMissing?o.MissingEmailError:o.InvalidEmailError;p(b)},[o.MissingEmailError,o.InvalidEmailError]),_=g(()=>{const e=j("email")??"",t=V(e);u==null||u(t?e:"")},[u]),w=g(()=>{m==null||m()},[m]),E=g(e=>{const t=j("email")??"",i=(e==null?void 0:e.email)??"";i!==t&&($(i),p(""),v(!0),z({email:i}))},[]);T(()=>{if(!l)return;const e=H.on("authenticated",t=>{R(t),ne().then(i=>{L(i)}).catch(console.error)},{eager:!0});return()=>{e==null||e.off()}},[l]),T(()=>{if(!l)return;const e=re();if(e){D(!0),E(e);return}const t=H.on("checkout/initialized",i=>{D(!0),E(i)},{eager:!0});return()=>{t==null||t.off()}},[l,E]),T(()=>{if(!l)return;const e=H.on("checkout/updated",E,{eager:!1});return()=>{e==null||e.off()}},[l,E]);const K=x(()=>{if(n)return r(P,{name:"checkout-login-form-title",slot:s==null?void 0:s.Title,children:r("h2",{children:o.Title})})},[n,s,o.Title]),Q=x(()=>{if(a)return r(P,{context:{authenticated:M},name:"checkout-login-form-heading-label",slot:s==null?void 0:s.Heading,children:M?r(Ee,{onClick:w}):r(de,{onClick:_})})},[a,M,s,_,w]),X=x(()=>B?"":d(Y,{children:[o.AlreadyHaveAccountHint," ",r("a",{href:"#",onClick:_,children:o.SignInLabel})," ",o.FasterCheckoutHint]}),[B,o.AlreadyHaveAccountHint,o.SignInLabel,o.FasterCheckoutHint,_]);return r(fe,{...N,customer:A,email:y,error:O,headingContent:Q,hint:X,initialized:U,title:K,visible:l,onEmailBlur:S,onEmailChange:G,onEmailInvalid:J})};export{De as LoginForm,De as default};
3
+ import{jsx as r,jsxs as d,Fragment as Y}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/errors.js";import{VComponent as W,classes as Z,Slot as P}from"@dropins/tools/lib.js";import{events as H}from"@dropins/tools/event-bus.js";import{n as z,g as j}from"../chunks/values.js";import{W as ee,a as te,g as re}from"../chunks/ConditionalWrapper.js";import{i as ie,s as oe,g as ne}from"../chunks/setGuestEmailOnCart.js";import{Field as ae,Input as le,Skeleton as se,SkeletonRow as q}from"@dropins/tools/components.js";import{useText as I}from"@dropins/tools/i18n.js";/* empty css */import"../chunks/TermsAndConditions.js";/* empty css *//* empty css *//* empty css */import{useState as f,useRef as ce,useCallback as g,useEffect as T,useMemo as x}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const me={EMAIL:/^[a-z0-9,!#$%&'*+/=?^_`{|}~-]+(\.[a-z0-9,!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i},V=a=>me.EMAIL.test(a),ue=({value:a,error:n,hint:c,onChange:u,onBlur:m,onInvalid:s})=>{const l=I({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return r(ae,{error:n,hint:c,children:r(le,{"aria-label":l.LoginFormLabel,"aria-required":!0,autocomplete:"email",floatingLabel:l.LoginFormFloatingLabel,id:"customer-email",name:"customer-email",placeholder:l.LoginFormPlaceholder,required:!0,type:"email",value:a,onBlur:m,onChange:u,onInvalid:s})})},de=({onClick:a})=>{const n=I({account:"Checkout.LoginForm.account",signIn:"Checkout.LoginForm.signIn"});return d("div",{className:"checkout-login-form__sign-in",children:[n.account,r("a",{className:"checkout-login-form__link","data-testid":"sign-in-link",href:"#",rel:"noreferrer",target:"_blank",onClick:c=>{c.preventDefault(),a(c)},children:n.signIn})]})},he=()=>d(se,{"data-testid":"login-form-skeleton",children:[r(q,{fullWidth:!0,variant:"heading"}),r(q,{fullWidth:!0,size:"medium"})]}),ge=({className:a,customer:n,email:c,error:u,headingContent:m,hint:s,name:l,onEmailBlur:k,onEmailChange:N,onEmailInvalid:A,title:L,...y})=>d("div",{className:"checkout-login-form","data-testid":"checkout-login-form",children:[d("div",{className:"checkout-login-form__heading",children:[L&&r(W,{className:"checkout-login-form__title",node:L}),m&&r(W,{className:"checkout-login-form__heading-label",node:m})]}),n?d("div",{className:"checkout-login-form__customer-details",children:[r("div",{className:"checkout-login-form__customer-name",children:`${n.firstName} ${n.lastName}`}),r("div",{className:"checkout-login-form__customer-email",children:n.email})]}):r("div",{className:"checkout-login-form__content",children:d("form",{...y,noValidate:!0,className:Z(["dropin-login-form__form",a]),name:l,children:[r("button",{disabled:!0,"aria-hidden":"true",style:"display: none",type:"submit"}),r(ue,{error:u,hint:s,value:c,onBlur:k,onChange:N,onInvalid:A})]})})]}),fe=ee(ge,he),Ee=({onClick:a})=>{const n=I({switch:"Checkout.LoginForm.switch",signOut:"Checkout.LoginForm.signOut"});return d("p",{className:"checkout-login-form__sign-out",children:[n.switch,r("a",{className:"checkout-login-form__link",href:"#",rel:"noreferrer",target:"_blank",onClick:c=>{c.preventDefault(),a==null||a(c)},children:n.signOut})]})},ke=1e3,De=({displayHeadingContent:a=!0,displayTitle:n=!0,initialData:c,onSignInClick:u,onSignOutClick:m,slots:s,active:l=!0,autoSync:k=!0,...N})=>{const[A,L]=f(null),[y,$]=f(""),[O,p]=f(""),[M,R]=f(!1),[B,v]=f(!0),[U,D]=f(!1),h=ce(null),o=I({AlreadyHaveAccountHint:"Checkout.LoginForm.emailExists.alreadyHaveAccount",FasterCheckoutHint:"Checkout.LoginForm.emailExists.forFasterCheckout",InvalidEmailError:"Checkout.LoginForm.invalidEmailError",MissingEmailError:"Checkout.LoginForm.missingEmailError",SignInLabel:"Checkout.LoginForm.emailExists.signInButton",Title:"Checkout.LoginForm.title"}),F=g(e=>{!V(e)||e===te()||(ie(e).then(t=>{v(t)}).catch(t=>{console.error(t),v(!0)}),k&&oe(e).catch(t=>{console.error("Error setting guest email on cart:",t)}))},[k]),G=g(e=>{const i=e.target.value;$(i),v(!0),p(""),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{F(i),z({email:i}),h.current=null},ke)},[F]),S=g(e=>{const t=e.target,i=t.value.trim(),b=V(i);let C="";i===""?C=o.MissingEmailError:b||(C=o.InvalidEmailError),p(C),t.setCustomValidity(C),b&&h.current&&(clearTimeout(h.current),h.current=null,F(i),z({email:i}))},[o.InvalidEmailError,o.MissingEmailError,F]),J=g(e=>{const b=e.target.validity.valueMissing?o.MissingEmailError:o.InvalidEmailError;p(b)},[o.MissingEmailError,o.InvalidEmailError]),_=g(()=>{const e=j("email")??"",t=V(e);u==null||u(t?e:"")},[u]),w=g(()=>{m==null||m()},[m]),E=g(e=>{const t=j("email")??"",i=(e==null?void 0:e.email)??"";i!==t&&($(i),p(""),v(!0),z({email:i}))},[]);T(()=>{if(!l)return;const e=H.on("authenticated",t=>{R(t),ne().then(i=>{L(i)}).catch(console.error)},{eager:!0});return()=>{e==null||e.off()}},[l]),T(()=>{if(!l)return;const e=re();if(e){D(!0),E(e);return}const t=H.on("checkout/initialized",i=>{D(!0),E(i)},{eager:!0});return()=>{t==null||t.off()}},[l,E]),T(()=>{if(!l)return;const e=H.on("checkout/updated",E,{eager:!1});return()=>{e==null||e.off()}},[l,E]);const K=x(()=>{if(n)return r(P,{name:"checkout-login-form-title",slot:s==null?void 0:s.Title,children:r("h2",{children:o.Title})})},[n,s,o.Title]),Q=x(()=>{if(a)return r(P,{context:{authenticated:M},name:"checkout-login-form-heading-label",slot:s==null?void 0:s.Heading,children:M?r(Ee,{onClick:w}):r(de,{onClick:_})})},[a,M,s,_,w]),X=x(()=>B?"":d(Y,{children:[o.AlreadyHaveAccountHint," ",r("a",{href:"#",onClick:_,children:o.SignInLabel})," ",o.FasterCheckoutHint]}),[B,o.AlreadyHaveAccountHint,o.SignInLabel,o.FasterCheckoutHint,_]);return r(fe,{...N,customer:A,email:y,error:O,headingContent:Q,hint:X,initialized:U,title:K,visible:l,onEmailBlur:S,onEmailChange:G,onEmailInvalid:J})};export{De as LoginForm,De as default};
@@ -1,3 +1,3 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsxs as w,jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import{h as D,s as $}from"../chunks/errors.js";import{classes as E,VComponent as F,Slot as z}from"@dropins/tools/lib.js";import{events as H}from"@dropins/tools/event-bus.js";import{W as G,i as J,h as K,g as Q}from"../chunks/ConditionalWrapper.js";import{n as X,g as Y}from"../chunks/values.js";import{s as ee}from"../chunks/setPaymentMethod.js";/* empty css */import{Skeleton as te,SkeletonRow as C,IllustratedMessage as ne,Icon as N,ProgressSpinner as oe,ToggleButton as re,RadioButton as ae}from"@dropins/tools/components.js";import*as S from"@dropins/tools/preact-compat.js";import{useText as O}from"@dropins/tools/i18n.js";import{useState as _,useCallback as v,useEffect as L,useMemo as ce}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const ie=t=>S.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},S.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"}),S.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),S.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),se=()=>w(te,{"data-testid":"payment-methods-skeleton",children:[n(C,{size:"medium",variant:"heading"}),n(C,{size:"medium",variant:"empty"}),n(C,{fullWidth:!0,size:"xlarge"}),n(C,{fullWidth:!0,size:"xlarge"})]}),le=({code:t,icon:o,isLoading:d,onChange:r,selected:a,title:m,UIComponentType:p="ToggleButton"})=>{const c={busy:d,className:"checkout-payment-methods__method",label:m,name:"payment-method",value:t,onChange:()=>r({code:t,title:m})};return p==="ToggleButton"?n(re,{...c,icon:o?n(N,{source:o}):void 0,selected:a}):n(ae,{...c,checked:a,icon:o??void 0})},de=({className:t,title:o,isLoading:d=!1,onChange:r=()=>{},options:a,paymentMethodContent:m,UIComponentType:p,selection:c})=>{const P=O({EmptyState:"Checkout.PaymentMethods.emptyState"});return w("div",{className:E(["checkout-payment-methods",t]),"data-testid":"checkout-payment-methods",children:[o&&n(F,{className:"checkout-payment-methods__title",node:o}),!d&&a.length===0&&n(ne,{"data-testid":"checkout-payment-methods-empty",icon:n(N,{source:ie}),message:n("p",{children:P.EmptyState})}),w("div",{className:E(["checkout-payment-methods__wrapper",["checkout-payment-methods__wrapper--loading",d]]),children:[d&&n(oe,{className:"checkout-payment-methods__spinner"}),n("div",{className:E(["checkout-payment-methods__methods",["checkout-payment-methods--full-width",a.length%2!==0]]),children:a==null?void 0:a.map(u=>n(le,{UIComponentType:p,code:u.code,icon:u.icon,selected:(c==null?void 0:c.code)===u.code,title:u.displayLabel??!0?u.title:"",onChange:r},u.code))}),m&&n("div",{className:"checkout-payment-methods__content",children:m})]})]})},me=G(de,se);function ue(t,o){return t?o.some(d=>d.code===t.code):!1}function he(t,o){return!t||!o?!1:t.code===o.code}function pe(t){return t?!!t.code&&!!t.title:!1}const Ie=({displayTitle:t=!0,active:o=!0,UIComponentType:d="ToggleButton",slots:r,autoSync:a=!0})=>{var I,b;const[m,p]=_(!1),[c,P]=_(null),[u,U]=_([]),i=r==null?void 0:r.Methods,B=D.value,j=u.filter(e=>{var s;return((s=i==null?void 0:i[e.code])==null?void 0:s.enabled)!==!1}).map(e=>{const s=(i==null?void 0:i[e.code])||{};return{...e,...s}}),V=O({Title:"Checkout.PaymentMethods.title"}),h=v(e=>{P(e),X({selectedPaymentMethod:e})},[]),y=v(async e=>{if(!(J()||K()))return;const l=i==null?void 0:i[e.code];((l==null?void 0:l.autoSync)??a)&&await ee({code:e.code}).catch(console.error)},[a,i]),A=v(async e=>{h(e),await y(e)},[h,y]),k=v(e=>{if(!e||e.isEmpty){h(null),U([]);return}const l=e.availablePaymentMethods??[];if(U(l),l.length===0){h(null);return}const g=e.selectedPaymentMethod??null,x=pe(g),f=Y("selectedPaymentMethod"),T=ue(f,l),q=he(f,g);if(f&&T&&!q){y(f);return}if((!f||!T)&&x){h(g);return}if((!f||!T)&&!x){const W=l[0];h(W),y(W)}},[h,y]);L(()=>{if(!o)return;const e=Q();if(e){p(!0),k(e);return}const s=H.on("checkout/initialized",l=>{p(!0),k(l)},{eager:!0});return()=>{s==null||s.off()}},[o,k]),L(()=>{if(!o)return;const e=H.on("checkout/updated",k,{eager:!1});return()=>{e==null||e.off()}},[o,k]);const M=c?(b=(I=r==null?void 0:r.Methods)==null?void 0:I[c.code])==null?void 0:b.render:null,R=M?n(z,{context:{cartId:$.cartId??"",replaceHTML(e){this.replaceWith(e)}},name:"PaymentMethodContent",slot:M},M):void 0,Z=ce(()=>{if(t)return n(z,{name:"checkout-payment-methods-title",slot:r==null?void 0:r.Title,children:n("h2",{children:V.Title})})},[t,r==null?void 0:r.Title,V.Title]);return n(me,{UIComponentType:d,initialized:m,isLoading:m&&B,options:j,paymentMethodContent:R,selection:c,title:Z,visible:o,onChange:A})};export{Ie as PaymentMethods,Ie as default};
3
+ import{jsxs as w,jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import{h as D,s as $}from"../chunks/errors.js";import{classes as E,VComponent as F,Slot as z}from"@dropins/tools/lib.js";import{events as H}from"@dropins/tools/event-bus.js";import{n as G,g as J}from"../chunks/values.js";import{W as K,i as Q,h as X,g as Y}from"../chunks/ConditionalWrapper.js";import{s as ee}from"../chunks/setPaymentMethod.js";/* empty css */import{Skeleton as te,SkeletonRow as C,IllustratedMessage as ne,Icon as N,ProgressSpinner as oe,ToggleButton as re,RadioButton as ae}from"@dropins/tools/components.js";import*as S from"@dropins/tools/preact-compat.js";import{useText as O}from"@dropins/tools/i18n.js";import{useState as _,useCallback as v,useEffect as L,useMemo as ce}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/synchronizeCheckout.js";const ie=t=>S.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},S.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"}),S.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),S.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),se=()=>w(te,{"data-testid":"payment-methods-skeleton",children:[n(C,{size:"medium",variant:"heading"}),n(C,{size:"medium",variant:"empty"}),n(C,{fullWidth:!0,size:"xlarge"}),n(C,{fullWidth:!0,size:"xlarge"})]}),le=({code:t,icon:o,isLoading:d,onChange:r,selected:a,title:m,UIComponentType:p="ToggleButton"})=>{const c={busy:d,className:"checkout-payment-methods__method",label:m,name:"payment-method",value:t,onChange:()=>r({code:t,title:m})};return p==="ToggleButton"?n(re,{...c,icon:o?n(N,{source:o}):void 0,selected:a}):n(ae,{...c,checked:a,icon:o??void 0})},de=({className:t,title:o,isLoading:d=!1,onChange:r=()=>{},options:a,paymentMethodContent:m,UIComponentType:p,selection:c})=>{const P=O({EmptyState:"Checkout.PaymentMethods.emptyState"});return w("div",{className:E(["checkout-payment-methods",t]),"data-testid":"checkout-payment-methods",children:[o&&n(F,{className:"checkout-payment-methods__title",node:o}),!d&&a.length===0&&n(ne,{"data-testid":"checkout-payment-methods-empty",icon:n(N,{source:ie}),message:n("p",{children:P.EmptyState})}),w("div",{className:E(["checkout-payment-methods__wrapper",["checkout-payment-methods__wrapper--loading",d]]),children:[d&&n(oe,{className:"checkout-payment-methods__spinner"}),n("div",{className:E(["checkout-payment-methods__methods",["checkout-payment-methods--full-width",a.length%2!==0]]),children:a==null?void 0:a.map(u=>n(le,{UIComponentType:p,code:u.code,icon:u.icon,selected:(c==null?void 0:c.code)===u.code,title:u.displayLabel??!0?u.title:"",onChange:r},u.code))}),m&&n("div",{className:"checkout-payment-methods__content",children:m})]})]})},me=K(de,se);function ue(t,o){return t?o.some(d=>d.code===t.code):!1}function he(t,o){return!t||!o?!1:t.code===o.code}function pe(t){return t?!!t.code&&!!t.title:!1}const Ie=({displayTitle:t=!0,active:o=!0,UIComponentType:d="ToggleButton",slots:r,autoSync:a=!0})=>{var I,b;const[m,p]=_(!1),[c,P]=_(null),[u,U]=_([]),i=r==null?void 0:r.Methods,B=D.value,j=u.filter(e=>{var s;return((s=i==null?void 0:i[e.code])==null?void 0:s.enabled)!==!1}).map(e=>{const s=(i==null?void 0:i[e.code])||{};return{...e,...s}}),V=O({Title:"Checkout.PaymentMethods.title"}),h=v(e=>{P(e),G({selectedPaymentMethod:e})},[]),y=v(async e=>{if(!(Q()||X()))return;const l=i==null?void 0:i[e.code];((l==null?void 0:l.autoSync)??a)&&await ee({code:e.code}).catch(console.error)},[a,i]),A=v(async e=>{h(e),await y(e)},[h,y]),k=v(e=>{if(!e||e.isEmpty){h(null),U([]);return}const l=e.availablePaymentMethods??[];if(U(l),l.length===0){h(null);return}const g=e.selectedPaymentMethod??null,x=pe(g),f=J("selectedPaymentMethod"),T=ue(f,l),q=he(f,g);if(f&&T&&!q){y(f);return}if((!f||!T)&&x){h(g);return}if((!f||!T)&&!x){const W=l[0];h(W),y(W)}},[h,y]);L(()=>{if(!o)return;const e=Y();if(e){p(!0),k(e);return}const s=H.on("checkout/initialized",l=>{p(!0),k(l)},{eager:!0});return()=>{s==null||s.off()}},[o,k]),L(()=>{if(!o)return;const e=H.on("checkout/updated",k,{eager:!1});return()=>{e==null||e.off()}},[o,k]);const M=c?(b=(I=r==null?void 0:r.Methods)==null?void 0:I[c.code])==null?void 0:b.render:null,R=M?n(z,{context:{cartId:$.cartId??"",replaceHTML(e){this.replaceWith(e)}},name:"PaymentMethodContent",slot:M},M):void 0,Z=ce(()=>{if(t)return n(z,{name:"checkout-payment-methods-title",slot:r==null?void 0:r.Title,children:n("h2",{children:V.Title})})},[t,r==null?void 0:r.Title,V.Title]);return n(me,{UIComponentType:d,initialized:m,isLoading:m&&B,options:j,paymentMethodContent:R,selection:c,title:Z,visible:o,onChange:A})};export{Ie as PaymentMethods,Ie as default};
@@ -1,3 +1,3 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsxs as U,jsx as o}from"@dropins/tools/preact-jsx-runtime.js";import{h as I,U as v,s as B}from"../chunks/errors.js";import{classes as j,Slot as w}from"@dropins/tools/lib.js";import{events as d}from"@dropins/tools/event-bus.js";import{W as M,g as N}from"../chunks/ConditionalWrapper.js";import{g as y}from"../chunks/values.js";/* empty css */import{Skeleton as T,SkeletonRow as g,Button as W}from"@dropins/tools/components.js";import{s as _}from"../chunks/ServerErrorSignal.js";import{useState as E,useCallback as m,useEffect as f}from"@dropins/tools/preact-hooks.js";import{useText as H}from"@dropins/tools/i18n.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const L=()=>U(T,{"data-testid":"place-order-skeleton",children:[o(g,{size:"small",variant:"empty"}),o(g,{size:"small"})]}),Q=({children:c,className:r,disabled:s=!1,onClick:a})=>o("div",{className:j(["checkout-place-order",r]),children:o(W,{className:"checkout-place-order__button","data-testid":"place-order-button",disabled:s,size:"medium",type:"submit",variant:"primary",onClick:a,children:c},"placeOrder")}),R=M(Q,L),te=({disabled:c=!1,active:r=!0,handleValidation:s,handlePlaceOrder:a,slots:i,...S})=>{var C;const[x,p]=E(!1),[P,h]=E(!1),b=I.value,l=H({CheckoutUnexpectedError:"Checkout.ServerError.unexpected",placeOrderButton:"Checkout.PlaceOrder.button"}),k=m(e=>{_.value=e instanceof TypeError||e instanceof v?l.CheckoutUnexpectedError:e.message},[l]),z=m(async()=>{var e;try{if(s&&!s())return;await a({cartId:B.cartId,code:((e=y("selectedPaymentMethod"))==null?void 0:e.code)??""})}catch(t){k(t)}},[s,a,k]),n=m(e=>{(!e||e.isEmpty)&&h(!1)},[]);return f(()=>{if(r===!1)return;const e=d.on("cart/initialized",t=>{const u=(t==null?void 0:t.items)||[];h(u.some(O=>O.outOfStock||O.insufficientQuantity))},{eager:!0});return()=>{e==null||e.off()}},[r]),f(()=>{if(!r)return;const e=N();if(e){p(!0),n(e);return}const t=d.on("checkout/initialized",u=>{p(!0),n(u)},{eager:!0});return()=>{t==null||t.off()}},[r,n]),f(()=>{if(!r)return;const e=d.on("checkout/updated",n,{eager:!1});return()=>{e==null||e.off()}},[r,n]),o(R,{...S,disabled:c||P||b,initialized:x,visible:r,onClick:z,children:o(w,{context:{code:((C=y("selectedPaymentMethod"))==null?void 0:C.code)??""},name:"Content",slot:i==null?void 0:i.Content,children:l.placeOrderButton})})};export{te as PlaceOrder,te as default};
3
+ import{jsxs as U,jsx as o}from"@dropins/tools/preact-jsx-runtime.js";import{h as I,U as v,s as B}from"../chunks/errors.js";import{classes as j,Slot as w}from"@dropins/tools/lib.js";import{events as d}from"@dropins/tools/event-bus.js";import{g as y}from"../chunks/values.js";import{W as M,g as N}from"../chunks/ConditionalWrapper.js";/* empty css */import{Skeleton as T,SkeletonRow as g,Button as W}from"@dropins/tools/components.js";import{s as _}from"../chunks/ServerErrorSignal.js";import{useState as E,useCallback as m,useEffect as f}from"@dropins/tools/preact-hooks.js";import{useText as H}from"@dropins/tools/i18n.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const L=()=>U(T,{"data-testid":"place-order-skeleton",children:[o(g,{size:"small",variant:"empty"}),o(g,{size:"small"})]}),Q=({children:c,className:r,disabled:s=!1,onClick:a})=>o("div",{className:j(["checkout-place-order",r]),children:o(W,{className:"checkout-place-order__button","data-testid":"place-order-button",disabled:s,size:"medium",type:"submit",variant:"primary",onClick:a,children:c},"placeOrder")}),R=M(Q,L),te=({disabled:c=!1,active:r=!0,handleValidation:s,handlePlaceOrder:a,slots:i,...S})=>{var C;const[x,p]=E(!1),[P,h]=E(!1),b=I.value,l=H({CheckoutUnexpectedError:"Checkout.ServerError.unexpected",placeOrderButton:"Checkout.PlaceOrder.button"}),k=m(e=>{_.value=e instanceof TypeError||e instanceof v?l.CheckoutUnexpectedError:e.message},[l]),z=m(async()=>{var e;try{if(s&&!s())return;await a({cartId:B.cartId,code:((e=y("selectedPaymentMethod"))==null?void 0:e.code)??""})}catch(t){k(t)}},[s,a,k]),n=m(e=>{(!e||e.isEmpty)&&h(!1)},[]);return f(()=>{if(r===!1)return;const e=d.on("cart/initialized",t=>{const u=(t==null?void 0:t.items)||[];h(u.some(O=>O.outOfStock||O.insufficientQuantity))},{eager:!0});return()=>{e==null||e.off()}},[r]),f(()=>{if(!r)return;const e=N();if(e){p(!0),n(e);return}const t=d.on("checkout/initialized",u=>{p(!0),n(u)},{eager:!0});return()=>{t==null||t.off()}},[r,n]),f(()=>{if(!r)return;const e=d.on("checkout/updated",n,{eager:!1});return()=>{e==null||e.off()}},[r,n]),o(R,{...S,disabled:c||P||b,initialized:x,visible:r,onClick:z,children:o(w,{context:{code:((C=y("selectedPaymentMethod"))==null?void 0:C.code)??""},name:"Content",slot:i==null?void 0:i.Content,children:l.placeOrderButton})})};export{te as PlaceOrder,te as default};
@@ -11,5 +11,6 @@ export interface ShippingMethodsProps extends HTMLAttributes<HTMLDivElement>, Ti
11
11
  active?: boolean;
12
12
  autoSync?: boolean;
13
13
  }
14
+ export declare function emitShippingEstimateEvent(selection: ShippingMethod): void;
14
15
  export declare const ShippingMethods: Container<ShippingMethodsProps>;
15
16
  //# sourceMappingURL=ShippingMethods.d.ts.map
@@ -1,3 +1,3 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsxs as C,jsx as t,Fragment as I}from"@dropins/tools/preact-jsx-runtime.js";import{a as q,h as Y,b as ee}from"../chunks/errors.js";import{classes as w,VComponent as te,Slot as ne}from"@dropins/tools/lib.js";import{events as O}from"@dropins/tools/event-bus.js";import{W as ie,h as V,g as oe}from"../chunks/ConditionalWrapper.js";import{n as re,g as H}from"../chunks/values.js";import{t as se,s as ae}from"../chunks/setShippingMethods.js";/* empty css */import{Skeleton as ce,SkeletonRow as L,IllustratedMessage as pe,Icon as le,ProgressSpinner as ue,RadioButton as de,Price as D,ToggleButton as he}from"@dropins/tools/components.js";import*as p from"@dropins/tools/preact-compat.js";import{useText as F}from"@dropins/tools/i18n.js";import{useState as T,useCallback as S,useEffect as A,useMemo as me}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/synchronizeCheckout.js";import"../fragments.js";const ge=i=>p.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...i},p.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"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.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"}),p.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"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),p.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),fe=()=>C(ce,{"data-testid":"shipping-methods-skeleton",children:[t(L,{size:"small",variant:"heading"}),t(L,{size:"small",variant:"empty"}),t(L,{fullWidth:!0,size:"medium"}),t(L,{fullWidth:!0,size:"medium"})]}),ke=({className:i,isLoading:o=!1,onSelectionChange:c=()=>{},options:d,selection:s,title:E,UIComponentType:l="RadioButton",...M})=>{const _=F({EmptyState:"Checkout.ShippingMethods.emptyState"}),b=(n,W)=>{const y={busy:o,key:n.value,className:"checkout-shipping-methods__method",name:"shipping-method",value:n.value,onChange:()=>c(n)};return W==="RadioButton"?t(de,{...y,checked:(s==null?void 0:s.value)===n.value,"data-testid":"shipping-method-radioButton",description:n.title,id:n.value,label:C(I,{children:[t(D,{amount:n.amount.value,currency:n.amount.currency})," ",t("span",{children:n.carrier.title})]})}):t(he,{...y,"data-testid":"shipping-method-toggleButton",label:C(I,{children:[t("span",{children:n.carrier.title}),t(D,{amount:n.amount.value,currency:n.amount.currency})]}),selected:(s==null?void 0:s.value)===n.value})};return C("div",{...M,className:w(["checkout-shipping-methods",i]),"data-testid":"checkout-shipping-methods",children:[E&&t(te,{className:"checkout-shipping-methods__title",node:E}),!o&&d.length===0&&t(pe,{"data-testid":"checkout-shipping-methods-empty",icon:t(le,{source:ge}),message:t("p",{children:_.EmptyState})}),C("div",{className:w(["checkout-shipping-methods__content"]),children:[o&&t(ue,{className:"checkout-shipping-methods__spinner"}),t("div",{className:w(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",o],["checkout-shipping-methods__options--toggleButton",l==="ToggleButton"]]),children:d.map(n=>b(n,l))})]})]})},ve=ie(ke,fe);function P(i){const o=q.peek();if(!(o!=null&&o.address))return;const c={address:o.address,shippingMethod:i?se(i):null};O.emit("shipping/estimate",c)}function Z(i,o){return i?o.some(c=>c.code===i.code):!1}function Se(i,o){return!i||!o?!1:i.code===o.code&&i.carrier.code===o.carrier.code}const Pe=({displayTitle:i=!0,initialData:o,onSelectionChange:c,onSelectionError:d,slots:s,UIComponentType:E="RadioButton",active:l=!0,autoSync:M=!0,..._})=>{const[b,n]=T(!1),[W,y]=T(null),[U,j]=T(),$=Y.value,G=ee.value,J=$||G,x=F({Title:"Checkout.ShippingMethods.title"}),a=S(e=>{y(e),re({selectedShippingMethod:e})},[]),f=S(async(e,r)=>{if(!M||!V())return;const m={method_code:e.code,carrier_code:e.carrier.code};try{await ae([m])}catch(h){a(r??null),d==null||d(h,e)}},[M,d,a]),K=S(async e=>{const r=H("selectedShippingMethod");a(e),c==null||c(e),V()||P(e),await f(e,r)},[c,a,f]),k=S(e=>{var N;const r=!e||e.isEmpty,m=!!(e!=null&&e.isVirtual);if(r||m){n(m),a(null),j([]);return}const h=(N=e.shippingAddresses)==null?void 0:N[0];if(!h)return;const v=h.availableShippingMethods??[];if(j(v),v.length===0){a(null);return}const u=h.selectedShippingMethod??null,g=H("selectedShippingMethod"),B=Z(g,v),X=Se(g,u);if(g&&B&&!X){f(g,u);return}if((!g||!B)&&u){a(u);return}if((!g||!B)&&!u){const R=v[0];a(R),f(R)}},[f,a]),z=S(e=>{if(e===void 0)return;const r=e.options;j(r);const m=r.length>0,h=H("selectedShippingMethod");if(!m){a(null),P(null);return}if(Z(h,r))return;const u=r[0];a(u),P(u)},[a]);A(()=>{if(!l)return;const e=oe();if(e){k(e);return}const r=O.on("checkout/initialized",k,{eager:!0});return()=>{r==null||r.off()}},[l,k]),A(()=>{if(!l)return;const e=O.on("checkout/updated",k,{eager:!1});return()=>{e==null||e.off()}},[l,k]),A(()=>{if(V())return;const e=q.subscribe(z);return()=>{e()}},[z]);const Q=me(()=>{if(i)return t(ne,{name:"checkout-shipping-methods-title",slot:s==null?void 0:s.Title,children:t("h3",{children:x.Title})})},[i,s==null?void 0:s.Title,x.Title]);return t(ve,{..._,UIComponentType:E,initialized:U!==void 0,isLoading:J,options:U??[],selection:W,title:Q,visible:l&&!b,onSelectionChange:K})};export{Pe as ShippingMethods,Pe as default};
3
+ import{jsxs as S,jsx as n,Fragment as b}from"@dropins/tools/preact-jsx-runtime.js";import{h as Q,a as X}from"../chunks/errors.js";import{classes as H,VComponent as Y,Slot as ee}from"@dropins/tools/lib.js";import{s as te,t as ne}from"../chunks/setShippingMethods.js";import{events as E}from"@dropins/tools/event-bus.js";import{n as re,g as A}from"../chunks/values.js";import{W as oe,h as T,g as ie}from"../chunks/ConditionalWrapper.js";/* empty css */import{Skeleton as se,SkeletonRow as _,IllustratedMessage as ae,Icon as ce,ProgressSpinner as ue,RadioButton as pe,Price as O,ToggleButton as de}from"@dropins/tools/components.js";import*as u from"@dropins/tools/preact-compat.js";import{useText as Z}from"@dropins/tools/i18n.js";import{useState as P,useCallback as C,useEffect as U,useMemo as le}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/synchronizeCheckout.js";import"../fragments.js";const he=o=>u.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o},u.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"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.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"}),u.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"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),u.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),me=()=>S(se,{"data-testid":"shipping-methods-skeleton",children:[n(_,{size:"small",variant:"heading"}),n(_,{size:"small",variant:"empty"}),n(_,{fullWidth:!0,size:"medium"}),n(_,{fullWidth:!0,size:"medium"})]}),ge=({className:o,isLoading:i=!1,onSelectionChange:d=()=>{},options:l,selection:s,title:M,UIComponentType:c="RadioButton",...y})=>{const W=Z({EmptyState:"Checkout.ShippingMethods.emptyState"}),j=(r,B)=>{const L={busy:i,key:r.value,className:"checkout-shipping-methods__method",name:"shipping-method",value:r.value,onChange:()=>d(r)};return B==="RadioButton"?n(pe,{...L,checked:(s==null?void 0:s.value)===r.value,"data-testid":"shipping-method-radioButton",description:r.title,id:r.value,label:S(b,{children:[n(O,{amount:r.amount.value,currency:r.amount.currency})," ",n("span",{children:r.carrier.title})]})}):n(de,{...L,"data-testid":"shipping-method-toggleButton",label:S(b,{children:[n("span",{children:r.carrier.title}),n(O,{amount:r.amount.value,currency:r.amount.currency})]}),selected:(s==null?void 0:s.value)===r.value})};return S("div",{...y,className:H(["checkout-shipping-methods",o]),"data-testid":"checkout-shipping-methods",children:[M&&n(Y,{className:"checkout-shipping-methods__title",node:M}),!i&&l.length===0&&n(ae,{"data-testid":"checkout-shipping-methods-empty",icon:n(ce,{source:he}),message:n("p",{children:W.EmptyState})}),S("div",{className:H(["checkout-shipping-methods__content"]),children:[i&&n(ue,{className:"checkout-shipping-methods__spinner"}),n("div",{className:H(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",i],["checkout-shipping-methods__options--toggleButton",c==="ToggleButton"]]),children:l.map(r=>j(r,c))})]})]})},fe=oe(ge,me);function ke(o,i){return o?i.some(d=>d.code===o.code):!1}function D(o,i){return!o||!i||o.amount.value!==i.amount.value?!1:o.code===i.code&&o.carrier.code===i.carrier.code}function ve(o){const i=E.lastPayload("shipping/estimate");i&&E.emit("shipping/estimate",{...i,shippingMethod:ne(o)})}const Ue=({displayTitle:o=!0,initialData:i,onSelectionChange:d,onSelectionError:l,slots:s,UIComponentType:M="RadioButton",active:c=!0,autoSync:y=!0,...W})=>{const[j,r]=P(!1),[B,L]=P(null),[x,w]=P(),q=Q.value,F=X.value,$=q||F,z=Z({Title:"Checkout.ShippingMethods.title"}),a=C(e=>{L(t=>D(t,e)?t:(re({selectedShippingMethod:e}),e))},[]),f=C(async(e,t)=>{if(!y||!T())return;const p={method_code:e.code,carrier_code:e.carrier.code};try{await te([p])}catch(h){a(t??null),l==null||l(h,e)}},[y,l,a]),G=C(async e=>{const t=A("selectedShippingMethod");a(e),d==null||d(e),T()||ve(e),await f(e,t)},[d,a,f]),k=C(e=>{var R;const t=!e||e.isEmpty,p=!!(e!=null&&e.isVirtual);if(t||p){r(p),a(null),w([]);return}const h=(R=e.shippingAddresses)==null?void 0:R[0];if(!h)return;const m=h.availableShippingMethods??[];if(w(m),m.length===0){a(null);return}const v=h.selectedShippingMethod??null,g=A("selectedShippingMethod"),V=ke(g,m),K=D(g,v);if(g&&V&&!K){f(g,v);return}if((!g||!V)&&v){a(v);return}if((!g||!V)&&!v){const I=m[0];a(I),f(I)}},[f,a]),N=C(e=>{if(e===void 0)return;const{shippingMethod:t,availableShippingMethods:p}=e,h=(p==null?void 0:p.find(m=>m.code===(t==null?void 0:t.methodCode)&&m.carrier.code===(t==null?void 0:t.carrierCode)))??null;w(p),a(h)},[a]);U(()=>{if(!c)return;const e=ie();if(e){k(e);return}const t=E.on("checkout/initialized",k,{eager:!0});return()=>{t==null||t.off()}},[c,k]),U(()=>{if(!c)return;const e=E.on("checkout/updated",k,{eager:!1});return()=>{e==null||e.off()}},[c,k]),U(()=>{if(!c||T())return;const e=E.on("shipping/estimate",N,{eager:!0});return()=>{e==null||e.off()}},[c,N]);const J=le(()=>{if(o)return n(ee,{name:"checkout-shipping-methods-title",slot:s==null?void 0:s.Title,children:n("h3",{children:z.Title})})},[o,s==null?void 0:s.Title,z.Title]);return n(fe,{...W,UIComponentType:M,initialized:x!==void 0,isLoading:$,options:x??[],selection:B,title:J,visible:c&&!j,onSelectionChange:G})};export{Ue as ShippingMethods,Ue as default,ve as emitShippingEstimateEvent};
@@ -1,6 +1,6 @@
1
- import { Price } from './price';
1
+ import { Price, ShippingMethod } from '.';
2
2
 
3
- export interface ShippingEstimatePartialAddress {
3
+ export interface PartialShippingAddress {
4
4
  countryCode: string;
5
5
  postCode?: string;
6
6
  region?: string;
@@ -15,7 +15,8 @@ export interface ShippingEstimateShippingMethod {
15
15
  amountInclTax?: Price;
16
16
  }
17
17
  export interface ShippingEstimate {
18
- address: ShippingEstimatePartialAddress;
18
+ address: PartialShippingAddress;
19
19
  shippingMethod: ShippingEstimateShippingMethod | null;
20
+ availableShippingMethods?: ShippingMethod[];
20
21
  }
21
22
  //# sourceMappingURL=shipping-estimate.d.ts.map
@@ -1,16 +1,14 @@
1
1
  import { Price } from './price';
2
2
 
3
- type Code = string;
4
- type Title = string;
5
3
  type Carrier = {
6
- code: Code;
7
- title: Title;
4
+ code: string;
5
+ title: string;
8
6
  };
9
7
  export type ShippingMethod = {
10
8
  amount: Price;
11
9
  carrier: Carrier;
12
- code: Code;
13
- title: Title;
10
+ code: string;
11
+ title: string;
14
12
  value: string;
15
13
  amountExclTax?: Price;
16
14
  amountInclTax?: Price;
@@ -1,4 +1,4 @@
1
- import { ShippingEstimatePartialAddress, ShippingEstimateShippingMethod, ShippingMethod } from '../models';
1
+ import { PartialShippingAddress, ShippingEstimateShippingMethod, ShippingMethod } from '../models';
2
2
 
3
3
  type TransformShippingEstimatePartialAddressInput = {
4
4
  country_id: string;
@@ -6,7 +6,7 @@ type TransformShippingEstimatePartialAddressInput = {
6
6
  region_id?: number;
7
7
  region?: string;
8
8
  };
9
- export declare const transformShippingEstimatePartialAddress: (data: TransformShippingEstimatePartialAddressInput) => ShippingEstimatePartialAddress;
9
+ export declare const transformShippingEstimatePartialAddress: (data: TransformShippingEstimatePartialAddressInput) => PartialShippingAddress;
10
10
  export declare const transformShippingEstimateShippingMethod: (data: ShippingMethod) => ShippingEstimateShippingMethod;
11
11
  export {};
12
12
  //# sourceMappingURL=transform-shipping-estimate.d.ts.map
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/storefront-checkout", "version": "2.0.0-beta2", "@dropins/tools": "~1.2.1", "license": "SEE LICENSE IN LICENSE.md"}
1
+ {"name": "@dropins/storefront-checkout", "version": "2.0.0-beta3", "@dropins/tools": "~1.2.1", "license": "SEE LICENSE IN LICENSE.md"}
@@ -15,5 +15,4 @@
15
15
  * from Adobe.
16
16
  *******************************************************************/
17
17
  export * from './ServerErrorSignal';
18
- export * from './ShippingEstimateSignal';
19
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +0,0 @@
1
- import { ShippingMethod } from '../../../data/models/shipping-method';
2
-
3
- export declare function emitShippingEstimateEvent(shippingMethod: ShippingMethod | null): void;
4
- //# sourceMappingURL=emitShippingEstimateEvent.d.ts.map
@@ -1,8 +0,0 @@
1
- import { ShippingEstimatePartialAddress, ShippingMethod } from '../data/models';
2
-
3
- export type ShippingEstimation = {
4
- address: ShippingEstimatePartialAddress;
5
- options: ShippingMethod[];
6
- };
7
- export declare const shippingEstimateSignal: import('@preact/signals-core').Signal<ShippingEstimation | undefined>;
8
- //# sourceMappingURL=ShippingEstimateSignal.d.ts.map