@salla.sa/twilight-bundles 0.1.39 → 0.1.40

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"),l=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 p=Object.defineProperty,d=(r,e,t,n)=>{for(var s=void 0,a=r.length-1,c;a>=0;a--)(c=r[a])&&(s=c(e,t,s)||s);return s&&p(e,t,s),s};const m=class m 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))}};m.styles=u.css`:host { display: block; }`;let o=m;d([l.property()],o.prototype,"key");d([l.property()],o.prototype,"data");d([l.property()],o.prototype,"imports");d([l.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} -->`,this.removeAttribute("component-name"),Salla.bundles.renderCustomComponentDom(`salla-${e}`,this)}}class h{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("assets");if(s)return this.injectBundleScript(s.split(","));const a=t.getAttribute("bundle-id");if(a)return this.injectBundleScript([this.getAssetForComponent(a,e.replace(/^salla-/,""))])}getAssetForComponent(e,t){var n,s;return(s=(n=Salla.config.get("theme.bundle_assets"))==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 h).then(()=>window.customElements.get("salla-custom-component")||window.customElements.define("salla-custom-component",g));exports.SallaComponent=o;
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} -->`,this.removeAttribute("component-name"),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;
@@ -1,5 +1,5 @@
1
- import { LitElement as u, css as p } from "lit";
2
- import { property as l } from "lit/decorators.js";
1
+ import { LitElement as p, css as h } from "lit";
2
+ import { property as d } from "lit/decorators.js";
3
3
  class i {
4
4
  static onBundlesReady() {
5
5
  return i.makeSureSallaIsReady().then(() => Salla.event.onlyWhen("twilight-bundles::initiated")).then(() => Salla.lang.onLoaded());
@@ -32,12 +32,12 @@ class i {
32
32
  });
33
33
  }
34
34
  }
35
- var h = Object.defineProperty, d = (r, e, t, n) => {
36
- for (var s = void 0, o = r.length - 1, c; o >= 0; o--)
37
- (c = r[o]) && (s = c(e, t, s) || s);
38
- return s && h(e, t, s), s;
35
+ var g = Object.defineProperty, m = (l, e, t, n) => {
36
+ for (var s = void 0, o = l.length - 1, r; o >= 0; o--)
37
+ (r = l[o]) && (s = r(e, t, s) || s);
38
+ return s && g(e, t, s), s;
39
39
  };
40
- const m = class m extends u {
40
+ const c = class c extends p {
41
41
  constructor() {
42
42
  super(...arguments), this.key = "", this.data = {}, this.imports = {}, this.shadowRootMode = "open";
43
43
  }
@@ -52,21 +52,21 @@ const m = class m extends u {
52
52
  return i.onBundlesReady().then(() => Salla.bundles.registerComponent(e, t));
53
53
  }
54
54
  };
55
- m.styles = p`:host { display: block; }`;
56
- let a = m;
57
- d([
58
- l()
55
+ c.styles = h`:host { display: block; }`;
56
+ let a = c;
57
+ m([
58
+ d()
59
59
  ], a.prototype, "key");
60
- d([
61
- l()
60
+ m([
61
+ d()
62
62
  ], a.prototype, "data");
63
- d([
64
- l()
63
+ m([
64
+ d()
65
65
  ], a.prototype, "imports");
66
- d([
67
- l()
66
+ m([
67
+ d()
68
68
  ], a.prototype, "shadowRootMode");
69
- class g extends HTMLElement {
69
+ class S extends HTMLElement {
70
70
  connectedCallback() {
71
71
  var t;
72
72
  let e = (t = this.getAttribute("component-name")) == null ? void 0 : t.replace(/^salla-/, "");
@@ -75,7 +75,7 @@ class g extends HTMLElement {
75
75
  this.innerHTML = `<!-- Loading ${e} -->`, this.removeAttribute("component-name"), Salla.bundles.renderCustomComponentDom(`salla-${e}`, this);
76
76
  }
77
77
  }
78
- class S {
78
+ class f {
79
79
  constructor() {
80
80
  this.components = /* @__PURE__ */ new Map(), this.pendingComponents = [], this.initialized = !1, Salla.onReady().then(() => {
81
81
  if (Salla.bundles) {
@@ -116,16 +116,25 @@ class S {
116
116
  if (n)
117
117
  return this.renderDynamicCustomComponentDom(n.dynamicTagName, t);
118
118
  this.pendingComponents.push({ tagName: e, component: t });
119
- const s = t.getAttribute("assets");
120
- if (s)
121
- return this.injectBundleScript(s.split(","));
122
- const o = t.getAttribute("bundle-id");
123
- if (o)
124
- return this.injectBundleScript([this.getAssetForComponent(o, e.replace(/^salla-/, ""))]);
119
+ const s = t.getAttribute("version"), o = t.getAttribute("assets");
120
+ if (o) {
121
+ this.injectBundleScript(o.split(",").map((u) => this.appendVersion(u, s)));
122
+ return;
123
+ }
124
+ const r = t.getAttribute("bundle-id");
125
+ if (r) {
126
+ this.injectBundleScript([this.appendVersion(this.getAssetForComponent(r, e.replace(/^salla-/, "")), s)]);
127
+ return;
128
+ }
129
+ }
130
+ appendVersion(e, t) {
131
+ if (!t) return e;
132
+ const n = e.includes("?") ? "&" : "?";
133
+ return `${e}${n}ver=${t}`;
125
134
  }
126
135
  getAssetForComponent(e, t) {
127
136
  var n, s;
128
- return (s = (n = Salla.config.get("theme.bundle_assets")) == null ? void 0 : n.replace(":bundle", e)) == null ? void 0 : s.replace(":component", t);
137
+ 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);
129
138
  }
130
139
  renderDynamicCustomComponentDom(e, t) {
131
140
  const n = document.createElement(e);
@@ -153,7 +162,7 @@ class S {
153
162
  return e.map((n) => t[n] || "").join("");
154
163
  }
155
164
  }
156
- i.makeSureSallaIsReady().then(() => new S()).then(() => window.customElements.get("salla-custom-component") || window.customElements.define("salla-custom-component", g));
165
+ i.makeSureSallaIsReady().then(() => new f()).then(() => window.customElements.get("salla-custom-component") || window.customElements.define("salla-custom-component", S));
157
166
  export {
158
167
  a as SallaComponent
159
168
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/twilight-bundles",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
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",