@dropins/storefront-checkout 0.1.0-alpha40 → 0.1.0-alpha42
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 +1 -1
- package/chunks/BillToShippingAddress.js +1 -0
- package/chunks/EmptyCart.js +1 -0
- package/chunks/OutOfStock.js +1 -1
- package/chunks/ShippingMethods.js +1 -1
- package/chunks/getCart.graphql.js +20 -6
- package/chunks/getCustomer.js +1 -1
- package/chunks/placeOrder.js +127 -0
- package/chunks/resetCustomer.js +1 -1
- package/chunks/setBillingAddress.js +3 -3
- package/chunks/setShippingMethods.js +85 -3
- package/components/AddressForm/useCheckoutAddressEventEmitter.d.ts +2 -1
- package/components/Checkout/Checkout.d.ts +8 -12
- package/components/ShippingMethods/ShippingMethods.d.ts +1 -1
- package/containers/BillToShippingAddress/BillToShippingAddress.d.ts +4 -2
- package/containers/BillToShippingAddress.js +1 -1
- package/containers/BillingForm/BillingForm.d.ts +4 -2
- package/containers/BillingForm.js +1 -1
- package/containers/Checkout/Checkout.d.ts +2 -6
- package/containers/Checkout.js +1 -1
- package/containers/EmptyCart/EmptyCart.d.ts +8 -0
- package/containers/EmptyCart/index.d.ts +3 -0
- package/containers/EmptyCart.d.ts +3 -0
- package/containers/EmptyCart.js +1 -0
- package/containers/EstimateShipping.js +1 -1
- package/containers/LoginForm/LoginForm.d.ts +4 -2
- package/containers/LoginForm.js +1 -1
- package/containers/OutOfStock.js +1 -1
- package/containers/PaymentMethods/PaymentMethods.d.ts +6 -4
- package/containers/PaymentMethods.js +1 -1
- package/containers/PlaceOrder/PlaceOrder.d.ts +4 -2
- package/containers/PlaceOrder.js +1 -1
- package/containers/ShippingForm/ShippingForm.d.ts +5 -3
- package/containers/ShippingForm.js +1 -1
- package/containers/ShippingMethods/ShippingMethods.d.ts +4 -2
- package/containers/ShippingMethods.js +1 -1
- package/containers/index.d.ts +1 -0
- package/hocs/index.d.ts +1 -0
- package/hocs/withConditionalRendering.d.ts +13 -0
- package/i18n/en_US.json.d.ts +8 -0
- package/package.json +1 -1
- package/render.js +3 -3
- package/utils/getDisplayName/getDisplayName.d.ts +4 -0
- package/utils/getDisplayName/index.d.ts +2 -0
- package/utils/index.d.ts +1 -0
- package/chunks/BillToShippingAddress2.js +0 -1
- package/chunks/BillingForm.js +0 -1
- package/chunks/LoginForm.js +0 -1
- package/chunks/PlaceOrder.js +0 -1
- package/chunks/ShippingForm.js +0 -1
- package/chunks/ToggleButton.js +0 -1
- package/chunks/ToggleButton2.js +0 -1
- package/chunks/constants.js +0 -1
- package/chunks/constants2.js +0 -1
- package/chunks/constants3.js +0 -1
- package/chunks/fixtures.js +0 -15
- package/chunks/getMultilineValues.js +0 -43
- package/chunks/placeOrder2.js +0 -127
- package/chunks/setGuestEmailOnCart.js +0 -17
- package/chunks/setPaymentMethod.js +0 -13
- package/chunks/setShippingAddress.js +0 -13
package/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as
|
|
1
|
+
import{D as d,F as g,I as m,c as h,M as l,d as c,a as C,b as f,S as A,U as F,i as u,g as E,h as M,j as S,r as x,s as T,e as D,f as G}from"./chunks/getCart.graphql.js";import{S as U,e as b,g as R,i as I,p as Q,s as _,a as k,b as v,c as y}from"./chunks/setShippingMethods.js";import{c as H,f as N,g as w,i as z,a as L,r as P,b as j}from"./chunks/resetCustomer.js";import{g as q,a as J,b as K}from"./chunks/getCustomer.js";import{p as W}from"./chunks/placeOrder.js";import{s as Z}from"./chunks/setBillingAddress.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";const o=e=>{var s;(s=window==null?void 0:window.location)==null||s.assign(e)};export{d as DEFAULT_COUNTRY,g as FetchError,m as InvalidArgument,h as MissingBillingAddress,l as MissingCart,c as MissingCountry,C as MissingEmail,f as MissingPaymentMethod,U as STANDARD_ATTRIBUTES,A as STORE_CONFIG_DEFAULTS,F as UnexpectedError,H as config,u as defaultFormFields,b as estimateShippingMethods,N as fetchAddressFormFields,E as fetchGraphQl,q as getCart,J as getCheckoutData,M as getConfig,w as getCountries,K as getCustomer,R as getRegions,S as getStoreConfig,z as initialize,L as initializeCheckout,I as isEmailAvailable,W as placeOrder,Q as prepareAddress,o as redirect,x as removeFetchGraphQlHeader,P as resetCheckout,j as resetCustomer,Z as setBillingAddress,T as setEndpoint,D as setFetchGraphQlHeader,G as setFetchGraphQlHeaders,_ as setGuestEmailOnCart,k as setPaymentMethod,v as setShippingAddress,y as setShippingMethodsOnCart};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as l}from"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/event-bus.js";import{n as g,v as h,w as k}from"./getCart.graphql.js";import{s as S}from"./setBillingAddress.js";import{classes as b}from"@dropins/tools/lib.js";import{Checkbox as v,Skeleton as C,SkeletonRow as _}from"@dropins/tools/components.js";import{useText as y}from"@dropins/tools/i18n.js";import{useState as A,useEffect as f}from"@dropins/tools/preact-compat.js";function B(t){return t.displayName||t.name||"Component"}const I=({className:t,isInitialized:s=!0,checked:i=!0,...n})=>{const e=y({title:"Checkout.BillToShippingAddress.title"});return s?l("div",{className:b(["checkout-bill-to-shipping-address",t]),children:l(v,{"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,...n})}):l(N,{})},N=()=>l(C,{className:"bill-to-shipping-address__skeleton",children:l(_,{variant:"row",size:"small"})}),m="is_bill_to_shipping_address",x=t=>{const s=B(t),i=({hideOnEmptyCart:n=!0,hideOnVirtualCart:e=!1,...c})=>{const r=g.value.data,a=r!==void 0&&(r===null||r.isEmpty),o=!!(r!=null&&r.isVirtual);return n&&a||e&&o?null:l(t,{...c})};return i.displayName=`Conditional(${s})`,i};function T(t,s,i){const n=t[i],e=s[i];return n===void 0&&e===void 0||n===null&&e===null?!0:typeof n=="object"&&typeof e=="object"?JSON.stringify(n)===JSON.stringify(e):n===e}function w(t,s,i){return!s&&!i?!0:!s||!i?!1:t.every(n=>{const e=n.code;return T(s,i,e)})}const z=({isBillToShipping:t})=>{var u;const[s,i]=A(!1),n=k.value.data,e=g.value.data,c=(e==null?void 0:e.id)||"",r=!!e,a=e==null?void 0:e.billingAddress,o=(u=e==null?void 0:e.shippingAddresses)==null?void 0:u[0],d=!!o;return f(()=>{if(s)return;const p=localStorage.getItem(m);p&&(i(!0),t.value={checked:p==="true",setByUser:!1})},[s,t]),f(()=>{if(s||!n||!r)return;i(!0);const p=w(n,a,o);t.value={checked:a?p:t.value.checked,setByUser:!1}},[a,n,r,t,s,o]),{cartId:c,isInitialized:s,hasShippingAddress:d}},E=({children:t,...s})=>{const i=h.value.checked,{hasShippingAddress:n,isInitialized:e}=z({isBillToShipping:h});return l(I,{...s,checked:i,isInitialized:e,onChange:r=>{const o=r.target.checked;if(h.value={checked:o,setByUser:!0},localStorage.setItem(m,o.toString()),!e||!o||!n)return;const d=new AbortController;return S({signal:d.signal,input:{same_as_shipping:!0}}).catch(u=>{console.error(u)}),()=>{d.abort()}},disabled:g.value.pending})},P=x(E);export{P as B,m as a,w as c,x as w};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import"./ShippingMethods.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/preact-hooks.js";import{n as s}from"./getCart.graphql.js";import{classes as i}from"@dropins/tools/lib.js";import{IllustratedMessage as l,Icon as m,Button as p}from"@dropins/tools/components.js";import"./BillToShippingAddress.js";import{useText as h}from"@dropins/tools/i18n.js";import*as e from"@dropins/tools/preact-compat.js";const x=({routeHome:r})=>{const a=s.value.data;return a!==void 0&&(a===null||a.isEmpty)?n(C,{routeHome:r}):null},u=r=>e.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},e.createElement("g",{clipPath:"url(#clip0_102_196)"},e.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3601 18.16H6.5601L4.8801 3H2.3501M19.6701 19.59C19.6701 20.3687 19.0388 21 18.2601 21C17.4814 21 16.8501 20.3687 16.8501 19.59C16.8501 18.8113 17.4814 18.18 18.2601 18.18C19.0388 18.18 19.6701 18.8113 19.6701 19.59ZM7.42986 19.59C7.42986 20.3687 6.79858 21 6.01986 21C5.24114 21 4.60986 20.3687 4.60986 19.59C4.60986 18.8113 5.24114 18.18 6.01986 18.18C6.79858 18.18 7.42986 18.8113 7.42986 19.59Z",stroke:"currentColor",strokeLinejoin:"round"}),e.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.25 6.37L20.89 8.06L20.14 14.8H6.19",stroke:"currentColor",strokeLinejoin:"round"})),e.createElement("defs",null,e.createElement("clipPath",{id:"clip0_102_196"},e.createElement("rect",{vectorEffect:"non-scaling-stroke",width:19.29,height:19.5,fill:"white",transform:"translate(2.3501 2.25)"})))),C=({className:r,title:a,routeHome:t,...o})=>{const c=h({Title:"Checkout.EmptyCart.title",Button:"Checkout.EmptyCart.button"});return n(l,{...o,"data-testid":"checkout-empty-cart",className:i(["checkout-empty-cart",r]),heading:a??c.Title,icon:n(m,{className:i(["checkout-empty-cart__icon"]),source:u}),action:t!=null&&t()?n(p,{className:"checkout-empty-cart__button",size:"medium",variant:"primary",type:"submit",href:t==null?void 0:t(),children:c.Button},"routeHome"):void 0})};export{x as E};
|
package/chunks/OutOfStock.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as c,jsxs as k}from"@dropins/tools/preact-jsx-runtime.js";import"./
|
|
1
|
+
import{jsx as c,jsxs as k}from"@dropins/tools/preact-jsx-runtime.js";import"./ShippingMethods.js";import{events as f}from"@dropins/tools/event-bus.js";import"@dropins/tools/preact-hooks.js";import"./getCart.graphql.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";import"./BillToShippingAddress.js";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};
|
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
import{jsx as o,Fragment as X,jsxs as M}from"@dropins/tools/preact-jsx-runtime.js";import{d as ve,A as b,f as B,e as Le,D as oe,g as Ze,M as ke,h as Fe,p as Me,i as Ke,s as Xe,a as Je,b as Ye,c as Qe}from"./setShippingMethods.js";import{events as ee}from"@dropins/tools/event-bus.js";import{A as U,y as O,n as T,V as z,w as be,z as et,m as Ie,o as de,v as Se,k as tt,B as Z,E as Q}from"./getCart.graphql.js";import{useState as H,useCallback as j,useEffect as R,useRef as nt,useMemo as ot}from"@dropins/tools/preact-hooks.js";import{classes as $,getFormErrors as rt,Slot as Ee,VComponent as I}from"@dropins/tools/lib.js";import{Text as q,useText as J}from"@dropins/tools/i18n.js";import{Field as re,Input as ue,Picker as it,Skeleton as me,SkeletonRow as A,IllustratedMessage as Ae,Icon as Ne,ProgressSpinner as he,Button as st,Divider as K,RadioButton as we,Price as at}from"@dropins/tools/components.js";import{w as Y,c as lt}from"./BillToShippingAddress.js";import{s as Pe}from"./setBillingAddress.js";import*as x from"@dropins/tools/preact-compat.js";import{forwardRef as ct,useRef as $e,useImperativeHandle as dt,useState as G,useEffect as V,useMemo as xe,useCallback as te}from"@dropins/tools/preact-compat.js";import{E as ut}from"./ErrorBanner.js";import{M as mt}from"./MergedCartBanner.js";const ht=e=>({countryCode:e.country_id,postCode:e.postcode||"",...e.region_id?{regionId:Number(e.region_id)}:{...e.region?{region:e.region}:{}}}),gt=e=>({carrierCode:e.carrier.code||"",methodCode:e.code||"",amount:e.amount,amountExclTax:e.amountExclTax,amountInclTax:e.amountInclTax}),ge={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 Re(e){return Object.keys(e).length===0&&e.constructor===Object}const pt=e=>e.map(t=>{var r;const n=((r=t==null?void 0:t.id)==null?void 0:r.toString())||t.code;return{text:t.name,value:n}}),ft=e=>e?e.map(t=>({text:t.label,value:t.value})):[];function vt({address:e,addressType:t,availableCountries:n,availableRegions:r,config:i,dismissError:a,errors:s,fields:l,onBlur:d,onChange:h,onInvalid:c,onSelection:p,setAddress:u}){const E=()=>{u(m=>({...m,[b.Region]:"",[b.RegionId]:""})),a(b.Region)},f=m=>{u(w=>({...w,[b.RegionId]:m}))};return l.map(m=>{var C;let w,F=m.frontendInput,k=p,v=h,L=m.isDisabled,P=m.isRequired,N=[],S;return F===U.Multiline?(S=ve(m.code,e),w=ve(m.code,s)):(S=e[m.code],w=s[m.code]||""),m.code===b.Country&&(N=ft(n),t===B.SHIPPING&&(O.value.country=S,k=g=>{const y=g.target,{value:_}=y;_&&le({country_code:_}),p(g),E()})),m.code===b.RegionId&&t===B.SHIPPING&&(O.value.selectedRegionId=S),m.code===b.Region&&(t===O.value.addressType&&(L=O.value.pending),P=i.countriesWithRequiredRegion.includes(e==null?void 0:e.country_id),N=pt(r),!P&&!i.displayStateIfOptional&&(F=U.Undefined),F=N.length>0?U.Select:U.Text,F===U.Select?t===B.SHIPPING?(O.value.selectedRegion=S,k=g=>{const _=g.target.value;le({country_code:O.value.country,region_id:_}),p(g),f(_)}):k=g=>{p(g);const _=g.target.value;f(_)}:F===U.Text&&t===B.SHIPPING&&(O.value.selectedRegion=S,v=g=>{const y=g.target,{value:_}=y;O.value.country&&le({country_code:O.value.country,region_name:_}),h(g)}),S=N.length>0?((C=N.find(g=>g.value===S))==null?void 0:C.value)||"":S),m.code===b.PostCode&&(P=!i.countriesWithOptionalZipCode.includes(e==null?void 0:e.country_id)),{...m,error:w,frontendInput:F,handleSelect:k,isDisabled:L,isRequired:P,onBlur:d,onChange:v,onInvalid:c,options:N,value:S}})}let Ce;function le(e){var a;const t=T.value.data,n=!!t,r=(a=t==null?void 0:t.shippingAddresses)==null?void 0:a[0],i=r==null?void 0:r.availableShippingMethods;n&&!i&&(clearTimeout(Ce),Ce=setTimeout(()=>{Le({criteria:e})},oe))}const ie=({addressType:e,code:t,index:n})=>n?`${e}-${t}-${n}`:`${e}-${t}`,se=e=>`checkout-address-form__${e}`,kt=({addressType:e,element:t})=>{const{code:n,value:r,defaultValue:i}=t;return o("input",{className:se(n),id:ie({addressType:e,code:n}),name:n,type:"hidden",value:r||i},n)},Ft=({addressType:e,element:t})=>{const{code:n,error:r,isDisabled:i,label:a,onBlur:s,onChange:l,onInvalid:d,validateRules:h,value:c}=t,p=Be(h);return o(re,{disabled:i,error:r,children:o(ue,{"aria-label":a,autocomplete:ge[n]||"off",className:se(n),floatingLabel:`${a} ${t.isRequired?"*":""}`,id:ie({addressType:e,code:n}),onBlur:s,onChange:l,onInvalid:d,placeholder:a,required:t.isRequired||!1,type:"text",name:n,value:c??void 0,...p})})},Et=({addressType:e,element:t})=>{const{code:n,error:r,isDisabled:i,isRequired:a,label:s,multilineCount:l,onBlur:d,onChange:h,onInvalid:c,validateRules:p,value:u}=t,E=l??0,f=Be(p);return o(X,{children:Array.from(Array(E).keys()).map(m=>o(re,{disabled:i,error:(r==null?void 0:r[m])||"",className:"dropin-field--multiline",children:o(ue,{id:ie({addressType:e,code:n,index:m}),className:se(n),floatingLabel:`${s} ${m!=0?m:""} ${a&&m===0?"*":""}`,autocomplete:m===0?ge[n]:"off","aria-label":s,placeholder:`${s} ${m!=0?m:""}`,type:"text",required:a&&m===0,onChange:h,onBlur:d,onInvalid:c,name:`${n}-${m}`,value:(u==null?void 0:u[m])||void 0,...f})},`${n}-${m}`))})},Ct=({addressType:e,element:t})=>{const{code:n,error:r,handleSelect:i,isDisabled:a,isRequired:s,label:l,onBlur:d,onInvalid:h,options:c,value:p}=t,u=i?{handleSelect:i}:{};return o(re,{disabled:a,error:r,children:o(it,{id:ie({addressType:e,code:n}),className:se(n),name:n,floatingLabel:`${l} ${s?"*":""}`,required:s,placeholder:l,"aria-label":l,options:c,value:p,autocomplete:ge[n]||"off",onBlur:d,onInvalid:h,...u},n)})},yt=({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 kt({addressType:e,element:t});case"TEXT":return Ft({addressType:e,element:t});case"MULTILINE":return Et({addressType:e,element:t});case"SELECT":return Ct({addressType:e,element:t});default:return null}},Be=e=>e?e.reduce((t,n)=>{switch(n.name){case z.DateRangeMax:return{...t,max:n.value};case z.DateRangeMin:return{...t,min:n.value};case z.FileExtensions:return{...t,accept:n.value};case z.InputValidation:return{...t,pattern:_t(n.value)};case z.MaxFileSize:case z.MaxImageHeight:case z.MaxImageWidth:return t;case z.MaxTextLength:return{...t,maxLength:n.value};case z.MinTextLength:return{...t,minLength:n.value};default:throw new Error(`Unknown rule: ${n.name}`)}},{}):{},D={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]*))?)$/},_t=e=>{switch(e){case"alpha":return D.alpha.source;case"alphanumeric":return D.alphanumeric.source;case"alphanumeric-w-space":return D["alphanumeric-w-space"].source;case"alphanum-with-spaces":return D["alphanum-with-spaces"].source;case"url":return D.url.source;case"numeric":return D.numeric.source;case"email":return D.email.source;default:throw new Error(`Unknown validation type: ${e}`)}},Lt=e=>M(me,{...e,children:[o(A,{variant:"heading",size:"medium"}),o(A,{variant:"empty",size:"medium"}),o(A,{size:"large"}),o(A,{size:"large"}),o(A,{size:"large",fullWidth:!0}),o(A,{size:"large",fullWidth:!0,lines:3}),o(A,{size:"large"}),o(A,{size:"large"}),o(A,{size:"large"}),o(A,{size:"large"}),o(A,{size:"large"}),o(A,{size:"large"}),o(A,{size:"large"})]}),Mt=({addressType:e,className:t,fields:n,formRef:r,headingId:i,name:a,...s})=>M("div",{...s,className:$(["checkout-fields-form",t]),children:[o(ne,{level:2,children:o(q,{id:i}),className:"checkout-fields-form__title"}),o("form",{name:a,ref:r,className:$(["checkout-fields-form__form",t]),noValidate:!0,children:n.sort((l,d)=>!l.sortOrder||!d.sortOrder?l.code<d.code?-1:1:l.sortOrder-d.sortOrder).map(l=>yt({element:l,addressType:e}))})]}),bt=e=>{const t=new FormData(e),n=Object.fromEntries(t);return Object.entries(n).reduce((i,[a])=>{const s=e.elements[a];return s!=null&&s.validationMessage?{...i,[a]:s.validationMessage}:{...i}},{})};function It(e){const[t,n]=G({});return V(()=>{e&&n(r=>({...r,country_id:e}))},[e]),{defaultValues:t}}function St({country:e,addressType:t}){const[n,r]=G([]);return V(()=>{if(!e){r([]);return}Ze(e,t).then(i=>{r(i||[])}).catch(i=>{console.error(i)})},[r,e,t]),{availableRegions:n}}function At({autoFill:e,addressType:t,dismissError:n,loadAutoFill:r}){const[i,a]=G(!1),s=de.value.data,l=!!s,d=T.value.data,h=!!d;V(()=>{var w;if(!e||!h||i)return;let c,p=!1;c=Gt({addressType:t,cart:d}),!c&&l&&(c=Dt({addressType:t,customer:s}),p=!0);const u=F=>F?F.split(Fe).length>1:!1;if(!c)return;a(!0);const E={[b.City]:c.city,[b.Company]:c.company||"",[b.Country]:c.country.value,[b.FirstName]:c.firstName,[b.LastName]:c.lastName,[b.PostCode]:c.postCode||"",[b.Telephone]:c.telephone||"",[b.Vat]:c.vatId||""},f=c.region;if(f){const F=(w=f==null?void 0:f.id)==null?void 0:w.toString();F?(E[b.Region]=F,E[b.RegionId]=F):E[b.Region]=f.code}c!=null&&c.street&&c.street.length>0&&c.street.forEach((F,k)=>{E[`${b.Street}${ke}${k}`]=F}),((c==null?void 0:c.customAttributes)||[]).forEach(F=>{u(F.code)?F.value.split(Fe).forEach((v,L)=>{E[`${F.code}${ke}${L}`]=v}):E[F.code]=F.value}),r({values:E,triggerAutoSave:p})},[t,e,d,s,i,h,l,r,n])}const Oe=ct(({addressType:e,autoFill:t=!0,children:n,headingId:r,name:i,preselectedFields:a,saveAddressHandler:s,onCheckoutDataUpdate:l,...d},h)=>{const{data:c,pending:p}=be.value,u=et.value.data,E=u===void 0,f=c===void 0||p,m=Ie.value.data,w=m===void 0,{defaultValues:F}=It(m==null?void 0:m.defaultCountry),k=Wt({fields:c,preselectedFields:a}),v=$e(null),{address:L,errors:P,loadAutoFill:N,onBlur:S,dismissError:C,onChange:g,onInvalid:y,onSelection:_,setAddress:W}=zt({defaultValues:F,formRef:v,onCheckoutDataUpdate:l,preselection:k,saveAddressHandler:s,type:e}),{availableRegions:ae}=St({country:L.country_id,addressType:e});if(dt(h,()=>({triggerSaveAddress:qe=>{if(!v.current)return;const Ue=bt(v.current);if(Re(Ue))return s({signal:qe,address:L})}})),At({addressType:e,autoFill:t,loadAutoFill:N,dismissError:C}),f||E||w)return o(Lt,{"data-testid":`${e}-skeleton`});const je=vt({address:L,addressType:e,availableCountries:u,availableRegions:ae,config:m,dismissError:C,errors:P,fields:c,onBlur:S,onChange:g,onInvalid:y,onSelection:_,setAddress:W}),fe={[B.SHIPPING]:"shipping",[B.BILLING]:"billing"};return o(Mt,{...d,name:i,addressType:e,className:`checkout-${fe[e]}-form`,"data-testid":`${fe[e]}-form`,fields:je,formRef:v,headingId:r})}),Nt="DROPIN__CHECKOUT",pe=e=>`${Nt}__${e.toUpperCase()}`,wt=(e,t)=>{window.localStorage.setItem(pe(e),JSON.stringify(t))},Pt=e=>{const t=window.localStorage.getItem(pe(e));return t?JSON.parse(t):null},$t=e=>{window.localStorage.removeItem(pe(e))};function xt(e){const[t,n]=H(null),r=j(a=>setTimeout(()=>{wt(e,a)},oe),[e]),i=j(()=>{$t(e)},[e]);return R(()=>{const a=Pt(e);a&&n(a)},[e]),R(()=>{const a=ee.on("checkout/order",()=>{i()});return()=>{a==null||a.off()}},[i]),{addressBackup:t,backupAddress:r,removeAddressBackup:i}}const Rt={[B.BILLING]:"billing",[B.SHIPPING]:"shipping"};function Bt({address:e,type:t,isValid:n}){R(()=>{const r=setTimeout(()=>{ee.emit("checkout/address",{type:Rt[t],address:e,isValid:n()})},oe);return()=>{clearTimeout(r)}},[e,n,t])}const Ot={badInput:"aria-label",patternMismatch:"aria-label",rangeOverflow:"max",rangeUnderflow:"min",tooLong:"maxlength",tooShort:"minlength",typeMismatch:"aria-label",valueMissing:"aria-label"},Ht=["badInput","patternMismatch","rangeOverflow","rangeUnderflow","tooLong","tooShort","typeMismatch","valueMissing"],Tt=e=>{const[t,n]=H({}),r=j(s=>{const{name:l,validity:d,validationMessage:h}=s;let c=d.valid?"":h;Ht.forEach(p=>{if(!d[p])return;const u=e[p];if(!u)return;const E=Ot[p];c=u.replace("{field}",s.getAttribute(E)||"")}),n(p=>({...p,[l]:c}))},[e]);return{errors:t,dismissError:s=>{t[s]&&n(l=>{const{[s]:d,...h}=l;return h})},validateFormElement:r,resetErrors:()=>{n({})}}},ye=e=>{const t=e.current;if(!t)return!1;const n=rt(t);return Re(n)},zt=({defaultValues:e={},formRef:t,onCheckoutDataUpdate:n,preselection:r={},saveAddressHandler:i,type:a})=>{const s=J({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"}),l=nt(!1),[d,h]=H({});Bt({address:d,type:a,isValid:j(()=>ye(t),[t])});const{addressBackup:c,backupAddress:p,removeAddressBackup:u}=xt(a),{errors:E,validateFormElement:f,dismissError:m,resetErrors:w}=Tt(s),F=j(C=>{l.current=!1,i(C).then(()=>{u(),n==null||n()}).catch(g=>{l.current=!0,console.error("Saving address form failed:",g)})},[u,i,n]),k=(C,g)=>{h(y=>({...y,[C]:g})),l.current=!0},v=({values:C,triggerAutoSave:g=!1})=>{w(),h(y=>({...y,...C})),g&&(l.current=!0)},L=C=>{const g=C.target,{name:y,value:_}=g;k(y,_),f(g)},P=C=>{const g=C.target;f(g)},N=C=>{const g=C.target,{name:y,value:_}=g;k(y,_),f(g)},S=C=>{C.target.checkValidity()};return R(()=>{h(C=>({...e,...r,...c,...C}))},[e,r,c]),R(()=>{if(!l.current)return;const C=p(d);return()=>{clearTimeout(C)}},[d,p]),R(()=>{if(!l.current||!ye(t))return;const C=new AbortController,g=C.signal,y=setTimeout(()=>{F({signal:g,address:d})},oe);return()=>{clearTimeout(y),C.abort()}},[d,t,F]),{address:d,errors:E,loadAutoFill:v,dismissError:m,onChange:L,onSelection:N,onBlur:S,onInvalid:P,setAddress:h}},Vt={countryCode:b.Country,region:b.Region,postCode:b.PostCode};function Wt({fields:e,preselectedFields:t}){return ot(()=>!(!!e&&e.length>0)||!!!t?{}:Object.keys(t).reduce((i,a)=>{const s=Vt[a];return!s||!e.some(d=>d.code===s)?i:{...i,[s]:t[a]}},{}),[e,t])}const Dt=({addressType:e,customer:t})=>e===B.BILLING?t.defaultBillingAddress:t.defaultShippingAddress,Gt=({addressType:e,cart:t})=>{if(e===B.BILLING)return t.billingAddress;const n=t.shippingAddresses;if(!(!n||n.length===0))return n[0]},He=e=>{var E;const t=$e(null),n=be.value.data,r=de.value.data,i=r==null?void 0:r.defaultBillingAddress,a=T.value.data,s=a==null?void 0:a.billingAddress,l=(E=a==null?void 0:a.shippingAddresses)==null?void 0:E[0],{checked:d,setByUser:h}=Se.value,c=!d,p=xe(()=>!n||!c?!1:s?!lt(n,s,l):!!i,[c,n,s,l,i]),u=te(f=>Pe({signal:f.signal,input:{address:d?void 0:Me(f.address),same_as_shipping:d}}),[d]);return V(()=>{if(!h)return;const f=new AbortController;return d||t.current.triggerSaveAddress(f.signal),()=>{f.abort()}},[d,h]),o(Oe,{...e,addressType:B.BILLING,autoFill:p,"data-testid":"billing-form",headingId:"Checkout.BillingAddress.title",name:jt,ref:t,saveAddressHandler:u,style:{display:c?"block":"none"}})};He.displayName="BillingFormContainer";const On=Y(He),jt="billing_address",qt=e=>x.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},x.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"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),Ut=e=>x.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},x.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"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),x.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"}),x.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"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),x.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),Te="login-form",Zt=({value:e,error:t,hint:n,onChange:r,onBlur:i,onInvalid:a})=>{const s=J({LoginFormLabel:"Checkout.LoginForm.ariaLabel",LoginFormFloatingLabel:"Checkout.LoginForm.floatingLabel",LoginFormPlaceholder:"Checkout.LoginForm.placeholder"});return o(re,{size:"medium",error:t,hint:n,children:o(ue,{id:"customer-email",name:"customer-email",type:"email",value:e,autocomplete:"email",placeholder:s.LoginFormPlaceholder,floatingLabel:s.LoginFormFloatingLabel,onChange:r,onBlur:i,onInvalid:a,required:!0,"aria-label":s.LoginFormLabel,"aria-required":!0})})},Kt=({onSignInClick:e,email:t})=>M("div",{className:"checkout-login-form__sign-in",children:[o(q,{id:"Checkout.LoginForm.account"}),o("a",{"data-testid":"sign-in-link",className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:n=>{n.preventDefault(),e==null||e(t)},children:o(q,{id:"Checkout.LoginForm.signIn"})})]}),Xt=({name:e,className:t,currentEmail:n,hint:r,error:i=null,onEmailChange:a,onEmailBlur:s,onEmailInvalid:l,onSignInClick:d,onSignOutClick:h,customer:c,...p})=>{const u=J({Title:"Checkout.LoginForm.title"}),E=!!c;return M("div",{...p,className:$(["checkout-login-form",t]),"data-testid":"checkout-login-form",children:[M("div",{className:"checkout-login-form__heading",children:[o(ne,{level:2,className:"checkout-login-form__title",children:u.Title}),E?o(Jt,{onSignOutClick:h}):o(Kt,{onSignInClick:d,email:n})]}),c?M("div",{className:"checkout-login-form__customer-details",children:[o("div",{className:"checkout-login-form__customer-name",children:`${c==null?void 0:c.firstName} ${c==null?void 0:c.lastName}`}),o("div",{className:"checkout-login-form__customer-email",children:c==null?void 0:c.email})]}):o("div",{className:"checkout-login-form__content",children:M("form",{className:$(["dropin-login-form__form",t]),name:e,noValidate:!0,children:[o("button",{type:"submit",disabled:!0,style:"display: none","aria-hidden":"true"}),o(Zt,{value:n||void 0,error:i||"",hint:r,onChange:a,onBlur:s,onInvalid:l})]})})]})},Jt=({onSignOutClick:e})=>M("p",{className:"checkout-login-form__sign-out",children:[o(q,{id:"Checkout.LoginForm.switch"}),o("a",{className:"checkout-login-form__link",href:"#",target:"_blank",rel:"noreferrer",onClick:t=>{t.preventDefault(),e==null||e()},children:o(q,{id:"Checkout.LoginForm.signOut"})})]}),Yt=e=>D.email.test(e),Qt=1e3,ze=({className:e,email:t=null,onSignInClick:n,onSignOutClick:r,...i})=>{const a=J({LoginFormInvalidEmailError:"Checkout.LoginForm.invalidEmailError",LoginFormMissingEmailError:"Checkout.LoginForm.missingEmailError",LoginFormEmailExistsAlreadyHaveAccount:"Checkout.LoginForm.emailExists.alreadyHaveAccount",LoginFormEmailExistsSignInButton:"Checkout.LoginForm.emailExists.signInButton",LoginFormEmailExistsForFasterCheckout:"Checkout.LoginForm.emailExists.forFasterCheckout"}),{data:s}=T.value,l=(s==null?void 0:s.id)||"",d=!!s,h=(s==null?void 0:s.email)||"",[c,p]=H(!1),[u,E]=H(t),[f,m]=H(null),[w,F]=H(!0),k=g=>g.valid?null:g.valueMissing?a.LoginFormMissingEmailError:a.LoginFormInvalidEmailError,v=de.value.data,L=g=>{const{value:y}=g.target;E(y),m(null),F(!0)},P=g=>{const{validity:y}=g.target;m(k(y))},N=g=>{const{validity:y}=g.target;m(k(y))};!c&&d&&(p(!0),E((s==null?void 0:s.email)||t)),R(()=>{if(f!==null&&f!==""||u===null||u===""||tt.authenticated)return;const g=setTimeout(()=>{Ke(u).then(y=>{F(y),h!==u&&Xe(u).catch(console.error)}).catch(y=>{console.log(y),m(a.LoginFormInvalidEmailError),F(!0)})},Qt);return()=>{g&&clearTimeout(g)}},[h,l,u,f,a.LoginFormInvalidEmailError]);const S=w?"":M(X,{children:[a.LoginFormEmailExistsAlreadyHaveAccount," ",o("a",{href:"#",onClick:g=>{g.preventDefault(),n==null||n(u)},children:a.LoginFormEmailExistsSignInButton})," ",a.LoginFormEmailExistsForFasterCheckout]});return o(Xt,{className:e,currentEmail:u,error:f,hint:S,name:Te,onEmailBlur:P,onEmailChange:L,onEmailInvalid:N,onSignInClick:g=>{const y=u?Yt(u):!1;n==null||n(y?g:null)},onSignOutClick:r,customer:v,...i})};ze.displayName="LoginFormContainer";const Hn=Y(ze),en=()=>M(me,{"data-testid":"payment-methods-skeleton",children:[o(A,{variant:"heading",size:"medium"}),o(A,{variant:"empty",size:"medium"}),o(A,{size:"xlarge",fullWidth:!0}),o(A,{size:"xlarge",fullWidth:!0})]}),tn=({code:e,isLoading:t,isSelected:n,onChange:r,title:i})=>o(kn,{className:"checkout-payment-methods__method",label:i,name:"payment-method",value:e,selected:n,onChange:r,radioButtonProps:{"aria-busy":t}}),nn=({className:e,paymentMethodContent:t,isLoading:n,onChange:r=()=>{},options:i,selection:a})=>{const s=J({Title:"Checkout.PaymentMethods.title",EmptyState:"Checkout.PaymentMethods.emptyState"});return i===void 0?o(en,{}):M("div",{className:$(["checkout-payment-methods",e]),children:[o(ne,{level:2,className:"checkout-payment-methods__title",children:s.Title}),!n&&i.length===0&&o(Ae,{icon:o(Ne,{source:qt}),message:o("p",{children:s.EmptyState})}),M("div",{className:$(["checkout-payment-methods__wrapper"]),children:[n&&o(he,{className:"checkout-payment-methods__spinner"}),o("div",{className:$(["checkout-payment-methods__methods",["checkout-payment-methods--loading",n],["checkout-payment-methods--full-width",i.length%2!==0]]),children:i==null?void 0:i.map(l=>o(tn,{code:l.code,onChange:r,isSelected:l.code===a,title:l.title},l.code))}),t&&o("div",{className:"checkout-payment-methods__content",children:t})]})]})},_e={free:{render:e=>{const t=document.createElement("div");t.innerText="",e.replaceHTML(t)}},checkmo:{render:e=>{const t=document.createElement("div");t.innerText="",e.replaceHTML(t)}}};function on(e){var y;const{onPlaceOrder:t,handleServerError:n,paymentMethodsSlot:r}=e,[i,a]=G(),[s,l]=G(),[d,h]=G(_e),[c,p]=G(!0),{data:u}=T.value,E=(u==null?void 0:u.id)??"",f=!!u,m=!!((y=u==null?void 0:u.shippingAddresses)!=null&&y[0]),F=!((u==null?void 0:u.isVirtual)??!1),k=u==null?void 0:u.availablePaymentMethods,v=u==null?void 0:u.selectedPaymentMethod,L=te(async _=>{try{if(a(_),!m&&F||_===(v==null?void 0:v.code))return;await Je(_)}catch(W){console.error("setting payment method failed:",W)}},[m,F,v]);V(()=>{f&&(v!=null&&v.code?(k==null?void 0:k.some(W=>W.code===v.code))?a(v.code):k!=null&&k.length?L(k[0].code):a(void 0):k[0]&&L(s||k[0].code))},[k,f,v,L,s]);const P=async _=>{t(),await L(_),v!=null&&v.code||l(_)},N=te((_,W)=>{if(!_){console.warn("Payment method handler is ignored because it has no code");return}if(!W){console.warn("Payment method handler is ignored because it is empty");return}h(ae=>({...ae,[_]:W}))},[]),S=r?o(Ee,{name:"PaymentMethods",slot:r,context:{addPaymentMethodHandler:N,replaceHTML(_){this.replaceWith(_),p(!1)}}}):null,C=i?d[i]:null,g=C?o(Ee,{name:"PaymentMethodContent",slot:C.render,context:{cartId:E,onPlaceOrder:t,handleServerError:n,replaceHTML(_){this.replaceWith(_)}}},C):void 0;return V(()=>{!c&&d!=_e&&console.warn("Payment method handlers you have added are ignored because the default content has been replaced")},[c,d]),{availablePaymentMethods:k,selectedPaymentMethod:i,onPaymentMethodChange:P,paymentMethodContent:g,mainSlotContent:S,isDefaultContentUsed:c}}const Ve=e=>{const{onPlaceOrder:t,handleServerError:n,paymentMethodsSlot:r}=e,{availablePaymentMethods:i,selectedPaymentMethod:a,onPaymentMethodChange:s,paymentMethodContent:l,mainSlotContent:d,isDefaultContentUsed:h}=on({onPlaceOrder:t,handleServerError:n,paymentMethodsSlot:r});return M(X,{children:[d&&o(d.type,{ref:d.ref,...d.props}),h&&o(nn,{options:i,selection:a,onChange:s,paymentMethodContent:l,isLoading:T.value.pending})]})};Ve.displayName="PaymentMethodsContainer";const Tn=Y(Ve),rn=({className:e,onClick:t=()=>{},disabled:n=!1})=>o("div",{className:$(["checkout-place-order",e]),children:o(st,{className:$(["checkout-place-order__button",e]),"data-testid":"place-order-button",disabled:n,onClick:t,size:"medium",type:"submit",variant:"primary",children:o(q,{id:"Checkout.PlaceOrder.button"})},"placeOrder")}),sn=[Te,"shipping_address","billing_address"],an=e=>{const t=e.querySelector(":invalid");t&&(t.scrollIntoView({behavior:"smooth"}),t.focus())},ln=()=>{const t=(Array.from(document.forms)||[]).filter(r=>sn.includes(r.name)).filter(r=>r.offsetParent!==null).filter(r=>!r.checkValidity()),n=t.length===0;if(!n){const r=t[0];an(r)}return n},cn=({onClick:e,handleServerError:t})=>{const[n,r]=G(!1),i=T.value.pending,a=async()=>{if(ln())try{await e()}catch(s){t(s)}};return V(()=>{const s=ee.on("cart/initialized",l=>{const d=(l==null?void 0:l.items)||[];r(d.some(h=>h.outOfStock||h.insufficientQuantity))},{eager:!0});return()=>{s==null||s.off()}},[]),o(rn,{onClick:a,disabled:i||n})},zn=Y(cn),We=({onCheckoutDataUpdate:e,preselectedFields:t,...n})=>{const r=Se.value.checked,i=te(a=>Ye({signal:a.signal,address:Me(a.address)}).then(()=>{if(r)return Pe({input:{same_as_shipping:!0}})}),[r]);return o(Oe,{...n,addressType:B.SHIPPING,headingId:"Checkout.ShippingAddress.title",name:dn,onCheckoutDataUpdate:e,preselectedFields:t,saveAddressHandler:i})};We.displayName="ShippingFormContainer";const Vn=Y(We),dn="shipping_address",un=()=>{const e=()=>window.innerWidth>=1920?"xxlarge":window.innerWidth>=1366?"xlarge":window.innerWidth>=1024?"large":window.innerWidth>=768?"medium":"small",[t,n]=H(e());return R(()=>{let r;const i=()=>{r&&clearTimeout(r),r=setTimeout(()=>n(e()),50)};return window.addEventListener("resize",i),()=>{window.removeEventListener("resize",i),r&&clearTimeout(r)}},[]),t},mn=()=>{const e=j(()=>{document.body.style.overflow="hidden"},[]),t=j(()=>{document.body.style.overflow=""},[]);return{lockScroll:e,unlockScroll:t}},De=()=>M("div",{className:"checkout-heading",children:[o(ne,{level:1,className:"checkout-heading__title",children:o(q,{id:"Checkout.title"})}),o(K,{variant:"primary",className:"checkout-heading__divider-primary"})]}),hn=({billingAddress:e,billToShippingAddress:t,cartSummaryList:n,emptyCart:r,login:i,orderSummary:a,outOfStock:s,paymentMethods:l,placeOrder:d,shippingAddress:h,shippingMethods:c})=>M(X,{children:[o(De,{}),n&&o(I,{node:n}),o(I,{node:r}),o(I,{node:s}),o(I,{node:i}),o(K,{variant:"primary"}),o(I,{node:h}),o(I,{node:t}),o(I,{node:c}),o(K,{variant:"primary"}),o(I,{node:l}),o(I,{node:e}),a&&o(I,{node:a}),o(I,{node:s}),o(I,{node:d})]}),gn=({billingAddress:e,billToShippingAddress:t,cartSummaryList:n,emptyCart:r,login:i,orderSummary:a,outOfStock:s,paymentMethods:l,placeOrder:d,shippingAddress:h,shippingMethods:c})=>M(X,{children:[M("div",{className:"checkout__main",children:[o(De,{}),o(I,{node:r}),o(I,{node:s}),o(I,{node:i}),o(K,{variant:"primary"}),o(I,{node:h}),o(I,{node:t}),o(I,{node:c}),o(K,{variant:"primary"}),o(I,{node:e}),o(I,{node:l}),o(K,{variant:"primary"}),o(I,{node:d})]}),M("div",{className:"checkout__aside",children:[a&&o(I,{node:a}),n&&o(I,{node:n})]})]}),pn=({blocks:e})=>un()==="small"?o(hn,{...e}):o(gn,{...e}),fn=({children:e,className:t,isLoading:n=!1,...r})=>M("div",{"data-testid":"checkout",className:$(["checkout",t]),...r,children:[n&&o(vn,{}),o(ut,{}),o(mt,{}),o("div",{className:"checkout__content",children:e})]});fn.Main=pn;const ne=({className:e,children:t,level:n=2})=>{const r=n>=1&&n<=6?`h${n}`:"h2";return o(r,{className:e,children:t})},vn=({className:e})=>{const{lockScroll:t,unlockScroll:n}=mn();return R(()=>(t(),n),[t,n]),o("div",{"data-testid":"checkout-overlay-loader",className:$(["checkout-overlay-loader",e]),children:o(he,{})})},kn=({label:e,name:t,value:n,icon:r,selected:i,onChange:a,className:s,children:l,radioButtonProps:d,...h})=>o("div",{className:$(["checkout-toggle-button",s,["checkout-toggle-button__selected",i]]),...h,children:M("label",{className:"checkout-toggle-button__actionButton",children:[o(we,{...d,label:"",name:t,value:n,checked:i,onChange:()=>a(n),"aria-label":e,className:$([s,"checkout-toggle-button__radioButton"])}),M("div",{className:"checkout-toggle-button__content",children:[r&&o(r.type,{...r==null?void 0:r.props,className:"checkout-toggle-button__icon"}),e]})]})}),Fn=({className:e,isLoading:t=!1,onSelectionChange:n=()=>{},options:r,selection:i,...a})=>{const s=J({Title:"Checkout.ShippingMethods.title",EmptyState:"Checkout.ShippingMethods.emptyState"});return r===void 0?o(En,{}):M("div",{...a,className:$(["checkout-shipping-methods",e]),children:[o(ne,{level:3,className:"checkout-shipping-methods__title",children:s.Title}),!t&&r.length===0&&o(Ae,{icon:o(Ne,{source:Ut}),message:o("p",{children:s.EmptyState})}),M("div",{className:$(["checkout-shipping-methods__content"]),children:[t&&o(he,{className:"checkout-shipping-methods__spinner"}),o("div",{className:$(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",t]]),children:r.map(l=>o(we,{"data-testid":"shipping-method-radiobutton","aria-busy":t,id:l.value,name:"shipping-method",className:"checkout-shipping-methods__method",label:M(X,{children:[o(at,{amount:l.amount.value,currency:l.amount.currency})," ",o("span",{children:l.carrier.title})]}),description:l.title,value:l.value,checked:(i==null?void 0:i.value)===l.value,onChange:()=>n(l)},l.value))})]})]})},En=()=>M(me,{"data-testid":"shipping-methods-skeleton",children:[o(A,{variant:"heading",size:"small"}),o(A,{variant:"empty",size:"small"}),o(A,{size:"medium",fullWidth:!0}),o(A,{size:"medium",fullWidth:!0})]});function Cn(){var u;const[e,t]=H(),[n,r]=H();R(()=>{ee.on("checkout/address",({address:E,type:f,isValid:m})=>{f==="shipping"&&t({address:E,isValid:m})})},[]),R(()=>{r(Z.value)},[Z.value]),R(()=>{Q.value.pending?r(void 0):r(Z.value)},[Q.value.pending]);const{country_id:i,region_id:a,region:s,postcode:l}=(e==null?void 0:e.address)||{},d=!!e,h=T.value.data,c=!!((u=h==null?void 0:h.shippingAddresses)!=null&&u[0]),p=e==null?void 0:e.isValid;R(()=>{c||p||!n||!d||ee.emit("shipping/estimate",{address:ht({country_id:i,region_id:a,region:s,postcode:l}),shippingMethod:gt(n)})},[n,i,a,s,l,d,c,p])}const ce=(e,t)=>e.code===t.code&&e.carrier.code===t.carrier.code;function yn({onCheckoutDataUpdate:e,preSelectedMethod:t}){const n=Ie.value.data,r=!n,i=T.value.data,a=T.value.pending,s=Q.value.data,l=Q.value.pending,d=Z.value,h=i==null?void 0:i.id,c=i==null?void 0:i.shippingAddresses,p=c==null?void 0:c[0],u=!!p,E=p==null?void 0:p.availableShippingMethods,f=p==null?void 0:p.selectedShippingMethod,m=E||s,w=te(v=>{if(!u)return;const L={method_code:v.code,carrier_code:v.carrier.code};Qe([L]).then(()=>{e==null||e()}).catch(P=>{console.error("setting shipping methods on cart failed:",P)})},[u,e]),F=v=>{Z.value=v},k=xe(()=>{if(!(m!=null&&m.length))return;const v=m[0],L=d||f;return L?m.some(N=>ce(N,L))?L:v:m.find(S=>S.carrier.code===(t==null?void 0:t.carrierCode)&&S.code===(t==null?void 0:t.methodCode))||v},[d,f,m,t]);return V(()=>{k&&((!d||!ce(k,d))&&(Z.value=k),(!f||!ce(k,f))&&w(k))},[k,d,f,w]),V(()=>{if(!h||E)return;const{country:v,selectedRegion:L,selectedRegionId:P}=O.value,N=v||(n==null?void 0:n.defaultCountry);N&&Le({criteria:{country_code:N,region_name:L,region_id:P}}).catch(C=>{Q.value={pending:!1,data:[]},console.error("shipping methods estimation failed:",C)})},[h,E,n]),{isLoading:a||r||l,options:m,selection:k,onSelectionChange:F}}const Ge=({preSelectedMethod:e,onCheckoutDataUpdate:t,...n})=>{const{isLoading:r,options:i,selection:a,onSelectionChange:s}=yn({preSelectedMethod:e,onCheckoutDataUpdate:t});return Cn(),o(Fn,{...n,className:"checkout-shipping-methods",isLoading:r,onSelectionChange:s,options:i,selection:a})};Ge.displayName="ShippingMethodsContainer";const Wn=Y(Ge);export{On as B,fn as C,Hn as L,zn as P,Wn as S,Vn as a,dn as b,Tn as c,Te as d,jt as e};
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{events as b}from"@dropins/tools/event-bus.js";import{signal as o,effect as S}from"@dropins/tools/signals.js";import{FetchGraphQL as N}from"@dropins/tools/fetch-graphql.js";class G extends Error{constructor(t){super(t.map(s=>s.message).join(" ")),this.name="FetchError"}}class p extends Error{constructor(t){super(t),this.name="InvalidArgument"}}class _e extends Error{constructor(t){super(t),this.name="UnexpectedError"}}class fe extends p{constructor(){super("Cart ID is required")}}class he extends p{constructor(){super("Email is required")}}class ge extends p{constructor(){super("Payment method code is required")}}class me extends p{constructor(){super("Billing address is required")}}class ve extends p{constructor(){super("Country Code is required")}}const m=[];function L(e){return new Promise((t,s)=>{m.push(e);const r=()=>{m[0]===e?e().then(t).catch(s).finally(()=>m.shift()):setTimeout(r,100)};r()})}const R=["sender_email","recipient_email"];function O(e){return e.filter(t=>!t.path||!R.some(s=>{var r;return((r=t.path)==null?void 0:r.at(-1))===s}))}const T=e=>{throw e instanceof DOMException&&e.name==="AbortError"||b.emit("error",{source:"checkout",type:"network",error:e}),e},U=o({data:void 0,pending:!1}),q=o({checked:!0,setByUser:!1}),h=o({pending:!1,data:void 0});S(()=>{var e;(e=h.value.data)!=null&&e.isVirtual&&(q.value={checked:!1,setByUser:!1})});S(()=>{h.value.pending||b.emit("checkout/data",h.value.data||null)});const X=o({data:void 0,pending:!1}),P=o({pending:!1,data:void 0}),k=o({pending:!1,data:void 0}),w=o({pending:!1,data:void 0}),ye=o(void 0),F=o({data:void 0,pending:!1}),H={cart:h,customer:P,estimateShippingMethods:k,regions:w,storeConfig:F,countryList:X,addressFormFields:U};function B(e,t){return t.split(".").reduce((s,r)=>s&&s[r]!==void 0?s[r]:void 0,e)}const E={cart:null,customer:null,estimateShippingMethods:null,regions:null,storeConfig:null,countryList:null,addressFormFields:null};async function W(e){const{defaultValueOnFail:t,query:s,options:r,path:n,signalType:d,type:g,transformer:_}=e,a=H[d],v=Symbol();E[d]=v,a.value={...a.value,pending:!0};try{const{data:f,errors:y}=await(g==="mutation"?L(()=>I(s,r).catch(T)):I(s,{method:"GET",cache:"no-cache",...r}).catch(T));if(y){const C=O(y);if(C.length>0)throw new G(C)}let u=B(f,n);if(u===void 0)throw new Error(`No data found at path: ${n}`);return _&&(u=_(u)),a.value={...a.value,data:u},setTimeout(()=>{a.value={...a.value,pending:E[d]===v?!1:a.value.pending}},0),u}catch(f){if(t)return a.value={pending:!1,data:t},t;if(f.name==="AbortError")return;throw a.value={...a.value,pending:!1},f}}const Q={cartId:null,authenticated:!1},Ce=new Proxy(Q,{set(e,t,s){return e[t]=s,!0},get(e,t){return e[t]}}),$=e=>{if(e)return{code:e.code,title:e.title}},V=e=>{if(e)return e.filter(t=>!!t).map(t=>{const{code:s,title:r}=t;return{code:s,title:r}})},Z=e=>e==null,j=(e,t)=>e.amount.value-t.amount.value,x=e=>!(!e||!e.method_code||!e.method_title||Z(e.amount.value)||!e.amount.currency),D=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}}}),z=e=>{if(x(e))return D(e)},Y=e=>{if(e)return e.filter(x).map(t=>D(t)).sort(j)},K=e=>e?!!e.code&&!!e.label:!1,J=e=>{if(!K(e))return;const{code:t,label:s,region_id:r}=e;return r?{code:t,name:s,id:r}:{code:t,name:s}},ee=e=>{const{code:t,label:s}=e;return{value:t,label:s}},te=e=>e?"code"in e&&"value"in e:!1,se=e=>e.filter(te).map(t=>{const{code:s,value:r}=t;return{code:s,value:r}}),A=e=>{const t=e.street.filter(Boolean);return{firstName:e.firstname,lastName:e.lastname,company:e.company||void 0,city:e.city,street:t,postCode:e.postcode||void 0,vatId:e.vat_id||void 0,telephone:e.telephone||void 0,region:J(e.region),country:ee(e.country),customAttributes:se(e.custom_attributes)}},re=e=>{if(e)return A(e)},ie=e=>e.filter(t=>!!t).map(t=>{const{available_shipping_methods:s,selected_shipping_method:r,...n}=t;return{...A(n),availableShippingMethods:Y(s),selectedShippingMethod:z(r)}}),Te=e=>({availablePaymentMethods:V(e.available_payment_methods),billingAddress:re(e.billing_address),email:e.email??void 0,id:e.id,isEmpty:e.total_quantity===0,isVirtual:e.is_virtual,selectedPaymentMethod:$(e.selected_payment_method),shippingAddresses:ie(e.shipping_addresses)}),ae=`
|
|
2
|
+
query getStoreConfig {
|
|
3
|
+
storeConfig {
|
|
4
|
+
countries_with_required_region
|
|
5
|
+
default_country
|
|
6
|
+
display_state_if_optional
|
|
7
|
+
is_guest_checkout_enabled
|
|
8
|
+
is_one_page_checkout_enabled
|
|
9
|
+
locale
|
|
10
|
+
optional_zip_countries
|
|
11
|
+
shopping_cart_display_shipping
|
|
12
|
+
store_code
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;var c=(e=>(e.EXCLUDING_TAX="EXCLUDING_TAX",e.INCLUDING_EXCLUDING_TAX="INCLUDING_AND_EXCLUDING_TAX",e.INCLUDING_TAX="INCLUDING_TAX",e))(c||{});const oe="US",l={defaultCountry:oe,countriesWithRequiredRegion:[],displayStateIfOptional:!1,countriesWithOptionalZipCode:[],isGuestCheckoutEnabled:!1,isOnePageCheckoutEnabled:!1,shoppingCartDisplaySetting:{shipping:c.EXCLUDING_TAX}},Ee=async()=>await W({type:"query",query:ae,options:{method:"GET",cache:"no-cache"},path:"storeConfig",signalType:"storeConfig",transformer:le,defaultValueOnFail:l});function ne(e){switch(e){case 1:return c.EXCLUDING_TAX;case 2:return c.INCLUDING_TAX;case 3:return c.INCLUDING_EXCLUDING_TAX;default:return c.EXCLUDING_TAX}}function le(e){if(!e)return l;const{default_country:t,countries_with_required_region:s,display_state_if_optional:r,optional_zip_countries:n,is_guest_checkout_enabled:d,is_one_page_checkout_enabled:g,shopping_cart_display_shipping:_}=e;return{defaultCountry:t||l.defaultCountry,countriesWithRequiredRegion:(s==null?void 0:s.split(","))||l.countriesWithRequiredRegion,displayStateIfOptional:r||l.displayStateIfOptional,countriesWithOptionalZipCode:(n==null?void 0:n.split(","))||l.countriesWithOptionalZipCode,isGuestCheckoutEnabled:d||l.isGuestCheckoutEnabled,isOnePageCheckoutEnabled:g||l.isOnePageCheckoutEnabled,shoppingCartDisplaySetting:{shipping:ne(_)}}}const{setEndpoint:Ie,setFetchGraphQlHeader:be,removeFetchGraphQlHeader:Se,setFetchGraphQlHeaders:xe,fetchGraphQl:I,getConfig:De}=new N().getMethods();var i=(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))(i||{}),ce=(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))(ce||{});const Ae=[{frontendInput:i.Text,code:"firstname",label:"First Name",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:10},{frontendInput:i.Text,code:"lastname",label:"Last Name",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:20},{frontendInput:i.Text,code:"company",label:"Company",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:30},{frontendInput:i.Multiline,code:"street",label:"Street Address",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:40},{frontendInput:i.Text,code:"city",label:"City",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:50},{frontendInput:i.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:i.Text,code:"region",label:"State/Province",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:70},{frontendInput:i.Hidden,code:"region_id",label:"State/Province",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:80},{frontendInput:i.Text,code:"postcode",label:"Zip/Postal Code",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:90},{frontendInput:i.Text,code:"telephone",label:"Phone Number",isRequired:!0,isDisabled:!1,options:[],validateRules:[],sortOrder:100},{frontendInput:i.Text,code:"vat_id",label:"VAT Number",isRequired:!1,isDisabled:!1,options:[],validateRules:[],sortOrder:110}],M=`
|
|
2
16
|
fragment CheckoutData on Cart {
|
|
3
17
|
is_virtual
|
|
4
18
|
email
|
|
@@ -100,20 +114,20 @@ import{t as a,u as l}from"./fixtures.js";const c=e=>{if(e)return{code:e.code,tit
|
|
|
100
114
|
title
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
|
-
`,
|
|
117
|
+
`,Me=`
|
|
104
118
|
query getCart($cartId: String!) {
|
|
105
119
|
cart(cart_id: $cartId) {
|
|
106
120
|
id
|
|
107
121
|
...CheckoutData
|
|
108
122
|
}
|
|
109
123
|
}
|
|
110
|
-
${
|
|
111
|
-
`,
|
|
124
|
+
${M}
|
|
125
|
+
`,Ne=`
|
|
112
126
|
query getCustomerCart {
|
|
113
127
|
cart: customerCart {
|
|
114
128
|
id
|
|
115
129
|
...CheckoutData
|
|
116
130
|
}
|
|
117
131
|
}
|
|
118
|
-
${
|
|
119
|
-
`;export{
|
|
132
|
+
${M}
|
|
133
|
+
`;export{i as A,ye as B,M as C,oe as D,k as E,G as F,p as I,fe as M,l as S,c as T,_e as U,ce as V,he as a,ge as b,me as c,ve as d,be as e,xe as f,I as g,De as h,Ae as i,Ee as j,Ce as k,W as l,F as m,h as n,P as o,T as p,Me as q,Se as r,Ie as s,Te as t,Ne as u,q as v,U as w,Y as x,w as y,X as z};
|
package/chunks/getCustomer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"@dropins/tools/event-bus.js";import{o,M as l,
|
|
1
|
+
import"@dropins/tools/event-bus.js";import{k as o,M as l,l as u,t as d,q as f,u as g}from"./getCart.graphql.js";const p=e=>e?"code"in e&&"value"in e:!1,y=e=>e.filter(p).map(t=>{const{code:r,value:s}=t;return{code:r,value:s}}),m=e=>{var n,i,c;const t=e.street.filter(Boolean),r=(n=e.region)==null?void 0:n.region_id,s=r&&r>0;return{id:String(e.id),firstName:e.firstname,lastName:e.lastname,company:e.company||void 0,city:e.city,street:t,postCode:e.postcode||void 0,vatId:e.vat_id||void 0,telephone:e.telephone||void 0,region:{id:s?r:void 0,code:(i=e.region)==null?void 0:i.region_code,name:(c=e.region)==null?void 0:c.region},country:{value:e.country_code,label:e.country_code},customAttributes:y(e.custom_attributesV2)}},h=e=>e?e.filter(Boolean).map(m):[],a=(e,t)=>{if(!t)return;const r=t.find(s=>(s==null?void 0:s[e])===!0);if(r)return m(r)},C=e=>{if(!e)return;const t=e.addresses;return{firstName:e.firstname||"",lastName:e.lastname||"",email:e.email||"",addresses:h(t),defaultBillingAddress:a("default_billing",t),defaultShippingAddress:a("default_shipping",t)}},_=async()=>{const e=o.cartId,t=o.authenticated===!1,r=t?f:g,s=t?{cartId:e}:{};if(t&&!e)throw new l;return await u({type:"query",query:r,options:{method:"POST",cache:"no-cache",variables:s},path:"cart",signalType:"cart",transformer:d})},q=async()=>{const e=o.cartId,t=o.authenticated;if(e)try{await _(),t&&await A()}catch(r){console.error(r)}},v=`
|
|
2
2
|
query getCustomer {
|
|
3
3
|
customer {
|
|
4
4
|
firstname
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import{k as T,M as w,g as A,p as k,n as D,F as L,U as R}from"./getCart.graphql.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
|
+
mutation placeOrder($cartId: String!) {
|
|
3
|
+
placeOrder(input: { cart_id: $cartId }) {
|
|
4
|
+
orderV2 {
|
|
5
|
+
number
|
|
6
|
+
status
|
|
7
|
+
token
|
|
8
|
+
is_virtual
|
|
9
|
+
applied_coupons {
|
|
10
|
+
code
|
|
11
|
+
}
|
|
12
|
+
email
|
|
13
|
+
id
|
|
14
|
+
total {
|
|
15
|
+
grand_total {
|
|
16
|
+
currency
|
|
17
|
+
value
|
|
18
|
+
}
|
|
19
|
+
subtotal {
|
|
20
|
+
currency
|
|
21
|
+
value
|
|
22
|
+
}
|
|
23
|
+
total_shipping {
|
|
24
|
+
currency
|
|
25
|
+
value
|
|
26
|
+
}
|
|
27
|
+
total_tax {
|
|
28
|
+
currency
|
|
29
|
+
value
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
shipping_method
|
|
33
|
+
payment_methods {
|
|
34
|
+
name
|
|
35
|
+
type
|
|
36
|
+
}
|
|
37
|
+
billing_address {
|
|
38
|
+
firstname
|
|
39
|
+
middlename
|
|
40
|
+
lastname
|
|
41
|
+
street
|
|
42
|
+
city
|
|
43
|
+
postcode
|
|
44
|
+
telephone
|
|
45
|
+
country_code
|
|
46
|
+
region
|
|
47
|
+
region_id
|
|
48
|
+
company
|
|
49
|
+
custom_attributesV2 {
|
|
50
|
+
code
|
|
51
|
+
... on AttributeValue {
|
|
52
|
+
value
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
shipping_address {
|
|
57
|
+
firstname
|
|
58
|
+
middlename
|
|
59
|
+
lastname
|
|
60
|
+
street
|
|
61
|
+
city
|
|
62
|
+
postcode
|
|
63
|
+
telephone
|
|
64
|
+
country_code
|
|
65
|
+
region
|
|
66
|
+
region_id
|
|
67
|
+
company
|
|
68
|
+
custom_attributesV2 {
|
|
69
|
+
code
|
|
70
|
+
... on AttributeValue {
|
|
71
|
+
value
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
items {
|
|
76
|
+
__typename
|
|
77
|
+
id
|
|
78
|
+
discounts {
|
|
79
|
+
amount {
|
|
80
|
+
value
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
product {
|
|
84
|
+
__typename
|
|
85
|
+
canonical_url
|
|
86
|
+
image {
|
|
87
|
+
url
|
|
88
|
+
}
|
|
89
|
+
thumbnail {
|
|
90
|
+
label
|
|
91
|
+
url
|
|
92
|
+
}
|
|
93
|
+
name
|
|
94
|
+
sku
|
|
95
|
+
uid
|
|
96
|
+
price_range {
|
|
97
|
+
maximum_price {
|
|
98
|
+
regular_price {
|
|
99
|
+
currency
|
|
100
|
+
value
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
selected_options {
|
|
106
|
+
label
|
|
107
|
+
value
|
|
108
|
+
}
|
|
109
|
+
product_sale_price {
|
|
110
|
+
value
|
|
111
|
+
currency
|
|
112
|
+
}
|
|
113
|
+
quantity_ordered
|
|
114
|
+
... on GiftCardOrderItem {
|
|
115
|
+
gift_card {
|
|
116
|
+
recipient_name
|
|
117
|
+
recipient_email
|
|
118
|
+
sender_name
|
|
119
|
+
sender_email
|
|
120
|
+
message
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
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};
|
package/chunks/resetCustomer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{events as n}from"@dropins/tools/event-bus.js";import{
|
|
1
|
+
import{events as n}from"@dropins/tools/event-bus.js";import{l,k as a,j as d,n as c,o as f}from"./getCart.graphql.js";import{Initializer as m}from"@dropins/tools/lib.js";import{a as i}from"./getCustomer.js";const _=e=>e?e.filter(Boolean).filter(r=>(r==null?void 0:r.label)&&(r==null?void 0:r.value)).map(r=>({text:r.label,value:r.value})):[],g=e=>e?e.filter(Boolean).filter(t=>(t==null?void 0:t.name)&&(t==null?void 0:t.value)):[],v=e=>e?e.filter(Boolean).map(r=>({code:r.code,defaultValue:r.default_value||void 0,frontendInput:r.frontend_input||void 0,isDisabled:!1,isRequired:r.is_required,label:r.label||void 0,multilineCount:r.multiline_count||void 0,options:_(r.options),sortOrder:r.sort_order||void 0,validateRules:g(r.validate_rules)})):[],p=e=>{if(e)return e.filter(t=>!!t).filter(t=>{const{two_letter_abbreviation:r,full_name_locale:s}=t;return!!r&&!!s}).map(t=>{const{two_letter_abbreviation:r,full_name_locale:s}=t;return{value:r,label:s}})},y=`
|
|
2
2
|
query fetchAddressFormFields {
|
|
3
3
|
attributesForm(formCode: "customer_register_address") {
|
|
4
4
|
items {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{C as n,k as e,M as d,c as l,l as o,t as c}from"./getCart.graphql.js";const g=`
|
|
2
2
|
mutation setBillingAddress($cartId: String!, $input: BillingAddressInput!) {
|
|
3
3
|
setBillingAddressOnCart(
|
|
4
4
|
input: { cart_id: $cartId, billing_address: $input }
|
|
@@ -9,5 +9,5 @@ import{o as n,M as e,c as d,p as l}from"./fixtures.js";import{C as o,t as c}from
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
${
|
|
13
|
-
`,
|
|
12
|
+
${n}
|
|
13
|
+
`,A=async({signal:a,input:s})=>{const t=e.cartId,{address:i,same_as_shipping:r}=s;if(!t)throw new d;if(!r&&!i)throw new l;return await o({type:"mutation",query:g,options:{signal:a,variables:{cartId:t,input:s}},path:"setBillingAddressOnCart.cart",signalType:"cart",transformer:c})};export{A as s};
|
|
@@ -1,4 +1,86 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{k as h,M as l,d as I,l as u,x as M,y as S,a as v,g as b,p as $,C as g,t as m,b as f}from"./getCart.graphql.js";import"@dropins/tools/event-bus.js";const E=`
|
|
2
|
+
mutation estimateShippingMethods(
|
|
3
|
+
$cartId: String!
|
|
4
|
+
$address: EstimateAddressInput!
|
|
5
|
+
) {
|
|
6
|
+
estimateShippingMethods(
|
|
7
|
+
input: {
|
|
8
|
+
cart_id: $cartId
|
|
9
|
+
address: $address
|
|
10
|
+
}
|
|
11
|
+
) {
|
|
12
|
+
carrier_title
|
|
13
|
+
carrier_code
|
|
14
|
+
method_title
|
|
15
|
+
method_code
|
|
16
|
+
available
|
|
17
|
+
amount {
|
|
18
|
+
currency
|
|
19
|
+
value
|
|
20
|
+
}
|
|
21
|
+
price_excl_tax {
|
|
22
|
+
currency
|
|
23
|
+
value
|
|
24
|
+
}
|
|
25
|
+
price_incl_tax {
|
|
26
|
+
currency
|
|
27
|
+
value
|
|
28
|
+
}
|
|
29
|
+
error_message
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`,w=t=>!!(t!=null&&t.is_email_available),C=t=>t?!!t.id&&!!t.code&&!!t.name:!1,T=t=>{if(t)return t.filter(C).map(a=>{const{id:e,code:i,name:o}=a;return{id:e,code:i,name:o}})};var O=(t=>(t.SHIPPING="shipping_addresses",t.BILLING="billing_address",t))(O||{}),s=(t=>(t.City="city",t.Company="company",t.Country="country_id",t.FirstName="firstname",t.LastName="lastname",t.PostCode="postcode",t.Region="region",t.RegionId="region_id",t.SaveInAddressBook="save_in_address_book",t.Street="street",t.Telephone="telephone",t.Vat="vat_id",t))(s||{});const V=async t=>{const a=h.cartId,{criteria:e}=t||{},{country_code:i,region_id:o,region_name:c,zip:n}=e||{};if(!a)throw new l;if(!i)throw new I;const r=typeof o=="string"?parseInt(o,10):o,p=o||c?{...r&&{region_id:r},...c&&{region_code:c}}:void 0,d={country_code:i,...n&&{postcode:n},...p&&{region:p}};return await u({type:"mutation",query:E,options:{variables:{cartId:a,address:d}},path:"estimateShippingMethods",signalType:"estimateShippingMethods",transformer:M})},R=`
|
|
33
|
+
query getRegions($countryCode: String!) {
|
|
34
|
+
country(id: $countryCode) {
|
|
35
|
+
id
|
|
36
|
+
available_regions {
|
|
37
|
+
id
|
|
38
|
+
code
|
|
39
|
+
name
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}`,Q=async(t,a)=>(S.value.addressType=a,u({type:"query",query:R,options:{variables:{countryCode:t}},path:"country.available_regions",signalType:"regions",transformer:T})),N=`
|
|
43
|
+
query isEmailAvailable($email: String!) {
|
|
44
|
+
isEmailAvailable(email: $email) {
|
|
45
|
+
is_email_available
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`,A=t=>{if(!(!t||t.length===0))throw Error(t.map(a=>a.message).join(" "))},H=async t=>{if(!t)throw new v;const{data:a,errors:e}=await b(N,{method:"GET",cache:"no-cache",variables:{email:t}}).catch($);return e&&A(e),w(a.isEmailAvailable)},k=`
|
|
49
|
+
mutation setGuestEmail($cartId: String!, $email: String!) {
|
|
50
|
+
setGuestEmailOnCart(input: { cart_id: $cartId, email: $email }) {
|
|
51
|
+
cart {
|
|
52
|
+
id
|
|
53
|
+
...CheckoutData
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
${g}
|
|
58
|
+
`,W=async t=>{const a=h.cartId;if(!a)throw new l;return await u({type:"mutation",query:k,options:{variables:{cartId:a,email:t}},path:"setGuestEmailOnCart.cart",signalType:"cart",transformer:m})},G=`
|
|
59
|
+
mutation setPaymentMethod($cartId: String!, $paymentMethod: String!) {
|
|
60
|
+
setPaymentMethodOnCart(
|
|
61
|
+
input: { cart_id: $cartId, payment_method: { code: $paymentMethod } }
|
|
62
|
+
) {
|
|
63
|
+
cart {
|
|
64
|
+
id
|
|
65
|
+
...CheckoutData
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
${g}
|
|
70
|
+
`,X=async t=>{const a=h.cartId;if(!a)throw new l;if(!t)throw new f;return await u({type:"mutation",query:G,options:{variables:{cartId:a,paymentMethod:t}},path:"setPaymentMethodOnCart.cart",signalType:"cart",transformer:m})},y="-",P=`
|
|
71
|
+
`,z=2e3,_=(t,a)=>Object.keys(a).filter(e=>e.startsWith(t)).sort((e,i)=>parseInt(e.replace(`${t}${y}`,""),10)-parseInt(i.replace(`${t}${y}`,""),10)).map(e=>a[e]),D=/^\d+$/,q=t=>{if(D.test(t))return parseInt(t,10)},L=`
|
|
72
|
+
mutation setShippingAddress($cartId: String!, $address: CartAddressInput!) {
|
|
73
|
+
setShippingAddressesOnCart(
|
|
74
|
+
input: { cart_id: $cartId, shipping_addresses: [{ address: $address }] }
|
|
75
|
+
) {
|
|
76
|
+
cart {
|
|
77
|
+
id
|
|
78
|
+
...CheckoutData
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
${g}
|
|
83
|
+
`,U=["city","company","country_code","firstname","lastname","postcode","region","region_id","save_in_address_book","street","telephone","vat_id"],K=t=>{const a={city:t[s.City],company:t[s.Company],country_code:t[s.Country],firstname:t[s.FirstName],lastname:t[s.LastName],postcode:t[s.PostCode],save_in_address_book:!0,street:_(s.Street,t),telephone:t[s.Telephone],vat_id:t[s.Vat]},e=t[s.Region],i=q(e);i?a.region_id=i:a.region=e;const c=Object.keys(t).filter(n=>!n.startsWith("street")).filter(n=>!U.includes(n)).filter(n=>n!=="country_id").map(n=>{const[r,p]=n.split(y);if(!p)return{attribute_code:r,value:t[n]};const d=_(r,t).join(P);return{attribute_code:r,value:d}}).filter((n,r,p)=>r===p.findIndex(d=>d.attribute_code===n.attribute_code));return c.length>0&&(a.custom_attributes=c),a},J=async({signal:t,address:a})=>{const e=h.cartId;if(!e)throw new l;return await u({type:"mutation",query:L,options:{signal:t,variables:{cartId:e,address:a}},path:"setShippingAddressesOnCart.cart",signalType:"cart",transformer:m})},x=`
|
|
2
84
|
mutation setShippingMethods(
|
|
3
85
|
$cartId: String!
|
|
4
86
|
$shippingMethods: [ShippingMethodInput]!
|
|
@@ -12,5 +94,5 @@ import{o as a,M as s,p}from"./fixtures.js";import{C as r,t as n}from"./getCart.g
|
|
|
12
94
|
}
|
|
13
95
|
}
|
|
14
96
|
}
|
|
15
|
-
${
|
|
16
|
-
`,
|
|
97
|
+
${g}
|
|
98
|
+
`,Y=async t=>{const a=h.cartId;if(!a)throw new l;return await u({type:"mutation",query:x,options:{variables:{cartId:a,shippingMethods:t}},path:"setShippingMethodsOnCart.cart",signalType:"cart",transformer:m})};export{s as A,z as D,y as M,U as S,X as a,J as b,Y as c,_ as d,V as e,O as f,Q as g,P as h,H as i,K as p,W as s};
|
|
@@ -3,7 +3,8 @@ import { AddressFormType, AddressFormValues } from '../../data/models';
|
|
|
3
3
|
type useCheckoutAddressEventEmitterProps = {
|
|
4
4
|
address: AddressFormValues;
|
|
5
5
|
type: AddressFormType;
|
|
6
|
+
isValid: () => boolean;
|
|
6
7
|
};
|
|
7
|
-
declare function useCheckoutAddressEventEmitter({ address, type, }: useCheckoutAddressEventEmitterProps): void;
|
|
8
|
+
declare function useCheckoutAddressEventEmitter({ address, type, isValid, }: useCheckoutAddressEventEmitterProps): void;
|
|
8
9
|
export default useCheckoutAddressEventEmitter;
|
|
9
10
|
//# sourceMappingURL=useCheckoutAddressEventEmitter.d.ts.map
|
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
import { FunctionComponent, VNode } from 'preact';
|
|
2
2
|
import { HTMLAttributes } from 'preact/compat';
|
|
3
3
|
|
|
4
|
-
export type
|
|
5
|
-
orderSummary?: VNode;
|
|
6
|
-
};
|
|
7
|
-
declare const Aside: FunctionComponent<{
|
|
8
|
-
sections: AsideSections;
|
|
9
|
-
}>;
|
|
10
|
-
export type MainSections = {
|
|
4
|
+
export type CheckoutBlocks = {
|
|
11
5
|
billingAddress: VNode;
|
|
12
|
-
billToShippingAddress
|
|
6
|
+
billToShippingAddress: VNode;
|
|
7
|
+
cartSummaryList?: VNode;
|
|
8
|
+
emptyCart: VNode;
|
|
13
9
|
login: VNode;
|
|
10
|
+
orderSummary?: VNode;
|
|
14
11
|
outOfStock: VNode;
|
|
15
12
|
paymentMethods: VNode;
|
|
16
13
|
placeOrder: VNode;
|
|
17
|
-
shippingAddress
|
|
18
|
-
shippingMethods
|
|
14
|
+
shippingAddress: VNode;
|
|
15
|
+
shippingMethods: VNode;
|
|
19
16
|
};
|
|
20
17
|
declare const Main: FunctionComponent<{
|
|
21
|
-
|
|
18
|
+
blocks: CheckoutBlocks;
|
|
22
19
|
}>;
|
|
23
20
|
export interface CheckoutProps extends HTMLAttributes<HTMLDivElement> {
|
|
24
21
|
isLoading?: boolean;
|
|
25
22
|
}
|
|
26
23
|
interface CheckoutComponent extends FunctionComponent<CheckoutProps> {
|
|
27
24
|
Main: typeof Main;
|
|
28
|
-
Aside: typeof Aside;
|
|
29
25
|
}
|
|
30
26
|
export declare const Checkout: CheckoutComponent;
|
|
31
27
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ShippingMethod } from '../../data/models';
|
|
1
2
|
import { FunctionComponent } from 'preact';
|
|
2
3
|
import { HTMLAttributes } from 'preact/compat';
|
|
3
|
-
import { ShippingMethod } from '../../data/models';
|
|
4
4
|
|
|
5
5
|
export interface ShippingMethodsProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
6
|
isLoading?: boolean;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { BillingAddress, ShippingAddress } from '../../data/models/address';
|
|
2
2
|
import { AddressFormField } from '../../data/models/address-form-fields';
|
|
3
3
|
import { CheckboxProps } from '@dropins/tools/types/elsie/src/components';
|
|
4
|
-
import { Container } from '@dropins/tools/types/elsie/src/lib';
|
|
5
4
|
|
|
6
5
|
export declare function compareAddresses(addressFormFields: AddressFormField[], first: BillingAddress | undefined, second: ShippingAddress | undefined): boolean;
|
|
7
6
|
export interface BillToShippingAddressProps extends Omit<CheckboxProps, 'name' | 'label'> {
|
|
8
7
|
}
|
|
9
|
-
export declare const BillToShippingAddress:
|
|
8
|
+
export declare const BillToShippingAddress: {
|
|
9
|
+
({ hideOnEmptyCart, hideOnVirtualCart, ...props }: import('../../hocs/withConditionalRendering').ConditionalProps & BillToShippingAddressProps): import("preact/compat").JSX.Element | null;
|
|
10
|
+
displayName: string;
|
|
11
|
+
};
|
|
10
12
|
//# sourceMappingURL=BillToShippingAddress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as I,B as _,c,B as f}from"../chunks/BillToShippingAddress.js";import"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/event-bus.js";import"../chunks/getCart.graphql.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/setBillingAddress.js";import"@dropins/tools/lib.js";import"@dropins/tools/components.js";import"@dropins/tools/i18n.js";import"@dropins/tools/preact-compat.js";export{I as BILL_TO_SHIPPING_KEY,_ as BillToShippingAddress,c as compareAddresses,f as default};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Container } from '@dropins/tools/types/elsie/src/lib';
|
|
2
1
|
import { HTMLAttributes } from 'preact/compat';
|
|
3
2
|
|
|
4
3
|
export interface BillingFormProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
4
|
}
|
|
6
|
-
export declare const BillingForm:
|
|
5
|
+
export declare const BillingForm: {
|
|
6
|
+
({ hideOnEmptyCart, hideOnVirtualCart, ...props }: import('../../hocs/withConditionalRendering').ConditionalProps & BillingFormProps): import("preact/compat").JSX.Element | null;
|
|
7
|
+
displayName: string;
|
|
8
|
+
};
|
|
7
9
|
//# sourceMappingURL=BillingForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{e as _,B as d,B as g}from"../chunks/ShippingMethods.js";import"@dropins/tools/preact-jsx-runtime.js";import"../chunks/setShippingMethods.js";import"../chunks/getCart.graphql.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/preact-hooks.js";import"@dropins/tools/lib.js";import"@dropins/tools/i18n.js";import"@dropins/tools/components.js";import"../chunks/BillToShippingAddress.js";import"../chunks/setBillingAddress.js";import"@dropins/tools/preact-compat.js";import"../chunks/ErrorBanner.js";import"../chunks/MergedCartBanner.js";export{_ as BILLING_FORM_NAME,d as BillingForm,g as default};
|