Newer
Older
import {AdapterLitElement} from "./src/adapter-lit-element";
export default class DBPLitElement extends AdapterLitElement {
_(selector) {
return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector);
}
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
});
}