@schukai/monster 3.22.1 → 3.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.22.1",
3
+ "version": "3.23.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -16,7 +16,6 @@ export {
16
16
  ATTRIBUTE_UPDATER_SELECT_THIS,
17
17
  ATTRIBUTE_UPDATER_REPLACE,
18
18
  ATTRIBUTE_UPDATER_INSERT,
19
- ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID,
20
19
  ATTRIBUTE_UPDATER_INSERT_REFERENCE,
21
20
  ATTRIBUTE_UPDATER_REMOVE,
22
21
  ATTRIBUTE_UPDATER_BIND,
@@ -143,14 +142,6 @@ const ATTRIBUTE_UPDATER_REPLACE = `${ATTRIBUTE_PREFIX}replace`;
143
142
  */
144
143
  const ATTRIBUTE_UPDATER_INSERT = `${ATTRIBUTE_PREFIX}insert`;
145
144
 
146
- /**
147
- * @memberOf Monster.DOM
148
- * @type {string}
149
- * @license AGPLv3
150
- * @since 3.21.0
151
- */
152
- const ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID = `${ATTRIBUTE_UPDATER_INSERT}-template-id`;
153
-
154
145
  /**
155
146
  * @memberOf Monster.DOM
156
147
  * @type {string}
@@ -5,18 +5,18 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import { internalSymbol } from "../constants.mjs";
9
- import { extend } from "../data/extend.mjs";
10
- import { Pathfinder } from "../data/pathfinder.mjs";
8
+ import {internalSymbol} from "../constants.mjs";
9
+ import {extend} from "../data/extend.mjs";
10
+ import {Pathfinder} from "../data/pathfinder.mjs";
11
11
 
12
- import { parseDataURL } from "../types/dataurl.mjs";
13
- import { getGlobalObject } from "../types/global.mjs";
12
+ import {parseDataURL} from "../types/dataurl.mjs";
13
+ import {getGlobalObject} from "../types/global.mjs";
14
14
  import {isArray, isFunction, isIterable, isObject, isString} from "../types/is.mjs";
15
- import { Observer } from "../types/observer.mjs";
16
- import { ProxyObserver } from "../types/proxyobserver.mjs";
17
- import { validateFunction, validateInstance, validateObject, validateString } from "../types/validate.mjs";
18
- import { clone } from "../util/clone.mjs";
19
- import { addAttributeToken, getLinkedObjects, hasObjectLink } from "./attributes.mjs";
15
+ import {Observer} from "../types/observer.mjs";
16
+ import {ProxyObserver} from "../types/proxyobserver.mjs";
17
+ import {validateFunction, validateInstance, validateObject, validateString} from "../types/validate.mjs";
18
+ import {clone} from "../util/clone.mjs";
19
+ import {addAttributeToken, getLinkedObjects, hasObjectLink} from "./attributes.mjs";
20
20
  import {
21
21
  ATTRIBUTE_DISABLED,
22
22
  ATTRIBUTE_ERRORMESSAGE,
@@ -24,9 +24,9 @@ import {
24
24
  ATTRIBUTE_OPTIONS_SELECTOR,
25
25
  customElementUpdaterLinkSymbol,
26
26
  } from "./constants.mjs";
27
- import { findDocumentTemplate, Template } from "./template.mjs";
28
- import { addObjectWithUpdaterToElement } from "./updater.mjs";
29
- import { instanceSymbol } from "../constants.mjs";
27
+ import {findDocumentTemplate, Template} from "./template.mjs";
28
+ import {addObjectWithUpdaterToElement} from "./updater.mjs";
29
+ import {instanceSymbol} from "../constants.mjs";
30
30
  import {getDocumentTranslations, Translations} from "../i18n/translations.mjs";
31
31
 
32
32
  export {
@@ -267,6 +267,7 @@ class CustomElement extends HTMLElement {
267
267
  * @property {Boolean} delegatesFocus=true A boolean that, when set to true, specifies behavior that mitigates custom element issues around focusability. When a non-focusable part of the shadow DOM is clicked, the first focusable part is given focus, and the shadow host is given any available :focus styling.
268
268
  * @property {Object} templates Templates
269
269
  * @property {string} templates.main=undefined Main template
270
+ * @property {Object} templateMapping Template mapping
270
271
  *
271
272
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow
272
273
  * @since 1.8.0
@@ -279,6 +280,7 @@ class CustomElement extends HTMLElement {
279
280
  templates: {
280
281
  main: undefined,
281
282
  },
283
+ templateMapping: {},
282
284
  };
283
285
  }
284
286
 
@@ -288,7 +290,7 @@ class CustomElement extends HTMLElement {
288
290
  * The labels are defined in the options object.
289
291
  * The key of the label is used to retrieve the translation from the document.
290
292
  * If the translation is different from the label, the label is updated.
291
- *
293
+ *
292
294
  * Before you can use this method, you must have loaded the translations.
293
295
  *
294
296
  * @returns {Monster.DOM.CustomElement}
@@ -301,10 +303,10 @@ class CustomElement extends HTMLElement {
301
303
  }
302
304
 
303
305
  const labels = this.getOption("labels");
304
- if(!isIterable(labels)){
306
+ if (!isIterable(labels)) {
305
307
  return this;
306
308
  }
307
-
309
+
308
310
  for (const key in labels) {
309
311
  const text = translations.getText(key, labels[key]);
310
312
  if (text !== labels[key]) {
@@ -313,8 +315,8 @@ class CustomElement extends HTMLElement {
313
315
 
314
316
  }
315
317
  return this;
316
- }
317
-
318
+ }
319
+
318
320
  /**
319
321
  * There is no check on the name by this class. the developer is responsible for assigning an appropriate tag.
320
322
  * if the name is not valid, registerCustomElement() will issue an error
@@ -327,7 +329,7 @@ class CustomElement extends HTMLElement {
327
329
  static getTag() {
328
330
  throw new Error("the method getTag must be overwritten by the derived class.");
329
331
  }
330
-
332
+
331
333
 
332
334
  /**
333
335
  * At this point a `CSSStyleSheet` object can be returned. If the environment does not
@@ -354,7 +356,7 @@ class CustomElement extends HTMLElement {
354
356
  static getCSSStyleSheet() {
355
357
  return undefined;
356
358
  }
357
-
359
+
358
360
  /**
359
361
  * attach a new observer
360
362
  *
@@ -398,7 +400,8 @@ class CustomElement extends HTMLElement {
398
400
 
399
401
  try {
400
402
  value = new Pathfinder(this[internalSymbol].getRealSubject()["options"]).getVia(path);
401
- } catch (e) {}
403
+ } catch (e) {
404
+ }
402
405
 
403
406
  if (value === undefined) return defaultValue;
404
407
  return value;
@@ -468,7 +471,8 @@ class CustomElement extends HTMLElement {
468
471
  try {
469
472
  initShadowRoot.call(self);
470
473
  elements = self.shadowRoot.childNodes;
471
- } catch (e) {}
474
+ } catch (e) {
475
+ }
472
476
 
473
477
  try {
474
478
  initCSSStylesheet.call(this);
@@ -519,7 +523,8 @@ class CustomElement extends HTMLElement {
519
523
  * @return {void}
520
524
  * @since 1.7.0
521
525
  */
522
- disconnectedCallback() {}
526
+ disconnectedCallback() {
527
+ }
523
528
 
524
529
  /**
525
530
  * The custom element has been moved into a new document (e.g. someone called document.adoptNode(el)).
@@ -527,7 +532,8 @@ class CustomElement extends HTMLElement {
527
532
  * @return {void}
528
533
  * @since 1.7.0
529
534
  */
530
- adoptedCallback() {}
535
+ adoptedCallback() {
536
+ }
531
537
 
532
538
  /**
533
539
  * Called when an observed attribute has been added, removed, updated, or replaced. Also called for initial
@@ -816,7 +822,8 @@ function parseOptionsJSON(data) {
816
822
  try {
817
823
  let dataUrl = parseDataURL(data);
818
824
  data = dataUrl.content;
819
- } catch (e) {}
825
+ } catch (e) {
826
+ }
820
827
 
821
828
  try {
822
829
  obj = JSON.parse(data);
@@ -838,6 +845,11 @@ function initHtmlContent() {
838
845
  } catch (e) {
839
846
  let html = this.getOption("templates.main", "");
840
847
  if (isString(html) && html.length > 0) {
848
+
849
+ const mapping = this.getOption("templateMapping", {});
850
+ if (isObject(mapping)) {
851
+ html = new Formatter(mapping).format(html);
852
+ }
841
853
  this.innerHTML = html;
842
854
  }
843
855
  }
@@ -17,8 +17,7 @@ import {
17
17
  ATTRIBUTE_UPDATER_INSERT_REFERENCE,
18
18
  ATTRIBUTE_UPDATER_REMOVE,
19
19
  ATTRIBUTE_UPDATER_REPLACE,
20
- ATTRIBUTE_UPDATER_SELECT_THIS,
21
- ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID
20
+ ATTRIBUTE_UPDATER_SELECT_THIS
22
21
  } from "../dom/constants.mjs";
23
22
 
24
23
  import {Base} from "../types/base.mjs";
@@ -514,50 +513,6 @@ function insertElement(change) {
514
513
  }
515
514
  }
516
515
 
517
- /**
518
- * @private
519
- * @param container
520
- * @param key
521
- * @param ref
522
- * @param path
523
- * @returns {any}
524
- */
525
- function internalTemplateLookUp(container, key, ref, path) {
526
-
527
- let templateID = key;
528
- let template;
529
-
530
- if (container.hasAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID)) {
531
- templateID = container.getAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID);
532
- template = findDocumentTemplate(templateID, container);
533
- if (template instanceof HTMLTemplateElement) {
534
- return template;
535
- }
536
- }
537
-
538
- if (container.closest(`[${ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID}]`)) {
539
- templateID = container.closest(`[${ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID}]`).getAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID);
540
- template = findDocumentTemplate(templateID, container);
541
- if (template instanceof HTMLTemplateElement) {
542
- return template;
543
- }
544
- }
545
-
546
- const rootNode = container.getRootNode();
547
- if (rootNode instanceof ShadowRoot) {
548
- const host = rootNode?.host;
549
- if (host && host.hasAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID)) {
550
- templateID = host.getAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID);
551
- template = findDocumentTemplate(templateID, container);
552
- if (template instanceof HTMLTemplateElement) {
553
- return template;
554
- }
555
- }
556
- }
557
-
558
- return findDocumentTemplate(templateID, container);
559
- }
560
-
561
516
  /**
562
517
  *
563
518
  * @private
@@ -570,8 +525,7 @@ function internalTemplateLookUp(container, key, ref, path) {
570
525
  * @throws {Error} no template was found with the specified key.
571
526
  */
572
527
  function appendNewDocumentFragment(container, key, ref, path) {
573
-
574
- let template = internalTemplateLookUp(container, key, ref, path);
528
+ let template = findDocumentTemplate(key, container);
575
529
 
576
530
  let nodes = template.createDocumentFragment();
577
531
  for (const [, node] of Object.entries(nodes.childNodes)) {
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.22.1");
145
+ monsterVersion = new Version("3.23.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.22.1")
10
+ monsterVersion = new Version("3.23.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13