// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /* eslint-disable @devtools/no-imperative-dom-api, @devtools/enforce-custom-element-definitions-location*/ import type * as Platform from '../../../core/platform/platform.js'; import type * as UI from '../../legacy/legacy.js'; import * as VisualLogging from '../../visual_logging/visual_logging.js'; export abstract class WrappableComponent extends HTMLElement { wrapper: T|null = null; async render(): Promise { } wasShown(): void { } willHide(): void { } } export type LegacyWrapper> = { getComponent(): Component, }&T; export function legacyWrapper, Component extends WrappableComponent>>( base: T, component: Component, jsLogContext?: string): LegacyWrapper, Component> { return new class extends base { #component: Component; constructor(..._args: any[]) { super(/* useShadowDom=*/ true); this.#component = component; this.#component.wrapper = this as InstanceType; void this.#component.render(); this.contentElement.appendChild(this.#component); if (jsLogContext) { this.element.setAttribute('jslog', `${VisualLogging.pane().context(jsLogContext)}`); } } override wasShown(): void { super.wasShown(); this.#component.wasShown(); void this.#component.render(); } override willHide(): void { super.willHide(); this.#component.willHide(); } override async performUpdate(): Promise { await this.#component.render(); } getComponent(): Component { return this.#component; } // clang-format off }() as unknown as LegacyWrapper, Component>; // clang-format on }