@salla.sa/twilight-bundles 0.1.36 → 0.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/twilight-bundles.cjs +1 -1
- package/dist/twilight-bundles.js +27 -19
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("lit"),
|
|
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;
|
package/dist/twilight-bundles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement as u, css as p } from "lit";
|
|
2
|
-
import { property as
|
|
2
|
+
import { property as l } 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,9 +32,9 @@ class i {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
var h = Object.defineProperty,
|
|
36
|
-
for (var s = void 0,
|
|
37
|
-
(c =
|
|
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
38
|
return s && h(e, t, s), s;
|
|
39
39
|
};
|
|
40
40
|
const m = class m extends u {
|
|
@@ -53,19 +53,19 @@ const m = class m extends u {
|
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
m.styles = p`:host { display: block; }`;
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
],
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
],
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
],
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
],
|
|
56
|
+
let a = m;
|
|
57
|
+
d([
|
|
58
|
+
l()
|
|
59
|
+
], a.prototype, "key");
|
|
60
|
+
d([
|
|
61
|
+
l()
|
|
62
|
+
], a.prototype, "data");
|
|
63
|
+
d([
|
|
64
|
+
l()
|
|
65
|
+
], a.prototype, "imports");
|
|
66
|
+
d([
|
|
67
|
+
l()
|
|
68
|
+
], a.prototype, "shadowRootMode");
|
|
69
69
|
class g extends HTMLElement {
|
|
70
70
|
connectedCallback() {
|
|
71
71
|
var t;
|
|
@@ -117,7 +117,15 @@ class S {
|
|
|
117
117
|
return this.renderDynamicCustomComponentDom(n.dynamicTagName, t);
|
|
118
118
|
this.pendingComponents.push({ tagName: e, component: t });
|
|
119
119
|
const s = t.getAttribute("assets");
|
|
120
|
-
|
|
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-/, ""))]);
|
|
125
|
+
}
|
|
126
|
+
getAssetForComponent(e, t) {
|
|
127
|
+
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);
|
|
121
129
|
}
|
|
122
130
|
renderDynamicCustomComponentDom(e, t) {
|
|
123
131
|
const n = document.createElement(e);
|
|
@@ -147,5 +155,5 @@ class S {
|
|
|
147
155
|
}
|
|
148
156
|
i.makeSureSallaIsReady().then(() => new S()).then(() => window.customElements.get("salla-custom-component") || window.customElements.define("salla-custom-component", g));
|
|
149
157
|
export {
|
|
150
|
-
|
|
158
|
+
a as SallaComponent
|
|
151
159
|
};
|
package/package.json
CHANGED