@gem-sdk/components 12.0.0-staging.81 → 12.0.0-staging.83
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/dist/cjs/post-purchase/product/components/product-subscription/ProductSubscription.js +1 -1
- package/dist/cjs/post-purchase/product/components/product-subscription/components/ProductSubscriptionContent.js +1 -0
- package/dist/cjs/post-purchase/product/components/product-subscription/components/ProductSubscriptionOptions.js +1 -0
- package/dist/cjs/post-purchase/product/components/product-subscription/helpers/handleContainerKeyDown.js +1 -0
- package/dist/cjs/post-purchase/product/components/product-subscription/hooks/useCheckProductsSubscriptionExistence.js +1 -0
- package/dist/cjs/post-purchase/product/components/product-subscription/hooks/useProductSubscriptionContentData.js +1 -0
- package/dist/cjs/post-purchase/product/helpers/product-price-breakdown/getPrice.js +1 -1
- package/dist/cjs/post-purchase/product/hooks/useProductPriceBreakdown.js +1 -1
- package/dist/cjs/post-purchase/product/hooks/useRecurringSubtotal.js +1 -1
- package/dist/esm/post-purchase/product/components/product-subscription/ProductSubscription.js +1 -1
- package/dist/esm/post-purchase/product/components/product-subscription/components/ProductSubscriptionContent.js +1 -0
- package/dist/esm/post-purchase/product/components/product-subscription/components/ProductSubscriptionOptions.js +1 -0
- package/dist/esm/post-purchase/product/components/product-subscription/helpers/handleContainerKeyDown.js +1 -0
- package/dist/esm/post-purchase/product/components/product-subscription/hooks/useCheckProductsSubscriptionExistence.js +1 -0
- package/dist/esm/post-purchase/product/components/product-subscription/hooks/useProductSubscriptionContentData.js +1 -0
- package/dist/esm/post-purchase/product/helpers/product-price-breakdown/getPrice.js +1 -1
- package/dist/esm/post-purchase/product/hooks/useProductPriceBreakdown.js +1 -1
- package/dist/esm/post-purchase/product/hooks/useRecurringSubtotal.js +1 -1
- package/package.json +2 -2
package/dist/cjs/post-purchase/product/components/product-subscription/ProductSubscription.js
CHANGED
|
@@ -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"),
|
|
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"),ProductSubscriptionContent=require("./components/ProductSubscriptionContent.js"),OneTimePurchaseTooltip=require("./components/OneTimePurchaseTooltip.js"),useProductSubscriptionContentData=require("./hooks/useProductSubscriptionContentData.js");const ProductSubscription=({styles:e,setting:t,builderProps:i,builderAttrs:s,style:r,children:n})=>{let{isEditMode:o}=core.useRenderMode(),u=system.createStyle({...r}),c=useProductSubscriptionContentData.useProductSubscriptionContentData({setting:t,styles:e,builderProps:i});return c.visibility.isOneTimeHidden||c.visibility.hasNoSellingPlanOptions||c.isDynamicProduct?jsxRuntime.jsxs("div",{...s,style:u,children:[o&&jsxRuntime.jsx(OneTimePurchaseTooltip.OneTimePurchaseTooltip,{ref:c.componentRef,setting:t}),core.filterToolbarPreview(n,!0)]}):c.visibility.isOnetimeOnly&&!o?"":jsxRuntime.jsxs("div",{...s,style:u,children:[jsxRuntime.jsx("div",{ref:c.componentRef,dir:c.direction,"data-selling-type":t?.sellingType,id:c.componentId,className:c.wrapperClasses,style:c.subscriptionWrapperStyles,children:jsxRuntime.jsx(ProductSubscriptionContent.ProductSubscriptionContent,{data:c,setting:t,styles:e,builderProps:i})}),core.filterToolbarPreview(n,!0)]})};exports.default=ProductSubscription;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var jsxRuntime=require("react/jsx-runtime"),ProductSubscriptionOptions=require("./ProductSubscriptionOptions.js"),SellingPlanLabel=require("./SellingPlanLabel.js"),SubscriptionRadio=require("./SubscriptionRadio.js"),index=require("../../../constants/index.js"),handleContainerKeyDown=require("../helpers/handleContainerKeyDown.js");const ProductSubscriptionContent=({data:e,setting:n,styles:i,builderProps:t})=>{let{visibility:s,productId:o,renderType:r,radioGroupName:l,direction:u,containerClasses:a,subscriptionStyles:d,selectedValue:c,sellingPlanOptions:p,handleSellingPlanChange:S,onSelectType:b}=e,x=r===index.SubscriptionEnum.SUBSCRIPTION&&(s.selectedType===index.SubscriptionEnum.ONE_TIME&&s.requiresSellingPlan||s.selectedType===r);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[s.shouldShowRadio&&jsxRuntime.jsx(SubscriptionRadio.SubscriptionRadio,{id:`${t?.uid??""}-${o}-${r}-radio`,name:l,value:r,checked:s.selectedType===r,className:"!gp-items-start",onChange:e=>{e.target.checked&&b(r)}}),jsxRuntime.jsxs("div",{"data-component-container":!0,className:a,style:d,onClick:()=>b(r),onKeyDown:e=>handleContainerKeyDown.handleContainerKeyDown({event:e,type:r,shouldShowRadio:s.shouldShowRadio,selectedType:s.selectedType,onSelectType:b}),role:"button",tabIndex:0,children:[jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:n,styles:i,id:`label-${t?.uid??""}-${o}-${r}-radio`}),x&&jsxRuntime.jsx(ProductSubscriptionOptions.ProductSubscriptionOptions,{direction:u,setting:n,styles:i,builderProps:t,productId:o,sellingPlanOptions:p,selectedValue:c,onSellingPlanChange:S})]})]})};exports.ProductSubscriptionContent=ProductSubscriptionContent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var jsxRuntime=require("react/jsx-runtime"),SellingPlanDropdown=require("./SellingPlanDropdown.js"),SellingPlanRadio=require("./SellingPlanRadio.js"),SubscriptionDetail=require("./SubscriptionDetail.js");const ProductSubscriptionOptions=({direction:i,setting:n,styles:e,builderProps:l,productId:s,sellingPlanOptions:t,selectedValue:o,onSellingPlanChange:r})=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n?.sellingStyle==="radio"?jsxRuntime.jsx(SellingPlanRadio.SellingPlanRadio,{setting:n,styles:e,builderProps:l,productId:s,sellingPlanOptions:t,selectedValue:o,onChange:r}):jsxRuntime.jsx(SellingPlanDropdown.SellingPlanDropdown,{dir:i,setting:n,sellingPlanOptions:t,selectedValue:o,onChange:r}),jsxRuntime.jsx(SubscriptionDetail.SubscriptionDetail,{setting:n,styles:e})]});exports.ProductSubscriptionOptions=ProductSubscriptionOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const handleContainerKeyDown=({event:e,type:n,shouldShowRadio:t,selectedType:o,onSelectType:a})=>{("Enter"===e.key||" "===e.key)&&t&&o!==n&&(e.preventDefault(),a(n))};exports.handleContainerKeyDown=handleContainerKeyDown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var React=require("react"),core=require("@gem-sdk/core");const useCheckProductsSubscriptionExistence=({productId:e,elementUid:t,isSubscription:r,hasNoSellingPlanOptions:s,isDynamicProduct:c})=>{let i=core.usePageStore(e=>e.setSubscriptionVisible),u=core.usePageStore(e=>e.getSubscriptionVisible);React.useEffect(()=>{if(!e||!r)return;let o=`${t}-${e}`,n=!(s||c),b=u()??{};if(!n){i({...b,[e]:(b[e]??[]).filter(e=>e!==o)});return}i({...b,[e]:[...b[e]??[],o]})},[t,u,s,c,r,e,i])};exports.useCheckProductsSubscriptionExistence=useCheckProductsSubscriptionExistence;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var 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"),helpers=require("../../../../../helpers.js"),useSellingPlanChange=require("./useSellingPlanChange.js"),useSellingPlanOptions=require("./useSellingPlanOptions.js"),useSellingSubscription=require("./useSellingSubscription.js"),useSubscriptionVisibility=require("./useSubscriptionVisibility.js"),useDynamicProduct=require("../../../hooks/useDynamicProduct.js"),useCheckProductsSubscriptionExistence=require("./useCheckProductsSubscriptionExistence.js");const DEFAULT_DIRECTION="ltr",useProductSubscriptionContentData=({setting:e,styles:s,builderProps:i})=>{let t=core.useProduct(),{defaultValue:n,selectedSellingPlan:r,setSelectedSellingPlan:u}=useSellingSubscription.useSellingSubscription(e),l=useSellingPlanOptions.useSellingPlanOptions(e),{selectedValue:c,handleSellingPlanChange:o}=useSellingPlanChange.useSellingPlanChange({defaultValue:n,selectedSellingPlan:r,setSelectedSellingPlan:u,sellingPlanOptions:l}),a=React.useRef(null),p=React.useId(),S=useSubscriptionVisibility.useSubscriptionVisibility({setting:e}),d=system.createStyle(styles.getSubscriptionStyles(s)),b=system.createStyle(styles.getSubscriptionWrapperStyles(s?.align)),g=system.createClass(classes.getWrapperClasses()),y=system.createClass(classes.getContainerClasses()),P=`product-subscription-${helpers.extractProductID(t?.baseID??"")}`,m=helpers.extractProductID(t?.baseID??""),C=`subscription-type-selection-${p}`,h=e?.sellingType===index.SubscriptionEnum.ONE_TIME,E=e?.sellingType===index.SubscriptionEnum.SUBSCRIPTION,I=h?index.SubscriptionEnum.ONE_TIME:index.SubscriptionEnum.SUBSCRIPTION,{isDynamicProduct:x}=useDynamicProduct.useDynamicProduct(),{sellingTitleDirection:q,sellingTitleOneTimeDirection:D}=s??{},O=I===index.SubscriptionEnum.ONE_TIME?D??"ltr":q??"ltr";useCheckProductsSubscriptionExistence.useCheckProductsSubscriptionExistence({productId:t?.id,elementUid:i?.uid,isSubscription:E,hasNoSellingPlanOptions:S.hasNoSellingPlanOptions,isDynamicProduct:x});let T=e=>{S.shouldShowRadio&&S.selectedType!==e&&S.setSubscriptionSellingType(e)};return{componentRef:a,componentId:P,wrapperClasses:g,subscriptionWrapperStyles:b,visibility:S,productId:m,renderType:I,radioGroupName:C,direction:O,containerClasses:y,subscriptionStyles:d,selectedValue:c,sellingPlanOptions:l,handleSellingPlanChange:o,onSelectType:T,isDynamicProduct:x}};exports.useProductSubscriptionContentData=useProductSubscriptionContentData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var types=require("../../components/product-subscription/types.js");const findPolicyWithoutAfterCycle=({policies:e})=>{let t=e.filter(e=>null!=e);if(0===t.length)return null;let l=t.find(e=>{let t=e?.AfterCycle??e.afterCycle;return!t});return l??t[0]??null},parseAmount=({value:e})=>{if(!e)return 0;let t=parseFloat(e);return isNaN(t)||t<=0?0:t},calculatePercentageDiscount=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?0:e*t/100,calculateFixedAmountDiscount=({amount:e})=>parseAmount({value:e}),calculatePriceDiscount=({variantPrice:e,fixedPrice:t})=>{let l=parseAmount({value:t});return l<=0?0:e-l},calculateSellingPlanDiscount=({variantPrice:e,pricingPolicies:t})=>{if(!t||0===t.length)return 0;let l=t.filter(e=>null!=e);if(0===l.length)return 0;let r=findPolicyWithoutAfterCycle({policies:l});if(!r)return 0;let n=r.AdjustmentType??r.adjustmentType,u=r.AdjustmentValue??r.adjustmentValue;return n&&u?n===types.AdjustmentType.FIXED_AMOUNT&&u.amount?calculateFixedAmountDiscount({amount:u.amount}):n===types.AdjustmentType.PERCENTAGE&&void 0!==u.percentage?calculatePercentageDiscount({variantPrice:e,percentage:u.percentage}):n===types.AdjustmentType.PRICE&&u.amount?calculatePriceDiscount({variantPrice:e,fixedPrice:u.amount}):0:0},calculateFixedAmountPrice=({variantPrice:e,amount:t})=>{let l=parseAmount({value:t});return l<=0?e:e-l},calculatePercentagePrice=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?e:e-e*t/100,calculateFixedPrice=({fixedPrice:e})=>parseAmount({value:e}),calculateRecurringPrice=({variantPrice:e,pricingPolicies:t})=>{if(!t||0===t.length)return e;let l=t.filter(e=>null!=e);if(0===l.length)return e;let r=findPolicyWithoutAfterCycle({policies:l});if(!r)return e;let n=r.AdjustmentType??r.adjustmentType,u=r.AdjustmentValue??r.adjustmentValue;return n&&u?n===types.AdjustmentType.FIXED_AMOUNT&&u.amount?calculateFixedAmountPrice({variantPrice:e,amount:u.amount}):n===types.AdjustmentType.PERCENTAGE&&void 0!==u.percentage?calculatePercentagePrice({variantPrice:e,percentage:u.percentage}):n===types.AdjustmentType.PRICE&&u.amount?calculateFixedPrice({fixedPrice:u.amount}):e:e},getIntervalText=({interval:e,intervalCount:t})=>{let l={DAY:{singular:"day",plural:"days"},WEEK:{singular:"week",plural:"weeks"},MONTH:{singular:"month",plural:"months"},YEAR:{singular:"year",plural:"years"}}[e];if(!l){let l=e.toLowerCase();return 1===t?`every ${l}`:`every ${t} ${l}`}let r=1===t?l.singular:l.plural;return 1===t?`every ${r}`:`every ${t} ${r}`},formatInterval=({
|
|
1
|
+
"use strict";var types=require("../../components/product-subscription/types.js");const findPolicyWithoutAfterCycle=({policies:e})=>{let t=e.filter(e=>null!=e);if(0===t.length)return null;let l=t.find(e=>{let t=e?.AfterCycle??e.afterCycle;return!t});return l??t[0]??null},parseAmount=({value:e})=>{if(!e)return 0;let t=parseFloat(e);return isNaN(t)||t<=0?0:t},calculatePercentageDiscount=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?0:e*t/100,calculateFixedAmountDiscount=({amount:e})=>parseAmount({value:e}),calculatePriceDiscount=({variantPrice:e,fixedPrice:t})=>{let l=parseAmount({value:t});return l<=0?0:e-l},calculateSellingPlanDiscount=({variantPrice:e,pricingPolicies:t})=>{if(!t||0===t.length)return 0;let l=t.filter(e=>null!=e);if(0===l.length)return 0;let r=findPolicyWithoutAfterCycle({policies:l});if(!r)return 0;let n=r.AdjustmentType??r.adjustmentType,u=r.AdjustmentValue??r.adjustmentValue;return n&&u?n===types.AdjustmentType.FIXED_AMOUNT&&u.amount?calculateFixedAmountDiscount({amount:u.amount}):n===types.AdjustmentType.PERCENTAGE&&void 0!==u.percentage?calculatePercentageDiscount({variantPrice:e,percentage:u.percentage}):n===types.AdjustmentType.PRICE&&u.amount?calculatePriceDiscount({variantPrice:e,fixedPrice:u.amount}):0:0},calculateFixedAmountPrice=({variantPrice:e,amount:t})=>{let l=parseAmount({value:t});return l<=0?e:e-l},calculatePercentagePrice=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?e:e-e*t/100,calculateFixedPrice=({fixedPrice:e})=>parseAmount({value:e}),calculateRecurringPrice=({variantPrice:e,pricingPolicies:t})=>{if(!t||0===t.length)return e;let l=t.filter(e=>null!=e);if(0===l.length)return e;let r=findPolicyWithoutAfterCycle({policies:l});if(!r)return e;let n=r.AdjustmentType??r.adjustmentType,u=r.AdjustmentValue??r.adjustmentValue;return n&&u?n===types.AdjustmentType.FIXED_AMOUNT&&u.amount?calculateFixedAmountPrice({variantPrice:e,amount:u.amount}):n===types.AdjustmentType.PERCENTAGE&&void 0!==u.percentage?calculatePercentagePrice({variantPrice:e,percentage:u.percentage}):n===types.AdjustmentType.PRICE&&u.amount?calculateFixedPrice({fixedPrice:u.amount}):e:e},getIntervalText=({interval:e,intervalCount:t})=>{let l={DAY:{singular:"day",plural:"days"},WEEK:{singular:"week",plural:"weeks"},MONTH:{singular:"month",plural:"months"},YEAR:{singular:"year",plural:"years"}}[e];if(!l){let l=e.toLowerCase();return 1===t?`every ${l}`:`every ${t} ${l}`}let r=1===t?l.singular:l.plural;return 1===t?`every ${r}`:`every ${t} ${r}`},formatInterval=({deliveryPolicy:e})=>{if(!e)return"";let t=e.interval?.toUpperCase();if(!t)return"";let l=e.intervalCount??1;return getIntervalText({interval:t,intervalCount:l})};exports.calculateRecurringPrice=calculateRecurringPrice,exports.calculateSellingPlanDiscount=calculateSellingPlanDiscount,exports.findPolicyWithoutAfterCycle=findPolicyWithoutAfterCycle,exports.formatInterval=formatInterval;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js"),useSubscriptionSellingType=require("./useSubscriptionSellingType.js");const useProductPriceBreakdown=()=>{let e=core.useProductOfferDiscount(),r=core.useCurrentVariant(),
|
|
1
|
+
"use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js"),useSubscriptionSellingType=require("./useSubscriptionSellingType.js");const useProductPriceBreakdown=()=>{let e=core.useProductOfferDiscount(),r=core.useCurrentVariant(),i=core.useProduct(),o=core.useProductStore(e=>e.selectedSellingPlan),{isOneTime:c}=useSubscriptionSellingType.useSubscriptionSellingType(),{quantity:n}=core.useQuantity(),t=React.useMemo(()=>{if(!o||c)return null;let e=r?.sellingPlanGroups??i?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===o);if(e)return e}return null},[r,i,o,c]),l=core.convertDecimalToNumber(r?.price)??0,u=React.useMemo(()=>!t||l<=0?0:getPrice.calculateSellingPlanDiscount({variantPrice:l,pricingPolicies:t.pricingPolicies}),[t,l]),s=React.useMemo(()=>{let e=t?.billingPolicy?.intervalCount,r=t?.deliveryPolicy?.intervalCount;return!!e&&!!r&&e>r},[t]),a=React.useMemo(()=>t&&s?t.billingPolicy?.intervalCount??n:n,[s,n,t]),P=Math.max(0,parseFloat(core.shopifyPriceRounding(l-u,2))),p=Math.max(0,parseFloat(core.shopifyPriceRounding(P*(a||1),2))),g=core.useFormatMoney(p,!1),d=e*(n||1),y=parseFloat(core.shopifyPriceRounding(d,2)),f=core.useFormatMoney(y,!1),m=core.shopifyPriceRounding(y,2),S=parseFloat(core.shopifyPriceRounding(p-parseFloat(m),2)),R=core.useFormatMoney(S>0?S:0,!1);return{price:l,sellingPlanDiscountPerUnit:u,priceAfterSellingPlanDiscount:P,subTotal:p,subTotalMoneyFormatted:g,offerDiscountTotal:d,discountWithQuantity:y,discountMoneyFormatted:f,totalMoneyFormatted:R}};exports.useProductPriceBreakdown=useProductPriceBreakdown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js");const useRecurringSubtotal=()=>{let e=core.useCurrentVariant(),r=core.useProduct(),i=core.useProductStore(e=>e.selectedSellingPlan),{quantity:
|
|
1
|
+
"use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js");const useRecurringSubtotal=()=>{let e=core.useCurrentVariant(),r=core.useProduct(),i=core.useProductStore(e=>e.selectedSellingPlan),{quantity:t}=core.useQuantity(),l=e?.sellingPlanGroups,u=core.convertDecimalToNumber(e?.price)??0,c=React.useMemo(()=>{if(!i)return null;let t=e?.sellingPlanGroups??r?.sellingPlanGroups??[];for(let e of t)if(e?.sellingPlans){for(let r of e.sellingPlans)if(r?.baseID===i)return r}return null},[JSON.stringify(l),i]),n=JSON.stringify(c?.pricingPolicies),o=JSON.stringify(c?.billingPolicy),s=c?.baseID,a=React.useMemo(()=>{if(!s||!e||u<=0||!c)return 0;let r=getPrice.calculateRecurringPrice({variantPrice:u,pricingPolicies:c.pricingPolicies}),i=r*(t||1);return parseFloat(core.shopifyPriceRounding(i,2))},[n,u,t,s]),g=React.useMemo(()=>{if(!s||!c)return null;let e=c.deliveryPolicy;return getPrice.formatInterval({deliveryPolicy:e})},[o,s]),P=core.useFormatMoney(Math.max(a,0),!1),f=React.useMemo(()=>s&&g?`${P} ${g}`:null,[s,g,P]);return f};exports.useRecurringSubtotal=useRecurringSubtotal;
|
package/dist/esm/post-purchase/product/components/product-subscription/ProductSubscription.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as
|
|
1
|
+
import{jsxs as i,jsx as e}from"react/jsx-runtime";import{useRenderMode as t,filterToolbarPreview as o}from"@gem-sdk/core";import{createStyle as s}from"@gem-sdk/system";import{ProductSubscriptionContent as r}from"./components/ProductSubscriptionContent.js";import{OneTimePurchaseTooltip as n}from"./components/OneTimePurchaseTooltip.js";import{useProductSubscriptionContentData as l}from"./hooks/useProductSubscriptionContentData.js";let ProductSubscription=({styles:m,setting:p,builderProps:c,builderAttrs:d,style:a,children:u})=>{let{isEditMode:y}=t(),f=s({...a}),b=l({setting:p,styles:m,builderProps:c});return b.visibility.isOneTimeHidden||b.visibility.hasNoSellingPlanOptions||b.isDynamicProduct?i("div",{...d,style:f,children:[y&&e(n,{ref:b.componentRef,setting:p}),o(u,!0)]}):b.visibility.isOnetimeOnly&&!y?"":i("div",{...d,style:f,children:[e("div",{ref:b.componentRef,dir:b.direction,"data-selling-type":p?.sellingType,id:b.componentId,className:b.wrapperClasses,style:b.subscriptionWrapperStyles,children:e(r,{data:b,setting:p,styles:m,builderProps:c})}),o(u,!0)]})};export{ProductSubscription as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsxs as e,Fragment as t,jsx as o}from"react/jsx-runtime";import{ProductSubscriptionOptions as n}from"./ProductSubscriptionOptions.js";import{SellingPlanLabel as i}from"./SellingPlanLabel.js";import{SubscriptionRadio as l}from"./SubscriptionRadio.js";import{SubscriptionEnum as r}from"../../../constants/index.js";import{handleContainerKeyDown as s}from"../helpers/handleContainerKeyDown.js";let ProductSubscriptionContent=({data:d,setting:a,styles:c,builderProps:p})=>{let{visibility:u,productId:m,renderType:h,radioGroupName:S,direction:y,containerClasses:g,subscriptionStyles:b,selectedValue:P,sellingPlanOptions:C,handleSellingPlanChange:T,onSelectType:f}=d,j=h===r.SUBSCRIPTION&&(u.selectedType===r.ONE_TIME&&u.requiresSellingPlan||u.selectedType===h);return e(t,{children:[u.shouldShowRadio&&o(l,{id:`${p?.uid??""}-${m}-${h}-radio`,name:S,value:h,checked:u.selectedType===h,className:"!gp-items-start",onChange:e=>{e.target.checked&&f(h)}}),e("div",{"data-component-container":!0,className:g,style:b,onClick:()=>f(h),onKeyDown:e=>s({event:e,type:h,shouldShowRadio:u.shouldShowRadio,selectedType:u.selectedType,onSelectType:f}),role:"button",tabIndex:0,children:[o(i,{setting:a,styles:c,id:`label-${p?.uid??""}-${m}-${h}-radio`}),j&&o(n,{direction:y,setting:a,styles:c,builderProps:p,productId:m,sellingPlanOptions:C,selectedValue:P,onSellingPlanChange:T})]})]})};export{ProductSubscriptionContent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsxs as t,Fragment as i,jsx as e}from"react/jsx-runtime";import{SellingPlanDropdown as n}from"./SellingPlanDropdown.js";import{SellingPlanRadio as o}from"./SellingPlanRadio.js";import{SubscriptionDetail as l}from"./SubscriptionDetail.js";let ProductSubscriptionOptions=({direction:s,setting:r,styles:p,builderProps:a,productId:d,sellingPlanOptions:c,selectedValue:g,onSellingPlanChange:u})=>t(i,{children:[r?.sellingStyle==="radio"?e(o,{setting:r,styles:p,builderProps:a,productId:d,sellingPlanOptions:c,selectedValue:g,onChange:u}):e(n,{dir:s,setting:r,sellingPlanOptions:c,selectedValue:g,onChange:u}),e(l,{setting:r,styles:p})]});export{ProductSubscriptionOptions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let handleContainerKeyDown=({event:e,type:n,shouldShowRadio:t,selectedType:a,onSelectType:o})=>{("Enter"===e.key||" "===e.key)&&t&&a!==n&&(e.preventDefault(),o(n))};export{handleContainerKeyDown};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as e}from"react";import{usePageStore as t}from"@gem-sdk/core";let useCheckProductsSubscriptionExistence=({productId:i,elementUid:r,isSubscription:s,hasNoSellingPlanOptions:c,isDynamicProduct:o})=>{let u=t(e=>e.setSubscriptionVisible),n=t(e=>e.getSubscriptionVisible);e(()=>{if(!i||!s)return;let e=`${r}-${i}`,t=!(c||o),p=n()??{};if(!t){u({...p,[i]:(p[i]??[]).filter(t=>t!==e)});return}u({...p,[i]:[...p[i]??[],e]})},[r,n,c,o,s,i,u])};export{useCheckProductsSubscriptionExistence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useProduct as o}from"@gem-sdk/core";import{createStyle as s,createClass as t}from"@gem-sdk/system";import{useRef as e,useId as i}from"react";import{SubscriptionEnum as r}from"../../../constants/index.js";import{getWrapperClasses as n,getContainerClasses as l}from"../common/classes.js";import{getSubscriptionStyles as m,getSubscriptionWrapperStyles as p}from"../common/styles.js";import{extractProductID as u}from"../../../../../helpers.js";import{useSellingPlanChange as c}from"./useSellingPlanChange.js";import{useSellingPlanOptions as a}from"./useSellingPlanOptions.js";import{useSellingSubscription as S}from"./useSellingSubscription.js";import{useSubscriptionVisibility as d}from"./useSubscriptionVisibility.js";import{useDynamicProduct as f}from"../../../hooks/useDynamicProduct.js";import{useCheckProductsSubscriptionExistence as g}from"./useCheckProductsSubscriptionExistence.js";let DEFAULT_DIRECTION="ltr",useProductSubscriptionContentData=({setting:I,styles:b,builderProps:T})=>{let j=o(),{defaultValue:P,selectedSellingPlan:y,setSelectedSellingPlan:E}=S(I),O=a(I),{selectedValue:h,handleSellingPlanChange:N}=c({defaultValue:P,selectedSellingPlan:y,setSelectedSellingPlan:E,sellingPlanOptions:O}),C=e(null),D=i(),k=d({setting:I}),R=s(m(b)),U=s(p(b?.align)),_=t(n()),x=t(l()),M=`product-subscription-${u(j?.baseID??"")}`,B=u(j?.baseID??""),$=`subscription-type-selection-${D}`,w=I?.sellingType===r.ONE_TIME,A=I?.sellingType===r.SUBSCRIPTION,F=w?r.ONE_TIME:r.SUBSCRIPTION,{isDynamicProduct:L}=f(),{sellingTitleDirection:V,sellingTitleOneTimeDirection:q}=b??{},v=F===r.ONE_TIME?q??"ltr":V??"ltr";g({productId:j?.id,elementUid:T?.uid,isSubscription:A,hasNoSellingPlanOptions:k.hasNoSellingPlanOptions,isDynamicProduct:L});let z=o=>{k.shouldShowRadio&&k.selectedType!==o&&k.setSubscriptionSellingType(o)};return{componentRef:C,componentId:M,wrapperClasses:_,subscriptionWrapperStyles:U,visibility:k,productId:B,renderType:F,radioGroupName:$,direction:v,containerClasses:x,subscriptionStyles:R,selectedValue:h,sellingPlanOptions:O,handleSellingPlanChange:N,onSelectType:z,isDynamicProduct:L}};export{useProductSubscriptionContentData};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AdjustmentType as e}from"../../components/product-subscription/types.js";let findPolicyWithoutAfterCycle=({policies:e})=>{let t=e.filter(e=>null!=e);if(0===t.length)return null;let l=t.find(e=>{let t=e?.AfterCycle??e.afterCycle;return!t});return l??t[0]??null},parseAmount=({value:e})=>{if(!e)return 0;let t=parseFloat(e);return isNaN(t)||t<=0?0:t},calculatePercentageDiscount=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?0:e*t/100,calculateFixedAmountDiscount=({amount:e})=>parseAmount({value:e}),calculatePriceDiscount=({variantPrice:e,fixedPrice:t})=>{let l=parseAmount({value:t});return l<=0?0:e-l},calculateSellingPlanDiscount=({variantPrice:t,pricingPolicies:l})=>{if(!l||0===l.length)return 0;let r=l.filter(e=>null!=e);if(0===r.length)return 0;let n=findPolicyWithoutAfterCycle({policies:r});if(!n)return 0;let u=n.AdjustmentType??n.adjustmentType,a=n.AdjustmentValue??n.adjustmentValue;return u&&a?u===e.FIXED_AMOUNT&&a.amount?calculateFixedAmountDiscount({amount:a.amount}):u===e.PERCENTAGE&&void 0!==a.percentage?calculatePercentageDiscount({variantPrice:t,percentage:a.percentage}):u===e.PRICE&&a.amount?calculatePriceDiscount({variantPrice:t,fixedPrice:a.amount}):0:0},calculateFixedAmountPrice=({variantPrice:e,amount:t})=>{let l=parseAmount({value:t});return l<=0?e:e-l},calculatePercentagePrice=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?e:e-e*t/100,calculateFixedPrice=({fixedPrice:e})=>parseAmount({value:e}),calculateRecurringPrice=({variantPrice:t,pricingPolicies:l})=>{if(!l||0===l.length)return t;let r=l.filter(e=>null!=e);if(0===r.length)return t;let n=findPolicyWithoutAfterCycle({policies:r});if(!n)return t;let u=n.AdjustmentType??n.adjustmentType,a=n.AdjustmentValue??n.adjustmentValue;return u&&a?u===e.FIXED_AMOUNT&&a.amount?calculateFixedAmountPrice({variantPrice:t,amount:a.amount}):u===e.PERCENTAGE&&void 0!==a.percentage?calculatePercentagePrice({variantPrice:t,percentage:a.percentage}):u===e.PRICE&&a.amount?calculateFixedPrice({fixedPrice:a.amount}):t:t},getIntervalText=({interval:e,intervalCount:t})=>{let l={DAY:{singular:"day",plural:"days"},WEEK:{singular:"week",plural:"weeks"},MONTH:{singular:"month",plural:"months"},YEAR:{singular:"year",plural:"years"}}[e];if(!l){let l=e.toLowerCase();return 1===t?`every ${l}`:`every ${t} ${l}`}let r=1===t?l.singular:l.plural;return 1===t?`every ${r}`:`every ${t} ${r}`},formatInterval=({
|
|
1
|
+
import{AdjustmentType as e}from"../../components/product-subscription/types.js";let findPolicyWithoutAfterCycle=({policies:e})=>{let t=e.filter(e=>null!=e);if(0===t.length)return null;let l=t.find(e=>{let t=e?.AfterCycle??e.afterCycle;return!t});return l??t[0]??null},parseAmount=({value:e})=>{if(!e)return 0;let t=parseFloat(e);return isNaN(t)||t<=0?0:t},calculatePercentageDiscount=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?0:e*t/100,calculateFixedAmountDiscount=({amount:e})=>parseAmount({value:e}),calculatePriceDiscount=({variantPrice:e,fixedPrice:t})=>{let l=parseAmount({value:t});return l<=0?0:e-l},calculateSellingPlanDiscount=({variantPrice:t,pricingPolicies:l})=>{if(!l||0===l.length)return 0;let r=l.filter(e=>null!=e);if(0===r.length)return 0;let n=findPolicyWithoutAfterCycle({policies:r});if(!n)return 0;let u=n.AdjustmentType??n.adjustmentType,a=n.AdjustmentValue??n.adjustmentValue;return u&&a?u===e.FIXED_AMOUNT&&a.amount?calculateFixedAmountDiscount({amount:a.amount}):u===e.PERCENTAGE&&void 0!==a.percentage?calculatePercentageDiscount({variantPrice:t,percentage:a.percentage}):u===e.PRICE&&a.amount?calculatePriceDiscount({variantPrice:t,fixedPrice:a.amount}):0:0},calculateFixedAmountPrice=({variantPrice:e,amount:t})=>{let l=parseAmount({value:t});return l<=0?e:e-l},calculatePercentagePrice=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?e:e-e*t/100,calculateFixedPrice=({fixedPrice:e})=>parseAmount({value:e}),calculateRecurringPrice=({variantPrice:t,pricingPolicies:l})=>{if(!l||0===l.length)return t;let r=l.filter(e=>null!=e);if(0===r.length)return t;let n=findPolicyWithoutAfterCycle({policies:r});if(!n)return t;let u=n.AdjustmentType??n.adjustmentType,a=n.AdjustmentValue??n.adjustmentValue;return u&&a?u===e.FIXED_AMOUNT&&a.amount?calculateFixedAmountPrice({variantPrice:t,amount:a.amount}):u===e.PERCENTAGE&&void 0!==a.percentage?calculatePercentagePrice({variantPrice:t,percentage:a.percentage}):u===e.PRICE&&a.amount?calculateFixedPrice({fixedPrice:a.amount}):t:t},getIntervalText=({interval:e,intervalCount:t})=>{let l={DAY:{singular:"day",plural:"days"},WEEK:{singular:"week",plural:"weeks"},MONTH:{singular:"month",plural:"months"},YEAR:{singular:"year",plural:"years"}}[e];if(!l){let l=e.toLowerCase();return 1===t?`every ${l}`:`every ${t} ${l}`}let r=1===t?l.singular:l.plural;return 1===t?`every ${r}`:`every ${t} ${r}`},formatInterval=({deliveryPolicy:e})=>{if(!e)return"";let t=e.interval?.toUpperCase();if(!t)return"";let l=e.intervalCount??1;return getIntervalText({interval:t,intervalCount:l})};export{calculateRecurringPrice,calculateSellingPlanDiscount,findPolicyWithoutAfterCycle,formatInterval};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useMemo as e}from"react";import{useProductOfferDiscount as r,useCurrentVariant as l,useProduct as i,useProductStore as t,useQuantity as
|
|
1
|
+
import{useMemo as e}from"react";import{useProductOfferDiscount as r,useCurrentVariant as l,useProduct as i,useProductStore as t,useQuantity as n,convertDecimalToNumber as o,shopifyPriceRounding as a,useFormatMoney as s}from"@gem-sdk/core";import{calculateSellingPlanDiscount as c}from"../helpers/product-price-breakdown/getPrice.js";import{useSubscriptionSellingType as p}from"./useSubscriptionSellingType.js";let useProductPriceBreakdown=()=>{let u=r(),P=l(),g=i(),m=t(e=>e.selectedSellingPlan),{isOneTime:d}=p(),{quantity:f}=n(),b=e(()=>{if(!m||d)return null;let e=P?.sellingPlanGroups??g?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===m);if(e)return e}return null},[P,g,m,d]),v=o(P?.price)??0,y=e(()=>!b||v<=0?0:c({variantPrice:v,pricingPolicies:b.pricingPolicies}),[b,v]),F=e(()=>{let e=b?.billingPolicy?.intervalCount,r=b?.deliveryPolicy?.intervalCount;return!!e&&!!r&&e>r},[b]),k=e(()=>b&&F?b.billingPolicy?.intervalCount??f:f,[F,f,b]),h=Math.max(0,parseFloat(a(v-y,2))),w=Math.max(0,parseFloat(a(h*(k||1),2))),x=s(w,!1),C=u*(f||1),S=parseFloat(a(C,2)),j=s(S,!1),B=a(S,2),G=parseFloat(a(w-parseFloat(B),2)),M=s(G>0?G:0,!1);return{price:v,sellingPlanDiscountPerUnit:y,priceAfterSellingPlanDiscount:h,subTotal:w,subTotalMoneyFormatted:x,offerDiscountTotal:C,discountWithQuantity:S,discountMoneyFormatted:j,totalMoneyFormatted:M}};export{useProductPriceBreakdown};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useMemo as
|
|
1
|
+
import{useMemo as r}from"react";import{useCurrentVariant as e,useProduct as l,useProductStore as i,useQuantity as n,convertDecimalToNumber as t,shopifyPriceRounding as o,useFormatMoney as s}from"@gem-sdk/core";import{calculateRecurringPrice as u,formatInterval as c}from"../helpers/product-price-breakdown/getPrice.js";let useRecurringSubtotal=()=>{let g=e(),a=l(),f=i(r=>r.selectedSellingPlan),{quantity:p}=n(),P=g?.sellingPlanGroups,m=t(g?.price)??0,b=r(()=>{if(!f)return null;let r=g?.sellingPlanGroups??a?.sellingPlanGroups??[];for(let e of r)if(e?.sellingPlans){for(let r of e.sellingPlans)if(r?.baseID===f)return r}return null},[JSON.stringify(P),f]),y=JSON.stringify(b?.pricingPolicies),S=JSON.stringify(b?.billingPolicy),d=b?.baseID,G=r(()=>{if(!d||!g||m<=0||!b)return 0;let r=u({variantPrice:m,pricingPolicies:b.pricingPolicies}),e=r*(p||1);return parseFloat(o(e,2))},[y,m,p,d]),J=r(()=>{if(!d||!b)return null;let r=b.deliveryPolicy;return c({deliveryPolicy:r})},[S,d]),N=s(Math.max(G,0),!1),O=r(()=>d&&J?`${N} ${J}`:null,[d,J,N]);return O};export{useRecurringSubtotal};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/components",
|
|
3
|
-
"version": "12.0.0-staging.
|
|
3
|
+
"version": "12.0.0-staging.83",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"i18n:extract": "rollup -c ./scripts/rollup.config.settings.mjs && node ./scripts/translate/extract-texts-to-locales.js && node ./scripts/translate/en-keys-usage.js"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@gem-sdk/core": "12.0.0-staging.
|
|
29
|
+
"@gem-sdk/core": "12.0.0-staging.83",
|
|
30
30
|
"@gem-sdk/styles": "12.0.0-staging.66",
|
|
31
31
|
"@gem-sdk/system": "12.0.0-staging.66",
|
|
32
32
|
"@types/react-transition-group": "^4.4.12",
|