@gem-sdk/components 12.0.0-staging.82 → 12.0.0-staging.85
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/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/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
|
@@ -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:t}=core.useQuantity(),n=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]),u=core.convertDecimalToNumber(r?.price)??0,s=React.useMemo(()=>!n||u<=0?0:getPrice.calculateSellingPlanDiscount({variantPrice:u,pricingPolicies:n.pricingPolicies}),[n,u]),{isPrepaidSubscription:l,prepaidMultiple:a}=React.useMemo(()=>{let e=n?.billingPolicy?.intervalCount,r=n?.deliveryPolicy?.intervalCount;return e&&r?{isPrepaidSubscription:e>r,prepaidMultiple:e/r}:{isPrepaidSubscription:!1,prepaidMultiple:1}},[n]),p=React.useMemo(()=>n&&l?(t||1)*a:t,[l,a,t,n]),P=Math.max(0,parseFloat(core.shopifyPriceRounding(u-s,2))),d=Math.max(0,parseFloat(core.shopifyPriceRounding(P*(p||1),2))),g=core.useFormatMoney(d,!1),y=e*(t||1),f=parseFloat(core.shopifyPriceRounding(y,2)),S=core.useFormatMoney(f,!1),m=core.shopifyPriceRounding(f,2),M=parseFloat(core.shopifyPriceRounding(d-parseFloat(m),2)),b=core.useFormatMoney(M>0?M:0,!1);return{price:u,sellingPlanDiscountPerUnit:s,priceAfterSellingPlanDiscount:P,subTotal:d,subTotalMoneyFormatted:g,offerDiscountTotal:y,discountWithQuantity:f,discountMoneyFormatted:S,totalMoneyFormatted:b}};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;
|
|
@@ -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
|
|
1
|
+
import{useMemo as e}from"react";import{useProductOfferDiscount as r,useCurrentVariant as i,useProduct as l,useProductStore as t,useQuantity as o,convertDecimalToNumber as n,shopifyPriceRounding as a,useFormatMoney as p}from"@gem-sdk/core";import{calculateSellingPlanDiscount as s}from"../helpers/product-price-breakdown/getPrice.js";import{useSubscriptionSellingType as u}from"./useSubscriptionSellingType.js";let useProductPriceBreakdown=()=>{let c=r(),P=i(),d=l(),g=t(e=>e.selectedSellingPlan),{isOneTime:m}=u(),{quantity:f}=o(),b=e(()=>{if(!g||m)return null;let e=P?.sellingPlanGroups??d?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===g);if(e)return e}return null},[P,d,g,m]),F=n(P?.price)??0,S=e(()=>!b||F<=0?0:s({variantPrice:F,pricingPolicies:b.pricingPolicies}),[b,F]),{isPrepaidSubscription:k,prepaidMultiple:v}=e(()=>{let e=b?.billingPolicy?.intervalCount,r=b?.deliveryPolicy?.intervalCount;return e&&r?{isPrepaidSubscription:e>r,prepaidMultiple:e/r}:{isPrepaidSubscription:!1,prepaidMultiple:1}},[b]),y=e(()=>b&&k?(f||1)*v:f,[k,v,f,b]),M=Math.max(0,parseFloat(a(F-S,2))),h=Math.max(0,parseFloat(a(M*(y||1),2))),w=p(h,!1),x=c*(f||1),j=parseFloat(a(x,2)),B=p(j,!1),C=a(j,2),G=parseFloat(a(h-parseFloat(C),2)),D=p(G>0?G:0,!1);return{price:F,sellingPlanDiscountPerUnit:S,priceAfterSellingPlanDiscount:M,subTotal:h,subTotalMoneyFormatted:w,offerDiscountTotal:x,discountWithQuantity:j,discountMoneyFormatted:B,totalMoneyFormatted:D}};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.85",
|
|
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.85",
|
|
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",
|