@schukai/monster 4.13.1 → 4.14.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
 
4
4
 
5
+ ## [4.14.0] - 2025-06-04
6
+
7
+ ### Add Features
8
+
9
+ - Add i18n support in CustomElement template formatting
10
+
11
+
12
+
5
13
  ## [4.13.1] - 2025-06-03
6
14
 
7
15
  ### Bug Fixes
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.1","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.13.1"}
1
+ {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.1","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.14.0"}
@@ -297,6 +297,7 @@ class CustomElement extends HTMLElement {
297
297
  * @property {Object} templateFormatter.marker Specifies the marker for the templates.
298
298
  * @property {Function} templateFormatter.marker.open=null Specifies the opening marker for the templates.
299
299
  * @property {Function} templateFormatter.marker.close=null Specifies the closing marker for the templates.
300
+ * @property {Boolean} templateFormatter.i18n=false Specifies whether the templates should be formatted with i18n.
300
301
  * @property {Boolean} eventProcessing=false Specifies whether the control processes events.
301
302
  * @since 1.8.0
302
303
  */
@@ -314,6 +315,7 @@ class CustomElement extends HTMLElement {
314
315
  open: null,
315
316
  close: null,
316
317
  },
318
+ i18n : false,
317
319
  },
318
320
 
319
321
  eventProcessing: false,
@@ -1075,6 +1077,27 @@ function parseOptionsJSON(data) {
1075
1077
  return validateObject(obj);
1076
1078
  }
1077
1079
 
1080
+ /**
1081
+ * @private
1082
+ * @param html
1083
+ * @returns {*|string}
1084
+ */
1085
+ function substituteI18n(html) {
1086
+
1087
+ if(!this.getOption("templateFormatter.i18n", false)) {
1088
+ return html;
1089
+ }
1090
+
1091
+ const labels = this.getOption("labels", {});
1092
+ if (!(isObject(labels) || isIterable(labels))) {
1093
+ return html;
1094
+ }
1095
+
1096
+ const formatter = new Formatter(labels, {});
1097
+ formatter.setMarker("i18n{", '}')
1098
+ return formatter.format(html);
1099
+ }
1100
+
1078
1101
  /**
1079
1102
  * @private
1080
1103
  * @return {initHtmlContent}
@@ -1090,7 +1113,7 @@ function initHtmlContent() {
1090
1113
  if (isObject(mapping)) {
1091
1114
  html = new Formatter(mapping, {}).format(html);
1092
1115
  }
1093
- this.innerHTML = html;
1116
+ this.innerHTML = substituteI18n.call(this, html);
1094
1117
  }
1095
1118
  }
1096
1119
 
@@ -1194,7 +1217,7 @@ function initShadowRoot() {
1194
1217
  html = formatter.format(html);
1195
1218
  }
1196
1219
 
1197
- this.shadowRoot.innerHTML = html;
1220
+ this.shadowRoot.innerHTML = substituteI18n.call(this, html);
1198
1221
  return this;
1199
1222
  }
1200
1223
 
@@ -38,13 +38,12 @@ describe('Button', function () {
38
38
  before(function (done) {
39
39
  initJSDOM().then(() => {
40
40
 
41
- import("element-internals-polyfill").catch(e => done(e));
42
-
43
- import("../../../../source/components/form/button.mjs").then((m) => {
44
- Button = m['Button'];
45
- done()
46
- }).catch(e => done(e))
47
-
41
+ import("element-internals-polyfill").then(()=>{
42
+ import("../../../../source/components/form/button.mjs").then((m) => {
43
+ Button = m['Button'];
44
+ done()
45
+ }).catch(e => done(e))
46
+ }).catch(e => done(e));
48
47
 
49
48
  });
50
49
  })
@@ -67,7 +67,7 @@ function initJSDOM(options) {
67
67
  'InputEvent',
68
68
  'KeyboardEvent',
69
69
  'MutationObserver',
70
- 'navigator',
70
+ // 'navigator',
71
71
  'Node',
72
72
  'NodeFilter',
73
73
  'NodeList',
@@ -76,7 +76,9 @@ function initJSDOM(options) {
76
76
  'XMLSerializer',
77
77
  ].forEach(key => {
78
78
  try {
79
- g[key] = window[key]
79
+ console.log("setting key", key);
80
+
81
+ g[key] = window[key]
80
82
  } catch(e) {
81
83
  console.error("Error setting key", key, e);
82
84
  }