// Copyright 2024 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import type * as Platform from '../../../../core/platform/platform.js'; import * as SDK from '../../../../core/sdk/sdk.js'; import type * as Protocol from '../../../../generated/protocol.js'; import * as Buttons from '../../../../ui/components/buttons/buttons.js'; import * as LegacyComponents from '../../../../ui/legacy/components/utils/utils.js'; import * as UI from '../../../../ui/legacy/legacy.js'; import * as Lit from '../../../../ui/lit/lit.js'; import * as PanelsCommon from '../../../common/common.js'; const {html} = Lit; const {widgetConfig} = UI.Widget; interface ViewInput { relatedNodeEl: Node|undefined; fallbackUrl?: Platform.DevToolsPath.UrlString; fallbackHtmlSnippet?: string; fallbackText?: string; } type View = (input: ViewInput, output: undefined, target: HTMLElement) => void; export const DEFAULT_VIEW: View = (input, output, target) => { const { relatedNodeEl, fallbackUrl, fallbackHtmlSnippet, fallbackText, } = input; let template; if (relatedNodeEl) { template = html`
${fallbackHtmlSnippet}`;
} else if (fallbackText) {
template = html`${fallbackText}`;
} else {
template = Lit.nothing;
}
Lit.render(template, target);
};
export interface NodeLinkData {
backendNodeId: Protocol.DOM.BackendNodeId;
frame?: string;
options?: PanelsCommon.DOMLinkifier.Options;
/**
* URL to display if backendNodeId cannot be resolved (ie for traces loaded from disk).
* Will be given to linkifyURL. Use this or one of the other fallback fields.
*/
fallbackUrl?: Platform.DevToolsPath.UrlString;
/**
* Text to display if backendNodeId cannot be resolved (ie for traces loaded from disk).
* Displayed as monospace code.
*/
fallbackHtmlSnippet?: string;
/**
* Text to display if backendNodeId cannot be resolved (ie for traces loaded from disk).
* Displayed as plain text.
*/
fallbackText?: string;
}
export class NodeLink extends UI.Widget.Widget {
#view: View;
#backendNodeId?: Protocol.DOM.BackendNodeId;
#frame?: string;
#options?: PanelsCommon.DOMLinkifier.Options;
#fallbackUrl?: Platform.DevToolsPath.UrlString;
#fallbackHtmlSnippet?: string;
#fallbackText?: string;
/**
* Track the linkified Node for a given backend NodeID to avoid repeated lookups on re-render.
* Also tracks if we fail to resolve a node, to ensure we don't try on each subsequent re-render.
*/
#linkifiedNodeForBackendId = new Map