@everymatrix/general-styling-wrapper 1.73.2 → 1.74.1

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.
@@ -10,21 +10,22 @@ const mergeTranslations = (url, target) => {
10
10
  .then((res) => res.json())
11
11
  .then((data) => {
12
12
  Object.keys(data).forEach((item) => {
13
- target[item] = target[item] || target['en'];
13
+ target[item] = target[item] || Object.assign({}, target['en']);
14
14
  Object.keys(data[item]).forEach((key) => {
15
15
  //if there is not key in target, do nothing
16
16
  if (!target['en'][key]) {
17
17
  return;
18
18
  }
19
- // if the key is not in target, then take from en
20
- target[item][key] = target[item][key] || target['en'][key];
19
+ const defaultTranslation = target['en'][key];
21
20
  if (typeof data[item][key] === 'object') {
21
+ // if the key is not in target, then take from en
22
+ target[item][key] = target[item][key] || Object.assign({}, defaultTranslation);
22
23
  Object.keys(data[item][key]).forEach((subKey) => {
23
24
  target[item][key][subKey] = data[item][key][subKey];
24
25
  });
25
26
  }
26
27
  else {
27
- target[item][key] = data[item][key];
28
+ target[item][key] = data[item][key] || defaultTranslation;
28
29
  }
29
30
  });
30
31
  });
@@ -4,21 +4,22 @@ export const mergeTranslations = (url, target) => {
4
4
  .then((res) => res.json())
5
5
  .then((data) => {
6
6
  Object.keys(data).forEach((item) => {
7
- target[item] = target[item] || target['en'];
7
+ target[item] = target[item] || Object.assign({}, target['en']);
8
8
  Object.keys(data[item]).forEach((key) => {
9
9
  //if there is not key in target, do nothing
10
10
  if (!target['en'][key]) {
11
11
  return;
12
12
  }
13
- // if the key is not in target, then take from en
14
- target[item][key] = target[item][key] || target['en'][key];
13
+ const defaultTranslation = target['en'][key];
15
14
  if (typeof data[item][key] === 'object') {
15
+ // if the key is not in target, then take from en
16
+ target[item][key] = target[item][key] || Object.assign({}, defaultTranslation);
16
17
  Object.keys(data[item][key]).forEach((subKey) => {
17
18
  target[item][key][subKey] = data[item][key][subKey];
18
19
  });
19
20
  }
20
21
  else {
21
- target[item][key] = data[item][key];
22
+ target[item][key] = data[item][key] || defaultTranslation;
22
23
  }
23
24
  });
24
25
  });
@@ -6,21 +6,22 @@ const mergeTranslations = (url, target) => {
6
6
  .then((res) => res.json())
7
7
  .then((data) => {
8
8
  Object.keys(data).forEach((item) => {
9
- target[item] = target[item] || target['en'];
9
+ target[item] = target[item] || Object.assign({}, target['en']);
10
10
  Object.keys(data[item]).forEach((key) => {
11
11
  //if there is not key in target, do nothing
12
12
  if (!target['en'][key]) {
13
13
  return;
14
14
  }
15
- // if the key is not in target, then take from en
16
- target[item][key] = target[item][key] || target['en'][key];
15
+ const defaultTranslation = target['en'][key];
17
16
  if (typeof data[item][key] === 'object') {
17
+ // if the key is not in target, then take from en
18
+ target[item][key] = target[item][key] || Object.assign({}, defaultTranslation);
18
19
  Object.keys(data[item][key]).forEach((subKey) => {
19
20
  target[item][key][subKey] = data[item][key][subKey];
20
21
  });
21
22
  }
22
23
  else {
23
- target[item][key] = data[item][key];
24
+ target[item][key] = data[item][key] || defaultTranslation;
24
25
  }
25
26
  });
26
27
  });
@@ -1 +1 @@
1
- import{r as t,h as i,g as n}from"./index-7ef90fae.js";function e(t,i){if(t){const n=document.createElement("style");n.innerHTML=i,t.appendChild(n)}}function s(t,i){const n=new URL(i);fetch(n.href).then((t=>t.text())).then((i=>{const n=document.createElement("style");n.innerHTML=i,t&&t.appendChild(n)})).catch((t=>{console.error("There was an error while trying to load client styling from URL",t)}))}const h=class{constructor(i){t(this,i),this.stylingAppends=!1,this.clientStyling="",this.clientStylingUrl="",this.mbSource=void 0,this.translationUrl="",this.targetTranslations=void 0}componentDidLoad(){this.el&&(null!=window.emMessageBus?function(t,i){if(window.emMessageBus){const n=document.createElement("style");window.emMessageBus.subscribe(i,(i=>{n.innerHTML=i,t&&t.appendChild(n)}))}}(this.el,`${this.mbSource}.Style`):(this.clientStyling&&e(this.el,this.clientStyling),this.clientStylingUrl&&s(this.el,this.clientStylingUrl),this.stylingAppends=!0))}disconnectedCallback(){this.stylingSubscription&&this.stylingSubscription.unsubscribe()}handleClientStylingChange(t,i){t!=i&&e(this.el,this.clientStyling)}handleClientStylingUrlChange(t,i){t!=i&&this.clientStylingUrl&&s(this.el,this.clientStylingUrl)}componentDidRender(){this.stylingAppends||(this.clientStyling&&e(this.el,this.clientStyling),this.clientStylingUrl&&s(this.el,this.clientStylingUrl),this.stylingAppends=!0)}async componentWillLoad(){const t=[];if(this.translationUrl){const e=(i=this.translationUrl,n=this.targetTranslations,new Promise((t=>{fetch(i).then((t=>t.json())).then((i=>{Object.keys(i).forEach((t=>{n[t]=n[t]||n.en,Object.keys(i[t]).forEach((e=>{n.en[e]&&(n[t][e]=n[t][e]||n.en[e],"object"==typeof i[t][e]?Object.keys(i[t][e]).forEach((s=>{n[t][e][s]=i[t][e][s]})):n[t][e]=i[t][e])}))})),t(!0)})).catch((i=>{console.error("Failed to load translations:",i),t(!1)}))})));t.push(e)}var i,n;return await Promise.all(t)}render(){return i("div",{key:"09ad83748bbad518743c8671b986c541c52bf3f0",class:"StyleShell"},i("slot",{key:"3b28b776d3944410c717b002b70946d274a4e8e7",name:"mainContent"}))}get el(){return n(this)}static get watchers(){return{clientStyling:["handleClientStylingChange"],clientStylingUrl:["handleClientStylingUrlChange"]}}};h.style=":host{display:block}";export{h as general_styling_wrapper}
1
+ import{r as t,h as i,g as e}from"./index-7ef90fae.js";function n(t,i){if(t){const e=document.createElement("style");e.innerHTML=i,t.appendChild(e)}}function s(t,i){const e=new URL(i);fetch(e.href).then((t=>t.text())).then((i=>{const e=document.createElement("style");e.innerHTML=i,t&&t.appendChild(e)})).catch((t=>{console.error("There was an error while trying to load client styling from URL",t)}))}const o=class{constructor(i){t(this,i),this.stylingAppends=!1,this.clientStyling="",this.clientStylingUrl="",this.mbSource=void 0,this.translationUrl="",this.targetTranslations=void 0}componentDidLoad(){this.el&&(null!=window.emMessageBus?function(t,i){if(window.emMessageBus){const e=document.createElement("style");window.emMessageBus.subscribe(i,(i=>{e.innerHTML=i,t&&t.appendChild(e)}))}}(this.el,`${this.mbSource}.Style`):(this.clientStyling&&n(this.el,this.clientStyling),this.clientStylingUrl&&s(this.el,this.clientStylingUrl),this.stylingAppends=!0))}disconnectedCallback(){this.stylingSubscription&&this.stylingSubscription.unsubscribe()}handleClientStylingChange(t,i){t!=i&&n(this.el,this.clientStyling)}handleClientStylingUrlChange(t,i){t!=i&&this.clientStylingUrl&&s(this.el,this.clientStylingUrl)}componentDidRender(){this.stylingAppends||(this.clientStyling&&n(this.el,this.clientStyling),this.clientStylingUrl&&s(this.el,this.clientStylingUrl),this.stylingAppends=!0)}async componentWillLoad(){const t=[];if(this.translationUrl){const n=(i=this.translationUrl,e=this.targetTranslations,new Promise((t=>{fetch(i).then((t=>t.json())).then((i=>{Object.keys(i).forEach((t=>{e[t]=e[t]||Object.assign({},e.en),Object.keys(i[t]).forEach((n=>{if(!e.en[n])return;const s=e.en[n];"object"==typeof i[t][n]?(e[t][n]=e[t][n]||Object.assign({},s),Object.keys(i[t][n]).forEach((s=>{e[t][n][s]=i[t][n][s]}))):e[t][n]=i[t][n]||s}))})),t(!0)})).catch((i=>{console.error("Failed to load translations:",i),t(!1)}))})));t.push(n)}var i,e;return await Promise.all(t)}render(){return i("div",{key:"09ad83748bbad518743c8671b986c541c52bf3f0",class:"StyleShell"},i("slot",{key:"3b28b776d3944410c717b002b70946d274a4e8e7",name:"mainContent"}))}get el(){return e(this)}static get watchers(){return{clientStyling:["handleClientStylingChange"],clientStylingUrl:["handleClientStylingUrlChange"]}}};o.style=":host{display:block}";export{o as general_styling_wrapper}
@@ -1,5 +1,5 @@
1
1
  interface Translation {
2
- [key: string]: string;
2
+ [key: string]: string | Translation;
3
3
  }
4
4
  export interface Translations {
5
5
  [key: string]: Translation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/general-styling-wrapper",
3
- "version": "1.73.2",
3
+ "version": "1.74.1",
4
4
  "main": "./dist/index.cjs.js",
5
5
  "module": "./dist/index.js",
6
6
  "es2015": "./dist/esm/index.mjs",