@gem-sdk/components 23.0.0-dev.24 → 23.0.0-dev.25
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/common/extractSellingPlanSettings.js +1 -1
- package/dist/cjs/post-purchase/product/components/product-subscription/helpers/sortByPlanOrder.js +1 -0
- package/dist/cjs/post-purchase/product/components/product-subscription/hooks/useSellingSubscription.js +1 -1
- package/dist/esm/post-purchase/product/components/product-subscription/common/extractSellingPlanSettings.js +1 -1
- package/dist/esm/post-purchase/product/components/product-subscription/helpers/sortByPlanOrder.js +1 -0
- package/dist/esm/post-purchase/product/components/product-subscription/hooks/useSellingSubscription.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=
|
|
1
|
+
"use strict";var e=require("../helpers/sortByPlanOrder.js");const t=e=>e?e.includes("/ProductVariant/")?e.split("/ProductVariant/")[1]||"":e:"",r=e=>e?e.includes("/Product/")?e.split("/Product/")[1]||"":e:"";exports.extractSellingPlanSettings=({sellingPlansSetting:i,currentVariant:s,product:a,isFromEvent:d=!1})=>{let n={sourceApp:void 0,group:void 0,defaultOptions:void 0};if(!i)return n;if(d&&s?.id){let d,n;if(a&&"baseID"in a&&a.baseID?(d=r(a.baseID),n=Object.keys(i)[0]):d="data"===(n=Object.keys(i)[0])&&i[n]?Object.keys(i[n])[0]:n,d){let r="data"===n?i.data:i[d],a="data"===n?r[d]:r;if(a){let r=t(s.id?.toString()||""),i=t(s.baseID||""),d=Object.keys(a).find(e=>e===s.id?.toString()||e===s.baseID||e===r||e===i||s.id?.toString()===e||s.baseID===e||s.id?.toString().includes(e)||s.baseID?.includes(e)||e.includes(r)||e.includes(i));if(d&&a[d]){let t=a[d];return{sourceApp:t?.sourceApp,group:t?.group,defaultOptions:t?.defaultOption,planOrder:e.normalizePlanOrder(t?.planOrder)}}}}}return n};
|
package/dist/cjs/post-purchase/product/components/product-subscription/helpers/sortByPlanOrder.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const r=r=>r?r.split("/").at(-1)||r:"";exports.findGroupPlanOrder=({planOrder:e,planIds:t})=>{if(!e)return;let n=new Set(t.map(e=>r(e)));return Object.values(e).find(e=>e.some(e=>n.has(r(e))))},exports.normalizePlanId=r,exports.normalizePlanOrder=r=>{if(!(!r||"object"!=typeof r||Array.isArray(r)))return Object.fromEntries(Object.entries(r).filter(r=>Array.isArray(r[1])).map(([r,e])=>[r,e.filter(r=>"string"==typeof r)]))},exports.sortByPlanOrder=({items:e,planOrder:t,getPlanId:n})=>{if(!t?.length||e.length<2)return e;let s=new Map(t.map((e,t)=>[r(e),t])),a=e=>s.get(r(n(e)))??t.length;return[...e].sort((r,e)=>a(r)-a(e))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@gem-sdk/core"),
|
|
1
|
+
"use strict";var e=require("@gem-sdk/core"),r=require("../common/extractSellingPlanSettings.js"),l=require("../helpers/sortByPlanOrder.js"),n=require("../helpers/findVariantByOptions.js"),t=require("../helpers/findMatchedGroup.js"),s=require("../helpers/findDefaultValue.js"),u=require("react");exports.useSellingSubscription=i=>{let a=e.useProduct(),o=e.useVariants(),{selectedOptions:d}=e.useSelectedOption(),c=e.useProductStore(e=>e.selectedSellingPlan),p=e.useProductStore(e=>e.setSelectedSellingPlan),f=e.usePageStore(e=>e.sellingPlanMeta),g=e.useEditorMode(),P=u.useRef(!1),m=u.useRef(void 0);u.useEffect(()=>{if(!P.current&&g===e.RenderModeEnv.EDIT&&!f){let e=new CustomEvent("element-subscription-mount");globalThis.dispatchEvent(e),P.current=!0}},[g,f]);let S=f??i?.sellingPlans,v=u.useMemo(()=>{if(!S)return{sourceApp:void 0,group:void 0,defaultOptions:void 0};let e=f&&d?n.findVariantByOptions({variants:o,selectedOptions:d}):null,l=r.extractSellingPlanSettings({sellingPlansSetting:S,currentVariant:e,product:a,isFromEvent:!!f});return l},[S,f,o,d,a]),O=u.useMemo(()=>d?n.findVariantByOptions({variants:o,selectedOptions:d}):null,[d,o]);u.useEffect(()=>{m.current=void 0},[O?.baseID]);let{sellingPlans:h,defaultValue:E}=u.useMemo(()=>{let e=O?.sellingPlanGroups??a?.sellingPlanGroups??[];if(!e||0===e.length)return{sellingPlans:[],defaultValue:void 0};let r=t.findMatchedGroup({sellingPlanGroups:e,extractedSettings:v,currentVariant:O}),n=r?.sellingPlans?.filter(e=>null!=e)??[],u=l.sortByPlanOrder({items:n,planOrder:l.findGroupPlanOrder({planOrder:v.planOrder,planIds:n.map(e=>e.baseID)}),getPlanId:e=>e.baseID}),i=u.map(e=>({label:e.name||"",value:e.baseID})),o=s.findDefaultValue({validPlans:u,extractedSettings:v,currentVariant:O,plans:i});return{sellingPlans:i,defaultValue:o}},[a,O,v]);return u.useEffect(()=>{!c&&E&&m.current!==E&&(m.current=E,p(E))},[E,c,p]),{sellingPlans:h,defaultValue:E,selectedSellingPlan:c,setSelectedSellingPlan:p}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let
|
|
1
|
+
import{normalizePlanOrder as t}from"../helpers/sortByPlanOrder.js";let e=t=>t?t.includes("/ProductVariant/")?t.split("/ProductVariant/")[1]||"":t:"",i=t=>t?t.includes("/Product/")?t.split("/Product/")[1]||"":t:"",r=({sellingPlansSetting:r,currentVariant:d,product:s,isFromEvent:a=!1})=>{let n={sourceApp:void 0,group:void 0,defaultOptions:void 0};if(!r)return n;if(a&&d?.id){let a,n;if(s&&"baseID"in s&&s.baseID?(a=i(s.baseID),n=Object.keys(r)[0]):a="data"===(n=Object.keys(r)[0])&&r[n]?Object.keys(r[n])[0]:n,a){let i="data"===n?r.data:r[a],s="data"===n?i[a]:i;if(s){let i=e(d.id?.toString()||""),r=e(d.baseID||""),a=Object.keys(s).find(t=>t===d.id?.toString()||t===d.baseID||t===i||t===r||d.id?.toString()===t||d.baseID===t||d.id?.toString().includes(t)||d.baseID?.includes(t)||t.includes(i)||t.includes(r));if(a&&s[a]){let e=s[a];return{sourceApp:e?.sourceApp,group:e?.group,defaultOptions:e?.defaultOption,planOrder:t(e?.planOrder)}}}}}return n};export{r as extractSellingPlanSettings};
|
package/dist/esm/post-purchase/product/components/product-subscription/helpers/sortByPlanOrder.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let r=r=>r?r.split("/").at(-1)||r:"",e=({items:e,planOrder:t,getPlanId:n})=>{if(!t?.length||e.length<2)return e;let a=new Map(t.map((e,t)=>[r(e),t])),l=e=>a.get(r(n(e)))??t.length;return[...e].sort((r,e)=>l(r)-l(e))},t=r=>{if(!(!r||"object"!=typeof r||Array.isArray(r)))return Object.fromEntries(Object.entries(r).filter(r=>Array.isArray(r[1])).map(([r,e])=>[r,e.filter(r=>"string"==typeof r)]))},n=({planOrder:e,planIds:t})=>{if(!e)return;let n=new Set(t.map(e=>r(e)));return Object.values(e).find(e=>e.some(e=>n.has(r(e))))};export{n as findGroupPlanOrder,r as normalizePlanId,t as normalizePlanOrder,e as sortByPlanOrder};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useProduct as e,useVariants as l,useSelectedOption as
|
|
1
|
+
import{useProduct as e,useVariants as l,useSelectedOption as r,useProductStore as n,usePageStore as t,useEditorMode as i,RenderModeEnv as s}from"@gem-sdk/core";import{extractSellingPlanSettings as a}from"../common/extractSellingPlanSettings.js";import{sortByPlanOrder as o,findGroupPlanOrder as u}from"../helpers/sortByPlanOrder.js";import{findVariantByOptions as p}from"../helpers/findVariantByOptions.js";import{findMatchedGroup as m}from"../helpers/findMatchedGroup.js";import{findDefaultValue as d}from"../helpers/findDefaultValue.js";import{useRef as f,useEffect as c,useMemo as g}from"react";let P=P=>{let v=e(),b=l(),{selectedOptions:h}=r(),I=n(e=>e.selectedSellingPlan),S=n(e=>e.setSelectedSellingPlan),D=t(e=>e.sellingPlanMeta),O=i(),j=f(!1),V=f(void 0);c(()=>{if(!j.current&&O===s.EDIT&&!D){let e=new CustomEvent("element-subscription-mount");globalThis.dispatchEvent(e),j.current=!0}},[O,D]);let E=D??P?.sellingPlans,G=g(()=>{if(!E)return{sourceApp:void 0,group:void 0,defaultOptions:void 0};let e=D&&h?p({variants:b,selectedOptions:h}):null,l=a({sellingPlansSetting:E,currentVariant:e,product:v,isFromEvent:!!D});return l},[E,D,b,h,v]),x=g(()=>h?p({variants:b,selectedOptions:h}):null,[h,b]);c(()=>{V.current=void 0},[x?.baseID]);let{sellingPlans:y,defaultValue:B}=g(()=>{let e=x?.sellingPlanGroups??v?.sellingPlanGroups??[];if(!e||0===e.length)return{sellingPlans:[],defaultValue:void 0};let l=m({sellingPlanGroups:e,extractedSettings:G,currentVariant:x}),r=l?.sellingPlans?.filter(e=>null!=e)??[],n=o({items:r,planOrder:u({planOrder:G.planOrder,planIds:r.map(e=>e.baseID)}),getPlanId:e=>e.baseID}),t=n.map(e=>({label:e.name||"",value:e.baseID})),i=d({validPlans:n,extractedSettings:G,currentVariant:x,plans:t});return{sellingPlans:t,defaultValue:i}},[v,x,G]);return c(()=>{!I&&B&&V.current!==B&&(V.current=B,S(B))},[B,I,S]),{sellingPlans:y,defaultValue:B,selectedSellingPlan:I,setSelectedSellingPlan:S}};export{P as useSellingSubscription};
|