mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 09:47:56 +08:00
The newest version of @typescript-eslint errors on declare globals. While this is usually good to point out, we have legitimate usages of these statements. Based on the discussion in https://github.com/typescript-eslint/typescript-eslint/issues/2519 it seems unlikely this will be fixed anytime soon. Therefore, let's disable these specific lines to unblock our upgrade of the linter. R=jacktfranklin@chromium.org Change-Id: Iee6339428eef0d5496783850a9026fed00942bcb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2566807 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as LitHtml from '../third_party/lit-html/lit-html.js';
|
|
|
|
const {render, html} = LitHtml;
|
|
|
|
export interface NodeTextData {
|
|
nodeTitle: string, nodeId?: string, nodeClasses?: string[]
|
|
}
|
|
|
|
export class NodeText extends HTMLElement {
|
|
private readonly shadow = this.attachShadow({mode: 'open'});
|
|
private nodeTitle: string = '';
|
|
private nodeId?: string = '';
|
|
private nodeClasses?: string[] = [];
|
|
|
|
set data(data: NodeTextData) {
|
|
this.nodeTitle = data.nodeTitle;
|
|
this.nodeId = data.nodeId;
|
|
this.nodeClasses = data.nodeClasses;
|
|
this.render();
|
|
}
|
|
|
|
private render() {
|
|
const hasId = !!this.nodeId;
|
|
const hasNodeClasses = !!(this.nodeClasses && this.nodeClasses.length > 0);
|
|
|
|
const parts = [
|
|
html`<span class="node-label-name">${this.nodeTitle}</span>`,
|
|
];
|
|
|
|
if (this.nodeId) {
|
|
const classes = LitHtml.Directives.classMap({
|
|
'node-label-id': true,
|
|
'node-multiple-descriptors': hasNodeClasses,
|
|
});
|
|
parts.push(html`<span class=${classes}>#${CSS.escape(this.nodeId)}</span>`);
|
|
}
|
|
|
|
if (this.nodeClasses && this.nodeClasses.length > 0) {
|
|
const text = this.nodeClasses.map(c => `.${CSS.escape(c)}`).join('');
|
|
const classes = LitHtml.Directives.classMap({
|
|
'node-label-class': true,
|
|
'node-multiple-descriptors': hasId,
|
|
});
|
|
parts.push(html`<span class=${classes}>${text}</span>`);
|
|
}
|
|
|
|
// Disabled until https://crbug.com/1079231 is fixed.
|
|
// clang-format off
|
|
render(html`
|
|
<style>
|
|
.node-label-name {
|
|
color: var(--node-text-label-color, --dom-tag-name-color);
|
|
}
|
|
|
|
.node-label-class {
|
|
color: var(--node-text-class-color, --dom-attribute-name-color);
|
|
}
|
|
|
|
.node-label-id {
|
|
color: var(--node-text-id-color);
|
|
}
|
|
|
|
.node-label-class.node-multiple-descriptors {
|
|
color: var(--node-text-multiple-descriptors-class, var(--node-text-class-color, --dom-attribute-name-color));
|
|
}
|
|
|
|
.node-label-id.node-multiple-descriptors {
|
|
color: var(--node-text-multiple-descriptors-id, var(--node-text-id-color, --dom-attribute-name-color));
|
|
}
|
|
</style>
|
|
${parts}
|
|
`, this.shadow, {
|
|
eventContext: this,
|
|
});
|
|
// clang-format on
|
|
}
|
|
}
|
|
|
|
if (!customElements.get('devtools-node-text')) {
|
|
customElements.define('devtools-node-text', NodeText);
|
|
}
|
|
|
|
declare global {
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
interface HTMLElementTagNameMap {
|
|
'devtools-node-text': NodeText;
|
|
}
|
|
}
|