You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug: none
Change-Id: Ie3e60269dcd54c67f32496e108cc3d3ea6790564
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7623115
Reviewed-by: Alina Varkki <alinavarkki@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
A controller for the each setting is added to the 'preferences' tab if they are visible, that is, they have a `title` and a `category`.
33
33
They can also be set with the command menu if they have `options` and a `category` (options’ names are added as commands).
34
+
35
+
---
36
+
37
+
# The DevTools Revealer System
38
+
39
+
The `Revealer.ts` module provides a centralized system that allows different parts of the DevTools UI to "reveal" or display various types of objects without being tightly coupled to one another. It's a powerful decoupling mechanism that makes the codebase more modular, extensible, and performant.
40
+
41
+
For example, if you click on a CSS file link in the **Console**, this system is responsible for telling the **Sources** panel to open and display that file, without the Console needing a direct reference to the Sources panel.
42
+
43
+
## Core Concepts
44
+
45
+
1.**`Revealer<T>` Interface**: This is the fundamental contract. A "Revealer" is any object (typically a UI panel or view) that knows how to display a specific type of data (`T`). It must implement a single method: `reveal(revealable: T): Promise<void>`.
46
+
47
+
2.**"Revealable" Object**: This is any object you want to show to the user. It can be a source code file (`SDK.SourceCode.UISourceCode`), a network request (`SDK.NetworkRequest.NetworkRequest`), a DOM node (`SDK.DOMModel.DOMNode`), or any other custom data type.
48
+
49
+
3.**`RevealerRegistry`**: This is a singleton class that acts as a central directory. It holds a list of all available `Revealer`s and maps them to the data types they can handle.
50
+
51
+
4.**`RevealerRegistration<T>`**: This is a configuration object used to register a `Revealer` with the `RevealerRegistry`. It contains three key pieces of information:
52
+
*`contextTypes`: A function that returns an array of classes (constructors) that the `Revealer` can handle.
53
+
*`loadRevealer`: An asynchronous function that returns a promise, which resolves to an instance of the `Revealer`. This allows for the lazy-loading of UI panels, improving initial application performance.
54
+
*`destination` (optional): A user-friendly, localized string that describes where the object will be revealed (e.g., "Network panel", "Elements panel"). This is used for UI text, such as in context menus ("Reveal in...").
55
+
56
+
---
57
+
58
+
## How to Create a New Revealer
59
+
60
+
Here are the steps to implement a new revealer that can take the user to a specific place in the DevTools UI.
61
+
62
+
### Step 1: Define the Object to be Revealed
63
+
64
+
First, ensure you have a class or data type that you want to make "revealable."
65
+
66
+
```ts
67
+
// front_end/models/my_app/MyApp.ts
68
+
exportclassMyDataObject {
69
+
id:string;
70
+
constructor(id:string) {
71
+
this.id=id;
72
+
}
73
+
}
74
+
```
75
+
76
+
### Step 2: Implement the `Revealer` Interface in Your UI Panel
77
+
78
+
The UI component that will display the object (e.g., your panel or widget) must implement the `Common.Revealer.Revealer<T>` interface for your specific data type.
// Now, highlight the specific item within your panel.
98
+
console.log(`Revealing data object with ID: ${dataObject.id}`);
99
+
// e.g., this.selectItemInUI(dataObject.id);
100
+
}
101
+
}
102
+
```
103
+
104
+
### Step 3: Register Your Panel as a `Revealer`
105
+
106
+
This is the most important step. You must tell the central `RevealerRegistry` that `MyPanel` knows how to handle `MyDataObject`. This registration is typically done in a module's `-meta.ts` or `-legacy.ts` configuration file, which is executed at startup.
107
+
108
+
```ts
109
+
// front_end/panels/my_panel/my_panel-meta.ts
110
+
import*asCommonfrom'../../core/common/common.js';
111
+
import*asi18nfrom'../../core/i18n/i18n.js';
112
+
113
+
const UIStrings = {
114
+
/**
115
+
* @description The name of the panel that reveals our custom data objects.
// 2. Provide a function to load and return an instance of your panel.
133
+
// This is what makes lazy loading possible.
134
+
async loadRevealer() {
135
+
const {MyPanel} =awaitimport('./MyPanel.js');
136
+
// If your panel is a singleton, return its instance, otherwise create a new one.
137
+
returnMyPanel.instance();
138
+
},
139
+
140
+
// 3. (Optional) Provide a user-facing destination name for context menus.
141
+
destination: i18nLazyString(UIStrings.myPanel),
142
+
});
143
+
```
144
+
145
+
### Step 4: Trigger the Reveal from Anywhere
146
+
147
+
Now that your revealer is registered, any other part of the DevTools codebase can ask to reveal an instance of `MyDataObject` without needing to know anything about `MyPanel`.
148
+
149
+
```ts
150
+
// In some other file, e.g., a context menu action.
0 commit comments