Remove redundant .shadow property as that is defined at the Custom Element level. (#1395)

This commit is contained in:
Andrea Giammarchi
2023-04-21 10:05:50 +02:00
committed by GitHub
parent 8590c7e5b8
commit 0021ccb49f
2 changed files with 3 additions and 13 deletions

View File

@@ -8,7 +8,6 @@ const logger = getLogger('py-register-widget');
function createWidget(interpreter: InterpreterClient, name: string, code: string, klass: string) { function createWidget(interpreter: InterpreterClient, name: string, code: string, klass: string) {
class CustomWidget extends HTMLElement { class CustomWidget extends HTMLElement {
shadow: ShadowRoot;
wrapper: HTMLElement; wrapper: HTMLElement;
name: string = name; name: string = name;
@@ -20,11 +19,8 @@ function createWidget(interpreter: InterpreterClient, name: string, code: string
constructor() { constructor() {
super(); super();
// attach shadow so we can preserve the element original innerHtml content
this.shadow = this.attachShadow({ mode: 'open' });
this.wrapper = document.createElement('slot'); this.wrapper = document.createElement('slot');
this.shadow.appendChild(this.wrapper); this.attachShadow({ mode: 'open' }).appendChild(this.wrapper);
} }
async connectedCallback() { async connectedCallback() {
@@ -45,7 +41,6 @@ function createWidget(interpreter: InterpreterClient, name: string, code: string
export function make_PyWidget(interpreter: InterpreterClient) { export function make_PyWidget(interpreter: InterpreterClient) {
class PyWidget extends HTMLElement { class PyWidget extends HTMLElement {
shadow: ShadowRoot;
name: string; name: string;
klass: string; klass: string;
outputElement: HTMLElement; outputElement: HTMLElement;
@@ -58,11 +53,8 @@ export function make_PyWidget(interpreter: InterpreterClient) {
constructor() { constructor() {
super(); super();
// attach shadow so we can preserve the element original innerHtml content
this.shadow = this.attachShadow({ mode: 'open' });
this.wrapper = document.createElement('slot'); this.wrapper = document.createElement('slot');
this.shadow.appendChild(this.wrapper); this.attachShadow({ mode: 'open' }).appendChild(this.wrapper);
this.addAttributes('src', 'name', 'klass'); this.addAttributes('src', 'name', 'klass');
} }

View File

@@ -242,7 +242,6 @@ type PyElementClass = (htmlElement: HTMLElement) => PyElementInstance;
export function define_custom_element(tag: string, pyElementClass: PyElementClass): any { export function define_custom_element(tag: string, pyElementClass: PyElementClass): any {
logger.info(`creating plugin: ${tag}`); logger.info(`creating plugin: ${tag}`);
class ProxyCustomElement extends HTMLElement { class ProxyCustomElement extends HTMLElement {
shadow: ShadowRoot;
wrapper: HTMLElement; wrapper: HTMLElement;
pyElementInstance: PyElementInstance; pyElementInstance: PyElementInstance;
originalInnerHTML: string; originalInnerHTML: string;
@@ -251,9 +250,8 @@ export function define_custom_element(tag: string, pyElementClass: PyElementClas
logger.debug(`creating ${tag} plugin instance`); logger.debug(`creating ${tag} plugin instance`);
super(); super();
this.shadow = this.attachShadow({ mode: 'open' });
this.wrapper = document.createElement('slot'); this.wrapper = document.createElement('slot');
this.shadow.appendChild(this.wrapper); this.attachShadow({ mode: 'open' }).appendChild(this.wrapper);
this.originalInnerHTML = this.innerHTML; this.originalInnerHTML = this.innerHTML;
this.pyElementInstance = pyElementClass(this); this.pyElementInstance = pyElementClass(this);
} }