@salla.sa/twilight-bundles 0.1.34 → 0.1.35

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.
@@ -20,4 +20,4 @@
20
20
  * @license
21
21
  * Copyright 2017 Google LLC
22
22
  * SPDX-License-Identifier: BSD-3-Clause
23
- */const Ut={attribute:!0,type:String,converter:k,reflect:!1,hasChanged:K},Ot=(n=Ut,t,e)=>{const{kind:s,metadata:i}=e;let r=globalThis.litPropertyMetadata.get(i);if(r===void 0&&globalThis.litPropertyMetadata.set(i,r=new Map),s==="setter"&&((n=Object.create(n)).wrapped=!0),r.set(e.name,n),s==="accessor"){const{name:o}=e;return{set(l){const a=t.get.call(this);t.set.call(this,l),this.requestUpdate(o,a,n)},init(l){return l!==void 0&&this.C(o,void 0,n,l),l}}}if(s==="setter"){const{name:o}=e;return function(l){const a=this[o];t.call(this,l),this.requestUpdate(o,a,n)}}throw Error("Unsupported decorator location: "+s)};function z(n){return(t,e)=>typeof e=="object"?Ot(n,t,e):((s,i,r)=>{const o=i.hasOwnProperty(r);return i.constructor.createProperty(r,s),o?Object.getOwnPropertyDescriptor(i,r):void 0})(n,t,e)}class y{static onBundlesReady(){return y.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 t=document.currentScript||document.querySelector('script[src*="twilight-bundles.js"]'),e=t==null?void 0:t.hasAttribute("demo-mode");let s=t==null?void 0:t.getAttribute("store-id"),i=JSON.parse((t==null?void 0:t.getAttribute("config"))||"false");return e||i||s?(s=s||"1510890315",i=i||await y.getStoreSettings(s),Salla.init(i||{debug:!0,store:{id:s}})):Salla.onReady()}static async getStoreSettings(t){let e=Salla.storage.session.get(`store-settings-${t}`);return e||(e=(await fetch("https://api.salla.dev/store/v1/store/settings",{headers:{"store-identifier":t}}).then(s=>s.json())).data,Salla.storage.session.set(`store-settings-${t}`,e),e)}static makeSureSallaIsReady(){return window.Salla?Promise.resolve(y.initializeSalla()):new Promise((t,e)=>{let s;const i=setTimeout(()=>{window.clearInterval(s),e(new Error("Timeout: Salla object not found after 10 seconds"))},1e4);s=window.setInterval(()=>{window.Salla&&(window.clearInterval(s),clearTimeout(i),t(y.initializeSalla()))},50)})}}var Rt=Object.defineProperty,L=(n,t,e,s)=>{for(var i=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=o(t,e,i)||i);return i&&Rt(t,e,i),i};const F=class F extends M{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(t){const e={component:this,dynamicTagName:`${t}-${Math.random().toString(36).substring(2,8)}`};return y.onBundlesReady().then(()=>Salla.bundles.registerComponent(t,e))}};F.styles=pt`:host { display: block; }`;let v=F;L([z()],v.prototype,"key");L([z()],v.prototype,"data");L([z()],v.prototype,"imports");L([z()],v.prototype,"shadowRootMode");class Ht extends HTMLElement{connectedCallback(){var e;let t=(e=this.getAttribute("component-name"))==null?void 0:e.replace(/^salla-/,"");if(!t)return Salla.error("Component name is required",this),Promise.resolve();this.innerHTML=`<!-- Loading ${t} -->`,this.removeAttribute("component-name"),Salla.bundles.renderCustomComponentDom(`salla-${t}`,this)}}class Nt{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(t){Salla.bundles.registerComponent(t,{component:this,dynamicTagName:`${t}-${Math.random().toString(36).substring(2,8)}`})},this.injectBundleScript(window.customComponents)}injectBundleScript(t){t.forEach(e=>{if(document.querySelector(`script[src="${e}"]`)){Salla.log("Script already exists",e);return}const s=document.createElement("script");s.type="module",s.src=e,document.head.appendChild(s)})}renderCustomComponentDom(t,e){Salla.log("Rendering custom component",t);const s=this.components.get(t);if(s)return this.renderDynamicCustomComponentDom(s.dynamicTagName,e);this.pendingComponents.push({tagName:t,component:e});const i=e.getAttribute("assets");i&&this.injectBundleScript(i.split(","))}renderDynamicCustomComponentDom(t,e){const s=document.createElement(t);Array.from(e.attributes).forEach(i=>s.setAttribute(i.name,i.value||"")),e.before(s),e.remove()}registerComponent(t,e){if(this.components.has(t))return console.warn(`Component ${t} is already registered into the this.components map. Skipping.`);if(!e.dynamicTagName)return console.warn(`Component ${t} is missing dynamicTagName. Skipping.`);if(!e.component)return console.warn(`Component ${t} is missing component. Skipping.`);if(window.customElements.get(e.dynamicTagName))return console.warn(`Component ${e.dynamicTagName} is already registered into the window custom elements. Skipping.`);window.customElements.define(e.dynamicTagName,e.component),this.components.set(t,e),Salla.log("Component registered:",e.dynamicTagName);const s=this.pendingComponents.filter(i=>i.tagName===t);s.length&&(s.forEach(i=>{this.renderDynamicCustomComponentDom(e.dynamicTagName,i.component)}),this.pendingComponents=this.pendingComponents.filter(i=>i.tagName!==t),Salla.log("Pending Components rendered:",t,e.dynamicTagName))}renderSharedAssests(...t){const e={sallaicons:`<link rel="stylesheet" href="${Salla.url.cdn("fonts/sallaicons.css")}">`};return t.map(s=>e[s]||"").join("")}}y.makeSureSallaIsReady().then(()=>new Nt).then(()=>window.customElements.get("salla-custom-component")||window.customElements.define("salla-custom-component",Ht));exports.SallaComponent=v;
23
+ */const Ut={attribute:!0,type:String,converter:k,reflect:!1,hasChanged:K},Ot=(n=Ut,t,e)=>{const{kind:s,metadata:i}=e;let r=globalThis.litPropertyMetadata.get(i);if(r===void 0&&globalThis.litPropertyMetadata.set(i,r=new Map),s==="setter"&&((n=Object.create(n)).wrapped=!0),r.set(e.name,n),s==="accessor"){const{name:o}=e;return{set(l){const a=t.get.call(this);t.set.call(this,l),this.requestUpdate(o,a,n)},init(l){return l!==void 0&&this.C(o,void 0,n,l),l}}}if(s==="setter"){const{name:o}=e;return function(l){const a=this[o];t.call(this,l),this.requestUpdate(o,a,n)}}throw Error("Unsupported decorator location: "+s)};function z(n){return(t,e)=>typeof e=="object"?Ot(n,t,e):((s,i,r)=>{const o=i.hasOwnProperty(r);return i.constructor.createProperty(r,s),o?Object.getOwnPropertyDescriptor(i,r):void 0})(n,t,e)}class y{static onBundlesReady(){return y.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 t=document.currentScript||document.querySelector('script[src*="twilight-bundles.js"]'),e=t==null?void 0:t.hasAttribute("demo-mode");let s=t==null?void 0:t.getAttribute("store-id"),i=JSON.parse((t==null?void 0:t.getAttribute("config"))||"false");return e||i||s?(s=s||"1510890315",i=i||await y.getStoreSettings(s),Salla.init(i||{debug:!0,store:{id:s}})):Salla.onReady()}static async getStoreSettings(t){let e=Salla.storage.session.get(`store-settings-${t}`);return e||(e=(await fetch("https://api.salla.dev/store/v1/store/settings",{headers:{"store-identifier":t}}).then(s=>s.json())).data,Salla.storage.session.set(`store-settings-${t}`,e),e)}static makeSureSallaIsReady(){return window.Salla?Promise.resolve(y.initializeSalla()):new Promise((t,e)=>{let s;const i=setTimeout(()=>{window.clearInterval(s),e(new Error("Timeout: Salla object not found after 10 seconds"))},1e4);s=window.setInterval(()=>{window.Salla&&(window.clearInterval(s),clearTimeout(i),t(y.initializeSalla()))},50)})}}var Rt=Object.defineProperty,L=(n,t,e,s)=>{for(var i=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=o(t,e,i)||i);return i&&Rt(t,e,i),i};const F=class F extends M{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(t){const e={component:this,dynamicTagName:`${t}-${Math.random().toString(36).substring(2,8)}`};return y.onBundlesReady().then(()=>Salla.bundles.registerComponent(t,e))}};F.styles=pt`:host { display: block; }`;let v=F;L([z()],v.prototype,"key");L([z()],v.prototype,"data");L([z()],v.prototype,"imports");L([z()],v.prototype,"shadowRootMode");class Ht extends HTMLElement{connectedCallback(){var e;let t=(e=this.getAttribute("component-name"))==null?void 0:e.replace(/^salla-/,"");if(!t)return Salla.error("Component name is required",this),Promise.resolve();this.innerHTML=`<!-- Loading ${t} -->`,this.removeAttribute("component-name"),Salla.bundles.renderCustomComponentDom(`salla-${t}`,this)}}class Nt{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(t){Salla.bundles.registerComponent(t,{component:this,dynamicTagName:`${t}-${Math.random().toString(36).substring(2,8)}`})},this.injectBundleScript(window.customComponents||[])}injectBundleScript(t){t==null||t.forEach(e=>{if(document.querySelector(`script[src="${e}"]`)){Salla.log("Script already exists",e);return}const s=document.createElement("script");s.type="module",s.src=e,document.head.appendChild(s)})}renderCustomComponentDom(t,e){Salla.log("Rendering custom component",t);const s=this.components.get(t);if(s)return this.renderDynamicCustomComponentDom(s.dynamicTagName,e);this.pendingComponents.push({tagName:t,component:e});const i=e.getAttribute("assets");i&&this.injectBundleScript(i.split(","))}renderDynamicCustomComponentDom(t,e){const s=document.createElement(t);Array.from(e.attributes).forEach(i=>s.setAttribute(i.name,i.value||"")),e.before(s),e.remove()}registerComponent(t,e){if(this.components.has(t))return console.warn(`Component ${t} is already registered into the this.components map. Skipping.`);if(!e.dynamicTagName)return console.warn(`Component ${t} is missing dynamicTagName. Skipping.`);if(!e.component)return console.warn(`Component ${t} is missing component. Skipping.`);if(window.customElements.get(e.dynamicTagName))return console.warn(`Component ${e.dynamicTagName} is already registered into the window custom elements. Skipping.`);window.customElements.define(e.dynamicTagName,e.component),this.components.set(t,e),Salla.log("Component registered:",e.dynamicTagName);const s=this.pendingComponents.filter(i=>i.tagName===t);s.length&&(s.forEach(i=>{this.renderDynamicCustomComponentDom(e.dynamicTagName,i.component)}),this.pendingComponents=this.pendingComponents.filter(i=>i.tagName!==t),Salla.log("Pending Components rendered:",t,e.dynamicTagName))}renderSharedAssests(...t){const e={sallaicons:`<link rel="stylesheet" href="${Salla.url.cdn("fonts/sallaicons.css")}">`};return t.map(s=>e[s]||"").join("")}}y.makeSureSallaIsReady().then(()=>new Nt).then(()=>window.customElements.get("salla-custom-component")||window.customElements.define("salla-custom-component",Ht));exports.SallaComponent=v;
@@ -677,10 +677,10 @@ class Nt {
677
677
  component: this,
678
678
  dynamicTagName: `${t}-${Math.random().toString(36).substring(2, 8)}`
679
679
  });
680
- }, this.injectBundleScript(window.customComponents);
680
+ }, this.injectBundleScript(window.customComponents || []);
681
681
  }
682
682
  injectBundleScript(t) {
683
- t.forEach((e) => {
683
+ t == null || t.forEach((e) => {
684
684
  if (document.querySelector(`script[src="${e}"]`)) {
685
685
  Salla.log("Script already exists", e);
686
686
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/twilight-bundles",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "description": "SDK for Salla Twilight Bundles - Develop and build custom components for Salla platform",
5
5
  "type": "module",
6
6
  "main": "./dist/twilight-bundles.js",