-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCustomElementRenderer.js
35 lines (34 loc) · 1016 Bytes
/
CustomElementRenderer.js
1
2
3
4
5
6
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
import { ElementRenderer } from '@lit-labs/ssr/lib/element-renderer.js';
import { escapeHtml } from '@lit-labs/ssr/lib/util/escape-html.js';
export class CustomElementRender extends ElementRenderer {
constructor(tagName) {
super(tagName);
this.element = new (customElements.get(tagName))();
this._attributes = {};
}
setAttribute(name, value) {
this._attributes[name] = value;
this.element.setAttribute(name, value);
}
*renderAttributes() {
for (const [name, value] of Object.entries(this._attributes)) {
if (value === '' || value === undefined || value === null) {
yield ` ${name}`;
}
else {
yield ` ${name}="${escapeHtml(value)}"`;
}
}
}
async connectedCallback() {
this.element?.connectedCallback?.();
await this.element?.updateComplete || Promise.resolve();
}
attributeChangedCallback() { }
*renderLight() {
yield this.element.innerHTML;
}
*renderShadow() {
yield this.element.shadowRoot.innerHTML;
}
}