@gem-sdk/components 12.0.0-staging.80 → 12.0.0-staging.82

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.
Files changed (17) hide show
  1. package/dist/cjs/post-purchase/product/components/product-subscription/ProductSubscription.js +1 -1
  2. package/dist/cjs/post-purchase/product/components/product-subscription/components/ProductSubscriptionContent.js +1 -0
  3. package/dist/cjs/post-purchase/product/components/product-subscription/components/ProductSubscriptionOptions.js +1 -0
  4. package/dist/cjs/post-purchase/product/components/product-subscription/helpers/findDefaultValue.js +1 -1
  5. package/dist/cjs/post-purchase/product/components/product-subscription/helpers/findMatchedGroup.js +1 -1
  6. package/dist/cjs/post-purchase/product/components/product-subscription/helpers/handleContainerKeyDown.js +1 -0
  7. package/dist/cjs/post-purchase/product/components/product-subscription/hooks/useCheckProductsSubscriptionExistence.js +1 -0
  8. package/dist/cjs/post-purchase/product/components/product-subscription/hooks/useProductSubscriptionContentData.js +1 -0
  9. package/dist/esm/post-purchase/product/components/product-subscription/ProductSubscription.js +1 -1
  10. package/dist/esm/post-purchase/product/components/product-subscription/components/ProductSubscriptionContent.js +1 -0
  11. package/dist/esm/post-purchase/product/components/product-subscription/components/ProductSubscriptionOptions.js +1 -0
  12. package/dist/esm/post-purchase/product/components/product-subscription/helpers/findDefaultValue.js +1 -1
  13. package/dist/esm/post-purchase/product/components/product-subscription/helpers/findMatchedGroup.js +1 -1
  14. package/dist/esm/post-purchase/product/components/product-subscription/helpers/handleContainerKeyDown.js +1 -0
  15. package/dist/esm/post-purchase/product/components/product-subscription/hooks/useCheckProductsSubscriptionExistence.js +1 -0
  16. package/dist/esm/post-purchase/product/components/product-subscription/hooks/useProductSubscriptionContentData.js +1 -0
  17. package/package.json +1 -1
@@ -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"),helpers=require("../../../../helpers.js");const DEFAULT_DIRECTION="ltr",ProductSubscription=({styles:e,setting:i,builderProps:s,builderAttrs:n,style:t,children:l})=>{let{isEditMode:r}=core.useRenderMode(),u=core.useProduct(),o=core.usePageStore(e=>e.setSubscriptionVisible),a=core.usePageStore(e=>e.getSubscriptionVisible),{defaultValue:c,selectedSellingPlan:d,setSelectedSellingPlan:p}=useSellingSubscription.useSellingSubscription(i),S=useSellingPlanOptions.useSellingPlanOptions(i),{selectedValue:m,handleSellingPlanChange:g}=useSellingPlanChange.useSellingPlanChange({defaultValue:c,selectedSellingPlan:d,setSelectedSellingPlan:p,sellingPlanOptions:S}),b=React.useRef(null),P=React.useId(),{selectedType:j,shouldShowRadio:x,isOneTimeHidden:y,isOnetimeOnly:R,hasNoSellingPlanOptions:h,requiresSellingPlan:T,setSubscriptionSellingType:I}=useSubscriptionVisibility.useSubscriptionVisibility({setting:i}),O=system.createStyle(styles.getSubscriptionStyles(e)),q=system.createStyle(styles.getSubscriptionWrapperStyles(e?.align)),E=system.createClass(classes.getWrapperClasses()),D=system.createClass(classes.getContainerClasses()),C=system.createStyle({...t}),f=`product-subscription-${helpers.extractProductID(u?.baseID??"")}`,N=helpers.extractProductID(u?.baseID??""),$=`subscription-type-selection-${P}`,k=i?.sellingType===index.SubscriptionEnum.ONE_TIME,v=i?.sellingType===index.SubscriptionEnum.SUBSCRIPTION,{isDynamicProduct:V}=useDynamicProduct.useDynamicProduct(),{sellingTitleDirection:_,sellingTitleOneTimeDirection:w}=e??{},M=e=>e===index.SubscriptionEnum.ONE_TIME?w??"ltr":_??"ltr";if(React.useEffect(()=>{if(!u?.id||!v)return;let e=u?.id,i=`${s?.uid}-${e}`,n=!(h||V),t=a()??{};if(!n){o({...t,[e]:(t[e]??[]).filter(e=>e!==i)});return}o({...t,[e]:[...t[e]??[],i]})},[s?.uid,a,h,V,v,u?.id,o]),y||h||V)return r?jsxRuntime.jsxs("div",{...n,style:C,children:[jsxRuntime.jsx(OneTimePurchaseTooltip.OneTimePurchaseTooltip,{ref:b,setting:i}),core.filterToolbarPreview(l,!0)]}):null;let L=e=>jsxRuntime.jsx(SubscriptionRadio.SubscriptionRadio,{id:`${s?.uid??""}-${N}-${e}-radio`,name:$,value:e,checked:j===e,className:"!gp-items-start",onChange:i=>{i.target.checked&&I(e)}}),U=t=>{let r=t===index.SubscriptionEnum.SUBSCRIPTION&&(j===index.SubscriptionEnum.ONE_TIME&&T||j===t);return jsxRuntime.jsxs("div",{...n,style:C,children:[jsxRuntime.jsxs("div",{ref:b,dir:M(t),"data-selling-type":i?.sellingType,id:f,className:E,style:q,children:[x&&L(t),jsxRuntime.jsxs("div",{"data-component-container":!0,className:D,style:O,children:[jsxRuntime.jsx(SellingPlanLabel.SellingPlanLabel,{setting:i,styles:e,id:`label-${s?.uid??""}-${N}-${t}-radio`}),r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[B(),jsxRuntime.jsx(SubscriptionDetail.SubscriptionDetail,{setting:i,styles:e})]})]})]}),core.filterToolbarPreview(l,!0)]})},B=()=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:i?.sellingStyle==="radio"?jsxRuntime.jsx(SellingPlanRadio.SellingPlanRadio,{setting:i,styles:e,builderProps:s,productId:N??"",sellingPlanOptions:S,selectedValue:m,onChange:g}):jsxRuntime.jsx(SellingPlanDropdown.SellingPlanDropdown,{dir:M(index.SubscriptionEnum.SUBSCRIPTION),setting:i,sellingPlanOptions:S,selectedValue:m,onChange:g})});return R&&!r?"":U(k?index.SubscriptionEnum.ONE_TIME:index.SubscriptionEnum.SUBSCRIPTION)};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"),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;
@@ -1 +1 @@
1
- "use strict";var calculateBestSellingPlan=require("./calculateBestSellingPlan.js"),core=require("@gem-sdk/core");const findDefaultValue=e=>{let{validPlans:l,extractedSettings:t,currentVariant:a,plans:i}=e;if(t.defaultOptions){let e=l.find(e=>e.baseID===t.defaultOptions),a=l.find(e=>e.id===t.defaultOptions);return e?.baseID??a?.baseID}if(l.length>0&&a){let e="number"==typeof a.price?String(a.price):a.price??void 0,t=core.convertDecimalToNumber(e)??0;if(t>0){let e=calculateBestSellingPlan.findBestPlanFromList({plans:l,variantPrice:t});if(e)return e.baseID}}return i[0]?.value};exports.findDefaultValue=findDefaultValue;
1
+ "use strict";var calculateBestSellingPlan=require("./calculateBestSellingPlan.js"),core=require("@gem-sdk/core");const findDefaultValue=e=>{let{validPlans:l,extractedSettings:t,currentVariant:a,plans:i}=e;if(t.defaultOptions){let e=l.find(e=>e.baseID===t.defaultOptions),a=l.find(e=>e.id===t.defaultOptions),i=e?.baseID??a?.baseID;if(i)return i}if(l.length>0){let e="number"==typeof a?.price?String(a.price):a?.price??void 0,t=core.convertDecimalToNumber(e)??0,i=calculateBestSellingPlan.findBestPlanFromList({plans:l,variantPrice:t});if(i)return i.baseID}return i[0]?.value};exports.findDefaultValue=findDefaultValue;
@@ -1 +1 @@
1
- "use strict";var calculateBestSellingPlan=require("./calculateBestSellingPlan.js"),core=require("@gem-sdk/core");const getAllValidPlans=e=>{let r=[];for(let l of e)if(l?.sellingPlans){let e=l.sellingPlans.filter(e=>null!=e);r.push(...e)}return r},getVariantPrice=e=>{if(!e)return 0;let r="number"==typeof e.price?String(e.price):e.price??void 0;return core.convertDecimalToNumber(r)??0},findGroupByPlanId=(e,r)=>e.find(e=>e?.sellingPlans?.some(e=>e?.baseID===r||e?.id===r)),findGroupByBestPlan=(e,r)=>{let l=getAllValidPlans(e);if(0===l.length)return;let n=calculateBestSellingPlan.findBestPlanFromList({plans:l,variantPrice:r});if(n)return findGroupByPlanId(e,n.baseID||n.id||"")},findMatchedGroup=e=>{let{sellingPlanGroups:r,extractedSettings:l,currentVariant:n}=e;if(l.group){if("__unknown__"===l.sourceApp){let e=r.find(e=>e?.id===l.group);if(e)return e}else if(l.sourceApp){let e=r.find(e=>e?.appID===l.sourceApp&&e?.id===l.group);if(e)return e}}if(l.defaultOptions){let e=findGroupByPlanId(r,l.defaultOptions);if(e)return e}if(l.sourceApp){let e=r.find(e=>e?.appID===l.sourceApp);if(e)return e}let i=getVariantPrice(n);if(i>0){let e=findGroupByBestPlan(r,i);if(e)return e}return r[0]};exports.findMatchedGroup=findMatchedGroup;
1
+ "use strict";var calculateBestSellingPlan=require("./calculateBestSellingPlan.js"),core=require("@gem-sdk/core");const DEFAULT_SOURCE_APP="__unknown__",getAllValidPlans=e=>{let r=[];for(let n of e)if(n?.sellingPlans){let e=n.sellingPlans.filter(e=>null!=e);r.push(...e)}return r},getVariantPrice=e=>{if(!e)return 0;let r="number"==typeof e.price?String(e.price):e.price??void 0;return core.convertDecimalToNumber(r)??0},findGroupByPlanId=(e,r)=>e.find(e=>e?.sellingPlans?.some(e=>e?.baseID===r||e?.id===r)),findGroupByBestPlan=(e,r)=>{let n=getAllValidPlans(e);if(0===n.length)return;let i=calculateBestSellingPlan.findBestPlanFromList({plans:n,variantPrice:r});if(i)return findGroupByPlanId(e,i.baseID||i.id||"")},findGroupByExactMeta=({sellingPlanGroups:e,extractedSettings:r,hasGroup:n,hasSourceApp:i,isUnknownSourceApp:l})=>n?l?e.find(e=>e?.id===r.group):i?e.find(e=>e?.appID===r.sourceApp&&e?.id===r.group):void 0:void 0,findMatchedGroup=e=>{let{sellingPlanGroups:r,extractedSettings:n,currentVariant:i}=e,l=getAllValidPlans(r),t=getVariantPrice(i),p=!!n.group,u=n.sourceApp===DEFAULT_SOURCE_APP,o=!!n.sourceApp,a=findGroupByExactMeta({sellingPlanGroups:r,extractedSettings:n,hasGroup:p,hasSourceApp:o,isUnknownSourceApp:u}),d=n.defaultOptions?findGroupByPlanId(r,n.defaultOptions):void 0,s=n.sourceApp&&n.sourceApp!==DEFAULT_SOURCE_APP?r.find(e=>e?.appID===n.sourceApp):void 0,f=!p||void 0===n.sourceApp||!!a,c=!n.defaultOptions||!!d,P=!n.sourceApp||n.sourceApp===DEFAULT_SOURCE_APP||!!s,A=!(f&&c&&P);if(A){let e=findGroupByBestPlan(r,t);return e||(l.length?r[0]:void 0)}if(n.defaultOptions){let e=findGroupByPlanId(r,n.defaultOptions);if(e)return e}if(n.sourceApp){let e=r.find(e=>e?.appID===n.sourceApp);if(e)return e}if(t>0){let e=findGroupByBestPlan(r,t);if(e)return e}return r[0]};exports.findMatchedGroup=findMatchedGroup;
@@ -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
- import{jsxs as e,jsx as i,Fragment as t}from"react/jsx-runtime";import{useRenderMode as o,useProduct as s,usePageStore as r,filterToolbarPreview as n}from"@gem-sdk/core";import{createStyle as l,createClass as m}from"@gem-sdk/system";import{useRef as p,useId as c,useEffect as a}from"react";import{SubscriptionEnum as d}from"../../constants/index.js";import{getWrapperClasses as u,getContainerClasses as g}from"./common/classes.js";import{getSubscriptionStyles as f,getSubscriptionWrapperStyles as S}from"./common/styles.js";import{useSellingPlanChange as h}from"./hooks/useSellingPlanChange.js";import{useSellingSubscription as b}from"./hooks/useSellingSubscription.js";import{useSellingPlanOptions as y}from"./hooks/useSellingPlanOptions.js";import{useSubscriptionVisibility as I}from"./hooks/useSubscriptionVisibility.js";import{OneTimePurchaseTooltip as j}from"./components/OneTimePurchaseTooltip.js";import{SellingPlanDropdown as P}from"./components/SellingPlanDropdown.js";import{SellingPlanLabel as T}from"./components/SellingPlanLabel.js";import{SellingPlanRadio as O}from"./components/SellingPlanRadio.js";import{SubscriptionDetail as N}from"./components/SubscriptionDetail.js";import{SubscriptionRadio as E}from"./components/SubscriptionRadio.js";import{useDynamicProduct as $}from"../../hooks/useDynamicProduct.js";import{extractProductID as k}from"../../../../helpers.js";let DEFAULT_DIRECTION="ltr",ProductSubscription=({styles:C,setting:D,builderProps:R,builderAttrs:v,style:U,children:V})=>{let{isEditMode:_}=o(),B=s(),M=r(e=>e.setSubscriptionVisible),x=r(e=>e.getSubscriptionVisible),{defaultValue:L,selectedSellingPlan:w,setSelectedSellingPlan:A}=b(D),F=y(D),{selectedValue:q,handleSellingPlanChange:z}=h({defaultValue:L,selectedSellingPlan:w,setSelectedSellingPlan:A,sellingPlanOptions:F}),G=p(null),H=c(),{selectedType:J,shouldShowRadio:K,isOneTimeHidden:Q,isOnetimeOnly:W,hasNoSellingPlanOptions:X,requiresSellingPlan:Y,setSubscriptionSellingType:Z}=I({setting:D}),ee=l(f(C)),ei=l(S(C?.align)),et=m(u()),eo=m(g()),es=l({...U}),er=`product-subscription-${k(B?.baseID??"")}`,en=k(B?.baseID??""),el=`subscription-type-selection-${H}`,em=D?.sellingType===d.ONE_TIME,ep=D?.sellingType===d.SUBSCRIPTION,{isDynamicProduct:ec}=$(),{sellingTitleDirection:ea,sellingTitleOneTimeDirection:ed}=C??{},eu=e=>e===d.ONE_TIME?ed??"ltr":ea??"ltr";if(a(()=>{if(!B?.id||!ep)return;let e=B?.id,i=`${R?.uid}-${e}`,t=!(X||ec),o=x()??{};if(!t){M({...o,[e]:(o[e]??[]).filter(e=>e!==i)});return}M({...o,[e]:[...o[e]??[],i]})},[R?.uid,x,X,ec,ep,B?.id,M]),Q||X||ec)return _?e("div",{...v,style:es,children:[i(j,{ref:G,setting:D}),n(V,!0)]}):null;let eg=e=>i(E,{id:`${R?.uid??""}-${en}-${e}-radio`,name:el,value:e,checked:J===e,className:"!gp-items-start",onChange:i=>{i.target.checked&&Z(e)}}),ef=o=>{let s=o===d.SUBSCRIPTION&&(J===d.ONE_TIME&&Y||J===o);return e("div",{...v,style:es,children:[e("div",{ref:G,dir:eu(o),"data-selling-type":D?.sellingType,id:er,className:et,style:ei,children:[K&&eg(o),e("div",{"data-component-container":!0,className:eo,style:ee,children:[i(T,{setting:D,styles:C,id:`label-${R?.uid??""}-${en}-${o}-radio`}),s&&e(t,{children:[eS(),i(N,{setting:D,styles:C})]})]})]}),n(V,!0)]})},eS=()=>i(t,{children:D?.sellingStyle==="radio"?i(O,{setting:D,styles:C,builderProps:R,productId:en??"",sellingPlanOptions:F,selectedValue:q,onChange:z}):i(P,{dir:eu(d.SUBSCRIPTION),setting:D,sellingPlanOptions:F,selectedValue:q,onChange:z})});return W&&!_?"":ef(em?d.ONE_TIME:d.SUBSCRIPTION)};export{ProductSubscription as default};
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};
@@ -1 +1 @@
1
- import{findBestPlanFromList as e}from"./calculateBestSellingPlan.js";import{convertDecimalToNumber as t}from"@gem-sdk/core";let findDefaultValue=i=>{let{validPlans:l,extractedSettings:r,currentVariant:a,plans:f}=i;if(r.defaultOptions){let e=l.find(e=>e.baseID===r.defaultOptions),t=l.find(e=>e.id===r.defaultOptions);return e?.baseID??t?.baseID}if(l.length>0&&a){let i="number"==typeof a.price?String(a.price):a.price??void 0,r=t(i)??0;if(r>0){let t=e({plans:l,variantPrice:r});if(t)return t.baseID}}return f[0]?.value};export{findDefaultValue};
1
+ import{findBestPlanFromList as e}from"./calculateBestSellingPlan.js";import{convertDecimalToNumber as t}from"@gem-sdk/core";let findDefaultValue=i=>{let{validPlans:l,extractedSettings:r,currentVariant:a,plans:f}=i;if(r.defaultOptions){let e=l.find(e=>e.baseID===r.defaultOptions),t=l.find(e=>e.id===r.defaultOptions),i=e?.baseID??t?.baseID;if(i)return i}if(l.length>0){let i="number"==typeof a?.price?String(a.price):a?.price??void 0,r=t(i)??0,f=e({plans:l,variantPrice:r});if(f)return f.baseID}return f[0]?.value};export{findDefaultValue};
@@ -1 +1 @@
1
- import{findBestPlanFromList as e}from"./calculateBestSellingPlan.js";import{convertDecimalToNumber as r}from"@gem-sdk/core";let getAllValidPlans=e=>{let r=[];for(let i of e)if(i?.sellingPlans){let e=i.sellingPlans.filter(e=>null!=e);r.push(...e)}return r},getVariantPrice=e=>{if(!e)return 0;let i="number"==typeof e.price?String(e.price):e.price??void 0;return r(i)??0},findGroupByPlanId=(e,r)=>e.find(e=>e?.sellingPlans?.some(e=>e?.baseID===r||e?.id===r)),findGroupByBestPlan=(r,i)=>{let l=getAllValidPlans(r);if(0===l.length)return;let n=e({plans:l,variantPrice:i});if(n)return findGroupByPlanId(r,n.baseID||n.id||"")},findMatchedGroup=e=>{let{sellingPlanGroups:r,extractedSettings:i,currentVariant:l}=e;if(i.group){if("__unknown__"===i.sourceApp){let e=r.find(e=>e?.id===i.group);if(e)return e}else if(i.sourceApp){let e=r.find(e=>e?.appID===i.sourceApp&&e?.id===i.group);if(e)return e}}if(i.defaultOptions){let e=findGroupByPlanId(r,i.defaultOptions);if(e)return e}if(i.sourceApp){let e=r.find(e=>e?.appID===i.sourceApp);if(e)return e}let n=getVariantPrice(l);if(n>0){let e=findGroupByBestPlan(r,n);if(e)return e}return r[0]};export{findMatchedGroup};
1
+ import{findBestPlanFromList as e}from"./calculateBestSellingPlan.js";import{convertDecimalToNumber as r}from"@gem-sdk/core";let DEFAULT_SOURCE_APP="__unknown__",getAllValidPlans=e=>{let r=[];for(let i of e)if(i?.sellingPlans){let e=i.sellingPlans.filter(e=>null!=e);r.push(...e)}return r},getVariantPrice=e=>{if(!e)return 0;let i="number"==typeof e.price?String(e.price):e.price??void 0;return r(i)??0},findGroupByPlanId=(e,r)=>e.find(e=>e?.sellingPlans?.some(e=>e?.baseID===r||e?.id===r)),findGroupByBestPlan=(r,i)=>{let n=getAllValidPlans(r);if(0===n.length)return;let t=e({plans:n,variantPrice:i});if(t)return findGroupByPlanId(r,t.baseID||t.id||"")},findGroupByExactMeta=({sellingPlanGroups:e,extractedSettings:r,hasGroup:i,hasSourceApp:n,isUnknownSourceApp:t})=>i?t?e.find(e=>e?.id===r.group):n?e.find(e=>e?.appID===r.sourceApp&&e?.id===r.group):void 0:void 0,findMatchedGroup=e=>{let{sellingPlanGroups:r,extractedSettings:i,currentVariant:n}=e,t=getAllValidPlans(r),l=getVariantPrice(n),p=!!i.group,o=i.sourceApp===DEFAULT_SOURCE_APP,u=!!i.sourceApp,d=findGroupByExactMeta({sellingPlanGroups:r,extractedSettings:i,hasGroup:p,hasSourceApp:u,isUnknownSourceApp:o}),a=i.defaultOptions?findGroupByPlanId(r,i.defaultOptions):void 0,f=i.sourceApp&&i.sourceApp!==DEFAULT_SOURCE_APP?r.find(e=>e?.appID===i.sourceApp):void 0,s=!p||void 0===i.sourceApp||!!d,P=!i.defaultOptions||!!a,c=!i.sourceApp||i.sourceApp===DEFAULT_SOURCE_APP||!!f,A=!(s&&P&&c);if(A){let e=findGroupByBestPlan(r,l);return e||(t.length?r[0]:void 0)}if(i.defaultOptions){let e=findGroupByPlanId(r,i.defaultOptions);if(e)return e}if(i.sourceApp){let e=r.find(e=>e?.appID===i.sourceApp);if(e)return e}if(l>0){let e=findGroupByBestPlan(r,l);if(e)return e}return r[0]};export{findMatchedGroup};
@@ -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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/components",
3
- "version": "12.0.0-staging.80",
3
+ "version": "12.0.0-staging.82",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",