@gem-sdk/components 12.0.0-dev.95 → 12.0.0-dev.97

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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),core=require("@gem-sdk/core"),system=require("@gem-sdk/system"),React=require("react"),index=require("../../constants/index.js"),classes=require("./common/classes.js"),styles=require("./common/styles.js"),useSellingPlanChange=require("./hooks/useSellingPlanChange.js"),useSellingSubscription=require("./hooks/useSellingSubscription.js"),useSellingPlanOptions=require("./hooks/useSellingPlanOptions.js"),useSubscriptionVisibility=require("./hooks/useSubscriptionVisibility.js"),OneTimePurchaseTooltip=require("./components/OneTimePurchaseTooltip.js"),SellingPlanDropdown=require("./components/SellingPlanDropdown.js"),SellingPlanLabel=require("./components/SellingPlanLabel.js"),SellingPlanRadio=require("./components/SellingPlanRadio.js"),SubscriptionDetail=require("./components/SubscriptionDetail.js"),SubscriptionRadio=require("./components/SubscriptionRadio.js"),useDynamicProduct=require("../../hooks/useDynamicProduct.js");const ProductSubscription=({styles:e,setting:s,builderProps:i,builderAttrs:n,style:t,children:l})=>{let r=core.useProduct(),u=core.usePageStore(e=>e.setSubscriptionVisible),{defaultValue:o,selectedSellingPlan:a,setSelectedSellingPlan:c}=useSellingSubscription.useSellingSubscription(s),d=useSellingPlanOptions.useSellingPlanOptions(s),{selectedValue:S,handleSellingPlanChange:p}=useSellingPlanChange.useSellingPlanChange({defaultValue:o,selectedSellingPlan:a,setSelectedSellingPlan:c,sellingPlanOptions:d}),m=React.useRef(null),g=React.useId(),{selectedType:j,shouldShowRadio:x,isOneTimeHidden:b,hasNoSellingPlanOptions:P,setSubscriptionSellingType:y}=useSubscriptionVisibility.useSubscriptionVisibility({setting:s}),R=system.createStyle(styles.getSubscriptionStyles(e)),h=system.createStyle(styles.getSubscriptionWrapperStyles(e?.align)),T=system.createClass(classes.getWrapperClasses()),O=system.createClass(classes.getContainerClasses()),I=system.createStyle({...t}),{isEditMode:q}=core.useRenderMode(),C=`product-subscription-${r?.baseID}`,E=r?.baseID,D=`subscription-type-selection-${g}`,N=s?.sellingType===index.SubscriptionEnum.ONE_TIME,v=s?.sellingType===index.SubscriptionEnum.SUBSCRIPTION,{isDynamicProduct:k}=useDynamicProduct.useDynamicProduct();if(React.useEffect(()=>{r?.id&&v&&!q&&u({productID:r.id,isShow:!(P||k)})},[P,k,q,v,r?.id,u]),b||P||k)return q?jsxRuntime.jsxs("div",{...n,style:I,children:[jsxRuntime.jsx(OneTimePurchaseTooltip.OneTimePurchaseTooltip,{ref:m,setting:s}),core.filterToolbarPreview(l,!0)]}):null;let f=e=>jsxRuntime.jsxs("div",{...n,style:I,children:[jsxRuntime.jsx("div",{ref:m,"data-selling-type":s?.sellingType,id:C,className:T,style:h,children:e}),core.filterToolbarPreview(l,!0)]}),L=()=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:s?.sellingStyle==="radio"?jsxRuntime.jsx(SellingPlanRadio.SellingPlanRadio,{setting:s,styles:e,builderProps:i,productId:E??"",sellingPlanOptions:d,selectedValue:S,onChange:p}):jsxRuntime.jsx(SellingPlanDropdown.SellingPlanDropdown,{setting:s,sellingPlanOptions:d,selectedValue:S,onChange:p})});return f(N&&x?jsxRuntime.jsx("div",{className:O,style:R,children:jsxRuntime.jsx(SubscriptionRadio.SubscriptionRadio,{id:`${E}-one-time-radio`,name:D,value:index.SubscriptionEnum.ONE_TIME,checked:j===index.SubscriptionEnum.ONE_TIME,className:"!gp-items-start",onChange:e=>{e.target.checked&&y(index.SubscriptionEnum.ONE_TIME)},children:jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:s,styles:e})})}):v&&x?jsxRuntime.jsxs("div",{className:O,style:R,children:[jsxRuntime.jsx(SubscriptionRadio.SubscriptionRadio,{id:`${E}-subscription-radio`,name:D,value:index.SubscriptionEnum.SUBSCRIPTION,checked:j===index.SubscriptionEnum.SUBSCRIPTION,className:"!gp-items-start",onChange:e=>{e.target.checked&&y(index.SubscriptionEnum.SUBSCRIPTION)},children:jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:s,styles:e})}),j===index.SubscriptionEnum.SUBSCRIPTION&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"gp-pl-7",children:L()}),jsxRuntime.jsx("div",{className:"gp-pl-7",children:jsxRuntime.jsx(SubscriptionDetail.SubscriptionDetail,{setting:s,styles:e})})]})]}):jsxRuntime.jsxs("div",{className:O,style:R,children:[jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:s,styles:e}),L(),jsxRuntime.jsx(SubscriptionDetail.SubscriptionDetail,{setting:s,styles:e})]}))};exports.default=ProductSubscription;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),core=require("@gem-sdk/core"),system=require("@gem-sdk/system"),React=require("react"),index=require("../../constants/index.js"),classes=require("./common/classes.js"),styles=require("./common/styles.js"),useSellingPlanChange=require("./hooks/useSellingPlanChange.js"),useSellingSubscription=require("./hooks/useSellingSubscription.js"),useSellingPlanOptions=require("./hooks/useSellingPlanOptions.js"),useSubscriptionVisibility=require("./hooks/useSubscriptionVisibility.js"),OneTimePurchaseTooltip=require("./components/OneTimePurchaseTooltip.js"),SellingPlanDropdown=require("./components/SellingPlanDropdown.js"),SellingPlanLabel=require("./components/SellingPlanLabel.js"),SellingPlanRadio=require("./components/SellingPlanRadio.js"),SubscriptionDetail=require("./components/SubscriptionDetail.js"),SubscriptionRadio=require("./components/SubscriptionRadio.js"),useDynamicProduct=require("../../hooks/useDynamicProduct.js");const ProductSubscription=({styles:e,setting:s,builderProps:i,builderAttrs:n,style:t,children:l})=>{let r=core.useProduct(),u=core.usePageStore(e=>e.setSubscriptionVisible),{defaultValue:o,selectedSellingPlan:a,setSelectedSellingPlan:c}=useSellingSubscription.useSellingSubscription(s),d=useSellingPlanOptions.useSellingPlanOptions(s),{selectedValue:S,handleSellingPlanChange:p}=useSellingPlanChange.useSellingPlanChange({defaultValue:o,selectedSellingPlan:a,setSelectedSellingPlan:c,sellingPlanOptions:d}),m=React.useRef(null),g=React.useId(),{selectedType:j,shouldShowRadio:x,isOneTimeHidden:b,hasNoSellingPlanOptions:P,setSubscriptionSellingType:y}=useSubscriptionVisibility.useSubscriptionVisibility({setting:s}),R=system.createStyle(styles.getSubscriptionStyles(e)),h=system.createStyle(styles.getSubscriptionWrapperStyles(e?.align)),T=system.createClass(classes.getWrapperClasses()),O=system.createClass(classes.getContainerClasses()),I=system.createStyle({...t}),{isEditMode:q}=core.useRenderMode(),C=`product-subscription-${r?.baseID}`,E=r?.baseID,D=`subscription-type-selection-${g}`,N=s?.sellingType===index.SubscriptionEnum.ONE_TIME,v=s?.sellingType===index.SubscriptionEnum.SUBSCRIPTION,{isDynamicProduct:k}=useDynamicProduct.useDynamicProduct();if(React.useEffect(()=>{r?.id&&v&&!q&&u({productID:r.id,isShow:!(P||k)})},[P,k,q,v,r?.id,u]),b||P||k)return q?jsxRuntime.jsxs("div",{...n,style:I,children:[jsxRuntime.jsx(OneTimePurchaseTooltip.OneTimePurchaseTooltip,{ref:m,setting:s}),core.filterToolbarPreview(l,!0)]}):null;let f=e=>jsxRuntime.jsxs("div",{...n,style:I,children:[jsxRuntime.jsx("div",{ref:m,"data-selling-type":s?.sellingType,id:C,className:T,style:h,children:e}),core.filterToolbarPreview(l,!0)]}),L=()=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:s?.sellingStyle==="radio"?jsxRuntime.jsx(SellingPlanRadio.SellingPlanRadio,{setting:s,styles:e,builderProps:i,productId:E??"",sellingPlanOptions:d,selectedValue:S,onChange:p}):jsxRuntime.jsx(SellingPlanDropdown.SellingPlanDropdown,{setting:s,sellingPlanOptions:d,selectedValue:S,onChange:p})});return f(N&&x?jsxRuntime.jsx("div",{className:O,style:R,children:jsxRuntime.jsx(SubscriptionRadio.SubscriptionRadio,{id:`${E}-one-time-radio`,name:D,value:index.SubscriptionEnum.ONE_TIME,checked:j===index.SubscriptionEnum.ONE_TIME,className:"!gp-items-start",onChange:e=>{e.target.checked&&y(index.SubscriptionEnum.ONE_TIME)},children:jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:s,styles:e})})}):v&&x?jsxRuntime.jsxs("div",{className:O,style:R,children:[jsxRuntime.jsx(SubscriptionRadio.SubscriptionRadio,{id:`${E}-subscription-radio`,name:D,value:index.SubscriptionEnum.SUBSCRIPTION,checked:j===index.SubscriptionEnum.SUBSCRIPTION,className:"!gp-items-start",onChange:e=>{e.target.checked&&y(index.SubscriptionEnum.SUBSCRIPTION)},children:jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:s,styles:e})}),j===index.SubscriptionEnum.SUBSCRIPTION&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"gp-pl-7",children:L()}),jsxRuntime.jsx("div",{className:"gp-pl-7",children:jsxRuntime.jsx(SubscriptionDetail.SubscriptionDetail,{setting:s,styles:e})})]})]}):jsxRuntime.jsxs("div",{className:O,style:R,children:[jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:s,styles:e}),v&&L(),v&&jsxRuntime.jsx(SubscriptionDetail.SubscriptionDetail,{setting:s,styles:e})]}))};exports.default=ProductSubscription;
@@ -1 +1 @@
1
- "use strict";var React=require("react"),core=require("@gem-sdk/core"),index=require("../../../constants/index.js"),useSellingPlanOptions=require("./useSellingPlanOptions.js");const useSubscriptionVisibility=({setting:e})=>{let i=core.useProductStore(e=>e.setSubscriptionSellingType),n=core.useProductStore(e=>e.subscriptionSellingType),s=useSellingPlanOptions.useSellingPlanOptions(e),u=core.useProduct(),t=u?.requiresSellingPlan,r=n===index.SubscriptionEnum.ONE_TIME?index.SubscriptionEnum.ONE_TIME:index.SubscriptionEnum.SUBSCRIPTION;React.useEffect(()=>{n||(e?.sellingType===index.SubscriptionEnum.ONE_TIME?i(index.SubscriptionEnum.ONE_TIME):i(e?.sellingType??index.SubscriptionEnum.SUBSCRIPTION))},[i,e?.sellingType,n]);let l=!t,o=e?.sellingType===index.SubscriptionEnum.SUBSCRIPTION&&(!s||0===s.length),c=e?.sellingType===index.SubscriptionEnum.ONE_TIME&&(t||!s||0===s.length);return{selectedType:r,shouldShowRadio:l,isOneTimeHidden:c,hasNoSellingPlanOptions:o,setSubscriptionSellingType:i}};exports.useSubscriptionVisibility=useSubscriptionVisibility;
1
+ "use strict";var React=require("react"),core=require("@gem-sdk/core"),index=require("../../../constants/index.js"),useSellingPlanOptions=require("./useSellingPlanOptions.js");const useSubscriptionVisibility=({setting:e})=>{let i=core.useProductStore(e=>e.setSubscriptionSellingType),n=core.useProductStore(e=>e.subscriptionSellingType),s=useSellingPlanOptions.useSellingPlanOptions(e),u=core.useProduct(),t=u?.requiresSellingPlan,r=n===index.SubscriptionEnum.ONE_TIME?index.SubscriptionEnum.ONE_TIME:index.SubscriptionEnum.SUBSCRIPTION;React.useEffect(()=>{n||(e?.sellingType===index.SubscriptionEnum.ONE_TIME?i(index.SubscriptionEnum.ONE_TIME):i(e?.sellingType??index.SubscriptionEnum.SUBSCRIPTION))},[i,e?.sellingType,n]);let l=!t&&s&&s.length>0,o=e?.sellingType===index.SubscriptionEnum.SUBSCRIPTION&&(!s||0===s.length),c=e?.sellingType===index.SubscriptionEnum.ONE_TIME&&t;return{selectedType:r,shouldShowRadio:l,isOneTimeHidden:c,hasNoSellingPlanOptions:o,setSubscriptionSellingType:i}};exports.useSubscriptionVisibility=useSubscriptionVisibility;
@@ -1 +1 @@
1
- "use strict";var core=require("@gem-sdk/core"),useDynamicProduct=require("./useDynamicProduct.js"),useRecurringSubtotal=require("./useRecurringSubtotal.js"),useProductPriceBreakdown=require("./useProductPriceBreakdown.js");const useGetMoneyLines=(e,t)=>{let{isDynamicProduct:u,dynamicPrice:i,dynamicDiscount:o,isEnableDynamicDiscount:s}=useDynamicProduct.useDynamicProduct(),{t:r}=core.useI18nStore(),a=useRecurringSubtotal.useRecurringSubtotal(),{subTotalMoneyFormatted:l,offerDiscountTotal:n,discountMoneyFormatted:c,totalMoneyFormatted:b}=useProductPriceBreakdown.useProductPriceBreakdown(),d=()=>{let d=[];return!1!==e.isShowSubTotalLabel&&d.push({title:t.subTotalLabel,money:u?i:l,uniqueId:"subTotalLabel"}),!1!==e.isShowDiscountLabel&&d.push({title:t.discountLabel,money:u&&o&&s?`${o.value}%`:n>0?c:"No discount",uniqueId:"discountLabel"}),!1!==e.isShowShippingLabel&&d.push({title:t.shippingLabel,uniqueId:"shippingLabel",tooltip:{content:"Shipping fee will be calculated on real offer page",width:"23em"}}),!1!==e.isShowTaxesLabel&&d.push({title:t.taxesLabel,uniqueId:"taxesLabel",tooltip:{content:"Taxes will be calculated on real offer page",width:"20em"}}),!1!==e.isShowTotalLabel&&d.push({title:t.totalLabel,money:u?i:b,uniqueId:"totalLabel"}),t?.isShowRecurringTotalLabel!==!1&&a&&d.push({title:r("Recurring subtotal"),money:a,uniqueId:"recurringTotalLabel",subTitle:r("Doesn't include shipping, tax or duties")}),d};return{getMoneyLines:d}};exports.useGetMoneyLines=useGetMoneyLines;
1
+ "use strict";var core=require("@gem-sdk/core"),useDynamicProduct=require("./useDynamicProduct.js"),useRecurringSubtotal=require("./useRecurringSubtotal.js"),useProductPriceBreakdown=require("./useProductPriceBreakdown.js"),index=require("../constants/index.js");const useGetMoneyLines=(e,t)=>{let{isDynamicProduct:u,dynamicPrice:i,dynamicDiscount:o,isEnableDynamicDiscount:s}=useDynamicProduct.useDynamicProduct(),{t:r}=core.useI18nStore(),n=useRecurringSubtotal.useRecurringSubtotal(),l=core.useProductStore(e=>e.subscriptionSellingType),{subTotalMoneyFormatted:a,offerDiscountTotal:c,discountMoneyFormatted:d,totalMoneyFormatted:b}=useProductPriceBreakdown.useProductPriceBreakdown(),p=()=>{let p=[];return!1!==e.isShowSubTotalLabel&&p.push({title:t.subTotalLabel,money:u?i:a,uniqueId:"subTotalLabel"}),!1!==e.isShowDiscountLabel&&p.push({title:t.discountLabel,money:u&&o&&s?`${o.value}%`:c>0?d:"No discount",uniqueId:"discountLabel"}),!1!==e.isShowShippingLabel&&p.push({title:t.shippingLabel,uniqueId:"shippingLabel",tooltip:{content:"Shipping fee will be calculated on real offer page",width:"23em"}}),!1!==e.isShowTaxesLabel&&p.push({title:t.taxesLabel,uniqueId:"taxesLabel",tooltip:{content:"Taxes will be calculated on real offer page",width:"20em"}}),!1!==e.isShowTotalLabel&&p.push({title:t.totalLabel,money:u?i:b,uniqueId:"totalLabel"}),t?.isShowRecurringTotalLabel!==!1&&n&&l!==index.SubscriptionEnum.ONE_TIME&&p.push({title:r("Recurring subtotal"),money:n,uniqueId:"recurringTotalLabel",subTitle:r("Doesn't include shipping, tax or duties")}),p};return{getMoneyLines:p}};exports.useGetMoneyLines=useGetMoneyLines;
@@ -1 +1 @@
1
- "use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js");const useProductPriceBreakdown=()=>{let e=core.useProductOfferDiscount(),r=core.useCurrentVariant(),o=core.useProduct(),c=core.useProductStore(e=>e.selectedSellingPlan),{quantity:i}=core.useQuantity(),t=React.useMemo(()=>{if(!c)return null;let e=r?.sellingPlanGroups??o?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===c);if(e)return e}return null},[r,o,c]),n=core.convertDecimalToNumber(r?.price)??0,s=React.useMemo(()=>!t||n<=0?0:getPrice.calculateSellingPlanDiscount({variantPrice:n,pricingPolicies:t.pricingPolicies}),[t,n]),u=Math.max(0,parseFloat(core.shopifyPriceRounding(n-s,2))),a=Math.max(0,parseFloat(core.shopifyPriceRounding(u*(i||1),2))),l=core.useFormatMoney(a,!1),P=e*(i||1),d=parseFloat(core.shopifyPriceRounding(P,2)),p=core.useFormatMoney(d,!1),g=core.shopifyPriceRounding(d,2),f=parseFloat(core.shopifyPriceRounding(a-parseFloat(g),2)),m=core.useFormatMoney(f>0?f:0,!1);return{price:n,sellingPlanDiscountPerUnit:s,priceAfterSellingPlanDiscount:u,subTotal:a,subTotalMoneyFormatted:l,offerDiscountTotal:P,discountWithQuantity:d,discountMoneyFormatted:p,totalMoneyFormatted:m}};exports.useProductPriceBreakdown=useProductPriceBreakdown;
1
+ "use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js"),index=require("../constants/index.js");const useProductPriceBreakdown=()=>{let e=core.useProductOfferDiscount(),r=core.useCurrentVariant(),o=core.useProduct(),i=core.useProductStore(e=>e.selectedSellingPlan),c=core.useProductStore(e=>e.subscriptionSellingType),{quantity:n}=core.useQuantity(),t=React.useMemo(()=>{if(!i||c===index.SubscriptionEnum.ONE_TIME)return null;let e=r?.sellingPlanGroups??o?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===i);if(e)return e}return null},[r,o,i,c]),s=core.convertDecimalToNumber(r?.price)??0,u=React.useMemo(()=>!t||s<=0?0:getPrice.calculateSellingPlanDiscount({variantPrice:s,pricingPolicies:t.pricingPolicies}),[t,s]),a=Math.max(0,parseFloat(core.shopifyPriceRounding(s-u,2))),l=Math.max(0,parseFloat(core.shopifyPriceRounding(a*(n||1),2))),P=core.useFormatMoney(l,!1),d=e*(n||1),p=parseFloat(core.shopifyPriceRounding(d,2)),g=core.useFormatMoney(p,!1),f=core.shopifyPriceRounding(p,2),m=parseFloat(core.shopifyPriceRounding(l-parseFloat(f),2)),y=core.useFormatMoney(m>0?m:0,!1);return{price:s,sellingPlanDiscountPerUnit:u,priceAfterSellingPlanDiscount:a,subTotal:l,subTotalMoneyFormatted:P,offerDiscountTotal:d,discountWithQuantity:p,discountMoneyFormatted:g,totalMoneyFormatted:y}};exports.useProductPriceBreakdown=useProductPriceBreakdown;
@@ -1 +1 @@
1
- "use strict";const getButtonClasses=({isDisabled:t,isLiquid:s})=>({"gp-cursor-default gp-opacity-30":t,"btn-disabled":t&&s}),getAddToCartButtonClasses=t=>{let{isLiquid:s=!1,isDisabled:e=!1}=t??{};return{...getButtonClasses({isDisabled:e,isLiquid:s}),"gp-button-atc tcustomizer-submit-button":s}},getSoldOutButtonClasses=t=>{let{isLiquid:s=!1}=t??{};return{...getButtonClasses({isDisabled:!0,isLiquid:s}),"gp-button-sold-out":s}},getProductPriceClasses=()=>({"gp-button-price":!0});exports.getAddToCartButtonClasses=getAddToCartButtonClasses,exports.getButtonClasses=getButtonClasses,exports.getProductPriceClasses=getProductPriceClasses,exports.getSoldOutButtonClasses=getSoldOutButtonClasses;
1
+ "use strict";const getButtonClasses=({isDisabled:t,isLiquid:s})=>({"gp-cursor-default gp-opacity-30":t,"btn-disabled":t&&s,"gp-add-to-cart":!s}),getAddToCartButtonClasses=t=>{let{isLiquid:s=!1,isDisabled:e=!1}=t??{};return{...getButtonClasses({isDisabled:e,isLiquid:s}),"gp-button-atc tcustomizer-submit-button":s}},getSoldOutButtonClasses=t=>{let{isLiquid:s=!1}=t??{};return{...getButtonClasses({isDisabled:!0,isLiquid:s}),"gp-button-sold-out":s}},getProductPriceClasses=()=>({"gp-button-price":!0});exports.getAddToCartButtonClasses=getAddToCartButtonClasses,exports.getButtonClasses=getButtonClasses,exports.getProductPriceClasses=getProductPriceClasses,exports.getSoldOutButtonClasses=getSoldOutButtonClasses;
@@ -1 +1 @@
1
- "use strict";var core=require("@gem-sdk/core"),React=require("react"),tracking=require("../../../helpers/tracking.js"),useDispatchAfterSubmitEvent=require("./useDispatchAfterSubmitEvent.js"),useCartMessage=require("./useCartMessage.js"),useCartOperations=require("./useCartOperations.js");const useBtnAddToCart=({styles:e,setting:r,builderProps:t})=>{let s=React.useRef(null),{isEditMode:u,isPreviewSharePageMode:a}=core.useRenderMode(),i=core.useProduct(),{currency:c}=core.useCurrency(),{quantity:n}=core.useQuantity(),o=core.useProductProperties(),l=core.useCurrentVariant(),{hasPreSelected:d}=core.useHasPreSelected(),b=core.useStickyStore(e=>e.setStickyVisible),v=core.useProductStore(e=>e.updateIsSubmit),C=useDispatchAfterSubmitEvent.useDispatchAfterSubmitEvent(t?.uid),{showMessage:g,notiComponent:p}=useCartMessage.useCartMessage(e,r),{handleSuccess:f,handleError:k,cartId:S}=useCartOperations.useCartOperations(r,g,C),{isMutating:m,trigger:D}=core.useCreateCart({onSuccess:f,onError:k}),{isMutating:I,trigger:E}=core.useAddToCart({onSuccess:f,onError:k});React.useEffect(()=>{let e=new IntersectionObserver(e=>{let r=e[0];b(r?.isIntersecting)},{threshold:.1}),r=s.current;return s.current&&e.observe(s.current),()=>{r&&e.unobserve(r)}},[b]);let A=React.useCallback(()=>{if(!l?.baseID||!n||!i?.baseID||void 0!==d&&!d||u||a)return;let e=o?.some(e=>e.required&&!e.value);if(v(!0),e)return;let t=o?.filter(e=>!!e.value)?.map(e=>({key:e.key,value:e.value}));tracking.addToCartTracking({quantity:n,currency:c,id:i?.baseID,name:i?.title,brand:i?.vendor,sku:l.sku,price:core.convertDecimalToNumber(l?.price),variant:l.title});let s={quantity:n,attributes:t,variantId:l.baseID};r?.actionEffect!=="buy-now"&&S?E({cartId:S,lines:[s]}):D({items:[s]})},[u,a,S,c,n,o,d,i?.title,i?.vendor,i?.baseID,l?.sku,l?.price,l?.title,l?.baseID,r?.actionEffect,D,E,v]),h=core.useCurrentVariantInStock(),q=m||I,y=l?r?.outOfStockLabel:"Unavailable";return{addToCartRef:s,isLoading:q,isInStock:h,notiComponent:p,outOfStockLabel:y,addToCart:A}};exports.useBtnAddToCart=useBtnAddToCart;
1
+ "use strict";var core=require("@gem-sdk/core"),React=require("react"),tracking=require("../../../helpers/tracking.js"),useDispatchAfterSubmitEvent=require("./useDispatchAfterSubmitEvent.js"),useCartMessage=require("./useCartMessage.js"),useCartOperations=require("./useCartOperations.js");const useBtnAddToCart=({styles:e,setting:r,builderProps:t})=>{let s=React.useRef(null),{isEditMode:u,isPreviewSharePageMode:a}=core.useRenderMode(),i=core.useProduct(),{currency:c}=core.useCurrency(),{quantity:n}=core.useQuantity(),o=core.useProductProperties(),l=core.useCurrentVariant(),{hasPreSelected:d}=core.useHasPreSelected(),b=core.useStickyStore(e=>e.setStickyVisible),v=core.useProductStore(e=>e.updateIsSubmit),C=useDispatchAfterSubmitEvent.useDispatchInteractionEvent(t?.uid),p=useDispatchAfterSubmitEvent.useDispatchCustomEvent({product:i,currentVariant:l,quantity:n}),{showMessage:g,notiComponent:f}=useCartMessage.useCartMessage(e,r),{handleSuccess:k,handleError:S,cartId:m}=useCartOperations.useCartOperations({setting:r,showMessage:g,dispatchInteractionEvent:C,dispatchCustomEvent:p}),{isMutating:D,trigger:I}=core.useCreateCart({onSuccess:k,onError:S}),{isMutating:E,trigger:h}=core.useAddToCart({onSuccess:k,onError:S});React.useEffect(()=>{let e=new IntersectionObserver(e=>{let r=e[0];b(r?.isIntersecting)},{threshold:.1}),r=s.current;return s.current&&e.observe(s.current),()=>{r&&e.unobserve(r)}},[b]);let A=React.useCallback(()=>{if(!l?.baseID||!n||!i?.baseID||void 0!==d&&!d||u||a)return;let e=o?.some(e=>e.required&&!e.value);if(v(!0),e)return;let t=o?.filter(e=>!!e.value)?.map(e=>({key:e.key,value:e.value}));tracking.addToCartTracking({quantity:n,currency:c,id:i?.baseID,name:i?.title,brand:i?.vendor,sku:l.sku,price:core.convertDecimalToNumber(l?.price),variant:l.title});let s={quantity:n,attributes:t,variantId:l.baseID};r?.actionEffect!=="buy-now"&&m?h({cartId:m,lines:[s]}):I({items:[s]})},[u,a,m,c,n,o,d,i?.title,i?.vendor,i?.baseID,l?.sku,l?.price,l?.title,l?.baseID,r?.actionEffect,I,h,v]),q=core.useCurrentVariantInStock(),y=D||E,M=l?r?.outOfStockLabel:"Unavailable";return{addToCartRef:s,isLoading:y,isInStock:q,notiComponent:f,outOfStockLabel:M,addToCart:A}};exports.useBtnAddToCart=useBtnAddToCart;
@@ -1 +1 @@
1
- "use strict";var React=require("react"),core=require("@gem-sdk/core");const useCartOperations=(e,r,t)=>{let{openCart:o}=core.useCartUI(),{storefrontToken:c}=core.useStoreFront(),{cartId:s,updateCartId:a}=core.useCartId(),n=React.useCallback((e,r)=>{e?.enableMessage&&r(e.successMessage||"","success"),o()},[o]),u=(e,r)=>{if(!e.checkoutUrl)return;let t=r?`${e.checkoutUrl}?access_token=${r}`:e.checkoutUrl;window.location.href=t},l=e=>{e?.customURL?.link&&("_blank"===e.customURL.target?window.open(e.customURL.link,"_blank"):window.location.href=e.customURL.link)},i=React.useCallback(s=>{let i={"open-cart-drawer":()=>o(),"go-to-url":()=>l(e),"buy-now":()=>u(s,c),"continue-shopping":()=>n(e,r)};e?.actionEffect!=="buy-now"&&a(s.id);let k=i[e?.actionEffect];k&&k(),t()},[e,c,o,r,a,t,n]),k=React.useCallback(t=>{e?.enableMessage&&(t?.[0]?.code==="INVALID"?r(t[0].message||"","error"):r(e.errorMessage||"","error"))},[e,r]);return{cartId:s,handleSuccess:i,handleError:k}};exports.useCartOperations=useCartOperations;
1
+ "use strict";var React=require("react"),core=require("@gem-sdk/core");const useCartOperations=({setting:e,showMessage:r,dispatchInteractionEvent:t,dispatchCustomEvent:o})=>{let{openCart:c}=core.useCartUI(),{storefrontToken:s}=core.useStoreFront(),{cartId:a,updateCartId:n}=core.useCartId(),u=React.useCallback((e,r)=>{e?.enableMessage&&r(e.successMessage||"","success"),c()},[c]),l=(e,r)=>{if(!e.checkoutUrl)return;let t=r?`${e.checkoutUrl}?access_token=${r}`:e.checkoutUrl;window.location.href=t},i=e=>{e?.customURL?.link&&("_blank"===e.customURL.target?window.open(e.customURL.link,"_blank"):window.location.href=e.customURL.link)},k=React.useCallback(a=>{let k={"open-cart-drawer":()=>c(),"go-to-url":()=>i(e),"buy-now":()=>l(a,s),"continue-shopping":()=>u(e,r)};e?.actionEffect!=="buy-now"&&n(a.id);let b=k[e?.actionEffect];b&&b(),t(),o()},[e,s,c,r,n,t,u,o]),b=React.useCallback(t=>{e?.enableMessage&&(t?.[0]?.code==="INVALID"?r(t[0].message||"","error"):r(e.errorMessage||"","error"))},[e,r]);return{cartId:a,handleSuccess:k,handleError:b}};exports.useCartOperations=useCartOperations;
@@ -1 +1 @@
1
- "use strict";var core=require("@gem-sdk/core"),React=require("react");const useDispatchAfterSubmitEvent=e=>{let{trigger:t}=core.useInteraction();return React.useCallback(()=>{let r=document.querySelector(`[data-id="${e}"]`);if(!r)return;let a=JSON.parse(r?.getAttribute("gp-interaction-after-submit")??"{}");Object.keys(a).length<=0||Object.entries(a).forEach(([a])=>{t({event:"gp:after-submit",selector:`[data-id="${e}"]`,data:Number(a),element:r})})},[e,t])};exports.useDispatchAfterSubmitEvent=useDispatchAfterSubmitEvent;
1
+ "use strict";var core=require("@gem-sdk/core"),React=require("react");const useDispatchInteractionEvent=t=>{let{trigger:e}=core.useInteraction();return React.useCallback(()=>{let a=document.querySelector(`[data-id="${t}"]`);if(!a)return;let s=JSON.parse(a?.getAttribute("gp-interaction-after-submit")??"{}");Object.keys(s).length<=0||Object.entries(s).forEach(([s])=>{e({event:"gp:after-submit",selector:`[data-id="${t}"]`,data:Number(s),element:a})})},[t,e])},useDispatchCustomEvent=({product:t,currentVariant:e,quantity:a})=>React.useCallback(()=>{let s=new CustomEvent("gp:add-to-cart-success",{detail:{data:{product:t,variant:e,quantity:a}}});window.dispatchEvent(s)},[t,e,a]);exports.useDispatchCustomEvent=useDispatchCustomEvent,exports.useDispatchInteractionEvent=useDispatchInteractionEvent;
@@ -1 +1 @@
1
- import{jsxs as e,jsx as s,Fragment as i}from"react/jsx-runtime";import{useProduct as t,usePageStore as o,useRenderMode as l,filterToolbarPreview as n}from"@gem-sdk/core";import{createStyle as r,createClass as m}from"@gem-sdk/system";import{useRef as c,useId as a,useEffect as p}from"react";import{SubscriptionEnum as d}from"../../constants/index.js";import{getWrapperClasses as g,getContainerClasses as u}from"./common/classes.js";import{getSubscriptionStyles as h,getSubscriptionWrapperStyles as S}from"./common/styles.js";import{useSellingPlanChange as f}from"./hooks/useSellingPlanChange.js";import{useSellingSubscription as y}from"./hooks/useSellingSubscription.js";import{useSellingPlanOptions as I}from"./hooks/useSellingPlanOptions.js";import{useSubscriptionVisibility as N}from"./hooks/useSubscriptionVisibility.js";import{OneTimePurchaseTooltip as P}from"./components/OneTimePurchaseTooltip.js";import{SellingPlanDropdown as b}from"./components/SellingPlanDropdown.js";import{SellingPlanLabel as j}from"./components/SellingPlanLabel.js";import{SellingPlanRadio as T}from"./components/SellingPlanRadio.js";import{SubscriptionDetail as O}from"./components/SubscriptionDetail.js";import{SubscriptionRadio as k}from"./components/SubscriptionRadio.js";import{useDynamicProduct as v}from"../../hooks/useDynamicProduct.js";let ProductSubscription=({styles:C,setting:E,builderProps:R,builderAttrs:D,style:B,children:U})=>{let M=t(),V=o(e=>e.setSubscriptionVisible),{defaultValue:$,selectedSellingPlan:_,setSelectedSellingPlan:x}=y(E),w=I(E),{selectedValue:L,handleSellingPlanChange:q}=f({defaultValue:$,selectedSellingPlan:_,setSelectedSellingPlan:x,sellingPlanOptions:w}),z=c(null),A=a(),{selectedType:F,shouldShowRadio:G,isOneTimeHidden:H,hasNoSellingPlanOptions:J,setSubscriptionSellingType:K}=N({setting:E}),Q=r(h(C)),W=r(S(C?.align)),X=m(g()),Y=m(u()),Z=r({...B}),{isEditMode:ee}=l(),es=`product-subscription-${M?.baseID}`,ei=M?.baseID,et=`subscription-type-selection-${A}`,eo=E?.sellingType===d.ONE_TIME,el=E?.sellingType===d.SUBSCRIPTION,{isDynamicProduct:en}=v();if(p(()=>{M?.id&&el&&!ee&&V({productID:M.id,isShow:!(J||en)})},[J,en,ee,el,M?.id,V]),H||J||en)return ee?e("div",{...D,style:Z,children:[s(P,{ref:z,setting:E}),n(U,!0)]}):null;let er=i=>e("div",{...D,style:Z,children:[s("div",{ref:z,"data-selling-type":E?.sellingType,id:es,className:X,style:W,children:i}),n(U,!0)]}),em=()=>s(i,{children:E?.sellingStyle==="radio"?s(T,{setting:E,styles:C,builderProps:R,productId:ei??"",sellingPlanOptions:w,selectedValue:L,onChange:q}):s(b,{setting:E,sellingPlanOptions:w,selectedValue:L,onChange:q})});return er(eo&&G?s("div",{className:Y,style:Q,children:s(k,{id:`${ei}-one-time-radio`,name:et,value:d.ONE_TIME,checked:F===d.ONE_TIME,className:"!gp-items-start",onChange:e=>{e.target.checked&&K(d.ONE_TIME)},children:s(j,{setting:E,styles:C})})}):el&&G?e("div",{className:Y,style:Q,children:[s(k,{id:`${ei}-subscription-radio`,name:et,value:d.SUBSCRIPTION,checked:F===d.SUBSCRIPTION,className:"!gp-items-start",onChange:e=>{e.target.checked&&K(d.SUBSCRIPTION)},children:s(j,{setting:E,styles:C})}),F===d.SUBSCRIPTION&&e(i,{children:[s("div",{className:"gp-pl-7",children:em()}),s("div",{className:"gp-pl-7",children:s(O,{setting:E,styles:C})})]})]}):e("div",{className:Y,style:Q,children:[s(j,{setting:E,styles:C}),em(),s(O,{setting:E,styles:C})]}))};export{ProductSubscription as default};
1
+ import{jsxs as e,jsx as s,Fragment as i}from"react/jsx-runtime";import{useProduct as t,usePageStore as o,useRenderMode as l,filterToolbarPreview as n}from"@gem-sdk/core";import{createStyle as r,createClass as m}from"@gem-sdk/system";import{useRef as c,useId as a,useEffect as p}from"react";import{SubscriptionEnum as d}from"../../constants/index.js";import{getWrapperClasses as g,getContainerClasses as u}from"./common/classes.js";import{getSubscriptionStyles as h,getSubscriptionWrapperStyles as S}from"./common/styles.js";import{useSellingPlanChange as f}from"./hooks/useSellingPlanChange.js";import{useSellingSubscription as y}from"./hooks/useSellingSubscription.js";import{useSellingPlanOptions as I}from"./hooks/useSellingPlanOptions.js";import{useSubscriptionVisibility as N}from"./hooks/useSubscriptionVisibility.js";import{OneTimePurchaseTooltip as P}from"./components/OneTimePurchaseTooltip.js";import{SellingPlanDropdown as b}from"./components/SellingPlanDropdown.js";import{SellingPlanLabel as j}from"./components/SellingPlanLabel.js";import{SellingPlanRadio as T}from"./components/SellingPlanRadio.js";import{SubscriptionDetail as O}from"./components/SubscriptionDetail.js";import{SubscriptionRadio as k}from"./components/SubscriptionRadio.js";import{useDynamicProduct as v}from"../../hooks/useDynamicProduct.js";let ProductSubscription=({styles:C,setting:E,builderProps:R,builderAttrs:D,style:B,children:U})=>{let M=t(),V=o(e=>e.setSubscriptionVisible),{defaultValue:$,selectedSellingPlan:_,setSelectedSellingPlan:x}=y(E),w=I(E),{selectedValue:L,handleSellingPlanChange:q}=f({defaultValue:$,selectedSellingPlan:_,setSelectedSellingPlan:x,sellingPlanOptions:w}),z=c(null),A=a(),{selectedType:F,shouldShowRadio:G,isOneTimeHidden:H,hasNoSellingPlanOptions:J,setSubscriptionSellingType:K}=N({setting:E}),Q=r(h(C)),W=r(S(C?.align)),X=m(g()),Y=m(u()),Z=r({...B}),{isEditMode:ee}=l(),es=`product-subscription-${M?.baseID}`,ei=M?.baseID,et=`subscription-type-selection-${A}`,eo=E?.sellingType===d.ONE_TIME,el=E?.sellingType===d.SUBSCRIPTION,{isDynamicProduct:en}=v();if(p(()=>{M?.id&&el&&!ee&&V({productID:M.id,isShow:!(J||en)})},[J,en,ee,el,M?.id,V]),H||J||en)return ee?e("div",{...D,style:Z,children:[s(P,{ref:z,setting:E}),n(U,!0)]}):null;let er=i=>e("div",{...D,style:Z,children:[s("div",{ref:z,"data-selling-type":E?.sellingType,id:es,className:X,style:W,children:i}),n(U,!0)]}),em=()=>s(i,{children:E?.sellingStyle==="radio"?s(T,{setting:E,styles:C,builderProps:R,productId:ei??"",sellingPlanOptions:w,selectedValue:L,onChange:q}):s(b,{setting:E,sellingPlanOptions:w,selectedValue:L,onChange:q})});return er(eo&&G?s("div",{className:Y,style:Q,children:s(k,{id:`${ei}-one-time-radio`,name:et,value:d.ONE_TIME,checked:F===d.ONE_TIME,className:"!gp-items-start",onChange:e=>{e.target.checked&&K(d.ONE_TIME)},children:s(j,{setting:E,styles:C})})}):el&&G?e("div",{className:Y,style:Q,children:[s(k,{id:`${ei}-subscription-radio`,name:et,value:d.SUBSCRIPTION,checked:F===d.SUBSCRIPTION,className:"!gp-items-start",onChange:e=>{e.target.checked&&K(d.SUBSCRIPTION)},children:s(j,{setting:E,styles:C})}),F===d.SUBSCRIPTION&&e(i,{children:[s("div",{className:"gp-pl-7",children:em()}),s("div",{className:"gp-pl-7",children:s(O,{setting:E,styles:C})})]})]}):e("div",{className:Y,style:Q,children:[s(j,{setting:E,styles:C}),el&&em(),el&&s(O,{setting:E,styles:C})]}))};export{ProductSubscription as default};
@@ -1 +1 @@
1
- import{useEffect as e}from"react";import{useProductStore as i,useProduct as l}from"@gem-sdk/core";import{SubscriptionEnum as s}from"../../../constants/index.js";import{useSellingPlanOptions as n}from"./useSellingPlanOptions.js";let useSubscriptionVisibility=({setting:t})=>{let r=i(e=>e.setSubscriptionSellingType),p=i(e=>e.subscriptionSellingType),o=n(t),T=l(),S=T?.requiresSellingPlan,g=p===s.ONE_TIME?s.ONE_TIME:s.SUBSCRIPTION;e(()=>{p||(t?.sellingType===s.ONE_TIME?r(s.ONE_TIME):r(t?.sellingType??s.SUBSCRIPTION))},[r,t?.sellingType,p]);let I=!S,E=t?.sellingType===s.SUBSCRIPTION&&(!o||0===o.length),m=t?.sellingType===s.ONE_TIME&&(S||!o||0===o.length);return{selectedType:g,shouldShowRadio:I,isOneTimeHidden:m,hasNoSellingPlanOptions:E,setSubscriptionSellingType:r}};export{useSubscriptionVisibility};
1
+ import{useEffect as e}from"react";import{useProductStore as i,useProduct as l}from"@gem-sdk/core";import{SubscriptionEnum as s}from"../../../constants/index.js";import{useSellingPlanOptions as n}from"./useSellingPlanOptions.js";let useSubscriptionVisibility=({setting:t})=>{let r=i(e=>e.setSubscriptionSellingType),p=i(e=>e.subscriptionSellingType),o=n(t),T=l(),S=T?.requiresSellingPlan,g=p===s.ONE_TIME?s.ONE_TIME:s.SUBSCRIPTION;e(()=>{p||(t?.sellingType===s.ONE_TIME?r(s.ONE_TIME):r(t?.sellingType??s.SUBSCRIPTION))},[r,t?.sellingType,p]);let I=!S&&o&&o.length>0,E=t?.sellingType===s.SUBSCRIPTION&&(!o||0===o.length),m=t?.sellingType===s.ONE_TIME&&S;return{selectedType:g,shouldShowRadio:I,isOneTimeHidden:m,hasNoSellingPlanOptions:E,setSubscriptionSellingType:r}};export{useSubscriptionVisibility};
@@ -1 +1 @@
1
- import{useI18nStore as e}from"@gem-sdk/core";import{useDynamicProduct as t}from"./useDynamicProduct.js";import{useRecurringSubtotal as i}from"./useRecurringSubtotal.js";import{useProductPriceBreakdown as o}from"./useProductPriceBreakdown.js";let useGetMoneyLines=(l,u)=>{let{isDynamicProduct:a,dynamicPrice:s,dynamicDiscount:n,isEnableDynamicDiscount:r}=t(),{t:b}=e(),p=i(),{subTotalMoneyFormatted:c,offerDiscountTotal:d,discountMoneyFormatted:h,totalMoneyFormatted:L}=o(),m=()=>{let e=[];return!1!==l.isShowSubTotalLabel&&e.push({title:u.subTotalLabel,money:a?s:c,uniqueId:"subTotalLabel"}),!1!==l.isShowDiscountLabel&&e.push({title:u.discountLabel,money:a&&n&&r?`${n.value}%`:d>0?h:"No discount",uniqueId:"discountLabel"}),!1!==l.isShowShippingLabel&&e.push({title:u.shippingLabel,uniqueId:"shippingLabel",tooltip:{content:"Shipping fee will be calculated on real offer page",width:"23em"}}),!1!==l.isShowTaxesLabel&&e.push({title:u.taxesLabel,uniqueId:"taxesLabel",tooltip:{content:"Taxes will be calculated on real offer page",width:"20em"}}),!1!==l.isShowTotalLabel&&e.push({title:u.totalLabel,money:a?s:L,uniqueId:"totalLabel"}),u?.isShowRecurringTotalLabel!==!1&&p&&e.push({title:b("Recurring subtotal"),money:p,uniqueId:"recurringTotalLabel",subTitle:b("Doesn't include shipping, tax or duties")}),e};return{getMoneyLines:m}};export{useGetMoneyLines};
1
+ import{useI18nStore as e,useProductStore as t}from"@gem-sdk/core";import{useDynamicProduct as i}from"./useDynamicProduct.js";import{useRecurringSubtotal as o}from"./useRecurringSubtotal.js";import{useProductPriceBreakdown as l}from"./useProductPriceBreakdown.js";import{SubscriptionEnum as u}from"../constants/index.js";let useGetMoneyLines=(s,a)=>{let{isDynamicProduct:n,dynamicPrice:r,dynamicDiscount:p,isEnableDynamicDiscount:b}=i(),{t:c}=e(),d=o(),h=t(e=>e.subscriptionSellingType),{subTotalMoneyFormatted:L,offerDiscountTotal:m,discountMoneyFormatted:g,totalMoneyFormatted:w}=l(),S=()=>{let e=[];return!1!==s.isShowSubTotalLabel&&e.push({title:a.subTotalLabel,money:n?r:L,uniqueId:"subTotalLabel"}),!1!==s.isShowDiscountLabel&&e.push({title:a.discountLabel,money:n&&p&&b?`${p.value}%`:m>0?g:"No discount",uniqueId:"discountLabel"}),!1!==s.isShowShippingLabel&&e.push({title:a.shippingLabel,uniqueId:"shippingLabel",tooltip:{content:"Shipping fee will be calculated on real offer page",width:"23em"}}),!1!==s.isShowTaxesLabel&&e.push({title:a.taxesLabel,uniqueId:"taxesLabel",tooltip:{content:"Taxes will be calculated on real offer page",width:"20em"}}),!1!==s.isShowTotalLabel&&e.push({title:a.totalLabel,money:n?r:w,uniqueId:"totalLabel"}),a?.isShowRecurringTotalLabel!==!1&&d&&h!==u.ONE_TIME&&e.push({title:c("Recurring subtotal"),money:d,uniqueId:"recurringTotalLabel",subTitle:c("Doesn't include shipping, tax or duties")}),e};return{getMoneyLines:S}};export{useGetMoneyLines};
@@ -1 +1 @@
1
- import{useMemo as e}from"react";import{useProductOfferDiscount as r,useCurrentVariant as l,useProduct as i,useProductStore as t,useQuantity as a,convertDecimalToNumber as o,shopifyPriceRounding as n,useFormatMoney as s}from"@gem-sdk/core";import{calculateSellingPlanDiscount as p}from"../helpers/product-price-breakdown/getPrice.js";let useProductPriceBreakdown=()=>{let c=r(),u=l(),P=i(),d=t(e=>e.selectedSellingPlan),{quantity:f}=a(),g=e(()=>{if(!d)return null;let e=u?.sellingPlanGroups??P?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===d);if(e)return e}return null},[u,P,d]),m=o(u?.price)??0,F=e(()=>!g||m<=0?0:p({variantPrice:m,pricingPolicies:g.pricingPolicies}),[g,m]),k=Math.max(0,parseFloat(n(m-F,2))),h=Math.max(0,parseFloat(n(k*(f||1),2))),w=s(h,!1),x=c*(f||1),b=parseFloat(n(x,2)),B=s(b,!1),G=n(b,2),M=parseFloat(n(h-parseFloat(G),2)),j=s(M>0?M:0,!1);return{price:m,sellingPlanDiscountPerUnit:F,priceAfterSellingPlanDiscount:k,subTotal:h,subTotalMoneyFormatted:w,offerDiscountTotal:x,discountWithQuantity:b,discountMoneyFormatted:B,totalMoneyFormatted:j}};export{useProductPriceBreakdown};
1
+ import{useMemo as e}from"react";import{useProductOfferDiscount as r,useCurrentVariant as l,useProduct as i,useProductStore as t,useQuantity as o,convertDecimalToNumber as n,shopifyPriceRounding as a,useFormatMoney as s}from"@gem-sdk/core";import{calculateSellingPlanDiscount as p}from"../helpers/product-price-breakdown/getPrice.js";import{SubscriptionEnum as c}from"../constants/index.js";let useProductPriceBreakdown=()=>{let u=r(),P=l(),m=i(),d=t(e=>e.selectedSellingPlan),f=t(e=>e.subscriptionSellingType),{quantity:g}=o(),F=e(()=>{if(!d||f===c.ONE_TIME)return null;let e=P?.sellingPlanGroups??m?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===d);if(e)return e}return null},[P,m,d,f]),k=n(P?.price)??0,x=e(()=>!F||k<=0?0:p({variantPrice:k,pricingPolicies:F.pricingPolicies}),[F,k]),b=Math.max(0,parseFloat(a(k-x,2))),h=Math.max(0,parseFloat(a(b*(g||1),2))),w=s(h,!1),M=u*(g||1),j=parseFloat(a(M,2)),B=s(j,!1),E=a(j,2),G=parseFloat(a(h-parseFloat(E),2)),I=s(G>0?G:0,!1);return{price:k,sellingPlanDiscountPerUnit:x,priceAfterSellingPlanDiscount:b,subTotal:h,subTotalMoneyFormatted:w,offerDiscountTotal:M,discountWithQuantity:j,discountMoneyFormatted:B,totalMoneyFormatted:I}};export{useProductPriceBreakdown};
@@ -1 +1 @@
1
- let getButtonClasses=({isDisabled:t,isLiquid:s})=>({"gp-cursor-default gp-opacity-30":t,"btn-disabled":t&&s}),getAddToCartButtonClasses=t=>{let{isLiquid:s=!1,isDisabled:e=!1}=t??{};return{...getButtonClasses({isDisabled:e,isLiquid:s}),"gp-button-atc tcustomizer-submit-button":s}},getSoldOutButtonClasses=t=>{let{isLiquid:s=!1}=t??{};return{...getButtonClasses({isDisabled:!0,isLiquid:s}),"gp-button-sold-out":s}},getProductPriceClasses=()=>({"gp-button-price":!0});export{getAddToCartButtonClasses,getButtonClasses,getProductPriceClasses,getSoldOutButtonClasses};
1
+ let getButtonClasses=({isDisabled:t,isLiquid:s})=>({"gp-cursor-default gp-opacity-30":t,"btn-disabled":t&&s,"gp-add-to-cart":!s}),getAddToCartButtonClasses=t=>{let{isLiquid:s=!1,isDisabled:e=!1}=t??{};return{...getButtonClasses({isDisabled:e,isLiquid:s}),"gp-button-atc tcustomizer-submit-button":s}},getSoldOutButtonClasses=t=>{let{isLiquid:s=!1}=t??{};return{...getButtonClasses({isDisabled:!0,isLiquid:s}),"gp-button-sold-out":s}},getProductPriceClasses=()=>({"gp-button-price":!0});export{getAddToCartButtonClasses,getButtonClasses,getProductPriceClasses,getSoldOutButtonClasses};
@@ -1 +1 @@
1
- import{useRenderMode as e,useProduct as t,useCurrency as r,useQuantity as i,useProductProperties as s,useCurrentVariant as n,useHasPreSelected as o,useStickyStore as a,useProductStore as u,useCreateCart as l,useAddToCart as c,convertDecimalToNumber as m,useCurrentVariantInStock as b}from"@gem-sdk/core";import{useRef as d,useEffect as f,useCallback as p}from"react";import{addToCartTracking as v}from"../../../helpers/tracking.js";import{useDispatchAfterSubmitEvent as g}from"./useDispatchAfterSubmitEvent.js";import{useCartMessage as I}from"./useCartMessage.js";import{useCartOperations as k}from"./useCartOperations.js";let useBtnAddToCart=({styles:D,setting:S,builderProps:E})=>{let h=d(null),{isEditMode:j,isPreviewSharePageMode:y}=e(),C=t(),{currency:A}=r(),{quantity:M}=i(),O=s(),w=n(),{hasPreSelected:B}=o(),T=a(e=>e.setStickyVisible),q=u(e=>e.updateIsSubmit),x=g(E?.uid),{showMessage:L,notiComponent:U}=I(D,S),{handleSuccess:V,handleError:z,cartId:F}=k(S,L,x),{isMutating:G,trigger:H}=l({onSuccess:V,onError:z}),{isMutating:J,trigger:K}=c({onSuccess:V,onError:z});f(()=>{let e=new IntersectionObserver(e=>{let t=e[0];T(t?.isIntersecting)},{threshold:.1}),t=h.current;return h.current&&e.observe(h.current),()=>{t&&e.unobserve(t)}},[T]);let N=p(()=>{if(!w?.baseID||!M||!C?.baseID||void 0!==B&&!B||j||y)return;let e=O?.some(e=>e.required&&!e.value);if(q(!0),e)return;let t=O?.filter(e=>!!e.value)?.map(e=>({key:e.key,value:e.value}));v({quantity:M,currency:A,id:C?.baseID,name:C?.title,brand:C?.vendor,sku:w.sku,price:m(w?.price),variant:w.title});let r={quantity:M,attributes:t,variantId:w.baseID};S?.actionEffect!=="buy-now"&&F?K({cartId:F,lines:[r]}):H({items:[r]})},[j,y,F,A,M,O,B,C?.title,C?.vendor,C?.baseID,w?.sku,w?.price,w?.title,w?.baseID,S?.actionEffect,H,K,q]),P=b(),Q=G||J,R=w?S?.outOfStockLabel:"Unavailable";return{addToCartRef:h,isLoading:Q,isInStock:P,notiComponent:U,outOfStockLabel:R,addToCart:N}};export{useBtnAddToCart};
1
+ import{useRenderMode as e,useProduct as t,useCurrency as r,useQuantity as i,useProductProperties as s,useCurrentVariant as n,useHasPreSelected as o,useStickyStore as a,useProductStore as u,useCreateCart as l,useAddToCart as c,convertDecimalToNumber as m,useCurrentVariantInStock as b}from"@gem-sdk/core";import{useRef as d,useEffect as f,useCallback as p}from"react";import{addToCartTracking as v}from"../../../helpers/tracking.js";import{useDispatchInteractionEvent as g,useDispatchCustomEvent as I}from"./useDispatchAfterSubmitEvent.js";import{useCartMessage as k}from"./useCartMessage.js";import{useCartOperations as D}from"./useCartOperations.js";let useBtnAddToCart=({styles:S,setting:E,builderProps:h})=>{let j=d(null),{isEditMode:y,isPreviewSharePageMode:C}=e(),A=t(),{currency:M}=r(),{quantity:O}=i(),w=s(),B=n(),{hasPreSelected:T}=o(),q=a(e=>e.setStickyVisible),x=u(e=>e.updateIsSubmit),L=g(h?.uid),U=I({product:A,currentVariant:B,quantity:O}),{showMessage:V,notiComponent:z}=k(S,E),{handleSuccess:F,handleError:G,cartId:H}=D({setting:E,showMessage:V,dispatchInteractionEvent:L,dispatchCustomEvent:U}),{isMutating:J,trigger:K}=l({onSuccess:F,onError:G}),{isMutating:N,trigger:P}=c({onSuccess:F,onError:G});f(()=>{let e=new IntersectionObserver(e=>{let t=e[0];q(t?.isIntersecting)},{threshold:.1}),t=j.current;return j.current&&e.observe(j.current),()=>{t&&e.unobserve(t)}},[q]);let Q=p(()=>{if(!B?.baseID||!O||!A?.baseID||void 0!==T&&!T||y||C)return;let e=w?.some(e=>e.required&&!e.value);if(x(!0),e)return;let t=w?.filter(e=>!!e.value)?.map(e=>({key:e.key,value:e.value}));v({quantity:O,currency:M,id:A?.baseID,name:A?.title,brand:A?.vendor,sku:B.sku,price:m(B?.price),variant:B.title});let r={quantity:O,attributes:t,variantId:B.baseID};E?.actionEffect!=="buy-now"&&H?P({cartId:H,lines:[r]}):K({items:[r]})},[y,C,H,M,O,w,T,A?.title,A?.vendor,A?.baseID,B?.sku,B?.price,B?.title,B?.baseID,E?.actionEffect,K,P,x]),R=b(),W=J||N,X=B?E?.outOfStockLabel:"Unavailable";return{addToCartRef:j,isLoading:W,isInStock:R,notiComponent:z,outOfStockLabel:X,addToCart:Q}};export{useBtnAddToCart};
@@ -1 +1 @@
1
- import{useCallback as e}from"react";import{useCartUI as o,useStoreFront as r,useCartId as t}from"@gem-sdk/core";let useCartOperations=(s,c,n)=>{let{openCart:a}=o(),{storefrontToken:i}=r(),{cartId:l,updateCartId:u}=t(),k=e((e,o)=>{e?.enableMessage&&o(e.successMessage||"","success"),a()},[a]),m=(e,o)=>{if(!e.checkoutUrl)return;let r=o?`${e.checkoutUrl}?access_token=${o}`:e.checkoutUrl;window.location.href=r},f=e=>{e?.customURL?.link&&("_blank"===e.customURL.target?window.open(e.customURL.link,"_blank"):window.location.href=e.customURL.link)},g=e(e=>{let o={"open-cart-drawer":()=>a(),"go-to-url":()=>f(s),"buy-now":()=>m(e,i),"continue-shopping":()=>k(s,c)};s?.actionEffect!=="buy-now"&&u(e.id);let r=o[s?.actionEffect];r&&r(),n()},[s,i,a,c,u,n,k]),p=e(e=>{s?.enableMessage&&(e?.[0]?.code==="INVALID"?c(e[0].message||"","error"):c(s.errorMessage||"","error"))},[s,c]);return{cartId:l,handleSuccess:g,handleError:p}};export{useCartOperations};
1
+ import{useCallback as e}from"react";import{useCartUI as o,useStoreFront as r,useCartId as t}from"@gem-sdk/core";let useCartOperations=({setting:s,showMessage:c,dispatchInteractionEvent:n,dispatchCustomEvent:a})=>{let{openCart:i}=o(),{storefrontToken:l}=r(),{cartId:u,updateCartId:k}=t(),m=e((e,o)=>{e?.enableMessage&&o(e.successMessage||"","success"),i()},[i]),f=(e,o)=>{if(!e.checkoutUrl)return;let r=o?`${e.checkoutUrl}?access_token=${o}`:e.checkoutUrl;window.location.href=r},g=e=>{e?.customURL?.link&&("_blank"===e.customURL.target?window.open(e.customURL.link,"_blank"):window.location.href=e.customURL.link)},p=e(e=>{let o={"open-cart-drawer":()=>i(),"go-to-url":()=>g(s),"buy-now":()=>f(e,l),"continue-shopping":()=>m(s,c)};s?.actionEffect!=="buy-now"&&k(e.id);let r=o[s?.actionEffect];r&&r(),n(),a()},[s,l,i,c,k,n,m,a]),w=e(e=>{s?.enableMessage&&(e?.[0]?.code==="INVALID"?c(e[0].message||"","error"):c(s.errorMessage||"","error"))},[s,c]);return{cartId:u,handleSuccess:p,handleError:w}};export{useCartOperations};
@@ -1 +1 @@
1
- import{useInteraction as t}from"@gem-sdk/core";import{useCallback as e}from"react";let useDispatchAfterSubmitEvent=r=>{let{trigger:i}=t();return e(()=>{let t=document.querySelector(`[data-id="${r}"]`);if(!t)return;let e=JSON.parse(t?.getAttribute("gp-interaction-after-submit")??"{}");Object.keys(e).length<=0||Object.entries(e).forEach(([e])=>{i({event:"gp:after-submit",selector:`[data-id="${r}"]`,data:Number(e),element:t})})},[r,i])};export{useDispatchAfterSubmitEvent};
1
+ import{useInteraction as t}from"@gem-sdk/core";import{useCallback as e}from"react";let useDispatchInteractionEvent=a=>{let{trigger:r}=t();return e(()=>{let t=document.querySelector(`[data-id="${a}"]`);if(!t)return;let e=JSON.parse(t?.getAttribute("gp-interaction-after-submit")??"{}");Object.keys(e).length<=0||Object.entries(e).forEach(([e])=>{r({event:"gp:after-submit",selector:`[data-id="${a}"]`,data:Number(e),element:t})})},[a,r])},useDispatchCustomEvent=({product:t,currentVariant:a,quantity:r})=>e(()=>{let e=new CustomEvent("gp:add-to-cart-success",{detail:{data:{product:t,variant:a,quantity:r}}});window.dispatchEvent(e)},[t,a,r]);export{useDispatchCustomEvent,useDispatchInteractionEvent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/components",
3
- "version": "12.0.0-dev.95",
3
+ "version": "12.0.0-dev.97",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",