@schukai/monster 3.27.0 → 3.29.0
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -295,25 +295,45 @@ class CustomElement extends HTMLElement {
|
|
295
295
|
* Before you can use this method, you must have loaded the translations.
|
296
296
|
*
|
297
297
|
* @returns {Monster.DOM.CustomElement}
|
298
|
+
* @throws {Error} Cannot find element with translations. Add a translations object to the document.
|
298
299
|
*/
|
299
300
|
updateI18n() {
|
300
|
-
|
301
301
|
const translations = getDocumentTranslations();
|
302
302
|
if (!translations) {
|
303
303
|
return this;
|
304
304
|
}
|
305
305
|
|
306
|
-
|
307
|
-
if (!isIterable(labels)) {
|
306
|
+
let labels = this.getOption("labels");
|
307
|
+
if (!(isObject(labels) || isIterable(labels))) {
|
308
308
|
return this;
|
309
309
|
}
|
310
310
|
|
311
311
|
for (const key in labels) {
|
312
|
-
const
|
313
|
-
|
314
|
-
|
312
|
+
const def = labels[key];
|
313
|
+
|
314
|
+
if (isString(def)) {
|
315
|
+
const text = translations.getText(key, def);
|
316
|
+
if (text !== def) {
|
317
|
+
this.setOption("labels." + key, text);
|
318
|
+
}
|
319
|
+
continue;
|
320
|
+
} else if (isObject(def)) {
|
321
|
+
for (const k in def) {
|
322
|
+
const d = def[k];
|
323
|
+
|
324
|
+
const text = translations.getPluralRuleText(key, k, d);
|
325
|
+
if (!isString(text)) {
|
326
|
+
throw new Error("Invalid labels definition");
|
327
|
+
}
|
328
|
+
if (text !== d) {
|
329
|
+
this.setOption("labels." + key + "." + k, text);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
continue;
|
315
333
|
}
|
316
334
|
|
335
|
+
throw new Error("Invalid labels definition");
|
336
|
+
|
317
337
|
}
|
318
338
|
return this;
|
319
339
|
}
|
@@ -973,10 +993,10 @@ function registerCustomElement(element) {
|
|
973
993
|
if (customElements === undefined) {
|
974
994
|
throw new Error("customElements is not supported.");
|
975
995
|
}
|
976
|
-
|
996
|
+
|
977
997
|
if (customElements.get(element.getTag()) !== undefined) {
|
978
998
|
return;
|
979
999
|
}
|
980
|
-
|
1000
|
+
|
981
1001
|
customElements.define(element.getTag(), element);
|
982
1002
|
}
|
package/source/dom/events.mjs
CHANGED
@@ -33,9 +33,11 @@ function fireEvent(element, type) {
|
|
33
33
|
return;
|
34
34
|
}
|
35
35
|
|
36
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Event/Event
|
36
37
|
let event = new Event(validateString(type), {
|
37
38
|
bubbles: true,
|
38
39
|
cancelable: true,
|
40
|
+
composed: true,
|
39
41
|
});
|
40
42
|
|
41
43
|
element.dispatchEvent(event);
|
@@ -72,6 +74,7 @@ function fireCustomEvent(element, type, detail) {
|
|
72
74
|
let event = new CustomEvent(validateString(type), {
|
73
75
|
bubbles: true,
|
74
76
|
cancelable: true,
|
77
|
+
composed: true,
|
75
78
|
detail,
|
76
79
|
});
|
77
80
|
|
@@ -104,7 +104,7 @@ class Translations extends Base {
|
|
104
104
|
} else {
|
105
105
|
count = validateInteger(count);
|
106
106
|
if (count === 0) {
|
107
|
-
// special
|
107
|
+
// special handling for zero count
|
108
108
|
if (r.hasOwnProperty("zero")) {
|
109
109
|
return validateString(r["zero"]);
|
110
110
|
}
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED