/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import {BaseElement, element} from "../../../base-ui/BaseElement.js"; import {info} from "../../../log/Log.js"; @element('trace-command') export class SpTraceCommand extends BaseElement { private codeHl: HTMLTextAreaElement | undefined | null; private copyEl: HTMLElement | undefined | null; private codeCopyText: HTMLInputElement | undefined; set show(show: boolean) { if (show) { this.setAttribute("show", '') } else { this.removeAttribute("show") } } get show() { return this.hasAttribute("show") } get hdcCommon(): string { return this.codeHl!.textContent + ""; } set hdcCommon(value: string) { info("hdc Common is:", value) this.codeHl!.textContent = value; } //当 custom element首次被插入文档DOM时,被调用。 public connectedCallback() { this.codeHl = this.shadowRoot?.querySelector('#code-text') as HTMLTextAreaElement; this.copyEl = this.shadowRoot?.querySelector('#copy-image') as HTMLElement; this.codeHl.textContent = "" this.copyEl?.addEventListener('click', this.codeCopyEvent) this.codeHl.addEventListener('selectionchange', this.textSelectEvent) } public disconnectedCallback() { this.copyEl?.removeEventListener('click', this.codeCopyEvent) } codeCopyEvent = (event: any) => { this.codeHl?.select(); navigator.clipboard.writeText(this.codeHl?.textContent!).then(() => {}) } textSelectEvent = (event: any) => { this.copyEl!.style.backgroundColor = '#FFFFFF'; } initElements(): void { } initHtml(): string { return `