Skip to content
Snippets Groups Projects
Commit 065b6fe2 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Transform all named template slots in the light DOM to named div slots

parent 8af9237c
No related branches found
No related tags found
No related merge requests found
Pipeline #46186 canceled
...@@ -14,7 +14,7 @@ import {BuildInfo} from './build-info.js'; ...@@ -14,7 +14,7 @@ import {BuildInfo} from './build-info.js';
import {send as notify} from '@dbp-toolkit/common/notification'; import {send as notify} from '@dbp-toolkit/common/notification';
import {appWelcomeMeta} from './dbp-app-shell-welcome.js'; import {appWelcomeMeta} from './dbp-app-shell-welcome.js';
import {MatomoElement} from "@dbp-toolkit/matomo/src/matomo"; import {MatomoElement} from "@dbp-toolkit/matomo/src/matomo";
import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element"; import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element";
const i18n = createI18nInstance(); const i18n = createI18nInstance();
...@@ -41,7 +41,7 @@ const importNotify = async (promise) => { ...@@ -41,7 +41,7 @@ const importNotify = async (promise) => {
} }
}; };
export class AppShell extends ScopedElementsMixin(AdapterLitElement) { export class AppShell extends ScopedElementsMixin(DBPLitElement) {
constructor() { constructor() {
super(); super();
this.lang = i18n.language; this.lang = i18n.language;
......
...@@ -4,4 +4,42 @@ export default class DBPLitElement extends AdapterLitElement { ...@@ -4,4 +4,42 @@ export default class DBPLitElement extends AdapterLitElement {
_(selector) { _(selector) {
return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector); return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector);
} }
connectedCallback() {
this.updateComplete.then(() => {
// transform all named template slots in the light DOM to named div slots
this.transformTemplateSlots();
});
super.connectedCallback();
}
/**
* Transforms all named template slots in the light DOM to named div slots
*/
transformTemplateSlots() {
// query all named slots of the component
const slots = this.shadowRoot.querySelectorAll("slot[name]");
slots.forEach((slot) => {
const name = slot.name;
// search if there is a template with the name of the slot in the light DOM of the component
const templateElem = this.querySelector("template[slot=" + name + "]");
if (!templateElem) {
return;
}
// create a slot div container to put in the cloned template content
const divElem = document.createElement('div');
divElem.slot = name;
divElem.appendChild(templateElem.content.cloneNode(true));
// remove the old template with slot attribute
templateElem.remove();
// put the slot div container with the cloned template in the light DOM
this.appendChild(divElem);
});
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment