@salla.sa/twilight-bundles 0.1.40 → 0.1.41
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("lit"),d=require("lit/decorators.js");class i{static onBundlesReady(){return i.makeSureSallaIsReady().then(()=>Salla.event.onlyWhen("twilight-bundles::initiated")).then(()=>Salla.lang.onLoaded())}static async initializeSalla(){if(Salla.status==="ready"){salla.log("Salla is ready");return}const e=document.currentScript||document.querySelector('script[src*="twilight-bundles.js"]'),t=e==null?void 0:e.hasAttribute("demo-mode");let n=e==null?void 0:e.getAttribute("store-id"),s=JSON.parse((e==null?void 0:e.getAttribute("config"))||"false");return t||s||n?(n=n||"1510890315",s=s||await i.getStoreSettings(n),Salla.init(s||{debug:!0,store:{id:n}})):Salla.onReady()}static async getStoreSettings(e){let t=Salla.storage.session.get(`store-settings-${e}`);return t||(t=(await fetch("https://api.salla.dev/store/v1/store/settings",{headers:{"store-identifier":e}}).then(n=>n.json())).data,Salla.storage.session.set(`store-settings-${e}`,t),t)}static makeSureSallaIsReady(){return window.Salla?Promise.resolve(i.initializeSalla()):new Promise((e,t)=>{let n;const s=setTimeout(()=>{window.clearInterval(n),t(new Error("Timeout: Salla object not found after 10 seconds"))},1e4);n=window.setInterval(()=>{window.Salla&&(window.clearInterval(n),clearTimeout(s),e(i.initializeSalla()))},50)})}}var h=Object.defineProperty,m=(l,e,t,n)=>{for(var s=void 0,a=l.length-1,r;a>=0;a--)(r=l[a])&&(s=r(e,t,s)||s);return s&&h(e,t,s),s};const c=class c extends u.LitElement{constructor(){super(...arguments),this.key="",this.data={},this.imports={},this.shadowRootMode="open"}createRenderRoot(){return this.shadowRootMode!==!1?this.attachShadow({mode:this.shadowRootMode||"closed"}):this}static register(e){const t={component:this,dynamicTagName:`${e}-${Math.random().toString(36).substring(2,8)}`};return i.onBundlesReady().then(()=>Salla.bundles.registerComponent(e,t))}};c.styles=u.css`:host { display: block; }`;let o=c;m([d.property()],o.prototype,"key");m([d.property()],o.prototype,"data");m([d.property()],o.prototype,"imports");m([d.property()],o.prototype,"shadowRootMode");class g extends HTMLElement{connectedCallback(){var t;let e=(t=this.getAttribute("component-name"))==null?void 0:t.replace(/^salla-/,"");if(!e)return Salla.error("Component name is required",this),Promise.resolve();this.innerHTML=`<!-- Loading ${e} -->`,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("lit"),d=require("lit/decorators.js");class i{static onBundlesReady(){return i.makeSureSallaIsReady().then(()=>Salla.event.onlyWhen("twilight-bundles::initiated")).then(()=>Salla.lang.onLoaded())}static async initializeSalla(){if(Salla.status==="ready"){salla.log("Salla is ready");return}const e=document.currentScript||document.querySelector('script[src*="twilight-bundles.js"]'),t=e==null?void 0:e.hasAttribute("demo-mode");let n=e==null?void 0:e.getAttribute("store-id"),s=JSON.parse((e==null?void 0:e.getAttribute("config"))||"false");return t||s||n?(n=n||"1510890315",s=s||await i.getStoreSettings(n),Salla.init(s||{debug:!0,store:{id:n}})):Salla.onReady()}static async getStoreSettings(e){let t=Salla.storage.session.get(`store-settings-${e}`);return t||(t=(await fetch("https://api.salla.dev/store/v1/store/settings",{headers:{"store-identifier":e}}).then(n=>n.json())).data,Salla.storage.session.set(`store-settings-${e}`,t),t)}static makeSureSallaIsReady(){return window.Salla?Promise.resolve(i.initializeSalla()):new Promise((e,t)=>{let n;const s=setTimeout(()=>{window.clearInterval(n),t(new Error("Timeout: Salla object not found after 10 seconds"))},1e4);n=window.setInterval(()=>{window.Salla&&(window.clearInterval(n),clearTimeout(s),e(i.initializeSalla()))},50)})}}var h=Object.defineProperty,m=(l,e,t,n)=>{for(var s=void 0,a=l.length-1,r;a>=0;a--)(r=l[a])&&(s=r(e,t,s)||s);return s&&h(e,t,s),s};const c=class c extends u.LitElement{constructor(){super(...arguments),this.key="",this.data={},this.imports={},this.shadowRootMode="open"}createRenderRoot(){return this.shadowRootMode!==!1?this.attachShadow({mode:this.shadowRootMode||"closed"}):this}static register(e){const t={component:this,dynamicTagName:`${e}-${Math.random().toString(36).substring(2,8)}`};return i.onBundlesReady().then(()=>Salla.bundles.registerComponent(e,t))}};c.styles=u.css`:host { display: block; }`;let o=c;m([d.property()],o.prototype,"key");m([d.property()],o.prototype,"data");m([d.property()],o.prototype,"imports");m([d.property()],o.prototype,"shadowRootMode");class g extends HTMLElement{connectedCallback(){var t;let e=(t=this.getAttribute("component-name"))==null?void 0:t.replace(/^salla-/,"");if(!e)return Salla.error("Component name is required",this),Promise.resolve();this.innerHTML=`<!-- Loading ${e} -->`,Salla.bundles.renderCustomComponentDom(`salla-${e}`,this)}}class S{constructor(){this.components=new Map,this.pendingComponents=[],this.initialized=!1,Salla.onReady().then(()=>{if(Salla.bundles){Salla.log("TwilightBundles is already initialized");return}this.init(),Salla.bundles=this,Salla.event.emit("twilight-bundles::initiated"),this.registerCustomComponents()})}async init(){this.initialized||(this.initialized=!0)}registerCustomComponents(){HTMLElement.registerSallaComponent=function(e){Salla.bundles.registerComponent(e,{component:this,dynamicTagName:`${e}-${Math.random().toString(36).substring(2,8)}`})},this.injectBundleScript(window.customComponents||[])}injectBundleScript(e){e==null||e.forEach(t=>{if(document.querySelector(`script[src="${t}"]`)){Salla.log("Script already exists",t);return}const n=document.createElement("script");n.type="module",n.src=t,document.head.appendChild(n)})}renderCustomComponentDom(e,t){Salla.log("Rendering custom component",e);const n=this.components.get(e);if(n)return this.renderDynamicCustomComponentDom(n.dynamicTagName,t);this.pendingComponents.push({tagName:e,component:t});const s=t.getAttribute("version"),a=t.getAttribute("assets");if(a){this.injectBundleScript(a.split(",").map(p=>this.appendVersion(p,s)));return}const r=t.getAttribute("bundle-id");if(r){this.injectBundleScript([this.appendVersion(this.getAssetForComponent(r,e.replace(/^salla-/,"")),s)]);return}}appendVersion(e,t){if(!t)return e;const n=e.includes("?")?"&":"?";return`${e}${n}ver=${t}`}getAssetForComponent(e,t){var n,s;return(s=(n=Salla.config.get("theme.bundle_assets","https://cdn.assets.salla.network/themes/:bundle/latest/:component.js"))==null?void 0:n.replace(":bundle",e))==null?void 0:s.replace(":component",t)}renderDynamicCustomComponentDom(e,t){const n=document.createElement(e);Array.from(t.attributes).forEach(s=>n.setAttribute(s.name,s.value||"")),t.before(n),t.remove()}registerComponent(e,t){if(this.components.has(e))return console.warn(`Component ${e} is already registered into the this.components map. Skipping.`);if(!t.dynamicTagName)return console.warn(`Component ${e} is missing dynamicTagName. Skipping.`);if(!t.component)return console.warn(`Component ${e} is missing component. Skipping.`);if(window.customElements.get(t.dynamicTagName))return console.warn(`Component ${t.dynamicTagName} is already registered into the window custom elements. Skipping.`);window.customElements.define(t.dynamicTagName,t.component),this.components.set(e,t),Salla.log("Component registered:",t.dynamicTagName);const n=this.pendingComponents.filter(s=>s.tagName===e);n.length&&(n.forEach(s=>{this.renderDynamicCustomComponentDom(t.dynamicTagName,s.component)}),this.pendingComponents=this.pendingComponents.filter(s=>s.tagName!==e),Salla.log("Pending Components rendered:",e,t.dynamicTagName))}renderSharedAssests(...e){const t={sallaicons:`<link rel="stylesheet" href="${Salla.url.cdn("fonts/sallaicons.css")}">`};return e.map(n=>t[n]||"").join("")}}i.makeSureSallaIsReady().then(()=>new S).then(()=>window.customElements.get("salla-custom-component")||window.customElements.define("salla-custom-component",g));exports.SallaComponent=o;
|
package/dist/twilight-bundles.js
CHANGED
|
@@ -72,7 +72,7 @@ class S extends HTMLElement {
|
|
|
72
72
|
let e = (t = this.getAttribute("component-name")) == null ? void 0 : t.replace(/^salla-/, "");
|
|
73
73
|
if (!e)
|
|
74
74
|
return Salla.error("Component name is required", this), Promise.resolve();
|
|
75
|
-
this.innerHTML = `<!-- Loading ${e} -->`,
|
|
75
|
+
this.innerHTML = `<!-- Loading ${e} -->`, Salla.bundles.renderCustomComponentDom(`salla-${e}`, this);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
class f {
|
package/package.json
CHANGED