@dropins/storefront-checkout 2.0.0-beta4 → 2.0.0-beta5

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.
@@ -1,3 +1,3 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsxs as _,jsx as n,Fragment as O}from"@dropins/tools/preact-jsx-runtime.js";import{h as te,a as ne}from"../chunks/errors.js";import{classes as U,VComponent as re,Slot as oe}from"@dropins/tools/lib.js";import{s as ie,t as se}from"../chunks/setShippingMethods.js";import{events as W}from"@dropins/tools/event-bus.js";import{h as x,g as ce}from"../chunks/events.js";import{n as ae,g as Z}from"../chunks/values.js";import{W as ue}from"../chunks/ConditionalWrapper.js";/* empty css */import{Skeleton as le,SkeletonRow as V,ProgressSpinner as pe,IllustratedMessage as de,Icon as he,InLineAlert as me,RadioButton as fe,Price as q,ToggleButton as ge}from"@dropins/tools/components.js";import{s as ke}from"../chunks/dom.js";import{useRef as ve,useEffect as H,useState as w,useCallback as k,useMemo as Ee}from"@dropins/tools/preact-hooks.js";import*as c from"@dropins/tools/preact-compat.js";import{useText as $}from"@dropins/tools/i18n.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/synchronizeCheckout.js";import"../fragments.js";const Se=i=>c.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...i},c.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"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.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"}),c.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"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),Ce=()=>_(le,{"data-testid":"shipping-methods-skeleton",children:[n(V,{size:"small",variant:"heading"}),n(V,{size:"small",variant:"empty"}),n(V,{fullWidth:!0,size:"medium"}),n(V,{fullWidth:!0,size:"medium"})]}),Me=({className:i,isLoading:t=!1,onSelectionChange:f=()=>{},options:v,selection:p,title:a,UIComponentType:l="RadioButton",error:d=null,onDismissError:T=()=>{},...P})=>{const E=$({EmptyState:"Checkout.ShippingMethods.emptyState"}),S=d!==null,C=ve(null);H(()=>{S&&C.current&&ke(C.current)},[S]);const j=(r,R)=>{const B={busy:t,key:r.value,className:"checkout-shipping-methods__method",name:"shipping-method",value:r.value,onChange:()=>f(r)};return R==="RadioButton"?n(fe,{...B,checked:(p==null?void 0:p.value)===r.value,"data-testid":"shipping-method-radioButton",description:r.title,id:r.value,label:_(O,{children:[n(q,{amount:r.amount.value,currency:r.amount.currency})," ",n("span",{children:r.carrier.title})]})}):n(ge,{...B,"data-testid":"shipping-method-toggleButton",label:_(O,{children:[n("span",{children:r.carrier.title}),n(q,{amount:r.amount.value,currency:r.amount.currency})]}),selected:(p==null?void 0:p.value)===r.value})};return _("div",{...P,className:U(["checkout-shipping-methods",i]),"data-testid":"checkout-shipping-methods",children:[a&&n(re,{className:"checkout-shipping-methods__title",node:a}),_("div",{className:U(["checkout-shipping-methods__content"]),children:[t&&n(pe,{className:"checkout-shipping-methods__spinner"}),n("div",{className:U(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",t],["checkout-shipping-methods__options--toggleButton",l==="ToggleButton"]]),children:v.length===0?n(de,{"data-testid":"checkout-shipping-methods-empty",icon:n(he,{source:Se}),message:n("p",{children:E.EmptyState})}):v.map(r=>j(r,l))})]}),S&&n("div",{ref:C,className:"checkout-shipping-methods__error","data-testid":"checkout-shipping-methods-alert",children:n(me,{heading:d,type:"error",variant:"primary",onDismiss:T})})]})},Le=ue(Me,Ce);function ye(i,t){return i?t.some(f=>f.code===i.code):!1}function F(i,t){return!i||!t||i.amount.value!==t.amount.value?!1:i.code===t.code&&i.carrier.code===t.carrier.code}function _e(i){const t=W.lastPayload("shipping/estimate");t&&W.emit("shipping/estimate",{...t,shippingMethod:se(i)})}const Oe=({UIComponentType:i="RadioButton",active:t=!0,autoSync:f=!0,displayTitle:v=!0,initialData:p,slots:a,onCartSyncError:l,onSelectionChange:d,...T})=>{const[P,E]=w(null),[S,C]=w(!1),[j,r]=w(),[R,B]=w(null),G=te.value,J=ne.value,K=G||J,{cartSyncError:z,defaultTitle:D}=$({cartSyncError:"Checkout.ShippingMethods.cartSyncError",defaultTitle:"Checkout.ShippingMethods.title"}),Q=k(()=>{E(null)},[]),s=k(e=>{E(null),B(o=>F(o,e)?o:(ae({selectedShippingMethod:e}),e))},[]),M=k(async(e,o)=>{if(!f||!x())return;const u={method_code:e.code,carrier_code:e.carrier.code};ie([u]).catch(h=>{s(o??null),l==null||l({method:e,error:h}),l||E(z)})},[f,s,l,z]),X=k(async e=>{const o=Z("selectedShippingMethod");s(e),d==null||d(e),x()||_e(e),await M(e,o)},[d,s,M]),L=k(e=>{var A;const o=!e||e.isEmpty,u=!!(e!=null&&e.isVirtual);if(o||u){C(u),s(null),r([]);return}const h=(A=e.shippingAddresses)==null?void 0:A[0];if(!h)return;const m=h.availableShippingMethods??[];if(r(m),m.length===0){s(null);return}const y=h.selectedShippingMethod??null,g=Z("selectedShippingMethod"),N=ye(g,m),ee=F(g,y);if(g&&N&&!ee){M(g,y);return}if((!g||!N)&&y){s(y);return}if((!g||!N)&&!y){const b=m[0];s(b),M(b)}},[M,s]),I=k(e=>{if(e===void 0)return;const{shippingMethod:o,availableShippingMethods:u}=e,h=(u==null?void 0:u.find(m=>m.code===(o==null?void 0:o.methodCode)&&m.carrier.code===(o==null?void 0:o.carrierCode)))??null;r(u),s(h)},[s]);H(()=>{if(!t)return;const e=ce();if(e){L(e);return}const o=W.on("checkout/initialized",L,{eager:!0});return()=>{o==null||o.off()}},[t,L]),H(()=>{if(!t)return;const e=W.on("checkout/updated",L,{eager:!1});return()=>{e==null||e.off()}},[t,L]),H(()=>{if(!t||x())return;const e=W.on("shipping/estimate",I,{eager:!0});return()=>{e==null||e.off()}},[t,I]);const Y=Ee(()=>{if(v)return n(oe,{name:"checkout-shipping-methods-title",slot:a==null?void 0:a.Title,children:n("h3",{children:D})})},[v,a==null?void 0:a.Title,D]);return n(Le,{...T,UIComponentType:i,error:P,initialized:j!==void 0,isLoading:K,options:j??[],selection:R,title:Y,visible:t&&!S,onDismissError:Q,onSelectionChange:X})};export{Oe as ShippingMethods,Oe as default,_e as emitShippingEstimateEvent};
3
+ import{jsxs as _,jsx as n,Fragment as Z}from"@dropins/tools/preact-jsx-runtime.js";import{h as te,a as ne}from"../chunks/errors.js";import{classes as U,VComponent as re,Slot as oe}from"@dropins/tools/lib.js";import{s as ie,t as se}from"../chunks/setShippingMethods.js";import{events as W}from"@dropins/tools/event-bus.js";import{h as x,g as ce}from"../chunks/events.js";import{n as ae,g as q}from"../chunks/values.js";import{W as ue}from"../chunks/ConditionalWrapper.js";/* empty css */import{Skeleton as le,SkeletonRow as w,ProgressSpinner as pe,IllustratedMessage as de,Icon as he,InLineAlert as me,RadioButton as fe,Price as F,ToggleButton as ge}from"@dropins/tools/components.js";import{s as ke}from"../chunks/dom.js";import{useRef as ve,useEffect as T,useState as H,useCallback as k,useMemo as Ee}from"@dropins/tools/preact-hooks.js";import*as c from"@dropins/tools/preact-compat.js";import{useText as $}from"@dropins/tools/i18n.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/synchronizeCheckout.js";import"../fragments.js";const Se=i=>c.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...i},c.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"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.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"}),c.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"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),c.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),Ce=()=>_(le,{"data-testid":"shipping-methods-skeleton",children:[n(w,{size:"small",variant:"heading"}),n(w,{size:"small",variant:"empty"}),n(w,{fullWidth:!0,size:"medium"}),n(w,{fullWidth:!0,size:"medium"})]}),Me=({className:i,isLoading:t=!1,onSelectionChange:f=()=>{},options:v,selection:p,title:a,UIComponentType:l="RadioButton",error:d=null,onDismissError:V=()=>{},...P})=>{const E=$({EmptyState:"Checkout.ShippingMethods.emptyState"}),S=d!==null,C=ve(null);T(()=>{S&&C.current&&ke(C.current)},[S]);const j=(r,R)=>{const B={busy:t,key:r.value,className:"checkout-shipping-methods__method",name:"shipping-method",value:r.value,onChange:()=>f(r)};return R==="RadioButton"?n(fe,{...B,checked:(p==null?void 0:p.value)===r.value,"data-testid":"shipping-method-radioButton",description:r.title,id:r.value,label:_(Z,{children:[n(F,{amount:r.amount.value,currency:r.amount.currency})," ",n("span",{children:r.carrier.title})]})}):n(ge,{...B,"data-testid":"shipping-method-toggleButton",label:_(Z,{children:[n("span",{children:r.carrier.title}),n(F,{amount:r.amount.value,currency:r.amount.currency})]}),selected:(p==null?void 0:p.value)===r.value})};return _("div",{...P,className:U(["checkout-shipping-methods",i]),"data-testid":"checkout-shipping-methods",children:[a&&n(re,{className:"checkout-shipping-methods__title",node:a}),_("div",{className:U(["checkout-shipping-methods__content"]),children:[t&&n(pe,{className:"checkout-shipping-methods__spinner"}),n("div",{className:U(["checkout-shipping-methods__options",["checkout-shipping-methods__options--loading",t],["checkout-shipping-methods__options--toggleButton",l==="ToggleButton"]]),children:v.length===0?n(de,{"data-testid":"checkout-shipping-methods-empty",icon:n(he,{source:Se}),message:n("p",{children:E.EmptyState})}):v.map(r=>j(r,l))})]}),S&&n("div",{ref:C,className:"checkout-shipping-methods__error","data-testid":"checkout-shipping-methods-alert",children:n(me,{heading:d,type:"error",variant:"primary",onDismiss:V})})]})},Le=ue(Me,Ce);function ye(i,t){return i?t.some(f=>z(f,i)):!1}function z(i,t){return!i||!t||i.amount.value!==t.amount.value?!1:i.code===t.code&&i.carrier.code===t.carrier.code}function _e(i){const t=W.lastPayload("shipping/estimate");t&&W.emit("shipping/estimate",{...t,shippingMethod:se(i)})}const Oe=({UIComponentType:i="RadioButton",active:t=!0,autoSync:f=!0,displayTitle:v=!0,initialData:p,slots:a,onCartSyncError:l,onSelectionChange:d,...V})=>{const[P,E]=H(null),[S,C]=H(!1),[j,r]=H(),[R,B]=H(null),G=te.value,J=ne.value,K=G||J,{cartSyncError:A,defaultTitle:D}=$({cartSyncError:"Checkout.ShippingMethods.cartSyncError",defaultTitle:"Checkout.ShippingMethods.title"}),Q=k(()=>{E(null)},[]),s=k(e=>{E(null),B(o=>z(o,e)?o:(ae({selectedShippingMethod:e}),e))},[]),M=k(async(e,o)=>{if(!f||!x())return;const u={method_code:e.code,carrier_code:e.carrier.code};ie([u]).catch(h=>{s(o??null),l==null||l({method:e,error:h}),l||E(A)})},[f,s,l,A]),X=k(async e=>{const o=q("selectedShippingMethod");s(e),d==null||d(e),x()||_e(e),await M(e,o)},[d,s,M]),L=k(e=>{var b;const o=!e||e.isEmpty,u=!!(e!=null&&e.isVirtual);if(o||u){C(u),s(null),r([]);return}const h=(b=e.shippingAddresses)==null?void 0:b[0];if(!h)return;const m=h.availableShippingMethods??[];if(r(m),m.length===0){s(null);return}const y=h.selectedShippingMethod??null,g=q("selectedShippingMethod"),N=ye(g,m),ee=z(g,y);if(g&&N&&!ee){M(g,y);return}if((!g||!N)&&y){s(y);return}if((!g||!N)&&!y){const O=m[0];s(O),M(O)}},[M,s]),I=k(e=>{if(e===void 0)return;const{shippingMethod:o,availableShippingMethods:u}=e,h=(u==null?void 0:u.find(m=>m.code===(o==null?void 0:o.methodCode)&&m.carrier.code===(o==null?void 0:o.carrierCode)))??null;r(u),s(h)},[s]);T(()=>{if(!t)return;const e=ce();if(e){L(e);return}const o=W.on("checkout/initialized",L,{eager:!0});return()=>{o==null||o.off()}},[t,L]),T(()=>{if(!t)return;const e=W.on("checkout/updated",L,{eager:!1});return()=>{e==null||e.off()}},[t,L]),T(()=>{if(!t||x())return;const e=W.on("shipping/estimate",I,{eager:!0});return()=>{e==null||e.off()}},[t,I]);const Y=Ee(()=>{if(v)return n(oe,{name:"checkout-shipping-methods-title",slot:a==null?void 0:a.Title,children:n("h3",{children:D})})},[v,a==null?void 0:a.Title,D]);return n(Le,{...V,UIComponentType:i,error:P,initialized:j!==void 0,isLoading:K,options:j??[],selection:R,title:Y,visible:t&&!S,onDismissError:Q,onSelectionChange:X})};export{Oe as ShippingMethods,Oe as default,_e as emitShippingEstimateEvent};
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/storefront-checkout", "version": "2.0.0-beta4", "@dropins/tools": "~1.2.1", "license": "SEE LICENSE IN LICENSE.md"}
1
+ {"name": "@dropins/storefront-checkout", "version": "2.0.0-beta5", "@dropins/tools": "~1.2.1", "license": "SEE LICENSE IN LICENSE.md"}