Skip to content
Snippets Groups Projects
Verified Commit 47ec86b4 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: template mapping

parent 3299bebf
No related branches found
No related tags found
No related merge requests found
......@@ -267,6 +267,7 @@ class CustomElement extends HTMLElement {
* @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.
* @property {Object} templates Templates
* @property {string} templates.main=undefined Main template
* @property {Object} templateMapping Template mapping
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow
* @since 1.8.0
......@@ -279,6 +280,7 @@ class CustomElement extends HTMLElement {
templates: {
main: undefined,
},
templateMapping: {},
};
}
......@@ -398,7 +400,8 @@ class CustomElement extends HTMLElement {
try {
value = new Pathfinder(this[internalSymbol].getRealSubject()["options"]).getVia(path);
} catch (e) {}
} catch (e) {
}
if (value === undefined) return defaultValue;
return value;
......@@ -468,7 +471,8 @@ class CustomElement extends HTMLElement {
try {
initShadowRoot.call(self);
elements = self.shadowRoot.childNodes;
} catch (e) {}
} catch (e) {
}
try {
initCSSStylesheet.call(this);
......@@ -519,7 +523,8 @@ class CustomElement extends HTMLElement {
* @return {void}
* @since 1.7.0
*/
disconnectedCallback() {}
disconnectedCallback() {
}
/**
* 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 {
* @return {void}
* @since 1.7.0
*/
adoptedCallback() {}
adoptedCallback() {
}
/**
* Called when an observed attribute has been added, removed, updated, or replaced. Also called for initial
......@@ -816,7 +822,8 @@ function parseOptionsJSON(data) {
try {
let dataUrl = parseDataURL(data);
data = dataUrl.content;
} catch (e) {}
} catch (e) {
}
try {
obj = JSON.parse(data);
......@@ -838,6 +845,11 @@ function initHtmlContent() {
} catch (e) {
let html = this.getOption("templates.main", "");
if (isString(html) && html.length > 0) {
const mapping = this.getOption("templateMapping", {});
if (isObject(mapping)) {
html = new Formatter(mapping).format(html);
}
this.innerHTML = html;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment