@combeenation/custom-code-sdk 0.0.1-alpha7 → 0.0.1-alpha8

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/README.md CHANGED
File without changes
@@ -1 +1 @@
1
- "use strict";var se=Object.defineProperty;var x=t=>{throw TypeError(t)};var re=(t,n,e)=>n in t?se(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var d=(t,n,e)=>re(t,typeof n!="symbol"?n+"":n,e),L=(t,n,e)=>n.has(t)||x("Cannot "+e);var o=(t,n,e)=>(L(t,n,"read from private field"),e?e.call(t):n.get(t)),a=(t,n,e)=>n.has(t)?x("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,e),c=(t,n,e,i)=>(L(t,n,"write to private field"),i?i.call(t,e):n.set(t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),O="0.0.1-alpha7";var z,C;class ae{constructor(n){d(this,"id");a(this,z,"v1");a(this,C);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,z));if(c(this,C,e==null?void 0:e.getButtonSdkBridge(this.id)),!o(this,C))throw new Error(`Cannot access API for Button "${this.id}".`)}onRendered(n){var e;return((e=o(this,C))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}onClick(n){var e;return((e=o(this,C))==null?void 0:e.addOnClickCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=o(this,C))==null?void 0:e.setVisible(n))}setText(n){var e;(e=o(this,C))==null||e.setText(n)}}z=new WeakMap,C=new WeakMap;var B,l;class de{constructor(n){d(this,"id");a(this,B,"v1");a(this,l);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,B));if(c(this,l,e==null?void 0:e.getCheckboxSdkBridge(this.id)),!o(this,l))throw new Error(`Cannot access API for Checkbox "${this.id}".`)}onRendered(n){var e;return((e=o(this,l))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=o(this,l))==null?void 0:e.setVisible(n))}}B=new WeakMap,l=new WeakMap;var E,h;class ce{constructor(n){d(this,"id");a(this,E,"v1");a(this,h);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,E));if(c(this,h,e==null?void 0:e.getCollapsibleSdkBridge(this.id)),!o(this,h))throw new Error(`Cannot access API for Collapsible "${this.id}".`)}onRendered(n){var e;return((e=o(this,h))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=o(this,h))==null?void 0:e.setVisible(n))}}E=new WeakMap,h=new WeakMap;var I,g;class Ce{constructor(n){d(this,"id");a(this,I,"v1");a(this,g);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,I));if(c(this,g,e==null?void 0:e.getCustomCtrlSdkBridge(this.id)),!o(this,g))throw new Error(`Cannot access API for Custom Control "${this.id}".`)}set renderFn(n){var e;(e=o(this,g))==null||e.setRenderFn(n)}async render(n){var e;typeof n=="function"&&(this.renderFn=n),await((e=o(this,g))==null?void 0:e.render())}getElement(){var e;return(e=o(this,g))==null?void 0:e.getElement()}async setVisible(n){var e;await((e=o(this,g))==null?void 0:e.setVisible(n))}}I=new WeakMap,g=new WeakMap;var S,b;class ge{constructor(n){d(this,"id");a(this,S,"v1");a(this,b);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,S));if(c(this,b,e==null?void 0:e.getDataviewSdkBridge(this.id)),!o(this,b))throw new Error(`Cannot access API for Dataview "${this.id}".`)}onRendered(n){var e;return((e=o(this,b))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=o(this,b))==null?void 0:e.setVisible(n))}}S=new WeakMap,b=new WeakMap;var v,p;class ue{constructor(n){d(this,"id");a(this,v,"v1");a(this,p);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,v));if(c(this,p,e==null?void 0:e.getInputSdkBridge(this.id)),!o(this,p))throw new Error(`Cannot access API for Input "${this.id}".`)}onRendered(n){var e;return((e=o(this,p))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=o(this,p))==null?void 0:e.setVisible(n))}}v=new WeakMap,p=new WeakMap;var R,m;class le{constructor(n){d(this,"id");a(this,R,"v1");a(this,m);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,R));if(c(this,m,e==null?void 0:e.getPanelSdkBridge(this.id)),!o(this,m))throw new Error(`Cannot access API for Panel "${this.id}".`)}onRendered(n){var e;return((e=o(this,m))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=o(this,m))==null?void 0:e.setVisible(n))}}R=new WeakMap,m=new WeakMap;var P,u;class he{constructor(n){d(this,"id");a(this,P,"v1");a(this,u);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,o(this,P));if(c(this,u,e==null?void 0:e.getTextSdkBridge(this.id)),!o(this,u))throw new Error(`Cannot access API for Text "${this.id}".`)}onRendered(n){var e;return((e=o(this,u))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=o(this,u))==null?void 0:e.setVisible(n))}setText(n){var e;(e=o(this,u))==null||e.setText(n)}}P=new WeakMap,u=new WeakMap;const U=1,y=[];function be(t,n){if(y.length>=U)throw new Error(`Only ${U} \`ConfiguratorClient\` can be created at a time.`);y.push({client:t,internals:n})}function D(){const t=y[0];if(!t)throw new Error("Operation not possible as no `ConfiguratorClient` has been registered yet.");return t.client}function pe(){const t=y[0];if(!t)throw new Error("Operation not possible as no `ConfiguratorClient` has been registered yet.");return t.internals}const me="v1";var A,Z;const F=(Z=(A=window.Cbn)==null?void 0:A.getCustomCodeSdkBridge)==null?void 0:Z.call(A,"v1");if(!F)throw new Error("Cannot access Configurator SDK bridge. Make sure to only use the `custom-code-sdk` inside a Combeenation Configurator.");const N=F.createCfgrClient(me,be);if(!N)throw new Error("Cannot create Configurator Client. Make sure to only use the `custom-code-sdk` inside a Combeenation Configurator.");const w=F.getParentPageUtilsSdkBridge(),j=F.getCfgrUtilsSdkBridge(),T=N,$={Text:"Text",Number:"Number",Logic:"Logic"},f={ValueComponent:"ValueComponent",TableComponent:"TableComponent",RecordComponent:"RecordComponent",ResourceComponent:"ResourceComponent",GraphicComponent:"GraphicComponent",CheckoutComponent:"CheckoutComponent"},k={ValueEditor:"ValueEditor",TableEditor:"TableEditor",Fiber:"Fiber",FiberEditor:"FiberEditor",CfgrField:"CfgrField"};s.z.enum([k.ValueEditor,k.TableEditor,k.Fiber,k.FiberEditor,k.CfgrField]);s.z.union([s.z.string(),s.z.number(),s.z.boolean()]);const V=t=>typeof t=="string";s.z.string();s.z.enum([$.Text,$.Number,$.Logic]);s.z.string();s.z.custom(t=>V(t)&&t.toLowerCase()===t);const G=t=>(t==null?void 0:t.toLowerCase())??"";s.z.string();const we=s.z.custom(t=>V(t)?new RegExp(`^${f.ValueComponent}<.*>$`).test(t):!1),fe=s.z.custom(t=>V(t)?new RegExp(`^${f.RecordComponent}<.*>$`).test(t):!1),ke=s.z.custom(t=>V(t)?new RegExp(`^${f.ResourceComponent}<.*>$`).test(t):!1),Ve=s.z.custom(t=>V(t)?new RegExp(`^${f.TableComponent}<.*>$`).test(t):!1);s.z.union([we,Ve,fe,ke,s.z.literal(f.GraphicComponent),s.z.literal(f.CheckoutComponent)]);const M=s.z.union([s.z.string(),s.z.number(),s.z.boolean()]),Ae=s.z.union([M,s.z.array(M),s.z.object({}),s.z.unknown()]),ye=s.z.object({$typ:s.z.literal("Error"),Id:s.z.string(),Message:s.z.string(),route:s.z.unknown().optional()});ye.or(Ae);const _=new Map;function Te(t){const n=G(t.name);_.has(n)||_.set(n,t)}class ze{constructor(n,e){d(this,"name");d(this,"zodType");this.name=n,this.zodType=e,Te(this)}async getValue(){return await D().getCmpValue(this.name)}async setInput(n){const e=G(this.name);await pe().setCmpInput(e,n,this.zodType)}onValueChanged(n,e=!1,i){D().onCmpValueChanged(this.name,n,i,e)}}var K=(t=>(t[t.Facebook=0]="Facebook",t[t.Pinterest=1]="Pinterest",t[t.Twitter=2]="Twitter",t[t.LinkedIn=3]="LinkedIn",t[t.WhatsApp=4]="WhatsApp",t[t.Custom=5]="Custom",t[t.NativeShare=6]="NativeShare",t))(K||{});const Be="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+X2ZkAAAAASUVORK5CYII=",W=T.onAnyCmpValueChanged.bind(T),H=async t=>{if(await T.finishConfiguration(t==null?void 0:t.input),t.sendDataToParentPage){const n=t.transformParentPageData();await w.sendConfigurationFinished(n)}},Q=async t=>{const n=K[t.platform],e=t.imageUrl??Be,i={...t,platform:n,imageUrl:e},r=await T.shareConfiguration(i);await j.openShareWindow(t.platform,r);const{shareUrl:ie,shareConfigurationId:oe}=r;return{shareUrl:ie,shareConfigurationId:oe}},X=()=>w.isInIFrame(),q=t=>w.setIFrameSize(t),Y=t=>j.navigateToLogin(t),J=(t,n)=>w.sendCustomMsg(t,n),ee=t=>w.redirectParentPage(t),te=()=>w.getParentPageUrl(),ne=(t,n)=>w.fireAnalyticsEvent(t,n),Ee=Object.freeze(Object.defineProperty({__proto__:null,configuratorIsInIFrame:X,finishConfiguration:H,fireAnalyticsEvent:ne,getParentPageUrl:te,navigateToLogin:Y,onAnyCmpValueChanged:W,redirectParentPage:ee,sendCustomMsgToParentPage:J,setConfiguratorIFrameSize:q,shareConfiguration:Q,version:O},Symbol.toStringTag,{value:"Module"}));console.log(`Loading custom code SDK v${O}`);exports.Button=ae;exports.CbnSdk=Ee;exports.Checkbox=de;exports.Collapsible=ce;exports.CustomControl=Ce;exports.Dataview=ge;exports.Input=ue;exports.Panel=le;exports.Text=he;exports.ValueComponent=ze;exports.configuratorIsInIFrame=X;exports.finishConfiguration=H;exports.fireAnalyticsEvent=ne;exports.getParentPageUrl=te;exports.navigateToLogin=Y;exports.onAnyCmpValueChanged=W;exports.redirectParentPage=ee;exports.sendCustomMsgToParentPage=J;exports.setConfiguratorIFrameSize=q;exports.shareConfiguration=Q;exports.version=O;
1
+ "use strict";var de=Object.defineProperty;var D=t=>{throw TypeError(t)};var ce=(t,n,e)=>n in t?de(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var d=(t,n,e)=>ce(t,typeof n!="symbol"?n+"":n,e),M=(t,n,e)=>n.has(t)||D("Cannot "+e);var s=(t,n,e)=>(M(t,n,"read from private field"),e?e.call(t):n.get(t)),a=(t,n,e)=>n.has(t)?D("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,e),C=(t,n,e,i)=>(M(t,n,"write to private field"),i?i.call(t,e):n.set(t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("zod"),L="0.0.1-alpha8";var S,l;class Ce{constructor(n){d(this,"id");a(this,S,"v1");a(this,l);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,S));if(C(this,l,e==null?void 0:e.getButtonSdkBridge(this.id)),!s(this,l))throw new Error(`Cannot access API for Button "${this.id}".`)}onRendered(n){var e;return((e=s(this,l))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}onClick(n){var e;return((e=s(this,l))==null?void 0:e.addOnClickCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=s(this,l))==null?void 0:e.setVisible(n))}setText(n){var e;(e=s(this,l))==null||e.setText(n)}}S=new WeakMap,l=new WeakMap;var T,g;class le{constructor(n){d(this,"id");a(this,T,"v1");a(this,g);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,T));if(C(this,g,e==null?void 0:e.getCheckboxSdkBridge(this.id)),!s(this,g))throw new Error(`Cannot access API for Checkbox "${this.id}".`)}onRendered(n){var e;return((e=s(this,g))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=s(this,g))==null?void 0:e.setVisible(n))}}T=new WeakMap,g=new WeakMap;var z,h;class ue{constructor(n){d(this,"id");a(this,z,"v1");a(this,h);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,z));if(C(this,h,e==null?void 0:e.getCollapsibleSdkBridge(this.id)),!s(this,h))throw new Error(`Cannot access API for Collapsible "${this.id}".`)}onRendered(n){var e;return((e=s(this,h))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=s(this,h))==null?void 0:e.setVisible(n))}}z=new WeakMap,h=new WeakMap;var B,c;class ge{constructor(n){d(this,"id");a(this,B,"v1");a(this,c);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,B));if(C(this,c,e==null?void 0:e.getCustomCtrlSdkBridge(this.id)),!s(this,c))throw new Error(`Cannot access API for Custom Control "${this.id}".`)}set renderFn(n){var e;(e=s(this,c))==null||e.setRenderFn(n)}async render(n){var e;typeof n=="function"&&(this.renderFn=n),await((e=s(this,c))==null?void 0:e.render())}onRendered(n){var e;return((e=s(this,c))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}getElement(){var e;return(e=s(this,c))==null?void 0:e.getElement()}async setVisible(n){var e;await((e=s(this,c))==null?void 0:e.setVisible(n))}}B=new WeakMap,c=new WeakMap;var E,b;class he{constructor(n){d(this,"id");a(this,E,"v1");a(this,b);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,E));if(C(this,b,e==null?void 0:e.getDataviewSdkBridge(this.id)),!s(this,b))throw new Error(`Cannot access API for Dataview "${this.id}".`)}onRendered(n){var e;return((e=s(this,b))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=s(this,b))==null?void 0:e.setVisible(n))}}E=new WeakMap,b=new WeakMap;var v,m;class be{constructor(n){d(this,"id");a(this,v,"v1");a(this,m);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,v));if(C(this,m,e==null?void 0:e.getInputSdkBridge(this.id)),!s(this,m))throw new Error(`Cannot access API for Input "${this.id}".`)}onRendered(n){var e;return((e=s(this,m))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=s(this,m))==null?void 0:e.setVisible(n))}}v=new WeakMap,m=new WeakMap;var R,p;class me{constructor(n){d(this,"id");a(this,R,"v1");a(this,p);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,R));if(C(this,p,e==null?void 0:e.getPanelSdkBridge(this.id)),!s(this,p))throw new Error(`Cannot access API for Panel "${this.id}".`)}onRendered(n){var e;return((e=s(this,p))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=s(this,p))==null?void 0:e.setVisible(n))}}R=new WeakMap,p=new WeakMap;var P,u;class pe{constructor(n){d(this,"id");a(this,P,"v1");a(this,u);var i,r;this.id=n;const e=(r=(i=window.Cbn)==null?void 0:i.getCustomCodeSdkBridge)==null?void 0:r.call(i,s(this,P));if(C(this,u,e==null?void 0:e.getTextSdkBridge(this.id)),!s(this,u))throw new Error(`Cannot access API for Text "${this.id}".`)}onRendered(n){var e;return((e=s(this,u))==null?void 0:e.addOnRenderedCallback(n))??{unsubscribe:()=>{}}}async setVisible(n){var e;await((e=s(this,u))==null?void 0:e.setVisible(n))}setText(n){var e;(e=s(this,u))==null||e.setText(n)}}P=new WeakMap,u=new WeakMap;const _=1,y=[];function we(t,n){if(y.length>=_)throw new Error(`Only ${_} \`ConfiguratorClient\` can be created at a time.`);y.push({client:t,internals:n})}function N(){const t=y[0];if(!t)throw new Error("Operation not possible as no `ConfiguratorClient` has been registered yet.");return t.client}function fe(){const t=y[0];if(!t)throw new Error("Operation not possible as no `ConfiguratorClient` has been registered yet.");return t.internals}const ke="v1";var A,G;const O=(G=(A=window.Cbn)==null?void 0:A.getCustomCodeSdkBridge)==null?void 0:G.call(A,"v1");if(!O)throw new Error("Cannot access Configurator SDK bridge. Make sure to only use the `custom-code-sdk` inside a Combeenation Configurator.");const K=O.createCfgrClient(ke,we);if(!K)throw new Error("Cannot create Configurator Client. Make sure to only use the `custom-code-sdk` inside a Combeenation Configurator.");const w=O.getParentPageUtilsSdkBridge(),U=O.getCfgrUtilsSdkBridge(),I=K,x={Text:"Text",Number:"Number",Logic:"Logic"},f={ValueComponent:"ValueComponent",TableComponent:"TableComponent",RecordComponent:"RecordComponent",ResourceComponent:"ResourceComponent",GraphicComponent:"GraphicComponent",CheckoutComponent:"CheckoutComponent"},k={ValueEditor:"ValueEditor",TableEditor:"TableEditor",Fiber:"Fiber",FiberEditor:"FiberEditor",CfgrField:"CfgrField"};o.z.enum([k.ValueEditor,k.TableEditor,k.Fiber,k.FiberEditor,k.CfgrField]);o.z.union([o.z.string(),o.z.number(),o.z.boolean()]);const V=t=>typeof t=="string";o.z.string();o.z.enum([x.Text,x.Number,x.Logic]);o.z.string();o.z.custom(t=>V(t)&&t.toLowerCase()===t);const W=t=>(t==null?void 0:t.toLowerCase())??"";o.z.string();const Ve=o.z.custom(t=>V(t)?new RegExp(`^${f.ValueComponent}<.*>$`).test(t):!1),Ae=o.z.custom(t=>V(t)?new RegExp(`^${f.RecordComponent}<.*>$`).test(t):!1),ye=o.z.custom(t=>V(t)?new RegExp(`^${f.ResourceComponent}<.*>$`).test(t):!1),Ie=o.z.custom(t=>V(t)?new RegExp(`^${f.TableComponent}<.*>$`).test(t):!1);o.z.union([Ve,Ie,Ae,ye,o.z.literal(f.GraphicComponent),o.z.literal(f.CheckoutComponent)]);const Z=o.z.union([o.z.string(),o.z.number(),o.z.boolean()]),Se=o.z.union([Z,o.z.array(Z),o.z.object({}),o.z.unknown()]),Te=o.z.object({$typ:o.z.literal("Error"),Id:o.z.string(),Message:o.z.string(),route:o.z.unknown().optional()});Te.or(Se);const j=new Map;function ze(t){const n=W(t.name);j.has(n)||j.set(n,t)}class Be{constructor(n,e){d(this,"name");d(this,"zodType");this.name=n,this.zodType=e,ze(this)}async getValue(){return await N().getCmpValue(this.name)}async setInput(n){const e=W(this.name);await fe().setCmpInput(e,n,this.zodType)}onValueChanged(n,e=!1,i){N().onCmpValueChanged(this.name,n,i,e)}}const H=()=>U.getAssetPaths();var Q=(t=>(t[t.Facebook=0]="Facebook",t[t.Pinterest=1]="Pinterest",t[t.Twitter=2]="Twitter",t[t.LinkedIn=3]="LinkedIn",t[t.WhatsApp=4]="WhatsApp",t[t.Custom=5]="Custom",t[t.NativeShare=6]="NativeShare",t))(Q||{});const Ee="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+X2ZkAAAAASUVORK5CYII=",X=I.onAnyCmpValueChanged.bind(I),q=async t=>{if(await I.finishConfiguration(t==null?void 0:t.input),t.sendDataToParentPage){const n=t.transformParentPageData();await w.sendConfigurationFinished(n)}},Y=async t=>{const n=Q[t.platform],e=t.imageUrl??Ee,i={...t,platform:n,imageUrl:e},r=await I.shareConfiguration(i);await U.openShareWindow(t.platform,r);const{shareUrl:F,shareConfigurationId:$}=r;return{shareUrl:F,shareConfigurationId:$}},J=async t=>{const{promise:n,resolve:e}=Promise.withResolvers(),i={};for(const[r,F]of Object.entries(t))F.onValueChanged($=>{i[r]=$,Object.keys(t).every(ae=>ae in i)&&e(i)},!0);return n},ee=()=>w.isInIFrame(),te=t=>w.setIFrameSize(t),ne=t=>U.navigateToLogin(t),ie=(t,n)=>w.sendCustomMsg(t,n),se=t=>w.redirectParentPage(t),oe=()=>w.getParentPageUrl(),re=(t,n)=>w.fireAnalyticsEvent(t,n),ve=Object.freeze(Object.defineProperty({__proto__:null,configuratorIsInIFrame:ee,createSyncCmpValuesStore:J,finishConfiguration:q,fireAnalyticsEvent:re,getAssetPaths:H,getParentPageUrl:oe,navigateToLogin:ne,onAnyCmpValueChanged:X,redirectParentPage:se,sendCustomMsgToParentPage:ie,setConfiguratorIFrameSize:te,shareConfiguration:Y,version:L},Symbol.toStringTag,{value:"Module"}));console.log(`Loading custom code SDK v${L}`);exports.Button=Ce;exports.CbnSdk=ve;exports.Checkbox=le;exports.Collapsible=ue;exports.CustomControl=ge;exports.Dataview=he;exports.Input=be;exports.Panel=me;exports.Text=pe;exports.ValueComponent=Be;exports.configuratorIsInIFrame=ee;exports.createSyncCmpValuesStore=J;exports.finishConfiguration=q;exports.fireAnalyticsEvent=re;exports.getAssetPaths=H;exports.getParentPageUrl=oe;exports.navigateToLogin=ne;exports.onAnyCmpValueChanged=X;exports.redirectParentPage=se;exports.sendCustomMsgToParentPage=ie;exports.setConfiguratorIFrameSize=te;exports.shareConfiguration=Y;exports.version=L;
package/dist/bundle.es.js CHANGED
@@ -1,54 +1,54 @@
1
- var Q = Object.defineProperty;
2
- var O = (t) => {
1
+ var X = Object.defineProperty;
2
+ var D = (t) => {
3
3
  throw TypeError(t);
4
4
  };
5
- var X = (t, n, e) => n in t ? Q(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
6
- var d = (t, n, e) => X(t, typeof n != "symbol" ? n + "" : n, e), L = (t, n, e) => n.has(t) || O("Cannot " + e);
7
- var s = (t, n, e) => (L(t, n, "read from private field"), e ? e.call(t) : n.get(t)), a = (t, n, e) => n.has(t) ? O("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(t) : n.set(t, e), c = (t, n, e, i) => (L(t, n, "write to private field"), i ? i.call(t, e) : n.set(t, e), e);
5
+ var Y = (t, n, e) => n in t ? X(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
6
+ var d = (t, n, e) => Y(t, typeof n != "symbol" ? n + "" : n, e), _ = (t, n, e) => n.has(t) || D("Cannot " + e);
7
+ var s = (t, n, e) => (_(t, n, "read from private field"), e ? e.call(t) : n.get(t)), a = (t, n, e) => n.has(t) ? D("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(t) : n.set(t, e), C = (t, n, e, i) => (_(t, n, "write to private field"), i ? i.call(t, e) : n.set(t, e), e);
8
8
  import { z as o } from "zod";
9
- const z = "0.0.1-alpha7";
10
- var E, C;
11
- class ke {
9
+ const G = "0.0.1-alpha8";
10
+ var E, l;
11
+ class Be {
12
12
  constructor(n) {
13
13
  d(this, "id");
14
14
  a(this, E, "v1");
15
- a(this, C);
15
+ a(this, l);
16
16
  var i, r;
17
17
  this.id = n;
18
18
  const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, E));
19
- if (c(this, C, e == null ? void 0 : e.getButtonSdkBridge(this.id)), !s(this, C))
19
+ if (C(this, l, e == null ? void 0 : e.getButtonSdkBridge(this.id)), !s(this, l))
20
20
  throw new Error(`Cannot access API for Button "${this.id}".`);
21
21
  }
22
22
  onRendered(n) {
23
23
  var e;
24
- return ((e = s(this, C)) == null ? void 0 : e.addOnRenderedCallback(n)) ?? { unsubscribe: () => {
24
+ return ((e = s(this, l)) == null ? void 0 : e.addOnRenderedCallback(n)) ?? { unsubscribe: () => {
25
25
  } };
26
26
  }
27
27
  onClick(n) {
28
28
  var e;
29
- return ((e = s(this, C)) == null ? void 0 : e.addOnClickCallback(n)) ?? { unsubscribe: () => {
29
+ return ((e = s(this, l)) == null ? void 0 : e.addOnClickCallback(n)) ?? { unsubscribe: () => {
30
30
  } };
31
31
  }
32
32
  async setVisible(n) {
33
33
  var e;
34
- await ((e = s(this, C)) == null ? void 0 : e.setVisible(n));
34
+ await ((e = s(this, l)) == null ? void 0 : e.setVisible(n));
35
35
  }
36
36
  setText(n) {
37
37
  var e;
38
- (e = s(this, C)) == null || e.setText(n);
38
+ (e = s(this, l)) == null || e.setText(n);
39
39
  }
40
40
  }
41
- E = new WeakMap(), C = new WeakMap();
42
- var T, g;
43
- class Ve {
41
+ E = new WeakMap(), l = new WeakMap();
42
+ var I, g;
43
+ class Ee {
44
44
  constructor(n) {
45
45
  d(this, "id");
46
- a(this, T, "v1");
46
+ a(this, I, "v1");
47
47
  a(this, g);
48
48
  var i, r;
49
49
  this.id = n;
50
- const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, T));
51
- if (c(this, g, e == null ? void 0 : e.getCheckboxSdkBridge(this.id)), !s(this, g))
50
+ const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, I));
51
+ if (C(this, g, e == null ? void 0 : e.getCheckboxSdkBridge(this.id)), !s(this, g))
52
52
  throw new Error(`Cannot access API for Checkbox "${this.id}".`);
53
53
  }
54
54
  onRendered(n) {
@@ -61,17 +61,17 @@ class Ve {
61
61
  await ((e = s(this, g)) == null ? void 0 : e.setVisible(n));
62
62
  }
63
63
  }
64
- T = new WeakMap(), g = new WeakMap();
65
- var I, h;
66
- class Ae {
64
+ I = new WeakMap(), g = new WeakMap();
65
+ var T, h;
66
+ class Ie {
67
67
  constructor(n) {
68
68
  d(this, "id");
69
- a(this, I, "v1");
69
+ a(this, T, "v1");
70
70
  a(this, h);
71
71
  var i, r;
72
72
  this.id = n;
73
- const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, I));
74
- if (c(this, h, e == null ? void 0 : e.getCollapsibleSdkBridge(this.id)), !s(this, h))
73
+ const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, T));
74
+ if (C(this, h, e == null ? void 0 : e.getCollapsibleSdkBridge(this.id)), !s(this, h))
75
75
  throw new Error(`Cannot access API for Collapsible "${this.id}".`);
76
76
  }
77
77
  onRendered(n) {
@@ -84,66 +84,105 @@ class Ae {
84
84
  await ((e = s(this, h)) == null ? void 0 : e.setVisible(n));
85
85
  }
86
86
  }
87
- I = new WeakMap(), h = new WeakMap();
88
- var S, l;
89
- class ye {
87
+ T = new WeakMap(), h = new WeakMap();
88
+ var R, c;
89
+ class Te {
90
90
  constructor(n) {
91
91
  d(this, "id");
92
- a(this, S, "v1");
93
- a(this, l);
92
+ a(this, R, "v1");
93
+ a(this, c);
94
94
  var i, r;
95
95
  this.id = n;
96
- const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, S));
97
- if (c(this, l, e == null ? void 0 : e.getCustomCtrlSdkBridge(this.id)), !s(this, l))
96
+ const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, R));
97
+ if (C(this, c, e == null ? void 0 : e.getCustomCtrlSdkBridge(this.id)), !s(this, c))
98
98
  throw new Error(`Cannot access API for Custom Control "${this.id}".`);
99
99
  }
100
100
  /**
101
- * Things to mention when writing docs:
102
- * - The `renderFn` is always meant to actively render/set the content/innerHTML of the given `element`.
103
- * ATM, system does sometimes pass a "pre-rendered" `element` but that will change in the future when introducing
104
- * some dedicated ctrl property like "Custom control controlled/custom control rendered/...".
105
- * - Assigning a new fn does not trigger a re-render
106
- * - Explain, when this fn is being called (automatically on show, manually on `.render()`)
107
- * - Explain, why this should be used instead of a pattern like the following:
108
- * ```ts
109
- * const el = myCtrl.getElement();
110
- * el.innerHTML = '...';
111
- * ```
112
- * - Explain difference to `onRendered` (see comments on `useCustomCodeSdkBridgeStoreBase`)
113
- * - ...
101
+ * This gives custom code full control over what is rendered inside the control. When setting this function, custom
102
+ * code is responsible to actively render/set the content/innerHTML of the given `element` inside the
103
+ * {@link renderFn}.
104
+ *
105
+ * The configurator will not render any content inside the control when a {@link renderFn} is set.
106
+ *
107
+ * For the {@link renderFn} to work, the property `Custom code controlled` needs to be enabled on the control.
108
+ * The {@link renderFn} will be ignored when `Custom code controlled` is not enabled.
109
+ *
110
+ * Good to know:
111
+ * - Setting a new {@link renderFn} does not trigger a re-render.\
112
+ * Use {@link render} if you want to trigger a re-render after setting a new {@link renderFn}.
113
+ * - There can only be one {@link renderFn} per control. Setting a new one will override the existing one.
114
+ * - The {@link renderFn} will be called in the following scenarios:
115
+ * - Everytime the control is being shown. This is on initial show as well as when toggling its visibility.
116
+ * - When forcing a render via the {@link render} method.
117
+ * - Difference to {@link onRendered}:
118
+ * - The {@link renderFn} is meant to control the rendered content whilst {@link onRendered} is a classic event
119
+ * listener which allows you to perform certain actions like installing event listener on DOM nodes etc.
120
+ * **after** the content has been rendered.
121
+ * - You can install multiple {@link onRendered} callbacks.
122
+ * - The {@link renderFn} and {@link onRendered} callbacks can be used side by side.
123
+ * - The {@link renderFn} should always be used instead of manually manipulating the DOM via vanilla JS.\
124
+ * When manipulating the DOM outside of the {@link renderFn}, your changes can always be overridden by the
125
+ * configurator.\
126
+ * Using the {@link renderFn} ensures that your changes are applied in a stable and predictable way.
114
127
  */
115
128
  set renderFn(n) {
116
129
  var e;
117
- (e = s(this, l)) == null || e.setRenderFn(n);
130
+ (e = s(this, c)) == null || e.setRenderFn(n);
118
131
  }
119
132
  /**
120
- * @param renderFn Convenience param which allows setting the `renderFn` and triggering a render in one call.
121
- * The `renderFn` will be permanently installed and will override any existing `renderFn`.
133
+ * Forces a re-render of the control.
134
+ *
135
+ * @param renderFn Convenience param which allows setting the {@link renderFn} and triggering a render in one call.
136
+ * The given `renderFn` will be permanently installed and will override any previously set
137
+ * {@link renderFn}.
122
138
  */
123
139
  async render(n) {
124
140
  var e;
125
- typeof n == "function" && (this.renderFn = n), await ((e = s(this, l)) == null ? void 0 : e.render());
141
+ typeof n == "function" && (this.renderFn = n), await ((e = s(this, c)) == null ? void 0 : e.render());
142
+ }
143
+ /**
144
+ * This allows custom code to register callbacks in which it can perform certain actions like installing event
145
+ * listeners on DOM nodes or adding CSS classes etc. **after** the control has been rendered.
146
+ *
147
+ * The control can be rendered in the following scenarios:
148
+ * - Everytime the control is being shown. This is on initial show as well as when toggling its visibility.
149
+ * - When forcing a render via the {@link render} method.
150
+ * - When the value of the control's `HTML` property changes e.g. via Hive in controls.
151
+ *
152
+ * !!! Important !!!
153
+ *
154
+ * This is **not** meant to be used for manipulating the rendered content of the control besides simple,
155
+ * non-structural/-behavioral changes like adding CSS classes or data attributes etc.
156
+ *
157
+ * For manipulating/controlling the rendered content, use the {@link renderFn} instead.
158
+ *
159
+ * See {@link renderFn} for more differences between the two.
160
+ */
161
+ onRendered(n) {
162
+ var e;
163
+ return ((e = s(this, c)) == null ? void 0 : e.addOnRenderedCallback(n)) ?? { unsubscribe: () => {
164
+ } };
126
165
  }
127
166
  getElement() {
128
167
  var e;
129
- return (e = s(this, l)) == null ? void 0 : e.getElement();
168
+ return (e = s(this, c)) == null ? void 0 : e.getElement();
130
169
  }
131
170
  async setVisible(n) {
132
171
  var e;
133
- await ((e = s(this, l)) == null ? void 0 : e.setVisible(n));
172
+ await ((e = s(this, c)) == null ? void 0 : e.setVisible(n));
134
173
  }
135
174
  }
136
- S = new WeakMap(), l = new WeakMap();
137
- var R, b;
138
- class Be {
175
+ R = new WeakMap(), c = new WeakMap();
176
+ var S, b;
177
+ class Re {
139
178
  constructor(n) {
140
179
  d(this, "id");
141
- a(this, R, "v1");
180
+ a(this, S, "v1");
142
181
  a(this, b);
143
182
  var i, r;
144
183
  this.id = n;
145
- const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, R));
146
- if (c(this, b, e == null ? void 0 : e.getDataviewSdkBridge(this.id)), !s(this, b))
184
+ const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, S));
185
+ if (C(this, b, e == null ? void 0 : e.getDataviewSdkBridge(this.id)), !s(this, b))
147
186
  throw new Error(`Cannot access API for Dataview "${this.id}".`);
148
187
  }
149
188
  onRendered(n) {
@@ -156,9 +195,9 @@ class Be {
156
195
  await ((e = s(this, b)) == null ? void 0 : e.setVisible(n));
157
196
  }
158
197
  }
159
- R = new WeakMap(), b = new WeakMap();
198
+ S = new WeakMap(), b = new WeakMap();
160
199
  var v, p;
161
- class Ee {
200
+ class Se {
162
201
  constructor(n) {
163
202
  d(this, "id");
164
203
  a(this, v, "v1");
@@ -166,7 +205,7 @@ class Ee {
166
205
  var i, r;
167
206
  this.id = n;
168
207
  const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, v));
169
- if (c(this, p, e == null ? void 0 : e.getInputSdkBridge(this.id)), !s(this, p))
208
+ if (C(this, p, e == null ? void 0 : e.getInputSdkBridge(this.id)), !s(this, p))
170
209
  throw new Error(`Cannot access API for Input "${this.id}".`);
171
210
  }
172
211
  onRendered(n) {
@@ -181,7 +220,7 @@ class Ee {
181
220
  }
182
221
  v = new WeakMap(), p = new WeakMap();
183
222
  var P, m;
184
- class Te {
223
+ class ve {
185
224
  constructor(n) {
186
225
  d(this, "id");
187
226
  a(this, P, "v1");
@@ -189,7 +228,7 @@ class Te {
189
228
  var i, r;
190
229
  this.id = n;
191
230
  const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, P));
192
- if (c(this, m, e == null ? void 0 : e.getPanelSdkBridge(this.id)), !s(this, m))
231
+ if (C(this, m, e == null ? void 0 : e.getPanelSdkBridge(this.id)), !s(this, m))
193
232
  throw new Error(`Cannot access API for Panel "${this.id}".`);
194
233
  }
195
234
  onRendered(n) {
@@ -203,16 +242,16 @@ class Te {
203
242
  }
204
243
  }
205
244
  P = new WeakMap(), m = new WeakMap();
206
- var $, u;
207
- class Ie {
245
+ var O, u;
246
+ class Pe {
208
247
  constructor(n) {
209
248
  d(this, "id");
210
- a(this, $, "v1");
249
+ a(this, O, "v1");
211
250
  a(this, u);
212
251
  var i, r;
213
252
  this.id = n;
214
- const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, $));
215
- if (c(this, u, e == null ? void 0 : e.getTextSdkBridge(this.id)), !s(this, u))
253
+ const e = (r = (i = window.Cbn) == null ? void 0 : i.getCustomCodeSdkBridge) == null ? void 0 : r.call(i, s(this, O));
254
+ if (C(this, u, e == null ? void 0 : e.getTextSdkBridge(this.id)), !s(this, u))
216
255
  throw new Error(`Cannot access API for Text "${this.id}".`);
217
256
  }
218
257
  onRendered(n) {
@@ -229,38 +268,38 @@ class Ie {
229
268
  (e = s(this, u)) == null || e.setText(n);
230
269
  }
231
270
  }
232
- $ = new WeakMap(), u = new WeakMap();
233
- const U = 1, y = [];
234
- function Y(t, n) {
235
- if (y.length >= U)
236
- throw new Error(`Only ${U} \`ConfiguratorClient\` can be created at a time.`);
271
+ O = new WeakMap(), u = new WeakMap();
272
+ const M = 1, y = [];
273
+ function q(t, n) {
274
+ if (y.length >= M)
275
+ throw new Error(`Only ${M} \`ConfiguratorClient\` can be created at a time.`);
237
276
  y.push({ client: t, internals: n });
238
277
  }
239
- function D() {
278
+ function N() {
240
279
  const t = y[0];
241
280
  if (!t)
242
281
  throw new Error("Operation not possible as no `ConfiguratorClient` has been registered yet.");
243
282
  return t.client;
244
283
  }
245
- function q() {
284
+ function J() {
246
285
  const t = y[0];
247
286
  if (!t)
248
287
  throw new Error("Operation not possible as no `ConfiguratorClient` has been registered yet.");
249
288
  return t.internals;
250
289
  }
251
- const J = "v1";
252
- var A, Z;
253
- const F = (Z = (A = window.Cbn) == null ? void 0 : A.getCustomCodeSdkBridge) == null ? void 0 : Z.call(A, "v1");
254
- if (!F)
290
+ const ee = "v1";
291
+ var A, j;
292
+ const $ = (j = (A = window.Cbn) == null ? void 0 : A.getCustomCodeSdkBridge) == null ? void 0 : j.call(A, "v1");
293
+ if (!$)
255
294
  throw new Error(
256
295
  "Cannot access Configurator SDK bridge. Make sure to only use the `custom-code-sdk` inside a Combeenation Configurator."
257
296
  );
258
- const N = F.createCfgrClient(J, Y);
259
- if (!N)
297
+ const K = $.createCfgrClient(ee, q);
298
+ if (!K)
260
299
  throw new Error(
261
300
  "Cannot create Configurator Client. Make sure to only use the `custom-code-sdk` inside a Combeenation Configurator."
262
301
  );
263
- const w = F.getParentPageUtilsSdkBridge(), j = F.getCfgrUtilsSdkBridge(), B = N, x = {
302
+ const w = $.getParentPageUtilsSdkBridge(), U = $.getCfgrUtilsSdkBridge(), B = K, L = {
264
303
  Text: "Text",
265
304
  Number: "Number",
266
305
  Logic: "Logic"
@@ -296,29 +335,29 @@ o.enum([
296
335
  o.union([o.string(), o.number(), o.boolean()]);
297
336
  const V = (t) => typeof t == "string";
298
337
  o.string();
299
- o.enum([x.Text, x.Number, x.Logic]);
338
+ o.enum([L.Text, L.Number, L.Logic]);
300
339
  o.string();
301
340
  o.custom((t) => V(t) && t.toLowerCase() === t);
302
- const G = (t) => (t == null ? void 0 : t.toLowerCase()) ?? "";
341
+ const W = (t) => (t == null ? void 0 : t.toLowerCase()) ?? "";
303
342
  o.string();
304
- const ee = o.custom(
343
+ const te = o.custom(
305
344
  (t) => V(t) ? new RegExp(`^${f.ValueComponent}<.*>$`).test(t) : !1
306
- ), te = o.custom(
307
- (t) => V(t) ? new RegExp(`^${f.RecordComponent}<.*>$`).test(t) : !1
308
345
  ), ne = o.custom(
309
- (t) => V(t) ? new RegExp(`^${f.ResourceComponent}<.*>$`).test(t) : !1
346
+ (t) => V(t) ? new RegExp(`^${f.RecordComponent}<.*>$`).test(t) : !1
310
347
  ), ie = o.custom(
348
+ (t) => V(t) ? new RegExp(`^${f.ResourceComponent}<.*>$`).test(t) : !1
349
+ ), se = o.custom(
311
350
  (t) => V(t) ? new RegExp(`^${f.TableComponent}<.*>$`).test(t) : !1
312
351
  );
313
352
  o.union([
314
- ee,
315
- ie,
316
353
  te,
354
+ se,
317
355
  ne,
356
+ ie,
318
357
  o.literal(f.GraphicComponent),
319
358
  o.literal(f.CheckoutComponent)
320
359
  ]);
321
- const _ = o.union([o.string(), o.number(), o.boolean()]), se = o.union([_, o.array(_), o.object({}), o.unknown()]), oe = o.object({
360
+ const Z = o.union([o.string(), o.number(), o.boolean()]), oe = o.union([Z, o.array(Z), o.object({}), o.unknown()]), re = o.object({
322
361
  $typ: o.literal("Error"),
323
362
  // TODO WTT: Introduce more specific typing here for known error IDs etc.? Maybe in combination w/ some server
324
363
  // generated enum?
@@ -332,30 +371,30 @@ const _ = o.union([o.string(), o.number(), o.boolean()]), se = o.union([_, o.arr
332
371
  */
333
372
  route: o.unknown().optional()
334
373
  });
335
- oe.or(se);
336
- const M = /* @__PURE__ */ new Map();
337
- function re(t) {
338
- const n = G(t.name);
339
- M.has(n) || M.set(n, t);
374
+ re.or(oe);
375
+ const z = /* @__PURE__ */ new Map();
376
+ function ae(t) {
377
+ const n = W(t.name);
378
+ z.has(n) || z.set(n, t);
340
379
  }
341
- class Se {
380
+ class Oe {
342
381
  constructor(n, e) {
343
382
  d(this, "name");
344
383
  d(this, "zodType");
345
- this.name = n, this.zodType = e, re(this);
384
+ this.name = n, this.zodType = e, ae(this);
346
385
  }
347
386
  /**
348
387
  * Function for receiving the value of a component.
349
388
  */
350
389
  async getValue() {
351
- return await D().getCmpValue(this.name);
390
+ return await N().getCmpValue(this.name);
352
391
  }
353
392
  /**
354
393
  * Sends the ChangeConfigurationValue request to the server
355
394
  */
356
395
  async setInput(n) {
357
- const e = G(this.name);
358
- await q().setCmpInput(e, n, this.zodType);
396
+ const e = W(this.name);
397
+ await J().setCmpInput(e, n, this.zodType);
359
398
  }
360
399
  /**
361
400
  * @param listener Called whenever the value of the given cmp has changed
@@ -367,55 +406,67 @@ class Se {
367
406
  * The function can decide on whether the listener is called or not by returning true or false.
368
407
  */
369
408
  onValueChanged(n, e = !1, i) {
370
- D().onCmpValueChanged(this.name, n, i, e);
409
+ N().onCmpValueChanged(this.name, n, i, e);
371
410
  }
372
411
  }
373
- var K = /* @__PURE__ */ ((t) => (t[t.Facebook = 0] = "Facebook", t[t.Pinterest = 1] = "Pinterest", t[t.Twitter = 2] = "Twitter", t[t.LinkedIn = 3] = "LinkedIn", t[t.WhatsApp = 4] = "WhatsApp", t[t.Custom = 5] = "Custom", t[t.NativeShare = 6] = "NativeShare", t))(K || {});
374
- const ae = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+X2ZkAAAAASUVORK5CYII=", de = B.onAnyCmpValueChanged.bind(B), ce = async (t) => {
412
+ const de = () => U.getAssetPaths();
413
+ var H = /* @__PURE__ */ ((t) => (t[t.Facebook = 0] = "Facebook", t[t.Pinterest = 1] = "Pinterest", t[t.Twitter = 2] = "Twitter", t[t.LinkedIn = 3] = "LinkedIn", t[t.WhatsApp = 4] = "WhatsApp", t[t.Custom = 5] = "Custom", t[t.NativeShare = 6] = "NativeShare", t))(H || {});
414
+ const ce = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+X2ZkAAAAASUVORK5CYII=", Ce = B.onAnyCmpValueChanged.bind(B), le = async (t) => {
375
415
  if (await B.finishConfiguration(t == null ? void 0 : t.input), t.sendDataToParentPage) {
376
416
  const n = t.transformParentPageData();
377
417
  await w.sendConfigurationFinished(n);
378
418
  }
379
- }, Ce = async (t) => {
380
- const n = K[t.platform], e = t.imageUrl ?? ae, i = { ...t, platform: n, imageUrl: e }, r = await B.shareConfiguration(i);
381
- await j.openShareWindow(t.platform, r);
382
- const { shareUrl: W, shareConfigurationId: H } = r;
383
- return { shareUrl: W, shareConfigurationId: H };
384
- }, le = () => w.isInIFrame(), ue = (t) => w.setIFrameSize(t), ge = (t) => j.navigateToLogin(t), he = (t, n) => w.sendCustomMsg(t, n), be = (t) => w.redirectParentPage(t), pe = () => w.getParentPageUrl(), me = (t, n) => w.fireAnalyticsEvent(t, n), Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
419
+ }, ue = async (t) => {
420
+ const n = H[t.platform], e = t.imageUrl ?? ce, i = { ...t, platform: n, imageUrl: e }, r = await B.shareConfiguration(i);
421
+ await U.openShareWindow(t.platform, r);
422
+ const { shareUrl: F, shareConfigurationId: x } = r;
423
+ return { shareUrl: F, shareConfigurationId: x };
424
+ }, ge = async (t) => {
425
+ const { promise: n, resolve: e } = Promise.withResolvers(), i = {};
426
+ for (const [r, F] of Object.entries(t))
427
+ F.onValueChanged((x) => {
428
+ i[r] = x, Object.keys(t).every((Q) => Q in i) && e(i);
429
+ }, !0);
430
+ return n;
431
+ }, he = () => w.isInIFrame(), be = (t) => w.setIFrameSize(t), pe = (t) => U.navigateToLogin(t), me = (t, n) => w.sendCustomMsg(t, n), we = (t) => w.redirectParentPage(t), fe = () => w.getParentPageUrl(), ke = (t, n) => w.fireAnalyticsEvent(t, n), $e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
385
432
  __proto__: null,
386
- configuratorIsInIFrame: le,
387
- finishConfiguration: ce,
388
- fireAnalyticsEvent: me,
389
- getParentPageUrl: pe,
390
- navigateToLogin: ge,
391
- onAnyCmpValueChanged: de,
392
- redirectParentPage: be,
393
- sendCustomMsgToParentPage: he,
394
- setConfiguratorIFrameSize: ue,
395
- shareConfiguration: Ce,
396
- version: z
433
+ configuratorIsInIFrame: he,
434
+ createSyncCmpValuesStore: ge,
435
+ finishConfiguration: le,
436
+ fireAnalyticsEvent: ke,
437
+ getAssetPaths: de,
438
+ getParentPageUrl: fe,
439
+ navigateToLogin: pe,
440
+ onAnyCmpValueChanged: Ce,
441
+ redirectParentPage: we,
442
+ sendCustomMsgToParentPage: me,
443
+ setConfiguratorIFrameSize: be,
444
+ shareConfiguration: ue,
445
+ version: G
397
446
  }, Symbol.toStringTag, { value: "Module" }));
398
- console.log(`Loading custom code SDK v${z}`);
447
+ console.log(`Loading custom code SDK v${G}`);
399
448
  export {
400
- ke as Button,
401
- Re as CbnSdk,
402
- Ve as Checkbox,
403
- Ae as Collapsible,
404
- ye as CustomControl,
405
- Be as Dataview,
406
- Ee as Input,
407
- Te as Panel,
408
- Ie as Text,
409
- Se as ValueComponent,
410
- le as configuratorIsInIFrame,
411
- ce as finishConfiguration,
412
- me as fireAnalyticsEvent,
413
- pe as getParentPageUrl,
414
- ge as navigateToLogin,
415
- de as onAnyCmpValueChanged,
416
- be as redirectParentPage,
417
- he as sendCustomMsgToParentPage,
418
- ue as setConfiguratorIFrameSize,
419
- Ce as shareConfiguration,
420
- z as version
449
+ Be as Button,
450
+ $e as CbnSdk,
451
+ Ee as Checkbox,
452
+ Ie as Collapsible,
453
+ Te as CustomControl,
454
+ Re as Dataview,
455
+ Se as Input,
456
+ ve as Panel,
457
+ Pe as Text,
458
+ Oe as ValueComponent,
459
+ he as configuratorIsInIFrame,
460
+ ge as createSyncCmpValuesStore,
461
+ le as finishConfiguration,
462
+ ke as fireAnalyticsEvent,
463
+ de as getAssetPaths,
464
+ fe as getParentPageUrl,
465
+ pe as navigateToLogin,
466
+ Ce as onAnyCmpValueChanged,
467
+ we as redirectParentPage,
468
+ me as sendCustomMsgToParentPage,
469
+ be as setConfiguratorIFrameSize,
470
+ ue as shareConfiguration,
471
+ G as version
421
472
  };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import { z } from 'zod';
2
2
 
3
3
  declare type AppLanguage = 'en' | 'de';
4
4
 
5
+ declare type AssetName = z.infer<typeof ZAssetName>;
6
+
5
7
  export declare class Button {
6
8
  #private;
7
9
  readonly id: CtrlId;
@@ -21,6 +23,7 @@ export declare namespace CbnSdk {
21
23
  configuratorIsInIFrame,
22
24
  finishConfiguration,
23
25
  fireAnalyticsEvent,
26
+ getAssetPaths,
24
27
  getParentPageUrl,
25
28
  navigateToLogin,
26
29
  onAnyCmpValueChanged,
@@ -28,6 +31,7 @@ export declare namespace CbnSdk {
28
31
  sendCustomMsgToParentPage,
29
32
  setConfiguratorIFrameSize,
30
33
  shareConfiguration,
34
+ createSyncCmpValuesStore,
31
35
  version
32
36
  }
33
37
  }
@@ -89,6 +93,64 @@ export declare class Collapsible {
89
93
  */
90
94
  export declare const configuratorIsInIFrame: () => boolean;
91
95
 
96
+ /**
97
+ * Creates a store holding component values which can be accessed synchronously.
98
+ *
99
+ * This is meant as an alternative to the async value access via `await cmp.getValue()` for situations where the async
100
+ * access is especially cumbersome.
101
+ *
102
+ * E.g.:
103
+ * ```ts
104
+ * const amount = await Amount.getValue();
105
+ * // vs.
106
+ * const amount = cmpValues.Amount;
107
+ * ```
108
+ *
109
+ * !!! Note !!!
110
+ *
111
+ * This shall not be used as the default way of accessing component values.\
112
+ * Using this extensively can have negative impact on the performance of your configurator.
113
+ *
114
+ * Avoid using this with too many components or components that hold very large values which change frequently.
115
+ *
116
+ * @returns An object holding the current value of each of the given `cmps`.\
117
+ * The keys of the properties in the returned object are the same as in the given `cmps`.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * // Create the store once and export for later use:
122
+ * import { Amount, ItemPrice } from './typings/cfgr-defs.generated';
123
+ * export const cmpValues = await createSyncCmpValuesStore({ Amount, ItemPrice });
124
+ *
125
+ * // Later in the code, access the values synchronously like this:
126
+ * const amount = cmpValues.Amount;
127
+ * const itemPrice = cmpValues.ItemPrice;
128
+ * // or:
129
+ * const { Amount: amount, ItemPrice: itemPrice } = cmpValues;
130
+ * ```
131
+ *
132
+ * !!! Important !!!
133
+ *
134
+ * Once the values of the returned store have been extracted, they will not update anymore.\
135
+ * -> Only extract the values in sync contexts.
136
+ *
137
+ * E.g.:
138
+ * ```ts
139
+ * import { cmpValues } from './path/to/store';
140
+ *
141
+ * const amount = cmpValues.Amount; // Current value of Amount is 10
142
+ *
143
+ * button.onClick(() => {
144
+ * // The value of Amount changed to 20 in the meantime
145
+ * console.log(amount); // 🔥 Stale value 10
146
+ * console.log(cmpValues.Amount); // ✅ Latest value 20
147
+ * });
148
+ * ```
149
+ */
150
+ export declare const createSyncCmpValuesStore: <TCmps extends {
151
+ [id: CmpName]: ValueComponent;
152
+ }>(cmps: TCmps) => Promise<Readonly<SyncCmpValuesStore<TCmps>>>;
153
+
92
154
  declare type CtrlId = z.infer<typeof ZCtrlId>;
93
155
 
94
156
  export declare class CustomControl {
@@ -96,30 +158,69 @@ export declare class CustomControl {
96
158
  readonly id: CtrlId;
97
159
  constructor(id: CtrlId);
98
160
  /**
99
- * Things to mention when writing docs:
100
- * - The `renderFn` is always meant to actively render/set the content/innerHTML of the given `element`.
101
- * ATM, system does sometimes pass a "pre-rendered" `element` but that will change in the future when introducing
102
- * some dedicated ctrl property like "Custom control controlled/custom control rendered/...".
103
- * - Assigning a new fn does not trigger a re-render
104
- * - Explain, when this fn is being called (automatically on show, manually on `.render()`)
105
- * - Explain, why this should be used instead of a pattern like the following:
106
- * ```ts
107
- * const el = myCtrl.getElement();
108
- * el.innerHTML = '...';
109
- * ```
110
- * - Explain difference to `onRendered` (see comments on `useCustomCodeSdkBridgeStoreBase`)
111
- * - ...
161
+ * This gives custom code full control over what is rendered inside the control. When setting this function, custom
162
+ * code is responsible to actively render/set the content/innerHTML of the given `element` inside the
163
+ * {@link renderFn}.
164
+ *
165
+ * The configurator will not render any content inside the control when a {@link renderFn} is set.
166
+ *
167
+ * For the {@link renderFn} to work, the property `Custom code controlled` needs to be enabled on the control.
168
+ * The {@link renderFn} will be ignored when `Custom code controlled` is not enabled.
169
+ *
170
+ * Good to know:
171
+ * - Setting a new {@link renderFn} does not trigger a re-render.\
172
+ * Use {@link render} if you want to trigger a re-render after setting a new {@link renderFn}.
173
+ * - There can only be one {@link renderFn} per control. Setting a new one will override the existing one.
174
+ * - The {@link renderFn} will be called in the following scenarios:
175
+ * - Everytime the control is being shown. This is on initial show as well as when toggling its visibility.
176
+ * - When forcing a render via the {@link render} method.
177
+ * - Difference to {@link onRendered}:
178
+ * - The {@link renderFn} is meant to control the rendered content whilst {@link onRendered} is a classic event
179
+ * listener which allows you to perform certain actions like installing event listener on DOM nodes etc.
180
+ * **after** the content has been rendered.
181
+ * - You can install multiple {@link onRendered} callbacks.
182
+ * - The {@link renderFn} and {@link onRendered} callbacks can be used side by side.
183
+ * - The {@link renderFn} should always be used instead of manually manipulating the DOM via vanilla JS.\
184
+ * When manipulating the DOM outside of the {@link renderFn}, your changes can always be overridden by the
185
+ * configurator.\
186
+ * Using the {@link renderFn} ensures that your changes are applied in a stable and predictable way.
112
187
  */
113
188
  set renderFn(callback: CustomCtrlRenderFn);
114
189
  /**
115
- * @param renderFn Convenience param which allows setting the `renderFn` and triggering a render in one call.
116
- * The `renderFn` will be permanently installed and will override any existing `renderFn`.
190
+ * Forces a re-render of the control.
191
+ *
192
+ * @param renderFn Convenience param which allows setting the {@link renderFn} and triggering a render in one call.
193
+ * The given `renderFn` will be permanently installed and will override any previously set
194
+ * {@link renderFn}.
117
195
  */
118
196
  render(renderFn?: CustomCtrlRenderFn): Promise<void>;
197
+ /**
198
+ * This allows custom code to register callbacks in which it can perform certain actions like installing event
199
+ * listeners on DOM nodes or adding CSS classes etc. **after** the control has been rendered.
200
+ *
201
+ * The control can be rendered in the following scenarios:
202
+ * - Everytime the control is being shown. This is on initial show as well as when toggling its visibility.
203
+ * - When forcing a render via the {@link render} method.
204
+ * - When the value of the control's `HTML` property changes e.g. via Hive in controls.
205
+ *
206
+ * !!! Important !!!
207
+ *
208
+ * This is **not** meant to be used for manipulating the rendered content of the control besides simple,
209
+ * non-structural/-behavioral changes like adding CSS classes or data attributes etc.
210
+ *
211
+ * For manipulating/controlling the rendered content, use the {@link renderFn} instead.
212
+ *
213
+ * See {@link renderFn} for more differences between the two.
214
+ */
215
+ onRendered(callback: OnRenderedCallback<HTMLDivElement>): CallbackUnsubscribeOption;
119
216
  getElement(): HTMLElement | undefined;
120
217
  setVisible(visible: boolean): Promise<void>;
121
218
  }
122
219
 
220
+ /**
221
+ * @param element The root element of the control into which you can render your custom content.
222
+ * @param rawHtml The raw HTML string which is set in the `HTML` property of the control.
223
+ */
123
224
  declare type CustomCtrlRenderFn = (element: HTMLDivElement, rawHtml: string | undefined) => void | Promise<void>;
124
225
 
125
226
  export declare class Dataview {
@@ -191,6 +292,14 @@ export declare const fireAnalyticsEvent: (event: string, eventData?: object | st
191
292
 
192
293
  export declare type FlexShopFinishJson = Shopware6FinishJson;
193
294
 
295
+ /**
296
+ * Returns the resolved 3D asset paths (babylon.js assets, material packs, texture image assets)
297
+ * for all pre-packed asset bundles configured for this Configurator.
298
+ *
299
+ * The result is fetched once and cached — subsequent calls resolve immediately from cache.
300
+ */
301
+ export declare const getAssetPaths: () => Promise<SdkAssetPaths>;
302
+
194
303
  /**
195
304
  * Retrieve the parent page's URI.
196
305
  *
@@ -219,6 +328,13 @@ declare type JsonObject = {
219
328
 
220
329
  declare type JsonPrimitive = string | number | boolean | null;
221
330
 
331
+ /**
332
+ * Raw material JSON which can be passed to Babylon.js e.g. via `Material.Parse(material)`
333
+ */
334
+ declare type MaterialAsset = z.infer<typeof ZMaterialAsset>;
335
+
336
+ declare type MaterialPackName = z.infer<typeof ZMaterialPackName>;
337
+
222
338
  /**
223
339
  * Navigates to the login page of the Configurator.
224
340
  *
@@ -353,6 +469,20 @@ export declare type ProductCustomFields = {
353
469
  */
354
470
  export declare const redirectParentPage: (url: string) => Promise<ParentPageComResult<void>>;
355
471
 
472
+ declare type SdkAssetPaths = {
473
+ babylonJsAssets: {
474
+ [key: AssetName]: Url;
475
+ };
476
+ materialPacks: {
477
+ [key: MaterialPackName]: {
478
+ [key: AssetName]: MaterialAsset;
479
+ };
480
+ };
481
+ textureImageAssets: {
482
+ [key: AssetName]: Url;
483
+ };
484
+ };
485
+
356
486
  /**
357
487
  * Send a custom message to the parent page via the "CustomMessage".\
358
488
  * The parent page can handle those messages by implementing the function `Combeenation.on{msgName}`.
@@ -503,6 +633,13 @@ export declare type Shopware6FinishJson = {
503
633
  }[];
504
634
  };
505
635
 
636
+ /**
637
+ * A simple key-value store where key = component name and value = current component value.
638
+ */
639
+ declare type SyncCmpValuesStore<TCmps extends Record<CmpName, ValueComponent>> = {
640
+ [K in keyof TCmps & CmpName]: TCmps[K] extends ValueComponent<any, infer TValue, any> ? TValue | undefined : never;
641
+ };
642
+
506
643
  declare class Text_2 {
507
644
  #private;
508
645
  readonly id: CtrlId;
@@ -513,6 +650,8 @@ declare class Text_2 {
513
650
  }
514
651
  export { Text_2 as Text }
515
652
 
653
+ declare type Url = z.infer<typeof ZUrl>;
654
+
516
655
  /**
517
656
  * Represents a component of type `Value`
518
657
  */
@@ -542,8 +681,33 @@ export declare class ValueComponent<TName extends CmpName = CmpName, TValue exte
542
681
 
543
682
  export declare const version: string;
544
683
 
684
+ declare const ZAssetName: z.ZodString;
685
+
545
686
  declare const ZCmpValue: z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, z.ZodUnknown]>;
546
687
 
547
688
  declare const ZCtrlId: z.ZodString;
548
689
 
690
+ /**
691
+ * Raw material JSON which can be passed to Babylon.js e.g. via `Material.Parse(material)`
692
+ *
693
+ * Whilst this is not a full zod schema for Babylon material definitions, we least check for the presence of some
694
+ * required properties like `name` and `id` to avoid passing obviously invalid material definitions.
695
+ *
696
+ * Could be extended as needed.
697
+ */
698
+ declare const ZMaterialAsset: z.ZodObject<{
699
+ name: z.ZodString;
700
+ id: z.ZodString;
701
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
702
+ name: z.ZodString;
703
+ id: z.ZodString;
704
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
705
+ name: z.ZodString;
706
+ id: z.ZodString;
707
+ }, z.ZodTypeAny, "passthrough">>;
708
+
709
+ declare const ZMaterialPackName: z.ZodString;
710
+
711
+ declare const ZUrl: z.ZodBranded<z.ZodString, "Url">;
712
+
549
713
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combeenation/custom-code-sdk",
3
- "version": "0.0.1-alpha7",
3
+ "version": "0.0.1-alpha8",
4
4
  "description": "Combeenation custom code SDK package",
5
5
  "keywords": [],
6
6
  "homepage": "",