_id
stringlengths 21
254
| text
stringlengths 1
93.7k
| metadata
dict |
---|---|---|
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-dialog.component.ts_0_554 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component} from '@angular/core';
import {MatProgressBar} from '@angular/material/progress-bar';
@Component({
selector: 'ng-recording-dialog',
templateUrl: './recording-dialog.component.html',
styleUrls: ['./recording-dialog.component.scss'],
standalone: true,
imports: [MatProgressBar],
})
export class RecordingDialogComponent {}
| {
"end_byte": 554,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-dialog.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline-controls.component.html_0_1923 | <div class="controls">
<div class="visual-controls">
<mat-form-field>
<mat-label>Filter</mat-label>
<input
matInput
class="filter-input"
(keyup)="filter.emit($event.target.value)"
placeholder="duration: >30 source: click"
/>
</mat-form-field>
<mat-form-field [class.hidden]="!record()">
<mat-select [value]="visualizationMode()" (selectionChange)="visualizationMode.set($event.value)">
<mat-option [value]="flameGraphMode"> Flame graph </mat-option>
<mat-option [value]="treeMapMode"> Tree map </mat-option>
<mat-option [value]="barGraphMode"> Bar chart </mat-option>
</mat-select>
</mat-form-field>
</div>
<div
class="details"
[class.flame-details]="visualizationMode() == flameGraphMode"
[class.bar-details]="visualizationMode() == barGraphMode"
>
@if (estimatedFrameRate() >= 60 && record()) {
<label>
Time spent: <span class="value">{{ record()?.duration | number }} ms</span>
</label>
}
@if (estimatedFrameRate() < 60 && record()) {
<label class="warning-label">
Time spent: <span class="value">{{ record()?.duration | number }} ms</span>
</label>
}
@if (estimatedFrameRate() < 60 && record()) {
<label class="warning-label">
Frame rate: <span class="value">{{ estimatedFrameRate() }} fps</span>
</label>
}
@if (record()?.source && record()) {
<label>
Source: <span class="value">{{ record()?.source }}</span>
</label>
}
@if (visualizationMode() == flameGraphMode) {
<mat-checkbox
[checked]="changeDetection()"
(change)="changeDetection.set($event.checked)"
>
Show only change detection
</mat-checkbox>
}
</div>
@if (!empty()) {
<button mat-stroked-button (click)="exportProfile.emit()">Save Profile</button>
}
</div>
| {
"end_byte": 1923,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline-controls.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/BUILD.bazel_0_2446 | load("//devtools/tools:ng_module.bzl", "ng_module")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//devtools/tools:typescript.bzl", "ts_test_library")
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
package(default_visibility = ["//visibility:public"])
_STYLE_SRCS = [
"frame-selector.component.scss",
"recording-dialog.component.scss",
"timeline.component.scss",
"timeline-controls.component.scss",
]
_STYLE_LABELS = [
src[:-len(".component.scss")].replace("-", "_") + "_styles"
for src in _STYLE_SRCS
]
[
sass_binary(
name = label,
src = src,
)
for label, src in zip(_STYLE_LABELS, _STYLE_SRCS)
]
sass_binary(
name = "recording_modal_styles",
src = "recording-modal.component.scss",
include_paths = ["node_modules"],
)
ng_module(
name = "timeline",
srcs = [
"filter.ts",
"frame-selector.component.ts",
"recording-dialog.component.ts",
"recording-modal.component.ts",
"timeline.component.ts",
"timeline-controls.component.ts",
],
angular_assets = [
"timeline.component.html",
"timeline-controls.component.html",
"recording-modal.component.html",
"recording-dialog.component.html",
"frame-selector.component.html",
":recording_modal_styles",
] + _STYLE_LABELS,
deps = [
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/visualization-mode",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/tab-update",
"//devtools/projects/protocol",
"//packages/common",
"//packages/core",
"//packages/forms",
"@npm//@angular/cdk",
"@npm//@angular/material",
"@npm//ngx-flamegraph",
"@npm//rxjs",
],
)
ts_test_library(
name = "test_lib",
srcs = [
"filter.spec.ts",
"timeline.component.spec.ts",
],
deps = [
":timeline",
],
)
# todo(aleksanderbodurri): fix this test suite
karma_web_test_suite(
name = "test",
deps = [
":test_lib",
"//packages/common/http",
"//packages/platform-browser",
"//packages/platform-browser/animations",
],
)
| {
"end_byte": 2446,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline.component.scss_0_408 | :host {
font-size: 11px;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.info {
margin-top: 16px;
font-size: 1.2em;
text-align: center;
}
.hidden {
/*
intentionally using visibility: hidden
display: none breaks the virtual scroll
*/
visibility: hidden;
}
.timeline-wrapper {
display: flex;
flex-direction: column;
height: 100%;
margin: 0 10px;
}
| {
"end_byte": 408,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-modal.component.scss_0_317 | // todo(aleksanderbodurri): fix this for bazel build
// @use '/node_modules/@angular/cdk/overlay-prebuilt.css';
:host {
overflow: hidden;
display: block;
width: 100%;
height: 100%;
}
#recorder-wrapper {
position: relative;
overflow: hidden;
height: 100%;
display: flex;
justify-content: center;
}
| {
"end_byte": 317,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-modal.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/frame-selector.component.html_0_1122 | <mat-card class="bar-graph-container">
<p class="txt-frames" matTooltip="{{ selectionLabel() }} / {{ frameCount() }}">
{{ selectionLabel() }} / {{ frameCount() }}
</p>
<button
mat-icon-button
matTooltip="Select previous frame"
(click)="move(-1)"
[disabled]="disablePreviousFrameButton()"
>
<mat-icon>chevron_left</mat-icon>
</button>
<cdk-virtual-scroll-viewport
#barContainer
orientation="horizontal"
[itemSize]="itemWidth"
class="bar-container"
(mouseleave)="stopDragScrolling()"
(mousedown)="startDragScroll($event)"
(mouseup)="stopDragScrolling()"
(mousemove)="dragScroll($event)"
>
<div
*cdkVirtualFor="let d of graphData(); let i = index"
[ngStyle]="d.style"
class="frame-bar"
[class.selected]="selectedFrameIndexes().has(i)"
(click)="handleFrameSelection(i, $event)"
></div>
</cdk-virtual-scroll-viewport>
<button
mat-icon-button
matTooltip="Select next frame"
(click)="move(1)"
[disabled]="disableNextFrameButton()"
>
<mat-icon>chevron_right</mat-icon>
</button>
</mat-card>
| {
"end_byte": 1122,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/frame-selector.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline.component.ts_0_5062 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, computed, effect, input, output, signal} from '@angular/core';
import {ProfilerFrame} from 'protocol';
import {Observable} from 'rxjs';
import {createFilter, Filter, noopFilter} from './filter';
import {mergeFrames} from './record-formatter/frame-merger';
import {GraphNode} from './record-formatter/record-formatter';
import {VisualizationMode} from './visualization-mode';
import {TimelineVisualizerComponent} from './recording-visualizer/timeline-visualizer.component';
import {FrameSelectorComponent} from './frame-selector.component';
import {TimelineControlsComponent} from './timeline-controls.component';
import {RecordingModalComponent} from './recording-modal.component';
const MAX_HEIGHT = 50;
@Component({
selector: 'ng-recording-timeline',
templateUrl: './timeline.component.html',
styleUrls: ['./timeline.component.scss'],
standalone: true,
imports: [
RecordingModalComponent,
TimelineControlsComponent,
FrameSelectorComponent,
TimelineVisualizerComponent,
],
})
export class TimelineComponent {
readonly stream = input.required<Observable<ProfilerFrame[]>>();
readonly exportProfile = output<void>();
readonly visualizationMode = signal(VisualizationMode.BarGraph);
readonly changeDetection = signal(false);
readonly selectFrames = signal<number[]>([]);
readonly frame = computed(() => {
const indexes = this.selectFrames();
const data = this.graphData();
return mergeFrames(indexes.map((index) => data[index]?.frame).filter(Boolean));
});
private readonly _filter = signal<Filter>(noopFilter);
private _maxDuration = -Infinity;
private _allRecords: ProfilerFrame[] = [];
readonly visualizing = signal(false);
private readonly _graphData = signal<GraphNode[]>([]);
readonly graphData = computed(() => {
const nodes = this._graphData();
const filter = this._filter();
return nodes.filter((node) => filter(node));
});
readonly currentFrameRate = computed(() =>
TimelineComponent.estimateFrameRate(this.frame()?.duration ?? 0),
);
readonly hasFrames = computed(() => this._graphData().length > 0);
constructor() {
effect((cleanup) => {
const data = this.stream();
this._allRecords = [];
this._maxDuration = -Infinity;
const _subscription = data.subscribe({
next: (frames: ProfilerFrame[]): void => {
this._processFrames(frames);
},
complete: (): void => {
this.visualizing.set(true);
},
});
cleanup(() => _subscription.unsubscribe());
});
}
static estimateFrameRate(timeSpent: number): number {
const multiplier = Math.max(Math.ceil(timeSpent / 16) - 1, 0);
return Math.floor(60 / 2 ** multiplier);
}
setFilter(filter: string): void {
this._filter.set(createFilter(filter));
}
getColorByFrameRate(framerate: number): string {
if (framerate >= 60) {
return '#d6f0d1';
} else if (framerate < 60 && framerate >= 30) {
return '#f2dca2';
} else if (framerate < 30 && framerate >= 15) {
return '#f9cc9d';
}
return '#fad1d1';
}
private _processFrames(frames: ProfilerFrame[]): void {
let regenerate = false;
for (const frame of frames) {
if (frame.duration >= this._maxDuration) {
regenerate = true;
}
this._allRecords.push(frame);
}
if (regenerate) {
this._graphData.set(this._generateBars());
return;
}
const multiplicationFactor = parseFloat((MAX_HEIGHT / this._maxDuration).toFixed(2));
this._graphData.update((value) => {
frames.forEach((frame) => value.push(this._getBarStyles(frame, multiplicationFactor)));
return [...value];
});
}
private _generateBars(): GraphNode[] {
const maxValue = this._allRecords.reduce(
(acc: number, frame: ProfilerFrame) => Math.max(acc, frame.duration),
0,
);
const multiplicationFactor = parseFloat((MAX_HEIGHT / maxValue).toFixed(2));
this._maxDuration = Math.max(this._maxDuration, maxValue);
return this._allRecords.map((r) => this._getBarStyles(r, multiplicationFactor));
}
private _getBarStyles(frame: ProfilerFrame, multiplicationFactor: number): GraphNode {
const height = frame.duration * multiplicationFactor;
const colorPercentage = Math.max(10, Math.round((height / MAX_HEIGHT) * 100));
const backgroundColor = this.getColorByFrameRate(
TimelineComponent.estimateFrameRate(frame.duration),
);
const style = {
'background-image': `-webkit-linear-gradient(bottom, ${backgroundColor} ${colorPercentage}%, transparent ${colorPercentage}%)`,
cursor: 'pointer',
'min-width': '25px',
width: '25px',
height: '50px',
};
const toolTip = `${frame.source} TimeSpent: ${frame.duration.toFixed(3)}ms`;
return {style, toolTip, frame};
}
}
| {
"end_byte": 5062,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-modal.component.html_0_89 | <section id="recorder-wrapper">
<ng-recording-dialog></ng-recording-dialog>
</section>
| {
"end_byte": 89,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-modal.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/frame-selector.component.scss_0_1407 | .bar-graph-container {
padding: 2px;
height: 54px;
display: flex;
flex-direction: row;
align-items: flex-end;
justify-content: center;
align-items: center;
margin-bottom: 10px;
.txt-frames {
font-weight: 500;
line-height: 50px;
padding: 0px;
margin: 0px 10px;
width: 150px;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bar-container {
max-width: calc(100vw - 150px);
align-items: baseline;
overflow-x: auto;
width: 100%;
height: 100%;
::ng-deep .cdk-virtual-scroll-content-wrapper {
display: flex;
}
&::-webkit-scrollbar {
display: none;
}
.frame-bar {
margin-left: 2.5px;
margin-right: 2.5px;
margin-top: 2px;
&:hover {
background-color: #ebf1fb;
}
&.selected {
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-left: 0.5px;
padding-right: 0.5px;
background-color: #cfe8fc;
border: 2px solid #cfe8fc;
}
}
}
button {
margin-bottom: 5px;
}
}
:host-context(.dark-theme) {
.bar-graph-container .bar-container .frame-bar {
&:hover {
background-color: #262d36;
}
&.selected {
background-color: #073d69;
border: 2px solid #073d69;
}
}
}
cdk-virtual-scroll-viewport {
height: 50px;
} | {
"end_byte": 1407,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/frame-selector.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline.component.html_0_984 | @if (!hasFrames() && !visualizing()) {
<ng-recording-modal/>
}
@if (!hasFrames() && visualizing()) {
<p class="info">There's no information to show.</p>
}
<div class="timeline-wrapper">
<ng-timeline-controls
[class.hidden]="!hasFrames()"
[record]="frame()"
[empty]="!hasFrames()"
[estimatedFrameRate]="currentFrameRate()"
[(visualizationMode)]="visualizationMode"
[(changeDetection)]="changeDetection"
(exportProfile)="exportProfile.emit($event)"
(filter)="setFilter($event)"
/>
<ng-frame-selector
[class.hidden]="!hasFrames()"
[graphData]="graphData()"
(selectFrames)="selectFrames.set($event.indexes)"
/>
@if (hasFrames() && !frame()) {
<p class="info">Select a bar to preview a particular change detection cycle.</p>
} @else if (hasFrames() && frame()) {
<ng-timeline-visualizer
[visualizationMode]="visualizationMode()"
[frame]="frame()"
[changeDetection]="changeDetection()"
/>
}
</div>
| {
"end_byte": 984,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline-controls.component.ts_0_1595 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, input, model, output} from '@angular/core';
import {ProfilerFrame} from 'protocol';
import {VisualizationMode} from './visualization-mode';
import {MatButton} from '@angular/material/button';
import {MatCheckbox} from '@angular/material/checkbox';
import {MatOption} from '@angular/material/core';
import {MatSelect} from '@angular/material/select';
import {MatInput} from '@angular/material/input';
import {MatFormField, MatLabel} from '@angular/material/form-field';
import {DecimalPipe} from '@angular/common';
@Component({
selector: 'ng-timeline-controls',
templateUrl: './timeline-controls.component.html',
styleUrls: ['./timeline-controls.component.scss'],
standalone: true,
imports: [
MatFormField,
MatLabel,
MatInput,
MatSelect,
MatOption,
MatCheckbox,
MatButton,
DecimalPipe,
],
})
export class TimelineControlsComponent {
readonly record = input<ProfilerFrame>();
readonly estimatedFrameRate = input.required<number>();
readonly visualizationMode = model.required<VisualizationMode>();
readonly empty = input.required<boolean>();
readonly changeDetection = model.required<boolean>();
readonly exportProfile = output<void>();
readonly filter = output<string>();
flameGraphMode = VisualizationMode.FlameGraph;
treeMapMode = VisualizationMode.TreeMap;
barGraphMode = VisualizationMode.BarGraph;
}
| {
"end_byte": 1595,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/timeline-controls.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/flamegraph-visualizer.component.ts_0_2457 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, computed, inject, input, output} from '@angular/core';
import {Color, RawData} from 'ngx-flamegraph/lib/utils';
import {ProfilerFrame} from 'protocol';
import {ThemeService} from '../../../../theme-service';
import {
FlamegraphFormatter,
FlamegraphNode,
ROOT_LEVEL_ELEMENT_LABEL,
} from '../record-formatter/flamegraph-formatter/flamegraph-formatter';
import {formatDirectiveProfile} from './profile-formatter';
import {SelectedDirective, SelectedEntry} from './timeline-visualizer.component';
import {NgxFlamegraphModule} from 'ngx-flamegraph';
@Component({
selector: 'ng-flamegraph-visualizer',
templateUrl: './flamegraph-visualizer.component.html',
styleUrls: ['./flamegraph-visualizer.component.scss'],
standalone: true,
imports: [NgxFlamegraphModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FlamegraphVisualizerComponent {
public themeService = inject(ThemeService);
readonly profilerBars = computed(() => {
return [
this._formatter.formatFrame(
this.frame(),
this.changeDetection(),
this.themeService.currentTheme(),
),
];
});
view: [number, number] = [235, 200];
private readonly _formatter = new FlamegraphFormatter();
readonly colors = computed<Color>(() => {
return this.themeService.currentTheme() === 'dark-theme'
? {
hue: [210, 90],
saturation: [90, 90],
lightness: [25, 25],
}
: {
hue: [50, 15],
saturation: [100, 100],
lightness: [75, 75],
};
});
readonly nodeSelect = output<SelectedEntry>();
readonly frame = input.required<ProfilerFrame>();
readonly changeDetection = input.required<boolean>();
selectFrame(frame: RawData): void {
if (frame.label === ROOT_LEVEL_ELEMENT_LABEL) {
return;
}
const flameGraphNode = frame as FlamegraphNode;
const directiveData = this.formatEntryData(flameGraphNode);
this.nodeSelect.emit({
entry: flameGraphNode,
selectedDirectives: directiveData,
});
}
formatEntryData(flameGraphNode: FlamegraphNode): SelectedDirective[] {
return formatDirectiveProfile(flameGraphNode.original.directives);
}
}
| {
"end_byte": 2457,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/flamegraph-visualizer.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bargraph-visualizer.component.scss_0_231 | :host {
width: 100%;
height: 100%;
display: flex;
-webkit-user-select: text;
-ms-user-select: text;
user-select: text;
overflow-y: auto;
}
.level-profile-wrapper {
height: 100%;
width: 100%;
cursor: pointer;
}
| {
"end_byte": 231,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bargraph-visualizer.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/timeline-visualizer.component.html_0_1511 | <as-split unit="percent" [gutterSize]="9">
<as-split-area size="75">
@switch (visualizationMode()) {
@case (cmpVisualizationModes.FlameGraph) {
<ng-flamegraph-visualizer
[frame]="frame()"
[changeDetection]="changeDetection()"
(nodeSelect)="handleNodeSelect($event)"
/>
}
@case (cmpVisualizationModes.TreeMap) {
<ng-tree-map-visualizer [frame]="frame()"/>
}
@case (cmpVisualizationModes.BarGraph) {
<ng-bargraph-visualizer [frame]="frame()" (nodeSelect)="handleNodeSelect($event)"/>
}
}
</as-split-area>
@if (selectedEntry(); as entry) {
<as-split-area size="25" minSize="15">
<mat-card class="selected-entry">
<mat-toolbar>{{ entry.label }} details</mat-toolbar>
<section class="entry-statistics">
<div class="txt-total-time">
<label>Total time spent:</label><span> {{ entry.value | number }} ms</span>
</div>
@if (entry.value > 0) {
<ng-execution-details [data]="selectedDirectives()"/>
}
@if (parentHierarchy().length > 0) {
<div>
<div class="txt-total-time"><label>Parent Hierarchy</label></div>
<ul>
@for (parent of parentHierarchy(); track $index) {
<li>{{ parent.name }}</li>
}
</ul>
</div>
}
</section>
</mat-card>
</as-split-area>
}
</as-split>
| {
"end_byte": 1511,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/timeline-visualizer.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/timeline-visualizer.component.scss_0_958 | :host {
display: block;
overflow: auto;
height: 100%;
::ng-deep {
.as-split-gutter-icon {
display: none;
}
}
}
.selected-entry {
padding: 0px;
height: 100%;
mat-toolbar {
padding-left: 9px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
line-height: 25px;
font-size: 11px;
font-weight: 500;
display: flex;
align-items: center;
justify-content: space-between;
height: auto;
}
section {
height: 100%;
overflow: auto;
font-family: Roboto, 'Helvetica Neue', sans-serif;
padding: 10px;
}
}
.entry-statistics {
div {
padding: 3px;
label {
opacity: 0.7;
}
}
span {
color: #8a1882;
}
}
.txt-total-time {
font-weight: bold;
}
ul {
list-style-type: square;
margin-block-start: 0px;
padding-inline-start: 20px;
}
:host-context(.dark-theme) {
.entry-statistics {
span {
color: #5cadd3;
}
}
}
| {
"end_byte": 958,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/timeline-visualizer.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bargraph-visualizer.component.html_0_155 | <div class="level-profile-wrapper">
<ng-bar-chart (barClick)="selectNode($event)" [color]="barColor()" [data]="profileRecords()"> </ng-bar-chart>
</div>
| {
"end_byte": 155,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bargraph-visualizer.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/flamegraph-visualizer.component.scss_0_684 | :host {
width: 100%;
height: 100%;
display: flex;
-webkit-user-select: text;
-ms-user-select: text;
user-select: text;
.level-profile-wrapper {
height: 100%;
width: 100%;
cursor: pointer;
overflow-y: auto;
}
::ng-deep {
.ngx-fg-label {
color: #000000de;
font-weight: 500;
font-size: 1em;
}
}
:host-context(.dark-theme) {
.entry-statistics {
span {
color: #54c9bd;
}
}
::ng-deep {
.ngx-fg-rect {
stroke: #303030;
transition: none;
}
.ngx-fg-label {
color: #bcc5ce;
}
.ngx-fg-svg-g {
transition: none;
}
}
}
}
| {
"end_byte": 684,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/flamegraph-visualizer.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/execution-details.component.html_0_429 | <table>
<thead>
<th class="name">Directive</th>
<th class="method">Method</th>
<th class="value">Time</th>
</thead>
<tbody>
@for (entry of data(); track $index) {
<tr>
<td class="name">
{{ entry.directive }}
</td>
<td class="method">
{{ entry.method }}
</td>
<td class="value">{{ entry.value }} ms</td>
</tr>
}
</tbody>
</table>
| {
"end_byte": 429,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/execution-details.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/tree-map-visualizer.component.ts_0_2523 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
afterNextRender,
ChangeDetectionStrategy,
Component,
computed,
effect,
ElementRef,
inject,
input,
NgZone,
OnDestroy,
viewChild,
} from '@angular/core';
import {ProfilerFrame} from 'protocol';
import {Subject, Subscription} from 'rxjs';
import {debounceTime} from 'rxjs/operators';
import {render} from '../../../../vendor/webtreemap/treemap';
import {TreeMapFormatter, TreeMapNode} from '../record-formatter/tree-map-formatter';
@Component({
selector: 'ng-tree-map-visualizer',
templateUrl: './tree-map-visualizer.component.html',
styleUrls: ['./tree-map-visualizer.component.scss'],
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TreeMapVisualizerComponent implements OnDestroy {
private _formatter = new TreeMapFormatter();
readonly frame = input.required<ProfilerFrame>();
private _ngZone = inject(NgZone);
private resize$ = new Subject<void>();
private _throttledResizeSubscription!: Subscription;
private _resizeObserver: ResizeObserver = new ResizeObserver(() =>
this._ngZone.run(() => this.resize$.next()),
);
private readonly treeMapRecords = computed<TreeMapNode>(() => {
// first element in data is the Application node
return this._formatter.formatFrame(this.frame());
});
readonly tree = viewChild.required<ElementRef<HTMLElement>>('webTree');
constructor() {
effect(() => {
if (this.tree()) this._renderTree();
});
afterNextRender({
read: () => {
this._throttledResizeSubscription = this.resize$
.pipe(debounceTime(100))
.subscribe(() => this._renderTree());
this._resizeObserver.observe(this.tree().nativeElement);
},
});
}
ngOnDestroy(): void {
this._throttledResizeSubscription.unsubscribe();
this._resizeObserver.unobserve(this.tree().nativeElement);
}
private _renderTree(): void {
this._removeTree();
this._createTree();
}
private _removeTree(): void {
Array.from(this.tree().nativeElement.children).forEach((child) => child.remove());
}
private _createTree(): void {
render(this.tree().nativeElement, this.treeMapRecords(), {
padding: [20, 5, 5, 5],
caption: (node) => `${node.id}: ${node.size.toFixed(3)} ms`,
showNode: () => true,
});
}
}
| {
"end_byte": 2523,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/tree-map-visualizer.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bar-chart.component.ts_0_1940 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
animate,
animateChild,
query,
stagger,
style,
transition,
trigger,
} from '@angular/animations';
import {ChangeDetectionStrategy, Component, computed, input, output} from '@angular/core';
import {BargraphNode} from '../record-formatter/bargraph-formatter/bargraph-formatter';
import {MatTooltip} from '@angular/material/tooltip';
interface BarData {
label: string;
count: number;
width: number;
time: number;
text: string;
}
@Component({
selector: 'ng-bar-chart',
templateUrl: './bar-chart.component.html',
styleUrls: ['./bar-chart.component.scss'],
animations: [
trigger('appear', [
transition(':enter', [style({width: 0}), animate('.3s ease', style({width: '*'}))]),
]),
trigger('stagger', [transition(':enter', [query(':enter', stagger('.1s', [animateChild()]))])]),
],
standalone: true,
imports: [MatTooltip],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BarChartComponent {
readonly data = input<BargraphNode[]>([]);
readonly internalData = computed(() => {
const nodes = this.data() ?? [];
const values: BarData[] = [];
const max = nodes.reduce((a: number, c) => Math.max(a, c.value), -Infinity);
for (const node of nodes) {
values.push({
label: node.label,
count: node.count ?? 1,
width: (node.value / max) * 100,
time: node.value,
text: createBarText(node),
});
}
return values;
});
readonly color = input.required<string>();
readonly barClick = output<BargraphNode>();
}
export function createBarText(bar: BargraphNode) {
return `${bar.label} | ${bar.value.toFixed(1)} ms | ${bar.count} ${
bar.count === 1 ? 'instance' : 'instances'
}`;
}
| {
"end_byte": 1940,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bar-chart.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/execution-details.component.scss_0_166 | table {
border-collapse: collapse;
width: 100%;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
}
th,
td {
border-bottom: 1px solid #ddd;
}
| {
"end_byte": 166,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/execution-details.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/flamegraph-visualizer.component.html_0_207 | <div class="level-profile-wrapper">
<ngx-flamegraph
(frameClick)="selectFrame($event)"
[config]="{ data: profilerBars(), color: colors() }"
siblingLayout="equal"
>
</ngx-flamegraph>
</div>
| {
"end_byte": 207,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/flamegraph-visualizer.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/timeline-visualizer.component.ts_0_3306 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
Component,
computed,
effect,
input,
signal,
untracked,
} from '@angular/core';
import {ProfilerFrame} from 'protocol';
import {BargraphNode} from '../record-formatter/bargraph-formatter';
import {FlamegraphNode} from '../record-formatter/flamegraph-formatter';
import {VisualizationMode} from '../visualization-mode';
import {ExecutionDetailsComponent} from './execution-details.component';
import {MatToolbar} from '@angular/material/toolbar';
import {MatCard} from '@angular/material/card';
import {BargraphVisualizerComponent} from './bargraph-visualizer.component';
import {TreeMapVisualizerComponent} from './tree-map-visualizer.component';
import {FlamegraphVisualizerComponent} from './flamegraph-visualizer.component';
import {SplitAreaDirective} from '../../../../vendor/angular-split/lib/component/splitArea.directive';
import {SplitComponent} from '../../../../vendor/angular-split/lib/component/split.component';
import {DecimalPipe} from '@angular/common';
export interface SelectedEntry {
entry: BargraphNode | FlamegraphNode;
selectedDirectives: SelectedDirective[];
parentHierarchy?: {name: string}[];
}
export interface SelectedDirective {
directive: string;
method: string;
value: number;
}
interface SelectedNode {
visualizationMode: VisualizationMode;
node: SelectedEntry;
}
@Component({
selector: 'ng-timeline-visualizer',
templateUrl: './timeline-visualizer.component.html',
styleUrls: ['./timeline-visualizer.component.scss'],
standalone: true,
imports: [
SplitComponent,
SplitAreaDirective,
FlamegraphVisualizerComponent,
TreeMapVisualizerComponent,
BargraphVisualizerComponent,
MatCard,
MatToolbar,
ExecutionDetailsComponent,
DecimalPipe,
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TimelineVisualizerComponent {
readonly visualizationMode = input.required<VisualizationMode>();
readonly frame = input.required<ProfilerFrame>();
readonly changeDetection = input.required<boolean>();
cmpVisualizationModes = VisualizationMode;
private readonly selectedNodeWithVizMode = signal<SelectedNode | null>(null);
private readonly selectedNode = computed(() => {
const nodeWithMode = this.selectedNodeWithVizMode();
if (this.visualizationMode() !== nodeWithMode?.visualizationMode) return null;
return nodeWithMode.node;
});
readonly selectedEntry = computed(() => this.selectedNode()?.entry ?? null);
readonly selectedDirectives = computed(() => this.selectedNode()?.selectedDirectives ?? []);
readonly parentHierarchy = computed(() => this.selectedNode()?.parentHierarchy ?? []);
constructor() {
effect(() => {
const nodeWithMode = untracked(this.selectedNodeWithVizMode);
if (nodeWithMode?.visualizationMode !== this.visualizationMode()) {
this.selectedNodeWithVizMode.set(null);
}
});
}
handleNodeSelect(selected: SelectedEntry): void {
this.selectedNodeWithVizMode.set({
visualizationMode: this.visualizationMode(),
node: selected,
});
}
}
| {
"end_byte": 3306,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/timeline-visualizer.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/BUILD.bazel_0_2286 | load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//devtools/tools:ng_module.bzl", "ng_module")
package(default_visibility = ["//visibility:public"])
_STYLE_SRCS = [
"bar-chart.component.scss",
"bargraph-visualizer.component.scss",
"execution-details.component.scss",
"flamegraph-visualizer.component.scss",
"timeline-visualizer.component.scss",
"tree-map-visualizer.component.scss",
]
_STYLE_LABELS = [
src[:-len(".component.scss")].replace("-", "_") + "_styles"
for src in _STYLE_SRCS
]
[
sass_binary(
name = label,
src = src,
)
for label, src in zip(_STYLE_LABELS, _STYLE_SRCS)
]
ng_module(
name = "recording-visualizer",
srcs = [
"bar-chart.component.ts",
"bargraph-visualizer.component.ts",
"execution-details.component.ts",
"flamegraph-visualizer.component.ts",
"profile-formatter.ts",
"timeline-visualizer.component.ts",
"tree-map-visualizer.component.ts",
],
angular_assets = [
"timeline-visualizer.component.html",
"tree-map-visualizer.component.html",
"flamegraph-visualizer.component.html",
"bargraph-visualizer.component.html",
"bar-chart.component.html",
"execution-details.component.html",
] + _STYLE_LABELS,
deps = [
"//devtools/projects/ng-devtools/src/lib:theme",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/bargraph-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/visualization-mode",
"//devtools/projects/ng-devtools/src/lib/vendor/angular-split",
"//devtools/projects/ng-devtools/src/lib/vendor/webtreemap",
"//devtools/projects/protocol",
"//packages/animations",
"//packages/common",
"//packages/core",
"//packages/core/rxjs-interop",
"@npm//@angular/material",
"@npm//@types",
"@npm//ngx-flamegraph",
"@npm//rxjs",
],
)
| {
"end_byte": 2286,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/profile-formatter.ts_0_1561 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DirectiveProfile} from 'protocol';
import {SelectedDirective} from './timeline-visualizer.component';
const ignore = /^([A-Z]|listener|\d|listener)/;
const formatOutput = (outputName: string) => {
const parts = outputName.split('_');
const output: string[] = [];
let idx = parts.length;
while (idx >= 0) {
idx--;
if (ignore.test(parts[idx]) && parts[idx] !== 'HostBindingHandler') {
continue;
}
output.push(parts[idx]);
}
return output
.filter((el) => !!el)
.reverse()
.join('-');
};
export const formatDirectiveProfile = (nodes: DirectiveProfile[]) => {
const graphData: SelectedDirective[] = [];
nodes.forEach((node) => {
const {changeDetection} = node;
if (changeDetection) {
graphData.push({
directive: node.name,
method: 'changes',
value: parseFloat(changeDetection.toFixed(2)),
});
}
Object.entries(node.lifecycle).forEach(([key, lifeCycleProfile]) => {
graphData.push({
directive: node.name,
method: key,
value: +lifeCycleProfile.toFixed(2),
});
});
Object.entries(node.outputs).forEach(([key, outputProfile]) => {
graphData.push({
directive: node.name,
method: formatOutput(key),
value: +outputProfile.toFixed(2),
});
});
});
return graphData;
};
| {
"end_byte": 1561,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/profile-formatter.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/tree-map-visualizer.component.scss_0_456 | .web-tree {
height: calc(100% - 25px);
width: calc(100% - 25px);
margin: auto;
}
:host {
::ng-deep {
.webtreemap-caption {
font-size: 0.9em;
}
.webtreemap-node:hover {
background: #ebf1fb;
}
}
}
:host-context(.dark-theme) {
::ng-deep {
.webtreemap-node {
background: #202124;
}
.webtreemap-node:hover {
background: #262d36;
}
.webtreemap-caption {
color: #ffffff;
}
}
}
| {
"end_byte": 456,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/tree-map-visualizer.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bar-chart.component.html_0_326 | <div class="wrapper" @stagger>
@for (bar of internalData(); track $index) {
<div
@appear
(click)="barClick.emit(data()[$index])"
class="bar"
[style.backgroundColor]="color()"
[style.width.%]="bar.width"
[matTooltip]="bar.text">
<span>{{ bar.text }}</span>
</div>
}
</div>
| {
"end_byte": 326,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bar-chart.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bar-chart.component.scss_0_575 | .bar {
width: 0%;
margin-bottom: 7px;
align-items: center;
display: flex;
padding-top: 3px;
padding-bottom: 3px;
opacity: 0.8;
cursor: pointer;
transition: opacity 0.3s ease-out, width 0.3s ease;
}
.bar span {
margin-left: 10px;
max-width: calc(100% - 20px);
display: inline-block;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
opacity: 1;
}
.bar:hover {
opacity: 1;
}
:host,
.wrapper {
width: calc(100% - 5px);
height: 100%;
display: block;
}
:host-context(.dark-theme) {
.bar span {
color: #bcc5ce;
}
}
| {
"end_byte": 575,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bar-chart.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/execution-details.component.ts_0_675 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, input} from '@angular/core';
import {SelectedDirective} from './timeline-visualizer.component';
@Component({
selector: 'ng-execution-details',
templateUrl: './execution-details.component.html',
styleUrls: ['./execution-details.component.scss'],
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ExecutionDetailsComponent {
readonly data = input.required<SelectedDirective[]>();
}
| {
"end_byte": 675,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/execution-details.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/tree-map-visualizer.component.html_0_38 | <div #webTree class="web-tree"></div>
| {
"end_byte": 38,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/tree-map-visualizer.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bargraph-visualizer.component.ts_0_1824 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, computed, inject, input, output} from '@angular/core';
import {ProfilerFrame} from 'protocol';
import {ThemeService} from '../../../../theme-service';
import {BarGraphFormatter, BargraphNode} from '../record-formatter/bargraph-formatter/index';
import {formatDirectiveProfile} from './profile-formatter';
import {SelectedDirective, SelectedEntry} from './timeline-visualizer.component';
import {BarChartComponent} from './bar-chart.component';
@Component({
selector: 'ng-bargraph-visualizer',
templateUrl: './bargraph-visualizer.component.html',
styleUrls: ['./bargraph-visualizer.component.scss'],
standalone: true,
imports: [BarChartComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BargraphVisualizerComponent {
public themeService = inject(ThemeService);
readonly barColor = computed(() => {
return this.themeService.currentTheme() === 'dark-theme' ? '#073d69' : '#cfe8fc';
});
readonly nodeSelect = output<SelectedEntry>();
private readonly _formatter = new BarGraphFormatter();
frame = input.required<ProfilerFrame>();
profileRecords = computed(() => this._formatter.formatFrame(this.frame()));
formatEntryData(bargraphNode: BargraphNode): SelectedDirective[] {
return formatDirectiveProfile(bargraphNode.directives ?? []);
}
selectNode(node: BargraphNode): void {
this.nodeSelect.emit({
entry: node,
parentHierarchy: node.parents.map((element) => {
return {name: element.directives[0].name};
}),
selectedDirectives: this.formatEntryData(node),
});
}
}
| {
"end_byte": 1824,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/recording-visualizer/bargraph-visualizer.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter-spec-constants.ts_0_9158 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {FlamegraphNode} from './flamegraph-formatter';
export const SIMPLE_RECORD = [
{
children: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'TooltipDirective',
lifecycle: {},
outputs: {},
changeDetection: 5,
changeDetected: true,
},
{
changeDetection: 5,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'TodoComponent',
changeDetected: true,
},
],
},
],
directives: [
{
isComponent: false,
isElement: false,
name: 'NgForOf',
changeDetected: false,
lifecycle: {ngDoCheck: 7},
outputs: {},
changeDetection: 0,
},
],
},
];
export const SIMPLE_FORMATTED_FLAMEGRAPH_RECORD = [
{
value: 7,
label: '[NgForOf]',
changeDetected: false,
children: [
{
value: 10,
label: 'TodoComponent[TooltipDirective]',
children: [],
instances: 1,
original: SIMPLE_RECORD[0].children[0],
changeDetected: true,
},
],
instances: 1,
original: SIMPLE_RECORD[0],
},
];
export const SIMPLE_FORMATTED_TREE_MAP_RECORD = [
Object({
id: '[NgForOf]',
size: 17,
value: 7,
children: [
Object({
id: 'TodoComponent[TooltipDirective]',
size: 10,
value: 10,
children: [],
original: SIMPLE_RECORD[0].children[0],
}),
],
original: SIMPLE_RECORD[0],
}),
];
export const NESTED_RECORD = [
{
children: [
{
children: [
{
children: [
{
children: [
{
children: [
{
children: [
{
children: [
{
children: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'TooltipDirective',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
{
changeDetection: 0,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'TodoComponent',
},
],
},
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'TooltipDirective',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
{
changeDetection: 0,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'TodoComponent',
},
],
},
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'TooltipDirective',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
{
changeDetection: 0,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'TodoComponent',
},
],
},
],
directives: [
{
isComponent: false,
isElement: false,
name: 'NgForOf',
lifecycle: {ngDoCheck: 7},
outputs: {},
changeDetection: 0,
},
],
},
],
directives: [
{
changeDetection: 9,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'TodosComponent',
},
],
},
],
directives: [
{
isComponent: false,
isElement: false,
name: 'RouterOutlet',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
],
},
],
directives: [
{
changeDetection: 1,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'AppComponent',
},
],
},
],
directives: [
{
isComponent: false,
isElement: false,
name: 'RouterOutlet',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
],
},
{
children: [],
directives: [
{
changeDetection: 1,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'HeavyComponent',
},
],
},
],
directives: [
{
changeDetection: 1,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'DemoAppComponent',
},
],
},
],
directives: [
{
isComponent: false,
isElement: false,
name: 'RouterOutlet',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
],
},
],
directives: [
{
changeDetection: 1,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'AppComponent',
},
],
},
{
children: [],
directives: [
{
changeDetection: 1,
isElement: true,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'ZippyComponent',
},
],
},
]; | {
"end_byte": 9158,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter-spec-constants.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter-spec-constants.ts_9159_14527 | export const NESTED_FORMATTED_FLAMEGRAPH_RECORD: FlamegraphNode[] = [
{
value: 1,
label: 'AppComponent',
changeDetected: true,
children: [
{
value: 0,
label: '[RouterOutlet]',
changeDetected: false,
children: [
{
value: 1,
label: 'DemoAppComponent',
changeDetected: true,
children: [
{
value: 0,
label: '[RouterOutlet]',
changeDetected: false,
children: [
{
value: 1,
label: 'AppComponent',
changeDetected: true,
children: [
{
value: 0,
label: '[RouterOutlet]',
changeDetected: false,
children: [
{
value: 9,
label: 'TodosComponent',
changeDetected: true,
children: [
{
value: 7,
label: '[NgForOf]',
changeDetected: false,
children: [
{
value: 0,
label: 'TodoComponent[TooltipDirective]',
changeDetected: true,
children: [],
instances: 1,
original:
NESTED_RECORD[0].children[0].children[0].children[0]
.children[0].children[0].children[0].children[0]
.children[0],
},
{
value: 0,
label: 'TodoComponent[TooltipDirective]',
changeDetected: true,
children: [],
instances: 1,
original:
NESTED_RECORD[0].children[0].children[0].children[0]
.children[0].children[0].children[0].children[0]
.children[1],
},
{
value: 0,
label: 'TodoComponent[TooltipDirective]',
changeDetected: true,
children: [],
instances: 1,
original:
NESTED_RECORD[0].children[0].children[0].children[0]
.children[0].children[0].children[0].children[0]
.children[2],
},
],
instances: 1,
original:
NESTED_RECORD[0].children[0].children[0].children[0].children[0]
.children[0].children[0].children[0],
},
],
instances: 1,
original:
NESTED_RECORD[0].children[0].children[0].children[0].children[0]
.children[0].children[0],
},
],
instances: 1,
original:
NESTED_RECORD[0].children[0].children[0].children[0].children[0]
.children[0],
},
],
instances: 1,
original: NESTED_RECORD[0].children[0].children[0].children[0].children[0],
},
],
instances: 1,
original: NESTED_RECORD[0].children[0].children[0].children[0],
},
{
value: 1,
label: 'HeavyComponent',
changeDetected: true,
children: [],
instances: 1,
original: NESTED_RECORD[0].children[0].children[0].children[1],
},
],
instances: 1,
original: NESTED_RECORD[0].children[0].children[0],
},
],
instances: 1,
original: NESTED_RECORD[0].children[0],
},
],
instances: 1,
original: NESTED_RECORD[0],
},
{
value: 1,
label: 'ZippyComponent',
children: [],
changeDetected: true,
instances: 1,
original: {
children: [],
directives: [
{
changeDetection: 1,
isElement: true,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'ZippyComponent',
},
],
},
},
]; | {
"end_byte": 14527,
"start_byte": 9159,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter-spec-constants.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/frame-merger.spec.ts_0_3918 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ProfilerFrame} from 'protocol';
import {mergeFrames} from './frame-merger';
describe('mergeFrames', () => {
it('should work with empty frames', () => {
expect(mergeFrames([])).toBeNull();
});
it('should work with a single frame', () => {
const frame = {
directives: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
name: 'Foo',
},
],
},
],
duration: 5,
source: 'foo',
};
const result = mergeFrames([frame]);
expect(result).toEqual(frame);
// Should be different reference
expect(result).not.toBe(frame);
});
it('should merge frames when nesting matches', () => {
const frame = {
directives: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
changeDetection: 10,
name: 'Foo',
},
],
},
],
duration: 5,
source: 'foo',
};
const result = mergeFrames([frame, frame]);
expect(result).toEqual({
directives: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
changeDetection: 20,
name: 'Foo',
},
],
},
],
duration: 10,
source: '',
});
});
it('should merge frames when nesting does not match', () => {
const frame = {
directives: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
changeDetection: 10,
name: 'Foo',
},
],
},
],
duration: 5,
source: 'foo',
};
const frame2: ProfilerFrame = {
directives: [
{
children: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
changeDetection: 10,
name: 'Foo',
},
],
},
],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
changeDetection: 10,
name: 'Foo',
},
],
},
],
duration: 5,
source: 'foo',
};
const result = mergeFrames([frame, frame2]);
expect(result).toEqual({
directives: [
{
children: [
{
children: [],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
changeDetection: 10,
name: 'Foo',
},
],
},
],
directives: [
{
isComponent: false,
isElement: false,
lifecycle: {},
outputs: {},
changeDetection: 20,
name: 'Foo',
},
],
},
],
duration: 10,
source: '',
});
});
});
| {
"end_byte": 3918,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/frame-merger.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/BUILD.bazel_0_1437 | load("//devtools/tools:typescript.bzl", "ts_library", "ts_test_library")
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "record-formatter",
srcs = glob(
include = [
"*.ts",
],
exclude = [
"record-formatter-spec-constants.ts",
"record-formatter.spec.ts",
"frame-merger.spec.ts",
],
),
deps = [
"//devtools/projects/protocol",
"//packages/core",
"@npm//@types",
"@npm//rxjs",
],
)
ts_library(
name = "record_formatter_spec_constants",
srcs = ["record-formatter-spec-constants.ts"],
deps = [
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter",
"//devtools/projects/protocol",
"//packages/core",
"@npm//@types",
"@npm//rxjs",
],
)
ts_test_library(
name = "test_lib",
srcs = [
"frame-merger.spec.ts",
"record-formatter.spec.ts",
],
deps = [
":record-formatter",
":record_formatter_spec_constants",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter",
"//devtools/projects/protocol",
],
)
karma_web_test_suite(
name = "test",
deps = [
":test_lib",
],
)
| {
"end_byte": 1437,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter.spec.ts_0_5781 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DirectiveProfile, ElementProfile, ProfilerFrame} from 'protocol';
import {RecordFormatter} from './record-formatter';
class MockFormatter extends RecordFormatter<any> {
override addFrame(nodes: any[], elements: ElementProfile[]): void {
return;
}
override formatFrame(frame: ProfilerFrame): any {
return;
}
}
const formatter = new MockFormatter();
describe('getValue cases', () => {
let element: any;
it('calculates value with no lifecycle hooks', () => {
element = {
children: [],
directives: [
{
changeDetection: 10,
isElement: false,
isComponent: true,
lifecycle: {},
name: 'AppComponent',
},
],
};
expect(formatter.getValue(element)).toBe(10);
});
it('calculates value with 0 change detection and existing lifecycle hooks', () => {
element = {
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'NgForOf',
lifecycle: {ngDoCheck: 5},
changeDetection: 0,
},
],
};
expect(formatter.getValue(element)).toBe(5);
});
it('calculates value with non 0 change detection and one lifecycle hook', () => {
element = {
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'NgForOf',
lifecycle: {ngDoCheck: 5},
changeDetection: 10,
},
],
};
expect(formatter.getValue(element)).toBe(15);
});
it('calculates value with non 0 change detection and multiple lifecycle hooks', () => {
element = {
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'NgForOf',
lifecycle: {ngDoCheck: 5, ngAfterViewInit: 100},
changeDetection: 10,
},
],
};
expect(formatter.getValue(element)).toBe(115);
});
});
describe('getLabel cases', () => {
let element: ElementProfile;
it('has only components', () => {
element = {
children: [],
directives: [
{
changeDetection: 10,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'AppComponent',
},
],
};
expect(formatter.getLabel(element)).toBe('AppComponent');
});
it('has only directives', () => {
element = {
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'RouterOutlet',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
],
};
expect(formatter.getLabel(element)).toBe('[RouterOutlet]');
});
it('has a component and a directive', () => {
element = {
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'TooltipDirective',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
{
changeDetection: 0,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'TodoComponent',
},
],
};
expect(formatter.getLabel(element)).toBe('TodoComponent[TooltipDirective]');
});
it('has a component and multiple directives', () => {
element = {
children: [],
directives: [
{
isComponent: false,
isElement: false,
name: 'TooltipDirective',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
{
isComponent: false,
isElement: false,
name: 'RandomDirective',
lifecycle: {},
outputs: {},
changeDetection: 0,
},
{
changeDetection: 0,
isElement: false,
isComponent: true,
lifecycle: {},
outputs: {},
name: 'TodoComponent',
},
],
};
expect(formatter.getLabel(element)).toBe('TodoComponent[TooltipDirective, RandomDirective]');
});
});
describe('getDirectiveValue cases', () => {
let directive!: DirectiveProfile;
it('calculates value with no lifecycle hooks', () => {
directive = {
changeDetection: 10,
isElement: false,
isComponent: true,
lifecycle: {},
name: 'AppComponent',
outputs: {},
};
expect(formatter.getDirectiveValue(directive)).toBe(10);
});
it('calculates value with 0 change detection and existing lifecycle hooks', () => {
directive = {
isComponent: false,
isElement: false,
name: 'NgForOf',
lifecycle: {ngDoCheck: 5},
changeDetection: 0,
outputs: {},
};
expect(formatter.getDirectiveValue(directive)).toBe(5);
});
it('calculates value with non 0 change detection and one lifecycle hook', () => {
directive = {
isComponent: false,
isElement: false,
name: 'NgForOf',
lifecycle: {ngDoCheck: 5},
changeDetection: 10,
outputs: {},
};
expect(formatter.getDirectiveValue(directive)).toBe(15);
});
it('calculates value with non 0 change detection and multiple lifecycle hooks', () => {
directive = {
isComponent: false,
isElement: false,
name: 'NgForOf',
lifecycle: {ngDoCheck: 5, ngAfterViewInit: 100},
changeDetection: 10,
outputs: {},
};
expect(formatter.getDirectiveValue(directive)).toBe(115);
});
});
| {
"end_byte": 5781,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter.ts_0_1661 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DirectiveProfile, ElementProfile, ProfilerFrame} from 'protocol';
export interface TimelineView<T> {
timeline: AppEntry<T>[];
}
export interface AppEntry<T> {
app: T[];
timeSpent: number;
source: string;
}
export interface GraphNode {
toolTip: string;
style: unknown;
frame: ProfilerFrame;
}
export abstract class RecordFormatter<T> {
abstract formatFrame(frame: ProfilerFrame): T;
abstract addFrame(nodes: T | T[], elements: ElementProfile[]): number | void;
getLabel(element: ElementProfile): string {
const name = element.directives
.filter((d) => d.isComponent)
.map((c) => c.name)
.join(', ');
const attributes = [
...new Set(element.directives.filter((d) => !d.isComponent).map((d) => d.name)),
].join(', ');
return attributes === '' ? name : `${name}[${attributes}]`;
}
getValue(element: ElementProfile): number {
let result = 0;
element.directives.forEach((dir) => {
result += this.getDirectiveValue(dir);
});
return result;
}
getDirectiveValue(directive: DirectiveProfile): number {
let result = 0;
let current = directive.changeDetection;
if (current === undefined) {
current = 0;
}
result += current;
Object.values(directive.lifecycle).forEach((lifecycleProfile) => {
const value = parseFloat(lifecycleProfile);
if (!isNaN(value)) {
result += value;
}
});
return result;
}
}
| {
"end_byte": 1661,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/record-formatter.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/frame-merger.ts_0_2005 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DirectiveProfile, ElementProfile, LifecycleProfile, ProfilerFrame} from 'protocol';
const mergeProperty = (mergeInProp: number | undefined, value: number | undefined) => {
if (mergeInProp === undefined) {
return value;
}
if (value === undefined) {
return mergeInProp;
}
return mergeInProp + value;
};
const mergeDirective = (mergeIn: DirectiveProfile, second: DirectiveProfile) => {
mergeIn.changeDetection = mergeProperty(mergeIn.changeDetection, second.changeDetection);
Object.keys(mergeIn.lifecycle).forEach((key) => {
const hook = key as keyof LifecycleProfile;
mergeIn.lifecycle[hook] = mergeProperty(mergeIn.lifecycle[hook], second.lifecycle[hook]);
});
};
const mergeDirectives = (mergeIn: ElementProfile[], second: ElementProfile[]) => {
for (let i = 0; i < second.length; i++) {
if (!mergeIn[i]) {
mergeIn[i] = {
children: [],
directives: [],
};
}
second[i].directives.forEach((d, idx) => {
const mergeInDirective = mergeIn[i].directives[idx];
if (mergeInDirective && mergeInDirective.name === d.name) {
mergeDirective(mergeInDirective, d);
} else {
mergeIn[i].directives.push(d);
}
});
mergeDirectives(mergeIn[i].children, second[i].children);
}
};
const mergeFrame = (mergeIn: ProfilerFrame, second: ProfilerFrame) => {
mergeIn.duration += second.duration;
mergeIn.source = '';
mergeDirectives(mergeIn.directives, second.directives);
};
export const mergeFrames = (frames: ProfilerFrame[]): ProfilerFrame | null => {
if (!frames || !frames.length) {
return null;
}
const first = JSON.parse(JSON.stringify(frames[0])) as ProfilerFrame;
for (let i = 1; i < frames.length; i++) {
mergeFrame(first, frames[i]);
}
return first;
};
| {
"end_byte": 2005,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/frame-merger.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/bargraph-formatter/BUILD.bazel_0_627 | load("//devtools/tools:typescript.bzl", "ts_library")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "bargraph-formatter",
srcs = glob(
include = [
"*.ts",
],
),
deps = [
"//devtools/projects/ng-devtools/src/lib:theme",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter",
"//devtools/projects/ng-devtools/src/lib/vendor/memo-decorator",
"//devtools/projects/protocol",
"//packages/core",
"@npm//@types",
"@npm//ngx-flamegraph",
"@npm//rxjs",
],
)
| {
"end_byte": 627,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/bargraph-formatter/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/bargraph-formatter/index.ts_0_242 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export * from './bargraph-formatter';
| {
"end_byte": 242,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/bargraph-formatter/index.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/bargraph-formatter/bargraph-formatter.ts_0_2725 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DirectiveProfile, ElementProfile, ProfilerFrame} from 'protocol';
import {memo} from '../../../../../vendor/memo-decorator';
import {RecordFormatter} from '../record-formatter';
export interface BargraphNode {
parents: ElementProfile[];
value: number;
label: string;
original: ElementProfile;
count: number; // number of merged nodes with the same label
directives?: DirectiveProfile[];
}
export class BarGraphFormatter extends RecordFormatter<BargraphNode[]> {
@memo({cache: new WeakMap()})
override formatFrame(frame: ProfilerFrame): BargraphNode[] {
const result: BargraphNode[] = [];
this.addFrame(result, frame.directives);
// Remove nodes with 0 value.
const nodesWithValue = result.filter((element) => element.value > 0);
// Merge nodes with the same label.
const uniqueBarGraphNodes: {[key: string]: BargraphNode} = {};
nodesWithValue.forEach((node) => {
if (uniqueBarGraphNodes[node.label] === undefined) {
uniqueBarGraphNodes[node.label] = {
label: node.label,
value: node.value,
original: node.original,
directives: [...node.original.directives],
parents: [],
count: 1,
};
} else {
// sum values of merged nodes
uniqueBarGraphNodes[node.label].value += node.value;
// merge directives of merged nodes
uniqueBarGraphNodes[node.label].directives!.push(...node.original.directives);
// increment count of merged nodes with the same label
uniqueBarGraphNodes[node.label].count++;
}
});
// Sort nodes by value.
return Object.values(uniqueBarGraphNodes).sort((a, b) => b.value - a.value);
}
override addFrame(
nodes: BargraphNode[],
elements: ElementProfile[],
parents: ElementProfile[] = [],
): number {
let timeSpent = 0;
elements.forEach((element) => {
// Possibly undefined because of the insertion on the backend.
if (!element) {
console.error('Unable to insert undefined element');
return;
}
timeSpent += this.addFrame(nodes, element.children, parents.concat(element));
timeSpent += super.getValue(element);
element.directives.forEach((dir) => {
const innerNode: BargraphNode = {
parents,
value: super.getDirectiveValue(dir),
label: dir.name,
original: element,
count: 1,
};
nodes.push(innerNode);
});
});
return timeSpent;
}
}
| {
"end_byte": 2725,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/bargraph-formatter/bargraph-formatter.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/flamegraph-formatter.spec.ts_0_1165 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {AppEntry} from '../record-formatter';
import {
NESTED_FORMATTED_FLAMEGRAPH_RECORD,
NESTED_RECORD,
SIMPLE_FORMATTED_FLAMEGRAPH_RECORD,
SIMPLE_RECORD,
} from '../record-formatter-spec-constants';
import {FlamegraphFormatter, FlamegraphNode} from './flamegraph-formatter';
const formatter = new FlamegraphFormatter();
describe('addFrame cases', () => {
let entry: AppEntry<FlamegraphNode>;
let timeSpent;
beforeEach(() => {
entry = {
app: [],
timeSpent: 0,
source: '',
};
});
it('add frame for simple case', () => {
timeSpent = formatter.addFrame(entry.app, SIMPLE_RECORD);
expect(timeSpent).toBe(17);
expect(entry.app).toEqual(SIMPLE_FORMATTED_FLAMEGRAPH_RECORD);
});
it('add frame for deeply nested records', () => {
timeSpent = formatter.addFrame(entry.app, NESTED_RECORD);
expect(timeSpent).toBe(21);
expect(entry.app).toEqual(NESTED_FORMATTED_FLAMEGRAPH_RECORD);
});
});
| {
"end_byte": 1165,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/flamegraph-formatter.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/flamegraph-formatter.ts_0_2849 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ElementProfile, ProfilerFrame} from 'protocol';
import {Theme} from '../../../../../theme-service';
import {RecordFormatter} from '../record-formatter';
export interface FlamegraphNode {
value: number;
color?: string;
children: FlamegraphNode[];
label: string;
instances: number;
original: ElementProfile;
changeDetected: boolean;
}
export const ROOT_LEVEL_ELEMENT_LABEL = 'Entire application';
export class FlamegraphFormatter extends RecordFormatter<FlamegraphNode> {
override formatFrame(
frame: ProfilerFrame,
showChangeDetection?: boolean,
theme?: Theme,
): FlamegraphNode {
const result: FlamegraphNode = {
value: 0,
label: ROOT_LEVEL_ELEMENT_LABEL,
children: [],
instances: 1,
changeDetected: false,
original: {
children: [],
directives: [],
},
};
if (showChangeDetection) {
result.color =
theme === 'dark-theme' ? CHANGE_DETECTION_COLOR_DARK : CHANGE_DETECTION_COLOR_LIGHT;
}
this.addFrame(result.children, frame.directives, showChangeDetection, theme);
return result;
}
override addFrame(
nodes: FlamegraphNode[],
elements: ElementProfile[],
showChangeDetection?: boolean,
theme?: Theme,
): number {
let timeSpent = 0;
elements.forEach((element) => {
// Possibly undefined because of
// the insertion on the backend.
if (!element) {
console.error('Unable to insert undefined element');
return;
}
const changeDetected = didRunChangeDetection(element);
const node: FlamegraphNode = {
value: super.getValue(element),
label: super.getLabel(element),
children: [],
instances: 1,
original: element,
changeDetected,
};
if (showChangeDetection) {
const CHANGE_DETECTION_COLOR =
theme === 'dark-theme' ? CHANGE_DETECTION_COLOR_DARK : CHANGE_DETECTION_COLOR_LIGHT;
node.color = changeDetected ? CHANGE_DETECTION_COLOR : NO_CHANGE_DETECTION_COLOR;
}
timeSpent += this.addFrame(node.children, element.children, showChangeDetection, theme);
timeSpent += node.value;
nodes.push(node);
});
return timeSpent;
}
}
const CHANGE_DETECTION_COLOR_LIGHT = '#5cadd3';
const CHANGE_DETECTION_COLOR_DARK = '#073d69';
const NO_CHANGE_DETECTION_COLOR = 'transparent';
const didRunChangeDetection = (profile: ElementProfile) => {
const components = profile.directives.filter((d) => d.isComponent);
if (!components.length) {
return false;
}
return components.some((c) => c.changeDetection !== undefined);
};
| {
"end_byte": 2849,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/flamegraph-formatter.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/BUILD.bazel_0_1239 | load("//devtools/tools:ng_module.bzl", "ng_module")
load("//devtools/tools:typescript.bzl", "ts_test_library")
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
package(default_visibility = ["//visibility:public"])
ng_module(
name = "flamegraph-formatter",
srcs = glob(
include = [
"*.ts",
],
exclude = ["flamegraph-formatter.spec.ts"],
),
deps = [
"//devtools/projects/ng-devtools/src/lib:theme",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter",
"//devtools/projects/protocol",
"//packages/core",
"@npm//@types",
"@npm//memo-decorator",
"@npm//rxjs",
],
)
ts_test_library(
name = "test_lib",
srcs = [
"flamegraph-formatter.spec.ts",
],
deps = [
":flamegraph-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter:record_formatter_spec_constants",
"//devtools/projects/protocol",
],
)
karma_web_test_suite(
name = "test",
deps = [
":test_lib",
],
)
| {
"end_byte": 1239,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/index.ts_0_244 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export * from './flamegraph-formatter';
| {
"end_byte": 244,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/flamegraph-formatter/index.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/tree-map-formatter.spec.ts_0_804 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {AppEntry} from '../record-formatter';
import {SIMPLE_FORMATTED_TREE_MAP_RECORD, SIMPLE_RECORD} from '../record-formatter-spec-constants';
import {TreeMapFormatter, TreeMapNode} from './tree-map-formatter';
const formatter = new TreeMapFormatter();
describe('addFrame cases', () => {
let entry: AppEntry<TreeMapNode>;
beforeEach(() => {
entry = {
app: [],
timeSpent: 0,
source: '',
};
});
it('add frame for simple case', () => {
formatter.addFrame(entry.app, SIMPLE_RECORD);
expect(entry.app).toEqual(SIMPLE_FORMATTED_TREE_MAP_RECORD);
});
});
| {
"end_byte": 804,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/tree-map-formatter.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/tree-map-formatter.ts_0_1631 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ElementProfile, ProfilerFrame} from 'protocol';
import {memo} from '../../../../../vendor/memo-decorator';
import {RecordFormatter} from '../record-formatter';
export interface TreeMapNode {
id: string;
value: number;
size: number;
children: TreeMapNode[];
original: ElementProfile | null;
}
export class TreeMapFormatter extends RecordFormatter<TreeMapNode> {
@memo({cache: new WeakMap()})
override formatFrame(record: ProfilerFrame): TreeMapNode {
const children: TreeMapNode[] = [];
this.addFrame(children, record.directives);
const size = children.reduce((accum, curr) => {
return accum + curr.size;
}, 0);
return {
id: 'Application',
size,
value: size,
children,
original: null,
};
}
override addFrame(
nodes: TreeMapNode[],
elements: ElementProfile[],
prev: TreeMapNode | null = null,
): void {
elements.forEach((element) => {
if (!element) {
console.error('Unable to insert undefined element');
return;
}
const nodeVal = super.getValue(element);
const node: TreeMapNode = {
id: super.getLabel(element),
size: nodeVal,
value: nodeVal,
children: [],
original: element,
};
this.addFrame(node.children, element.children, node);
if (prev) {
prev.size += node.size;
}
nodes.push(node);
});
}
}
| {
"end_byte": 1631,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/tree-map-formatter.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/BUILD.bazel_0_1128 | load("//devtools/tools:typescript.bzl", "ts_library", "ts_test_library")
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "tree-map-formatter",
srcs = glob(
include = [
"*.ts",
],
exclude = [
"tree-map-formatter.spec.ts",
],
),
deps = [
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter",
"//devtools/projects/ng-devtools/src/lib/vendor/memo-decorator",
"//devtools/projects/protocol",
],
)
ts_test_library(
name = "test_lib",
srcs = [
"tree-map-formatter.spec.ts",
],
deps = [
":tree-map-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter:record_formatter_spec_constants",
"//devtools/projects/protocol",
],
)
karma_web_test_suite(
name = "test",
deps = [
":test_lib",
],
)
| {
"end_byte": 1128,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/index.ts_0_242 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export * from './tree-map-formatter';
| {
"end_byte": 242,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/record-formatter/tree-map-formatter/index.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/visualization-mode/BUILD.bazel_0_182 | load("//devtools/tools:typescript.bzl", "ts_library")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "visualization-mode",
srcs = ["index.ts"],
)
| {
"end_byte": 182,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/visualization-mode/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/visualization-mode/index.ts_0_275 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export enum VisualizationMode {
FlameGraph,
TreeMap,
BarGraph,
}
| {
"end_byte": 275,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/timeline/visualization-mode/index.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.scss_0_320 | :host {
height: 100%;
::ng-deep {
as-split-area {
overflow-y: hidden;
}
.as-split-gutter-icon {
display: none;
}
}
}
.prop-split {
display: flex;
flex-direction: column;
}
.property-tab-wrapper {
flex: 1;
overflow: auto;
width: 100%;
}
.hydration {
padding: 4px 8px;
} | {
"end_byte": 320,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.ts_0_2018 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
afterNextRender,
Component,
ElementRef,
inject,
Input,
input,
OnDestroy,
output,
signal,
ViewChild,
viewChild,
} from '@angular/core';
import {
ComponentExplorerView,
ComponentExplorerViewQuery,
DevToolsNode,
DirectivePosition,
ElementPosition,
Events,
MessageBus,
PropertyQuery,
PropertyQueryTypes,
} from 'protocol';
import {SplitComponent} from '../../../lib/vendor/angular-split/public_api';
import {ApplicationOperations} from '../../application-operations/index';
import {FrameManager} from '../../frame_manager';
import {BreadcrumbsComponent} from './directive-forest/breadcrumbs/breadcrumbs.component';
import {FlatNode} from './directive-forest/component-data-source';
import {DirectiveForestComponent} from './directive-forest/directive-forest.component';
import {IndexedNode} from './directive-forest/index-forest';
import {constructPathOfKeysToPropertyValue} from './property-resolver/directive-property-resolver';
import {
ElementPropertyResolver,
FlatNode as PropertyFlatNode,
} from './property-resolver/element-property-resolver';
import {PropertyTabComponent} from './property-tab/property-tab.component';
import {SplitAreaDirective} from '../../vendor/angular-split/lib/component/splitArea.directive';
import {MatSlideToggle} from '@angular/material/slide-toggle';
import {FormsModule} from '@angular/forms';
const sameDirectives = (a: IndexedNode, b: IndexedNode) => {
if ((a.component && !b.component) || (!a.component && b.component)) {
return false;
}
if (a.component && b.component && a.component.id !== b.component.id) {
return false;
}
const aDirectives = new Set(a.directives.map((d) => d.id));
for (const dir of b.directives) {
if (!aDirectives.has(dir.id)) {
return false;
}
}
return true;
}; | {
"end_byte": 2018,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.ts_2020_10356 | @Component({
selector: 'ng-directive-explorer',
templateUrl: './directive-explorer.component.html',
styleUrls: ['./directive-explorer.component.scss'],
providers: [
{
provide: ElementPropertyResolver,
useClass: ElementPropertyResolver,
},
],
standalone: true,
imports: [
SplitComponent,
SplitAreaDirective,
DirectiveForestComponent,
BreadcrumbsComponent,
PropertyTabComponent,
MatSlideToggle,
FormsModule,
],
})
export class DirectiveExplorerComponent implements OnDestroy {
readonly showCommentNodes = input(false);
@Input() isHydrationEnabled = false;
readonly toggleInspector = output<void>();
readonly directiveForest = viewChild(DirectiveForestComponent);
@ViewChild(SplitComponent, {static: true, read: ElementRef}) splitElementRef!: ElementRef;
@ViewChild('directiveForestSplitArea', {static: true, read: ElementRef})
directiveForestSplitArea!: ElementRef;
readonly currentSelectedElement = signal<IndexedNode | null>(null);
readonly forest = signal<DevToolsNode[]>([]);
readonly splitDirection = signal<'horizontal' | 'vertical'>('horizontal');
readonly parents = signal<FlatNode[] | null>(null);
readonly showHydrationNodeHighlights = signal(false);
private _resizeObserver!: ResizeObserver;
private _clickedElement: IndexedNode | null = null;
private _refreshRetryTimeout: null | ReturnType<typeof setTimeout> = null;
private readonly _appOperations = inject(ApplicationOperations);
private readonly _messageBus = inject<MessageBus<Events>>(MessageBus);
private readonly _propResolver = inject(ElementPropertyResolver);
private readonly _frameManager = inject(FrameManager);
constructor() {
afterNextRender(() => {
this._resizeObserver = new ResizeObserver((entries) => {
this.refreshHydrationNodeHighlightsIfNeeded();
const resizedEntry = entries[0];
if (resizedEntry.target === this.splitElementRef.nativeElement) {
this.splitDirection.set(
resizedEntry.contentRect.width <= 500 ? 'vertical' : 'horizontal',
);
}
});
this.subscribeToBackendEvents();
this.refresh();
this._resizeObserver.observe(this.splitElementRef.nativeElement);
this._resizeObserver.observe(this.directiveForestSplitArea.nativeElement);
});
}
ngOnDestroy(): void {
this._resizeObserver.unobserve(this.splitElementRef.nativeElement);
this._resizeObserver.unobserve(this.directiveForestSplitArea.nativeElement);
}
handleNodeSelection(node: IndexedNode | null): void {
if (node) {
// We want to guarantee that we're not reusing any of the previous properties.
// That's possible if the user has selected an NgForOf and after that
// they select another NgForOf instance. In this case, we don't want to diff the props
// we want to render from scratch.
if (this._clickedElement && !sameDirectives(this._clickedElement, node)) {
this._propResolver.clearProperties();
}
this._clickedElement = node;
this._messageBus.emit('setSelectedComponent', [node.position]);
this.refresh();
} else {
this._clickedElement = null;
this.currentSelectedElement.set(null);
}
}
subscribeToBackendEvents(): void {
this._messageBus.on('latestComponentExplorerView', (view: ComponentExplorerView) => {
this.forest.set(view.forest);
this.currentSelectedElement.set(this._clickedElement);
if (view.properties && this._clickedElement) {
this._propResolver.setProperties(this._clickedElement, view.properties);
}
});
this._messageBus.on('componentTreeDirty', () => this.refresh());
}
refresh(): void {
const success = this._messageBus.emit('getLatestComponentExplorerView', [
this._constructViewQuery(),
]);
// If the event was not throttled, we no longer need to retry.
if (success) {
this._refreshRetryTimeout && clearTimeout(this._refreshRetryTimeout);
this._refreshRetryTimeout = null;
return;
}
// If the event was throttled and we haven't scheduled a retry yet.
if (!this._refreshRetryTimeout) {
this._refreshRetryTimeout = setTimeout(() => this.refresh(), 500);
}
this.refreshHydrationNodeHighlightsIfNeeded();
}
viewSource(directiveName: string): void {
// find the index of the directive with directiveName in this.currentSelectedElement.directives
const selectedEl = this.currentSelectedElement();
if (!selectedEl) return;
const directiveIndex = selectedEl.directives.findIndex(
(directive) => directive.name === directiveName,
);
const selectedFrame = this._frameManager.selectedFrame;
if (!this._frameManager.frameHasUniqueUrl(selectedFrame)) {
this._messageBus.emit('log', [
{
level: 'warn',
message: `The currently inspected frame does not have a unique url on this page. Cannot view source.`,
},
]);
return;
}
this._appOperations.viewSource(
selectedEl.position,
directiveIndex !== -1 ? directiveIndex : undefined,
new URL(selectedFrame!.url),
);
}
handleSelectDomElement(node: IndexedNode): void {
const selectedFrame = this._frameManager.selectedFrame;
if (!this._frameManager.frameHasUniqueUrl(selectedFrame)) {
this._messageBus.emit('log', [
{
level: 'warn',
message: `The currently inspected frame does not have a unique url on this page. Cannot select DOM element.`,
},
]);
return;
}
this._appOperations.selectDomElement(node.position, new URL(selectedFrame!.url));
}
highlight(node: FlatNode): void {
if (!node.original.component) {
return;
}
this._messageBus.emit('createHighlightOverlay', [node.position]);
}
unhighlight(): void {
this._messageBus.emit('removeHighlightOverlay');
}
private _constructViewQuery(): ComponentExplorerViewQuery | undefined {
if (!this._clickedElement) {
return;
}
return {
selectedElement: this._clickedElement.position,
propertyQuery: this._getPropertyQuery(),
};
}
private _getPropertyQuery(): PropertyQuery {
// Here we handle the case when a given element has already been selected.
// We check if we're dealing with the same instance (i.e., if we have the same
// set of directives and component on it), if we do, we want to get the same
// set of properties which are already expanded.
if (
!this._clickedElement ||
!this.currentSelectedElement() ||
!sameDirectives(this._clickedElement, this.currentSelectedElement()!)
) {
return {
type: PropertyQueryTypes.All,
};
}
return {
type: PropertyQueryTypes.Specified,
properties: this._propResolver.getExpandedProperties() || {},
};
}
highlightComponent(position: ElementPosition): void {
this._messageBus.emit('createHighlightOverlay', [position]);
}
removeComponentHighlight(): void {
this._messageBus.emit('removeHighlightOverlay');
}
handleSelect(node: FlatNode): void {
this.directiveForest()?.handleSelect(node);
}
handleSetParents(parents: FlatNode[] | null): void {
this.parents.set(parents);
}
inspect({
node,
directivePosition,
}: {
node: PropertyFlatNode;
directivePosition: DirectivePosition;
}): void {
const objectPath = constructPathOfKeysToPropertyValue(node.prop);
const selectedFrame = this._frameManager.selectedFrame;
if (!this._frameManager.frameHasUniqueUrl(selectedFrame)) {
this._messageBus.emit('log', [
{
level: 'warn',
message: `The currently inspected frame does not have a unique url on this page. Cannot inspect object.`,
},
]);
return;
}
this._appOperations.inspect(directivePosition, objectPath, new URL(selectedFrame!.url));
}
hightlightHydrationNodes() {
this._messageBus.emit('createHydrationOverlay');
}
removeHydrationNodesHightlights() {
this._messageBus.emit('removeHydrationOverlay');
}
refreshHydrationNodeHighlightsIfNeeded() {
if (this.showHydrationNodeHighlights()) {
this.removeHydrationNodesHightlights();
this.hightlightHydrationNodes();
}
}
} | {
"end_byte": 10356,
"start_byte": 2020,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.html_0_1781 | <as-split unit="percent" [direction]="splitDirection()" [gutterSize]="9">
<as-split-area #directiveForestSplitArea size="60">
<as-split direction="vertical" [gutterSize]="9" unit="pixel" [disabled]="true">
<as-split-area size="*">
<ng-directive-forest
(selectNode)="handleNodeSelection($event)"
(selectDomElement)="handleSelectDomElement($event)"
(setParents)="handleSetParents($event)"
(highlightComponent)="highlightComponent($event)"
(removeComponentHighlight)="removeComponentHighlight()"
(toggleInspector)="toggleInspector.emit()"
[forest]="forest()"
[currentSelectedElement]="currentSelectedElement()"
[showCommentNodes]="showCommentNodes()"
/>
</as-split-area>
<as-split-area size="22">
@if (parents()) {
<ng-breadcrumbs
(mouseLeaveNode)="unhighlight()"
(mouseOverNode)="highlight($event)"
(handleSelect)="handleSelect($event)"
[parents]="parents()"
/>
}
</as-split-area>
</as-split>
</as-split-area>
<as-split-area size="40" minSize="25" class="prop-split">
<div class="property-tab-wrapper">
<ng-property-tab
[currentSelectedElement]="currentSelectedElement()"
(inspect)="inspect($event)"
(viewSource)="viewSource($event)"
/>
</div>
@if(isHydrationEnabled) {
<div class="hydration">
<mat-slide-toggle
[(ngModel)]="showHydrationNodeHighlights"
(change)="showHydrationNodeHighlights() ? hightlightHydrationNodes() : removeHydrationNodesHightlights()"
>Show hydration overlays</mat-slide-toggle
>
</div>
}
</as-split-area>
</as-split>
| {
"end_byte": 1781,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/BUILD.bazel_0_2834 | load("//devtools/tools:ng_module.bzl", "ng_module")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//devtools/tools:typescript.bzl", "ts_test_library")
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
package(default_visibility = ["//visibility:public"])
sass_binary(
name = "directive_explorer_component_styles",
src = "directive-explorer.component.scss",
)
ng_module(
name = "directive-explorer",
srcs = [
"directive-explorer.component.ts",
],
angular_assets = [
"directive-explorer.component.html",
":directive_explorer_component_styles",
],
deps = [
"//devtools/projects/ng-devtools/src/lib/application-operations",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-resolver",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab",
"//devtools/projects/ng-devtools/src/lib/vendor/angular-split",
"//devtools/projects/protocol",
"//packages/common",
"//packages/core",
"@npm//@angular/cdk",
"@npm//@angular/material",
"@npm//@types",
"@npm//rxjs",
],
)
ts_test_library(
name = "directive_explorer_test",
srcs = ["directive-explorer.spec.ts"],
deps = [
":directive-explorer",
"//devtools/projects/ng-devtools/src/lib:frame_manager",
"//devtools/projects/ng-devtools/src/lib/application-operations",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-resolver",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/tab-update",
"//devtools/projects/protocol",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
],
)
# todo(aleksanderbodurri): fix this test suite
karma_web_test_suite(
name = "test",
deps = [
":directive_explorer_test",
],
)
| {
"end_byte": 2834,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.spec.ts_0_7578 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {ApplicationOperations} from '../../application-operations';
import {DirectivePosition, MessageBus, PropType, PropertyQueryTypes} from 'protocol';
import {DirectiveExplorerComponent} from './directive-explorer.component';
import {DirectiveForestComponent} from './directive-forest/directive-forest.component';
import {IndexedNode} from './directive-forest/index-forest';
import SpyObj = jasmine.SpyObj;
import {By} from '@angular/platform-browser';
import {FrameManager} from '../../frame_manager';
import {TabUpdate} from '../tab-update';
import {Component, CUSTOM_ELEMENTS_SCHEMA, output, input} from '@angular/core';
import {ElementPropertyResolver, FlatNode} from './property-resolver/element-property-resolver';
import {BreadcrumbsComponent} from './directive-forest/breadcrumbs/breadcrumbs.component';
import {PropertyTabComponent} from './property-tab/property-tab.component';
@Component({
selector: 'ng-directive-forest',
template: '',
standalone: true,
})
class MockDirectiveForestComponent {
readonly forest = input<IndexedNode[]>([]);
readonly currentSelectedElement = input<IndexedNode | null>(null);
readonly showCommentNodes = input(false);
readonly selectNode = output<IndexedNode>();
readonly selectDomElement = output<IndexedNode>();
readonly setParents = output<IndexedNode>();
readonly highlightComponent = output<IndexedNode>();
readonly removeComponentHighlight = output<void>();
readonly toggleInspector = output<void>();
}
@Component({
selector: 'ng-breadcrumbs',
template: '',
standalone: true,
})
class MockBreadcrumbsComponent {
readonly parents = input<IndexedNode[]>([]);
readonly handleSelect = output<any>();
readonly mouseLeaveNode = output<any>();
readonly mouseOverNode = output<any>();
}
@Component({
selector: 'ng-property-tab',
template: '',
standalone: true,
})
class MockPropertyTabComponent {
readonly currentSelectedElement = input<IndexedNode | null>(null);
readonly inspect = output<{node: FlatNode; directivePosition: DirectivePosition}>();
readonly viewSource = output<string>();
}
describe('DirectiveExplorerComponent', () => {
let messageBusMock: SpyObj<any>;
let fixture: ComponentFixture<DirectiveExplorerComponent>;
let comp: DirectiveExplorerComponent;
let applicationOperationsSpy: SpyObj<ApplicationOperations>;
let contentScriptConnected = (frameId: number, name: string, url: string) => {};
let frameConnected = (frameId: number) => {};
beforeEach(() => {
applicationOperationsSpy = jasmine.createSpyObj<ApplicationOperations>('_appOperations', [
'viewSource',
'selectDomElement',
'inspect',
]);
messageBusMock = jasmine.createSpyObj('messageBus', ['on', 'once', 'emit', 'destroy']);
messageBusMock.on.and.callFake((topic: string, cb: Function) => {
if (topic === 'contentScriptConnected') {
contentScriptConnected = cb as (frameId: number, name: string, url: string) => void;
}
if (topic === 'frameConnected') {
frameConnected = cb as (frameId: number) => void;
}
});
messageBusMock.emit.and.callFake((topic: string, args: any[]) => {
if (topic === 'enableFrameConnection') {
frameConnected(args[0]);
}
});
TestBed.configureTestingModule({
providers: [
{provide: ApplicationOperations, useValue: applicationOperationsSpy},
{provide: MessageBus, useValue: messageBusMock},
{
provide: ElementPropertyResolver,
useValue: new ElementPropertyResolver(messageBusMock),
},
{provide: FrameManager, useFactory: () => FrameManager.initialize(123)},
],
}).overrideComponent(DirectiveExplorerComponent, {
add: {schemas: [CUSTOM_ELEMENTS_SCHEMA]},
remove: {imports: [DirectiveForestComponent]},
});
fixture = TestBed.overrideComponent(DirectiveExplorerComponent, {
remove: {imports: [DirectiveForestComponent, BreadcrumbsComponent, PropertyTabComponent]},
add: {
imports: [MockDirectiveForestComponent, MockBreadcrumbsComponent, MockPropertyTabComponent],
},
}).createComponent(DirectiveExplorerComponent);
comp = fixture.componentInstance;
TestBed.inject(FrameManager);
comp = fixture.componentInstance;
fixture.detectChanges();
});
it('should create instance from class', () => {
expect(comp).toBeTruthy();
});
it('subscribe to backend events', () => {
expect(messageBusMock.on).toHaveBeenCalledWith(
'latestComponentExplorerView',
jasmine.any(Function),
);
expect(messageBusMock.on).toHaveBeenCalledWith('componentTreeDirty', jasmine.any(Function));
});
describe('refresh', () => {
it('should emit getLatestComponentExplorerView event on refresh', () => {
comp.refresh();
expect(messageBusMock.emit).toHaveBeenCalledWith('getLatestComponentExplorerView', [
undefined,
]);
});
it('should emit getLatestComponentExplorerView event with null view query', () => {
comp.refresh();
expect(messageBusMock.emit).toHaveBeenCalledWith('getLatestComponentExplorerView', [
undefined,
]);
});
it('should emit getLatestComponentExplorerView event on refresh with view query no properties', () => {
const currentSelectedElement = jasmine.createSpyObj('currentSelectedElement', [
'position',
'children',
]);
currentSelectedElement.position = [0];
currentSelectedElement.children = [];
comp.currentSelectedElement.set(currentSelectedElement);
comp.refresh();
expect(comp.currentSelectedElement()).toBeTruthy();
expect(messageBusMock.emit).toHaveBeenCalledWith('getLatestComponentExplorerView', [
undefined,
]);
});
});
describe('node selection event', () => {
let nodeMock: SpyObj<IndexedNode>;
beforeEach(() => {
nodeMock = jasmine.createSpyObj('node', ['position', 'children']);
});
it('fires node selection events', () => {
const position = [0];
nodeMock.position = position;
comp.handleNodeSelection(nodeMock);
expect(messageBusMock.emit).toHaveBeenCalledWith('setSelectedComponent', [nodeMock.position]);
expect(messageBusMock.emit).toHaveBeenCalledWith('getLatestComponentExplorerView', [
{
selectedElement: position,
propertyQuery: {
type: PropertyQueryTypes.All,
},
},
]);
});
});
describe('hydration', () => {
it('should highlight hydration nodes', () => {
comp.hightlightHydrationNodes();
expect(messageBusMock.emit).toHaveBeenCalledWith('createHydrationOverlay');
comp.removeHydrationNodesHightlights();
expect(messageBusMock.emit).toHaveBeenCalledWith('removeHydrationOverlay');
});
it('should show hydration slide toggle', () => {
fixture.componentRef.setInput('isHydrationEnabled', true);
fixture.detectChanges();
const toggle = fixture.debugElement.query(By.css('mat-slide-toggle'));
expect(toggle).toBeTruthy();
fixture.componentRef.setInput('isHydrationEnabled', false);
fixture.detectChanges();
const toggle2 = fixture.debugElement.query(By.css('mat-slide-toggle'));
expect(toggle2).toBeFalsy();
});
}); | {
"end_byte": 7578,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.spec.ts_7582_14284 | describe('applicaton operations', () => {
describe('view source', () => {
it('should not call application operations view source if no frames are detected', () => {
const directiveName = 'test';
comp.currentSelectedElement.set({
directives: [{name: directiveName}],
position: [0],
children: [] as IndexedNode[],
} as IndexedNode);
comp.viewSource(directiveName);
expect(applicationOperationsSpy.viewSource).toHaveBeenCalledTimes(0);
});
it('should not call application operations view source if a frame is selected that does not have a unique url on the page', () => {
contentScriptConnected(0, 'test1', 'http://localhost:4200/url');
contentScriptConnected(1, 'test2', 'http://localhost:4200/url');
const directiveName = 'test';
comp.currentSelectedElement.set({
directives: [{name: directiveName}],
position: [0],
children: [] as IndexedNode[],
} as IndexedNode);
comp.viewSource(directiveName);
expect(applicationOperationsSpy.viewSource).toHaveBeenCalledTimes(0);
expect(messageBusMock.emit).toHaveBeenCalledWith('enableFrameConnection', [0, 123]);
expect(messageBusMock.emit).toHaveBeenCalledWith('log', [
{
level: 'warn',
message: `The currently inspected frame does not have a unique url on this page. Cannot view source.`,
},
]);
});
it('should call application operations view source if a frame is selected that has a unique url on the page', () => {
contentScriptConnected(0, 'test1', 'http://localhost:4200/url');
contentScriptConnected(1, 'test2', 'http://localhost:4200/url2');
const directiveName = 'test';
comp.currentSelectedElement.set({
directives: [{name: directiveName}],
position: [0],
children: [] as IndexedNode[],
} as IndexedNode);
comp.viewSource(directiveName);
expect(applicationOperationsSpy.viewSource).toHaveBeenCalledTimes(1);
expect(messageBusMock.emit).toHaveBeenCalledWith('enableFrameConnection', [0, 123]);
expect(applicationOperationsSpy.viewSource).toHaveBeenCalledWith(
[0], // current selected element position
0, // directive index
new URL('http://localhost:4200/url'), // selected frame url
);
});
});
describe('select dom element', () => {
it('should not call application operations select dom element if no frames are detected', () => {
comp.handleSelectDomElement({position: [0], children: [] as IndexedNode[]} as IndexedNode);
expect(applicationOperationsSpy.selectDomElement).toHaveBeenCalledTimes(0);
});
it('should not call application operations select dom element if a frame is selected that does not have a unique url on the page', () => {
contentScriptConnected(0, 'test1', 'http://localhost:4200/url');
contentScriptConnected(1, 'test2', 'http://localhost:4200/url');
comp.handleSelectDomElement({position: [0], children: [] as IndexedNode[]} as IndexedNode);
expect(applicationOperationsSpy.selectDomElement).toHaveBeenCalledTimes(0);
expect(messageBusMock.emit).toHaveBeenCalledWith('enableFrameConnection', [0, 123]);
expect(messageBusMock.emit).toHaveBeenCalledWith('log', [
{
level: 'warn',
message: `The currently inspected frame does not have a unique url on this page. Cannot select DOM element.`,
},
]);
});
it('should call application operations select dom element if a frame is selected that has a unique url on the page', () => {
contentScriptConnected(0, 'test1', 'http://localhost:4200/url');
contentScriptConnected(1, 'test2', 'http://localhost:4200/url2');
comp.handleSelectDomElement({position: [0], children: [] as IndexedNode[]} as IndexedNode);
expect(applicationOperationsSpy.selectDomElement).toHaveBeenCalledTimes(1);
expect(messageBusMock.emit).toHaveBeenCalledWith('enableFrameConnection', [0, 123]);
expect(applicationOperationsSpy.selectDomElement).toHaveBeenCalledWith(
[0], // current selected element position
new URL('http://localhost:4200/url'), // selected frame url
);
});
});
describe('inspect', () => {
let node: FlatNode;
let directivePosition: DirectivePosition;
beforeEach(() => {
node = {
expandable: true,
prop: {
name: 'foo',
parent: null,
descriptor: {
expandable: true,
editable: false,
type: PropType.String,
preview: 'preview',
containerType: null,
},
},
level: 1,
};
directivePosition = {element: [0], directive: 0};
});
it('should not call application operations inspect if no frames are detected', () => {
comp.inspect({node, directivePosition});
expect(applicationOperationsSpy.selectDomElement).toHaveBeenCalledTimes(0);
});
it('should not call application operations inspect if a frame is selected that does not have a unique url on the page', () => {
contentScriptConnected(0, 'test1', 'http://localhost:4200/url');
contentScriptConnected(1, 'test2', 'http://localhost:4200/url');
comp.inspect({node, directivePosition});
expect(applicationOperationsSpy.inspect).toHaveBeenCalledTimes(0);
expect(messageBusMock.emit).toHaveBeenCalledWith('enableFrameConnection', [0, 123]);
expect(messageBusMock.emit).toHaveBeenCalledWith('log', [
{
level: 'warn',
message: `The currently inspected frame does not have a unique url on this page. Cannot inspect object.`,
},
]);
});
it('should call application operations inspect if a frame is selected that has a unique url on the page', () => {
contentScriptConnected(0, 'test1', 'http://localhost:4200/url');
contentScriptConnected(1, 'test2', 'http://localhost:4200/url2');
comp.inspect({node, directivePosition});
expect(applicationOperationsSpy.inspect).toHaveBeenCalledTimes(1);
expect(messageBusMock.emit).toHaveBeenCalledWith('enableFrameConnection', [0, 123]);
expect(applicationOperationsSpy.inspect).toHaveBeenCalledWith(
directivePosition,
['foo'],
new URL('http://localhost:4200/url'), // selected frame url
);
});
});
});
}); | {
"end_byte": 14284,
"start_byte": 7582,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-explorer.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest-utils.ts_0_945 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {FlatTreeControl} from '@angular/cdk/tree';
import {FlatNode} from './component-data-source';
export const isChildOf = (childPosition: number[], parentPosition: number[]) => {
if (childPosition.length <= parentPosition.length) {
return false;
}
for (let i = 0; i < parentPosition.length; i++) {
if (childPosition[i] !== parentPosition[i]) {
return false;
}
}
return true;
};
export const parentCollapsed = (
nodeIdx: number,
all: FlatNode[],
treeControl: FlatTreeControl<FlatNode>,
) => {
const node = all[nodeIdx];
for (let i = nodeIdx - 1; i >= 0; i--) {
if (isChildOf(node.position, all[i].position) && !treeControl.isExpanded(all[i])) {
return true;
}
}
return false;
};
| {
"end_byte": 945,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest-utils.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/BUILD.bazel_0_1407 | load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//devtools/tools:ng_module.bzl", "ng_module")
package(default_visibility = ["//visibility:public"])
sass_binary(
name = "directive_forest_component_styles",
src = "directive-forest.component.scss",
)
ng_module(
name = "directive-forest",
srcs = [
"directive-forest.component.ts",
"directive-forest-utils.ts",
],
angular_assets = [
"directive-forest.component.html",
":directive_forest_component_styles",
],
deps = [
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/diffing",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/tab-update",
"//devtools/projects/protocol",
"//packages/common",
"//packages/core",
"//packages/core/rxjs-interop",
"@npm//@angular/cdk",
"@npm//@angular/material",
"@npm//@types",
"@npm//rxjs",
],
)
| {
"end_byte": 1407,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts_0_1490 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
CdkVirtualScrollViewport,
CdkFixedSizeVirtualScroll,
CdkVirtualForOf,
} from '@angular/cdk/scrolling';
import {FlatTreeControl} from '@angular/cdk/tree';
import {
afterRenderEffect,
ChangeDetectionStrategy,
Component,
computed,
effect,
ElementRef,
HostListener,
inject,
input,
output,
signal,
viewChild,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {DevToolsNode, ElementPosition, Events, MessageBus} from 'protocol';
import {TabUpdate} from '../../tab-update/index';
import {ComponentDataSource, FlatNode} from './component-data-source';
import {isChildOf, parentCollapsed} from './directive-forest-utils';
import {IndexedNode} from './index-forest';
import {MatIcon} from '@angular/material/icon';
import {FilterComponent} from './filter/filter.component';
import {MatTooltip} from '@angular/material/tooltip';
@Component({
selector: 'ng-directive-forest',
templateUrl: './directive-forest.component.html',
styleUrls: ['./directive-forest.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
FilterComponent,
CdkVirtualScrollViewport,
CdkFixedSizeVirtualScroll,
CdkVirtualForOf,
MatIcon,
MatTooltip,
],
})
export | {
"end_byte": 1490,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts_1491_9962 | class DirectiveForestComponent {
readonly forest = input<DevToolsNode[]>([]);
readonly showCommentNodes = input<boolean>(false);
readonly currentSelectedElement = input.required<IndexedNode>();
readonly selectNode = output<IndexedNode | null>();
readonly selectDomElement = output<IndexedNode>();
readonly setParents = output<FlatNode[] | null>();
readonly highlightComponent = output<ElementPosition>();
readonly removeComponentHighlight = output<void>();
readonly toggleInspector = output<void>();
readonly viewport = viewChild.required<CdkVirtualScrollViewport>(CdkVirtualScrollViewport);
private readonly updateForestResult = computed(() => this._updateForest(this.forest()));
filterRegex = new RegExp('.^');
currentlyMatchedIndex = -1;
selectedNode: FlatNode | null = null;
parents!: FlatNode[];
private readonly highlightIDinTreeFromElement = signal<number | null>(null);
readonly treeControl = new FlatTreeControl<FlatNode>(
(node) => node!.level,
(node) => node.expandable,
);
readonly dataSource = new ComponentDataSource(this.treeControl);
readonly itemHeight = 18;
private _initialized = false;
private resizeObserver: ResizeObserver;
private _tabUpdate = inject(TabUpdate);
private _messageBus = inject<MessageBus<Events>>(MessageBus);
private elementRef = inject(ElementRef);
constructor() {
this.subscribeToInspectorEvents();
afterRenderEffect(() => {
// Listen for tab updates to reset the scroll position to the top
// This ensures the viewport is properly updated when switching tabs
this._tabUpdate.tabUpdate();
const viewport = this.viewport();
viewport.scrollToIndex(0);
viewport.checkViewportSize();
});
// In some cases there a height changes, we need to recalculate the viewport size.
this.resizeObserver = new ResizeObserver(() => {
this.viewport().scrollToIndex(0);
this.viewport().checkViewportSize();
});
this.resizeObserver.observe(this.elementRef.nativeElement);
effect(() => {
const result = this.updateForestResult();
const changed =
result.movedItems.length || result.newItems.length || result.removedItems.length;
if (this.currentSelectedElement() && changed) {
this._reselectNodeOnUpdate();
}
});
}
ngOnDestroy(): void {
this.resizeObserver.disconnect();
}
subscribeToInspectorEvents(): void {
this._messageBus.on('selectComponent', (id: number) => {
this.selectNodeByComponentId(id);
this.toggleInspector.emit();
this.expandParents();
});
this._messageBus.on('highlightComponent', (id: number) => {
this.highlightIDinTreeFromElement.set(id);
});
this._messageBus.on('removeComponentHighlight', () => {
this.highlightIDinTreeFromElement.set(null);
});
}
selectNodeByComponentId(id: number): void {
const foundNode = this.dataSource.data.find((node) => node.original.component?.id === id);
if (foundNode) {
this.handleSelect(foundNode);
}
}
handleSelect(node: FlatNode): void {
this.currentlyMatchedIndex = this.dataSource.data.findIndex(
(matchedNode) => matchedNode.id === node.id,
);
this.selectAndEnsureVisible(node);
}
handleSelectDomElement(node: FlatNode): void {
this.selectDomElement.emit(node.original);
}
selectAndEnsureVisible(node: FlatNode): void {
this.select(node);
const scrollParent = this.viewport().elementRef.nativeElement;
// The top most point we see an element
const top = scrollParent.scrollTop;
// That's the bottom most point we currently see an element.
const parentHeight = scrollParent.offsetHeight;
const bottom = top + parentHeight;
const idx = this.dataSource.expandedDataValues.findIndex((el) => el.id === node.id);
// The node might be hidden.
if (idx < 0) {
return;
}
const itemTop = idx * this.itemHeight;
if (itemTop < top) {
scrollParent.scrollTo({top: itemTop});
} else if (bottom < itemTop + this.itemHeight) {
scrollParent.scrollTo({top: itemTop - parentHeight + this.itemHeight});
}
}
select(node: FlatNode): void {
this.populateParents(node.position);
this.selectNode.emit(node.original);
this.selectedNode = node;
}
clearSelectedNode(): void {
this.selectNode.emit(null);
this.selectedNode = null;
this.parents = [];
this.setParents.emit(null);
}
private _reselectNodeOnUpdate(): void {
const nodeThatStillExists = this.dataSource.getFlatNodeFromIndexedNode(
this.currentSelectedElement(),
);
if (nodeThatStillExists) {
this.select(nodeThatStillExists);
} else {
this.clearSelectedNode();
}
}
private _updateForest(forest: DevToolsNode[]): {
newItems: FlatNode[];
movedItems: FlatNode[];
removedItems: FlatNode[];
} {
const result = this.dataSource.update(forest, this.showCommentNodes());
if (!this._initialized && forest && forest.length) {
this.treeControl.expandAll();
this._initialized = true;
result.newItems.forEach((item) => (item.newItem = false));
}
// We want to expand them once they are rendered.
result.newItems.forEach((item) => {
this.treeControl.expand(item);
});
return result;
}
private populateParents(position: ElementPosition): void {
this.parents = [];
for (let i = 1; i <= position.length; i++) {
const current = position.slice(0, i);
const selectedNode = this.dataSource.data.find(
(item) => item.position.toString() === current.toString(),
);
// We might not be able to find the parent if the user has hidden the comment nodes.
if (selectedNode) {
this.parents.push(selectedNode);
}
}
this.setParents.emit(this.parents);
}
@HostListener('document:keydown.ArrowUp', ['$event'])
navigateUp(event: KeyboardEvent): void {
if (this.isEditingDirectiveState(event)) {
return;
}
event.preventDefault();
const data = this.dataSource.expandedDataValues;
let prevIdx = data.findIndex((e) => this.selectedNode && e.id === this.selectedNode.id) - 1;
if (prevIdx < 0) {
return;
}
let prevNode = data[prevIdx];
const currentNode = data[prevIdx + 1];
if (prevNode.position.length <= currentNode.position.length) {
return this.selectAndEnsureVisible(data[prevIdx]);
}
while (prevIdx >= 0 && parentCollapsed(prevIdx, data, this.treeControl)) {
prevIdx--;
prevNode = data[prevIdx];
}
this.selectAndEnsureVisible(data[prevIdx]);
}
@HostListener('document:keydown.ArrowDown', ['$event'])
navigateDown(event: KeyboardEvent): void {
if (this.isEditingDirectiveState(event)) {
return;
}
event.preventDefault();
const data = this.dataSource.expandedDataValues;
let idx = data.findIndex((e) => this.selectedNode && e.id === this.selectedNode.id);
const currentNode = data[idx];
if (!this.treeControl.isExpanded(currentNode) && currentNode.expandable) {
for (let i = idx + 1; i < data.length; i++) {
const node = data[i];
if (!isChildOf(node.position, currentNode.position)) {
idx = i;
break;
}
}
} else {
idx++;
}
if (idx >= data.length) {
return;
}
this.selectAndEnsureVisible(data[idx]);
}
@HostListener('document:keydown.ArrowLeft', ['$event'])
collapseCurrent(event: KeyboardEvent): void {
if (this.isEditingDirectiveState(event)) {
return;
}
if (!this.selectedNode) {
return;
}
this.treeControl.collapse(this.selectedNode);
event.preventDefault();
}
@HostListener('document:keydown.ArrowRight', ['$event'])
expandCurrent(event: KeyboardEvent): void {
if (this.isEditingDirectiveState(event)) {
return;
}
if (!this.selectedNode) {
return;
}
this.treeControl.expand(this.selectedNode);
event.preventDefault();
}
isEditingDirectiveState(event: KeyboardEvent): boolean {
return (event.target as Element).tagName === 'INPUT' || !this.selectedNode;
}
isSelected(node: FlatNode): boolean {
return !!this.selectedNode && this.selectedNode.id === node.id;
}
isMatched(node: FlatNode): boolean {
return (
this.filterRegex.test(node.name.toLowerCase()) ||
this.filterRegex.test(node.directives.toLowerCase())
);
} | {
"end_byte": 9962,
"start_byte": 1491,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts_9966_12578 | handleFilter(filterText: string): void {
this.currentlyMatchedIndex = -1;
try {
this.filterRegex = new RegExp(filterText.toLowerCase() || '.^');
} catch {
this.filterRegex = new RegExp('.^');
}
}
stopPropagation(event: Event): void {
event.stopPropagation();
}
private _findMatchedNodes(): number[] {
const indexesOfMatchedNodes: number[] = [];
for (let i = 0; i < this.dataSource.data.length; i++) {
if (this.isMatched(this.dataSource.data[i])) {
indexesOfMatchedNodes.push(i);
}
}
return indexesOfMatchedNodes;
}
get hasMatched(): boolean {
return this._findMatchedNodes().length > 0;
}
nextMatched(): void {
const indexesOfMatchedNodes = this._findMatchedNodes();
this.currentlyMatchedIndex = (this.currentlyMatchedIndex + 1) % indexesOfMatchedNodes.length;
const indexToSelect = indexesOfMatchedNodes[this.currentlyMatchedIndex];
const nodeToSelect = this.dataSource.data[indexToSelect];
if (indexToSelect !== undefined) {
this.treeControl.expand(nodeToSelect);
this.selectAndEnsureVisible(nodeToSelect);
}
const nodeIsVisible = this.dataSource.expandedDataValues.find((node) => node === nodeToSelect);
if (!nodeIsVisible) {
this.expandParents();
}
}
prevMatched(): void {
const indexesOfMatchedNodes = this._findMatchedNodes();
this.currentlyMatchedIndex =
(this.currentlyMatchedIndex - 1 + indexesOfMatchedNodes.length) %
indexesOfMatchedNodes.length;
const indexToSelect = indexesOfMatchedNodes[this.currentlyMatchedIndex];
const nodeToSelect = this.dataSource.data[indexToSelect];
if (indexToSelect !== undefined) {
this.treeControl.expand(nodeToSelect);
this.selectAndEnsureVisible(nodeToSelect);
}
const nodeIsVisible = this.dataSource.expandedDataValues.find((node) => node === nodeToSelect);
if (!nodeIsVisible) {
this.expandParents();
}
}
expandParents(): void {
this.parents.forEach((parent) => this.treeControl.expand(parent));
}
highlightNode(position: ElementPosition): void {
this.highlightIDinTreeFromElement.set(null);
this.highlightComponent.emit(position);
}
removeHighlight(): void {
this.removeComponentHighlight.emit();
}
isHighlighted(node: FlatNode): boolean {
return (
!!this.highlightIDinTreeFromElement() &&
this.highlightIDinTreeFromElement() === node.original.component?.id
);
}
isElement(node: FlatNode): boolean | null {
return node.original.component && node.original.component.isElement;
}
} | {
"end_byte": 12578,
"start_byte": 9966,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.html_0_2768 | <ng-filter
[hasMatched]="hasMatched"
(filter)="handleFilter($event)"
(nextMatched)="nextMatched()"
(prevMatched)="prevMatched()"
>
</ng-filter>
<cdk-virtual-scroll-viewport class="tree-wrapper" [itemSize]="itemHeight">
<ng-container *cdkVirtualFor="let node of dataSource; let idx = index">
<div
[class]="{
matched: isMatched(node),
selected: isSelected(node),
highlighted: isHighlighted(node),
'new-node': node.newItem
}"
class="tree-node"
(click)="selectAndEnsureVisible(node)"
(dblclick)="handleSelectDomElement(node)"
(mouseenter)="highlightNode(node.position)"
(mouseleave)="removeHighlight()"
[style.padding-left]="15 + 15 * node.level + 'px'"
>
<div class="tree-node-info">
@if (node.expandable) {
<!-- We stop propagration on dblClick to prevent to show the element panel -->
<button
[style.left]="15 * node.level + 'px'"
(click)="treeControl.toggle(node)"
(dblclick)="stopPropagation($event)"
[attr.aria-label]="'toggle ' + node.name"
>
<mat-icon class="mat-icon-rtl-mirror">
{{ treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right' }}
</mat-icon>
</button>
}
<span class="element-name" [class.angular-element]="isElement(node)">{{ node.name }}</span>
@if (node.directives) {
<span class="dir-names">[{{ node.directives }}]</span>
}
@if (isSelected(node)) {
<span class="console-reference"> == $ng0 </span>
}
@switch (node.hydration?.status) {
@case ('hydrated') {
<mat-icon matTooltip="Hydrated" class="hydration">water_drop</mat-icon>
}
@case ('skipped') {
<mat-icon matTooltip="Hydration skipped" class="hydration skipped">invert_colors_off</mat-icon>
}
@case ('mismatched') {
<mat-icon matTooltip="Hydration mismatch" class="hydration mismatched">error_outline</mat-icon>
}
}
</div>
@if (
treeControl.isExpanded(node) &&
node.hydration?.status === 'mismatched' &&
(node.hydration.expectedNodeDetails || node.hydration.actualNodeDetails)
) {
<div class="hydration-error">
@if (node.hydration.expectedNodeDetails) {
<div>Expected Dom:</div>
<pre>{{node.hydration.expectedNodeDetails}}</pre>
}
@if (node.hydration.actualNodeDetails) {
<div>Actual Dom:</div>
<pre>{{node.hydration.actualNodeDetails}}</pre>
}
</div>
}
</div>
</ng-container>
</cdk-virtual-scroll-viewport>
| {
"end_byte": 2768,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.scss_0_3082 | :host {
width: 100%;
height: 100%;
overflow: auto;
.tree-node {
position: relative;
color: #8a1882;
cursor: default;
font-family: Menlo, monospace;
font-size: 11px;
line-height: 18px;
white-space: nowrap;
text-overflow: ellipsis;
.tree-node-info {
display: flex;
& > button {
outline: none;
border: 0;
padding: 0;
position: absolute;
background-color: transparent;
top: 2px;
}
}
.mat-icon {
font-size: 0.8em;
width: 16px;
height: 13px;
display: inline-block;
}
.dir-names {
color: #9b4807;
}
.console-reference {
color: #748591;
padding-left: 8px;
font-style: italic;
}
&:hover {
background-color: #ebf1fb;
}
&.matched {
background-color: #ebf1fb;
&:hover {
background-color: #cfe8fc;
}
}
&.selected,
&.highlighted {
background-color: #cfe8fc;
}
.hydration {
margin: auto 8px auto auto;
font-size: 14px;
color: #60a6fc;
position: sticky;
right: 0;
&.skipped {
color: #9a9a9a;
}
&.mismatched {
color: #ff0040;
}
}
}
}
@keyframes appear {
0% {
background-color: transparent;
}
50% {
background-color: #cfe8fc;
}
100% {
background-color: transparent;
}
}
.new-node {
animation: appear 1.5s;
}
.filter {
display: flex;
.icon {
width: 20px;
height: 20px;
margin: auto 12px;
opacity: 0.7;
}
.filter-input {
border: none;
background: rgba(0, 0, 0, 0.003);
box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03);
width: 100%;
font-size: 2em;
font-family: inherit;
font-weight: inherit;
line-height: 1.4em;
padding: 12px 6px;
}
}
.up-down-buttons {
width: 20%;
display: flex;
}
.tree-wrapper {
overflow-y: auto;
height: calc(100% - 33px);
}
.angular-element {
content: '';
color: #1b1aa5;
&::before {
content: '<';
}
&::after {
content: '/>';
}
}
.hydration-error {
color: #e62222;
margin-left: 16px;
padding: 0 8px 8px 0px;
pre {
margin: 0;
background: rgba(1, 1, 1, 0.05);
padding: 8px;
border-radius: 8px;
&:not(:last-child) {
margin-bottom: 16px;
}
}
}
:host-context(.dark-theme) {
.tree-node {
color: #5cadd3;
.mat-icon {
color: #bcc5ce;
}
.dir-names {
color: #91adcb;
}
.angular-element {
color: #dc8c61;
}
&:hover {
background-color: #262d36;
}
&.matched {
background-color: #262d36;
&:hover {
background-color: #073d69;
}
}
&.selected,
&.highlighted {
background-color: #073d69;
}
.hydration {
color: #60a6fc;
&.skipped {
color: #9a9a9a;;
}
&.mismatched {
color: #ff0040;
}
}
.hydration-error {
color: #ea7171;
pre {
background: rgb(1, 1, 1, 0.2);
}
}
}
}
| {
"end_byte": 3082,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source/component-data-source.spec.ts_0_5665 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {FlatTreeControl} from '@angular/cdk/tree';
import {DevToolsNode} from 'protocol';
import {ComponentDataSource, FlatNode} from '.';
const tree1: DevToolsNode = {
element: 'app',
directives: [
{
id: 1,
name: 'foo',
},
],
component: null,
hydration: null,
children: [
{
children: [],
component: {
id: 2,
isElement: false,
name: 'bar',
},
directives: [],
element: 'bar',
hydration: null,
nativeElement: document.createElement('bar'),
},
],
nativeElement: document.createElement('foo'),
};
const tree2: DevToolsNode = {
element: 'app',
directives: [
{
id: 1,
name: 'foo',
},
],
component: null,
hydration: null,
children: [
{
children: [],
component: {
id: 2,
isElement: false,
name: 'bar',
},
directives: [],
element: 'bar',
hydration: null,
nativeElement: document.createElement('bar'),
},
{
children: [],
component: {
id: 3,
isElement: false,
name: 'qux',
},
directives: [],
element: 'qux',
hydration: null,
nativeElement: document.createElement('qux'),
},
],
nativeElement: document.createElement('foo'),
};
const tree3: DevToolsNode = {
element: 'app',
directives: [
{
id: 1,
name: 'foo',
},
],
component: null,
hydration: null,
children: [
{
children: [],
component: {
id: 2,
isElement: false,
name: 'bar',
},
directives: [],
element: '#comment',
hydration: null,
nativeElement: document.createComment('bar'),
},
{
children: [],
component: {
id: 3,
isElement: false,
name: 'qux',
},
directives: [],
element: '#comment',
hydration: null,
nativeElement: document.createComment('bar'),
},
],
nativeElement: document.createElement('foo'),
};
const tree4: DevToolsNode = {
element: 'app',
hydration: null,
directives: [
{
id: 1,
name: 'foo',
},
],
component: null,
children: [
{
children: [
{
children: [
{
children: [
{
children: [
{
children: [],
component: {
id: 6,
isElement: false,
name: 'qux',
},
directives: [],
element: 'bar',
hydration: null,
nativeElement: document.createComment('bar'),
},
],
component: {
id: 5,
isElement: false,
name: 'qux',
},
directives: [],
element: '#comment',
hydration: null,
nativeElement: document.createComment('bar'),
},
],
component: {
id: 4,
isElement: false,
name: 'qux',
},
directives: [],
element: '#comment',
hydration: null,
nativeElement: document.createComment('bar'),
},
],
component: {
id: 3,
isElement: false,
name: 'qux',
},
directives: [],
element: '#comment',
hydration: null,
nativeElement: document.createComment('bar'),
},
],
component: {
id: 2,
isElement: false,
name: 'bar',
},
directives: [],
element: '#comment',
hydration: null,
nativeElement: document.createComment('bar'),
},
],
nativeElement: document.createElement('foo'),
};
describe('ComponentDataSource', () => {
let dataSource: ComponentDataSource;
const treeControl = new FlatTreeControl<FlatNode>(
(node) => node.level,
(node) => node.expandable,
);
beforeEach(() => (dataSource = new ComponentDataSource(treeControl)));
it('should return new and old items', () => {
const result = dataSource.update([tree1], true);
expect(result.movedItems.length).toBe(0);
expect(result.newItems.length).toBe(2);
const updatedResult = dataSource.update([tree2], true);
expect(updatedResult.movedItems.length).toBe(0);
expect(updatedResult.removedItems.length).toBe(0);
expect(updatedResult.newItems.length).toBe(1);
expect(updatedResult.newItems[0].name).toBe('qux');
});
it('should not return comment nodes when not requested', () => {
const result = dataSource.update([tree3], false);
expect(result.movedItems.length).toBe(0);
expect(result.newItems.length).toBe(1);
expect(result.newItems[0].name).toBe('app');
});
it('should not break nesting with nested comment nodes', () => {
const result = dataSource.update([tree4], false);
expect(result.newItems.length).toBe(2);
expect(result.newItems[0].name).toBe('app');
expect(result.newItems[1].name).toBe('qux');
expect(result.newItems[0].level).toBe(0);
expect(result.newItems[1].level).toBe(1);
expect(result.newItems[1].position).toEqual([0, 0, 0, 0, 0, 0]);
});
});
| {
"end_byte": 5665,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source/component-data-source.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source/BUILD.bazel_0_1144 | load("//devtools/tools:typescript.bzl", "ts_library", "ts_test_library")
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "component-data-source",
srcs = ["index.ts"],
deps = [
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/diffing",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest",
"//devtools/projects/protocol",
"//packages/core",
"@npm//@angular/cdk",
"@npm//@angular/material",
"@npm//@types",
"@npm//rxjs",
],
)
ts_test_library(
name = "component_data_source_test",
srcs = glob(["**/*.spec.ts"]),
deps = [
":component-data-source",
"//devtools/projects/protocol",
"@npm//@angular/cdk",
],
)
# todo(aleksanderbodurri): fix this test suite
karma_web_test_suite(
name = "test",
deps = [
":component_data_source_test",
"//packages/common/http",
"//packages/platform-browser",
"//packages/platform-browser/animations",
],
)
| {
"end_byte": 1144,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source/index.ts_0_6115 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {CollectionViewer, DataSource} from '@angular/cdk/collections';
import {FlatTreeControl} from '@angular/cdk/tree';
import {DefaultIterableDiffer, TrackByFunction} from '@angular/core';
import {MatTreeFlattener} from '@angular/material/tree';
import {DevToolsNode, HydrationStatus} from 'protocol';
import {BehaviorSubject, merge, Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {diff} from '../../../diffing';
import {IndexedNode, indexForest} from '../index-forest';
/** Flat node with expandable and level information */
export interface FlatNode {
id: string;
expandable: boolean;
name: string;
directives: string;
position: number[];
level: number;
original: IndexedNode;
newItem?: boolean;
hydration: HydrationStatus;
}
const expandable = (node: IndexedNode) => !!node.children && node.children.length > 0;
const trackBy: TrackByFunction<FlatNode> = (_: number, item: FlatNode) =>
`${item.id}#${item.expandable}`;
const getId = (node: IndexedNode) => {
let prefix = '';
if (node.component) {
prefix = node.component.id.toString();
}
const dirIds = node.directives
.map((d) => d.id)
.sort((a, b) => {
return a - b;
});
return prefix + '-' + dirIds.join('-');
};
/**
* Takes an `IndexedNode` forest and returns a transformed forest without `#comment` nodes.
* The algorithm has linear complexity and O(depth(forest)) memory complexity.
*
* @param nodes indexed nodes, which have already have associated positions within the original
* tree and associated indices.
* @returns forest with filtered `#comment` nodes.
*/
const filterCommentNodes = (nodes: IndexedNode[]) => {
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if (node.element !== '#comment') {
continue;
}
nodes.splice(i, 1, ...node.children);
i--;
}
for (const node of nodes) {
filterCommentNodes(node.children);
}
return nodes;
};
export class ComponentDataSource extends DataSource<FlatNode> {
private _differ = new DefaultIterableDiffer<FlatNode>(trackBy);
private _expandedData = new BehaviorSubject<FlatNode[]>([]);
private _flattenedData = new BehaviorSubject<FlatNode[]>([]);
private _nodeToFlat = new WeakMap<IndexedNode, FlatNode>();
private _treeFlattener = new MatTreeFlattener(
(node: IndexedNode, level: number) => {
if (this._nodeToFlat.has(node)) {
return this._nodeToFlat.get(node);
}
const flatNode: FlatNode = {
expandable: expandable(node),
id: getId(node),
// We can compare the nodes in the navigation functions above
// based on this identifier directly, since it's a reference type
// and the reference is preserved after transformation.
position: node.position,
name: node.component ? node.component.name : node.element,
directives: node.directives.map((d) => d.name).join(', '),
original: node,
level,
hydration: node.hydration,
};
this._nodeToFlat.set(node, flatNode);
return flatNode;
},
(node) => (node ? node.level : -1),
(node) => (node ? node.expandable : false),
(node) => (node ? node.children : []),
);
constructor(private _treeControl: FlatTreeControl<FlatNode>) {
super();
}
get data(): FlatNode[] {
return this._flattenedData.value;
}
get expandedDataValues(): FlatNode[] {
return this._expandedData.value;
}
getFlatNodeFromIndexedNode(indexedNode: IndexedNode): FlatNode | undefined {
return this._nodeToFlat.get(indexedNode);
}
update(
forest: DevToolsNode[],
showCommentNodes: boolean,
): {newItems: FlatNode[]; movedItems: FlatNode[]; removedItems: FlatNode[]} {
if (!forest) {
return {newItems: [], movedItems: [], removedItems: []};
}
let indexedForest = indexForest(forest);
// We filter comment nodes here because we need to preserve the positions within the component
// tree.
//
// For example:
// ```
// - #comment
// - bar
// ```
//
// #comment's position will be [0] and bar's will be [0, 0]. If we trim #comment nodes earlier
// before indexing, bar's position will be [0] which will be inaccurate and will make the
// backend enable to find the corresponding node when we request its properties.
if (!showCommentNodes) {
indexedForest = filterCommentNodes(indexedForest);
}
const flattenedCollection = this._treeFlattener.flattenNodes(indexedForest) as FlatNode[];
this.data.forEach((i) => (i.newItem = false));
const expandedNodes: Record<string, boolean> = {};
this.data.forEach((item) => {
expandedNodes[item.id] = this._treeControl.isExpanded(item);
});
const {newItems, movedItems, removedItems} = diff<FlatNode>(
this._differ,
this.data,
flattenedCollection,
);
this._treeControl.dataNodes = this.data;
this._flattenedData.next(this.data);
movedItems.forEach((i) => {
this._nodeToFlat.set(i.original, i);
if (expandedNodes[i.id]) {
this._treeControl.expand(i);
}
});
newItems.forEach((i) => (i.newItem = true));
removedItems.forEach((i) => this._nodeToFlat.delete(i.original));
return {newItems, movedItems, removedItems};
}
override connect(collectionViewer: CollectionViewer): Observable<FlatNode[]> {
const changes = [
collectionViewer.viewChange,
this._treeControl.expansionModel.changed,
this._flattenedData,
];
return merge<unknown[]>(...changes).pipe(
map(() => {
this._expandedData.next(
this._treeFlattener.expandFlattenedNodes(
this.data,
this._treeControl as FlatTreeControl<FlatNode | undefined>,
) as FlatNode[],
);
return this._expandedData.value;
}),
);
}
override disconnect(): void {}
}
| {
"end_byte": 6115,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source/index.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest/index-forest.spec.ts_0_4030 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {indexForest} from './';
describe('indexForest', () => {
it('should work with an empty forest', () => {
expect(indexForest([])).toEqual([]);
});
it('should index a forest', () => {
expect(
indexForest([
{
element: 'Parent1',
directives: [],
hydration: null,
component: {
isElement: false,
name: 'Cmp1',
id: 1,
},
children: [
{
element: 'Child1_1',
hydration: null,
directives: [
{
name: 'Dir1',
id: 1,
},
{
name: 'Dir2',
id: 1,
},
],
component: null,
children: [],
},
{
element: 'Child1_2',
directives: [],
hydration: null,
component: {
isElement: false,
name: 'Cmp2',
id: 1,
},
children: [],
},
],
},
{
element: 'Parent2',
directives: [],
component: null,
hydration: null,
children: [
{
element: 'Child2_1',
directives: [
{
name: 'Dir3',
id: 1,
},
],
hydration: null,
component: null,
children: [],
},
{
element: 'Child2_2',
directives: [
{
name: 'Dir4',
id: 1,
},
{
name: 'Dir5',
id: 1,
},
],
component: null,
hydration: null,
children: [],
},
],
},
]),
).toEqual([
{
element: 'Parent1',
directives: [],
position: [0],
hydration: null,
component: {
isElement: false,
name: 'Cmp1',
id: 1,
},
children: [
{
element: 'Child1_1',
position: [0, 0],
directives: [
{
name: 'Dir1',
id: 1,
},
{
name: 'Dir2',
id: 1,
},
],
component: null,
hydration: null,
children: [],
},
{
element: 'Child1_2',
directives: [],
position: [0, 1],
component: {
isElement: false,
name: 'Cmp2',
id: 1,
},
hydration: null,
children: [],
},
],
},
{
element: 'Parent2',
directives: [],
component: null,
position: [1],
hydration: null,
children: [
{
element: 'Child2_1',
position: [1, 0],
directives: [
{
name: 'Dir3',
id: 1,
},
],
component: null,
hydration: null,
children: [],
},
{
element: 'Child2_2',
position: [1, 1],
directives: [
{
name: 'Dir4',
id: 1,
},
{
name: 'Dir5',
id: 1,
},
],
component: null,
children: [],
hydration: null,
},
],
},
]);
});
});
| {
"end_byte": 4030,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest/index-forest.spec.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest/BUILD.bazel_0_578 | load("//devtools/tools:typescript.bzl", "ts_library", "ts_test_library")
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "index-forest",
srcs = ["index.ts"],
deps = [
"//devtools/projects/protocol",
"@npm//@angular/material",
],
)
ts_test_library(
name = "index_forest_test",
srcs = glob(["**/*.spec.ts"]),
deps = [
":index-forest",
],
)
karma_web_test_suite(
name = "test",
deps = [
":index_forest_test",
],
)
| {
"end_byte": 578,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest/index.ts_0_900 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DevToolsNode, ElementPosition} from 'protocol';
export interface IndexedNode extends DevToolsNode {
position: ElementPosition;
children: IndexedNode[];
}
const indexTree = (
node: DevToolsNode,
idx: number,
parentPosition: ElementPosition = [],
): IndexedNode => {
const position = parentPosition.concat([idx]);
return {
position,
element: node.element,
component: node.component,
directives: node.directives.map((d, i) => ({name: d.name, id: d.id})),
children: node.children.map((n, i) => indexTree(n, i, position)),
hydration: node.hydration,
};
};
export const indexForest = (forest: DevToolsNode[]) => forest.map((n, i) => indexTree(n, i));
| {
"end_byte": 900,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest/index.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/BUILD.bazel_0_593 | load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//devtools/tools:ng_module.bzl", "ng_module")
package(default_visibility = ["//visibility:public"])
sass_binary(
name = "filter_component_styles",
src = "filter.component.scss",
)
ng_module(
name = "filter",
srcs = [
"filter.component.ts",
],
angular_assets = [
"filter.component.html",
":filter_component_styles",
],
deps = [
"//packages/common",
"//packages/core",
"@npm//@angular/material",
"@npm//@types",
"@npm//rxjs",
],
)
| {
"end_byte": 593,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/filter.component.ts_0_958 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, input, output} from '@angular/core';
import {MatIcon} from '@angular/material/icon';
import {MatCard} from '@angular/material/card';
@Component({
selector: 'ng-filter',
templateUrl: './filter.component.html',
styleUrls: ['./filter.component.scss'],
standalone: true,
imports: [MatCard, MatIcon],
})
export class FilterComponent {
readonly filter = output<string>();
readonly nextMatched = output<void>();
readonly prevMatched = output<void>();
readonly hasMatched = input(false);
emitFilter(event: InputEvent): void {
this.filter.emit((event.target as HTMLInputElement).value);
}
emitNextMatched(): void {
this.nextMatched.emit();
}
emitPrevMatched(): void {
this.prevMatched.emit();
}
}
| {
"end_byte": 958,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/filter.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/filter.component.scss_0_1186 | .filter {
display: flex;
padding: 0px;
border-radius: 0px;
box-shadow: none !important;
border-bottom: 1px solid rgba(0, 0, 0, 0.12);
label {
display: flex;
width: 100%;
.search-icon {
display: flex;
align-items: center;
padding-right: 5px;
margin-left: 8px;
margin-top: 8px;
mat-icon {
font-size: 1.3em;
}
}
.filter-input {
border: none;
border-left: 1px solid rgba(0, 0, 0, 0.12);
padding-left: 5px;
width: 100%;
font-size: 11px;
font-family: inherit;
font-weight: inherit;
height: 30px;
outline: none;
color: rgba(0, 0, 0, 0.87);
}
}
}
.mdc-card {
flex-direction: row;
}
.up-down-buttons {
display: flex;
button {
width: 28px;
height: 28px;
padding: 0;
background: none;
border: none;
cursor: pointer;
opacity: 0.5;
&:hover {
opacity: 0.8;
}
&:active {
opacity: 1;
}
}
}
:host-context(.dark-theme) {
.filter {
label {
.filter-input {
background-color: #202124;
color: #ffffff;
}
}
}
mat-icon {
color: #fff;
}
}
| {
"end_byte": 1186,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/filter.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/filter.component.html_0_794 | <mat-card class="filter">
<label>
<div class="search-icon">
<mat-icon color="primary">search</mat-icon>
</div>
<input
matInput
(input)="emitFilter($event)"
(keydown.enter)="emitNextMatched()"
(keydown.shift.enter)="emitPrevMatched()"
class="filter-input"
placeholder="Search components"
/>
</label>
@if (hasMatched()) {
<div class="up-down-buttons">
<button matTooltip="Select previous element" (click)="emitPrevMatched()">
<mat-icon class="mat-icon-rtl-mirror">
expand_less
</mat-icon>
</button>
<button matTooltip="Select next element" (click)="emitNextMatched()">
<mat-icon class="">
expand_more
</mat-icon>
</button>
</div>
}
</mat-card>
| {
"end_byte": 794,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/filter/filter.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/breadcrumbs.component.ts_0_2307 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
Component,
computed,
effect,
ElementRef,
input,
output,
signal,
viewChild,
} from '@angular/core';
import {FlatNode} from '../component-data-source';
import {MatButton} from '@angular/material/button';
import {MatIcon} from '@angular/material/icon';
import {MatCard} from '@angular/material/card';
@Component({
selector: 'ng-breadcrumbs',
templateUrl: './breadcrumbs.component.html',
styleUrls: ['./breadcrumbs.component.scss'],
standalone: true,
imports: [MatCard, MatIcon, MatButton],
})
export class BreadcrumbsComponent {
readonly parents = input.required<FlatNode[]>();
readonly handleSelect = output<FlatNode>();
readonly mouseOverNode = output<FlatNode>();
readonly mouseLeaveNode = output<FlatNode>();
readonly breadcrumbsScrollContent = viewChild.required<ElementRef>('breadcrumbs');
readonly showScrollLeftButton = computed(() => {
const value = this.breadcrumbsScrollLayout();
return value && value.scrollLeft > 0;
});
readonly showScrollRightButton = computed(() => {
const value = this.breadcrumbsScrollLayout();
if (!value) {
return false;
}
const {clientWidth, scrollWidth, scrollLeft} = value;
return scrollWidth > clientWidth && scrollLeft + clientWidth < scrollWidth;
});
private readonly breadcrumbsScrollLayout = signal<
| {
clientWidth: number;
scrollWidth: number;
scrollLeft: number;
}
| undefined
>(undefined);
constructor() {
effect((cleanup) => {
const observer = new ResizeObserver(() => this.updateScrollButtonVisibility());
observer.observe(this.breadcrumbsScrollContent().nativeElement);
cleanup(() => observer.disconnect());
});
}
scroll(pixels: number): void {
this.breadcrumbsScrollContent().nativeElement.scrollLeft += pixels;
this.updateScrollButtonVisibility();
}
updateScrollButtonVisibility(): void {
const {clientWidth, scrollWidth, scrollLeft} = this.breadcrumbsScrollContent().nativeElement;
this.breadcrumbsScrollLayout.set({clientWidth, scrollWidth, scrollLeft});
}
}
| {
"end_byte": 2307,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/breadcrumbs.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/breadcrumbs.component.scss_0_1270 | .mdc-card.breadcrumb-card {
padding: 0;
width: 100%;
height: 24px;
display: flex;
flex-direction: row;
.scroll-button {
height: 100%;
background-color: rgb(243, 243, 243);
border: none;
cursor: pointer;
&.hidden {
visibility: hidden;
}
}
.breadcrumbs {
overflow-x: auto;
white-space: nowrap;
display: inline-block;
// width: calc(100% - 50px);
height: 100%;
scroll-behavior: smooth;
&::-webkit-scrollbar {
display: none;
}
button {
height: 24px;
&.selected {
background-color: rgb(243, 243, 243);
}
}
}
.mdc-button {
height: 20px;
line-height: 20px;
font-size: 11px;
margin-right: 5px;
width: fit-content;
color: #8a1882;
&:hover {
background-color: #ebf1fb;
}
}
}
:host-context(.dark-theme) {
.mdc-card {
&.breadcrumb-card {
.scroll-button {
background-color: rgb(41, 42, 45);
color: #ffffff;
}
.breadcrumbs {
button {
&.selected {
background-color: rgb(41, 42, 45);
}
}
}
.mdc-button {
color: #5caace;
&:hover {
background-color: #093e69;
}
}
}
}
}
| {
"end_byte": 1270,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/breadcrumbs.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/breadcrumbs.component.html_0_807 | <mat-card class="breadcrumb-card">
<button class="scroll-button" [class.hidden]="!showScrollLeftButton()" (click)="scroll(-100)">
<mat-icon> more_horiz </mat-icon>
</button>
<div class="breadcrumbs" #breadcrumbs (scroll)="updateScrollButtonVisibility()">
@for (node of parents(); track $index) {
<button
(mouseover)="mouseOverNode.emit(node)"
(mouseleave)="mouseLeaveNode.emit(node)"
mat-button
color="primary"
(click)="handleSelect.emit(node)"
[class.selected]="$last"
>
{{ node.original.component?.name || node.original.element }}
</button>
}
</div>
<button class="scroll-button" [class.hidden]="!showScrollRightButton()" (click)="scroll(100)">
<mat-icon> more_horiz </mat-icon>
</button>
</mat-card>
| {
"end_byte": 807,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/breadcrumbs.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/BUILD.bazel_0_746 | load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//devtools/tools:ng_module.bzl", "ng_module")
package(default_visibility = ["//visibility:public"])
sass_binary(
name = "breadcrumbs_component_styles",
src = "breadcrumbs.component.scss",
)
ng_module(
name = "breadcrumbs",
srcs = [
"breadcrumbs.component.ts",
],
angular_assets = [
"breadcrumbs.component.html",
":breadcrumbs_component_styles",
],
deps = [
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/component-data-source",
"//packages/common",
"//packages/core",
"@npm//@angular/material",
"@npm//@types",
"@npm//rxjs",
],
)
| {
"end_byte": 746,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/breadcrumbs/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/component-metadata.component.ts_0_1574 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, computed, inject, input} from '@angular/core';
import {ComponentType} from 'protocol';
import {ElementPropertyResolver} from '../property-resolver/element-property-resolver';
@Component({
selector: 'ng-component-metadata',
templateUrl: './component-metadata.component.html',
styleUrls: ['./component-metadata.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
export class ComponentMetadataComponent {
readonly currentSelectedComponent = input.required<ComponentType>();
private _nestedProps = inject(ElementPropertyResolver);
viewEncapsulationModes = ['Emulated', 'Native', 'None', 'ShadowDom'];
readonly controller = computed(() => {
const comp = this.currentSelectedComponent();
if (!comp) {
return;
}
return this._nestedProps.getDirectiveController(comp.name);
});
readonly viewEncapsulation = computed(() => {
const encapsulationIndex = this.controller()?.directiveViewEncapsulation;
if (encapsulationIndex !== undefined) {
return this.viewEncapsulationModes[encapsulationIndex];
}
return undefined;
});
readonly changeDetectionStrategy = computed(() => {
const onPush = this.controller()?.directiveHasOnPushStrategy;
return onPush ? 'OnPush' : onPush !== undefined ? 'Default' : undefined;
});
}
| {
"end_byte": 1574,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/component-metadata.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab.component.ts_0_1019 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, input, output} from '@angular/core';
import {DirectivePosition} from 'protocol';
import {IndexedNode} from '../directive-forest/index-forest';
import {FlatNode} from '../property-resolver/element-property-resolver';
import {PropertyTabBodyComponent} from './property-view/property-tab-body.component';
import {PropertyTabHeaderComponent} from './property-tab-header.component';
@Component({
templateUrl: './property-tab.component.html',
selector: 'ng-property-tab',
standalone: true,
imports: [PropertyTabHeaderComponent, PropertyTabBodyComponent],
})
export class PropertyTabComponent {
readonly currentSelectedElement = input.required<IndexedNode>();
readonly viewSource = output<string>();
readonly inspect = output<{node: FlatNode; directivePosition: DirectivePosition}>();
}
| {
"end_byte": 1019,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab-header.component.ts_0_878 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, input} from '@angular/core';
import {IndexedNode} from '../directive-forest/index-forest';
import {ComponentMetadataComponent} from './component-metadata.component';
import {MatExpansionModule} from '@angular/material/expansion';
@Component({
templateUrl: './property-tab-header.component.html',
selector: 'ng-property-tab-header',
styleUrls: ['./property-tab-header.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [MatExpansionModule, ComponentMetadataComponent],
})
export class PropertyTabHeaderComponent {
currentSelectedElement = input.required<IndexedNode>();
}
| {
"end_byte": 878,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab-header.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab.component.html_0_274 | <ng-property-tab-header [currentSelectedElement]="currentSelectedElement()">
</ng-property-tab-header>
<ng-property-tab-body (inspect)="inspect.emit($event)" (viewSource)="viewSource.emit($event)" [currentSelectedElement]="currentSelectedElement()">
</ng-property-tab-body>
| {
"end_byte": 274,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/component-metadata.component.html_0_590 | <div class="meta-data-container">
@if (viewEncapsulation()) {
<a
mat-button
color="primary"
href="https://angular.dev/api/core/ViewEncapsulation"
target="_blank"
>
View Encapsulation: <span class="meta-data">{{ viewEncapsulation() }}</span>
</a>
}
@if (changeDetectionStrategy()) {
<a
mat-button
color="primary"
href="https://angular.dev/api/core/ChangeDetectionStrategy"
target="_blank"
>
Change Detection Strategy: <span class="meta-data">{{ changeDetectionStrategy() }}</span>
</a>
}
</div>
| {
"end_byte": 590,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/component-metadata.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab-header.component.html_0_925 | @if (currentSelectedElement()) {
@let comp = currentSelectedElement().component;
@if (comp) {
<mat-accordion class="property-tab-header">
<div>
<mat-expansion-panel [hideToggle]="true">
<mat-expansion-panel-header collapsedHeight="32px" expandedHeight="32px">
<mat-panel-title>
<div class="element-header">
<div class="component-name">{{ comp.name }}</div>
</div>
</mat-panel-title>
</mat-expansion-panel-header>
<ng-component-metadata [currentSelectedComponent]="comp"></ng-component-metadata>
</mat-expansion-panel>
</div>
</mat-accordion>
} @else {
<div class="element-header">
<div class="element-name">{{ currentSelectedElement().element }}</div>
</div>
}
} @else {
<div class="element-header">
<div class="element-name">No selected Element</div>
</div>
}
| {
"end_byte": 925,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab-header.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab-header.component.scss_0_775 | .element-header {
display: flex;
justify-content: space-between;
width: 100%;
align-items: center;
font-size: 11px;
.component-name {
margin-left: 10px;
font-weight: 700;
line-height: 25px;
}
.element-name {
margin-left: 10px;
line-height: 25px;
font-weight: 700;
}
}
::ng-deep {
.property-tab-header {
mat-expansion-panel {
border-radius: unset !important;
}
&.mat-accordion {
.mat-expansion-panel {
.mat-expansion-panel-header {
padding: 0;
.mat-expansion-panel-header-title {
margin-right: 0;
}
}
.mat-expansion-panel-content {
.mat-expansion-panel-body {
padding: 0;
}
}
}
}
}
}
| {
"end_byte": 775,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab-header.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/component-metadata.component.scss_0_203 | .meta-data-container {
display: flex;
flex-direction: column;
}
.meta-data-container a {
width: 100%;
font-size: 11px;
height: 22px;
line-height: 22px;
}
.meta-data {
font-weight: 400;
}
| {
"end_byte": 203,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/component-metadata.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/BUILD.bazel_0_1419 | load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("//devtools/tools:ng_module.bzl", "ng_module")
package(default_visibility = ["//visibility:public"])
_STYLE_SRCS = [
"component-metadata.component.scss",
"property-tab.component.scss",
"property-tab-header.component.scss",
]
_STYLE_LABELS = [
src[:-len(".component.scss")].replace("-", "_") + "_styles"
for src in _STYLE_SRCS
]
[
sass_binary(
name = label,
src = src,
)
for label, src in zip(_STYLE_LABELS, _STYLE_SRCS)
]
ng_module(
name = "property-tab",
srcs = [
"component-metadata.component.ts",
"property-tab.component.ts",
"property-tab-header.component.ts",
],
angular_assets = [
"property-tab.component.html",
"property-tab-header.component.html",
"component-metadata.component.html",
] + _STYLE_LABELS,
deps = [
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/index-forest",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-resolver",
"//devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view",
"//devtools/projects/protocol",
"//packages/common",
"//packages/core",
"@npm//@angular/material",
"@npm//@types",
"@npm//rxjs",
],
)
| {
"end_byte": 1419,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/BUILD.bazel"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab.component.scss_0_59 | ng-property-view-body {
width: 100%;
overflow: auto;
}
| {
"end_byte": 59,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-tab.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-tab-body.component.html_0_267 | @if (currentSelectedElement()) {
@for (directive of currentDirectives(); track $index) {
<div class="explorer-panel">
<ng-property-view (inspect)="inspect.emit($event)" (viewSource)="viewSource.emit(directive)" [directive]="directive" />
</div>
}
}
| {
"end_byte": 267,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-tab-body.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-body.component.ts_0_6341 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {CdkDragDrop, moveItemInArray, CdkDropList, CdkDrag} from '@angular/cdk/drag-drop';
import {Component, computed, forwardRef, input, output} from '@angular/core';
import {DirectivePosition, SerializedInjectedService} from 'protocol';
import {
DirectivePropertyResolver,
DirectiveTreeData,
} from '../../property-resolver/directive-property-resolver';
import {FlatNode} from '../../property-resolver/element-property-resolver';
import {ResolutionPathComponent} from '../../../dependency-injection/resolution-path.component';
import {MatChipsModule} from '@angular/material/chips';
import {PropertyViewTreeComponent} from './property-view-tree.component';
import {MatIcon} from '@angular/material/icon';
import {MatTooltip} from '@angular/material/tooltip';
import {MatExpansionModule} from '@angular/material/expansion';
@Component({
selector: 'ng-property-view-body',
templateUrl: './property-view-body.component.html',
styleUrls: ['./property-view-body.component.scss'],
standalone: true,
imports: [
MatExpansionModule,
CdkDropList,
MatTooltip,
MatIcon,
forwardRef(() => InjectedServicesComponent),
CdkDrag,
PropertyViewTreeComponent,
],
})
export class PropertyViewBodyComponent {
readonly controller = input.required<DirectivePropertyResolver>();
readonly directiveInputControls = input.required<DirectiveTreeData>();
readonly directiveOutputControls = input.required<DirectiveTreeData>();
readonly directiveStateControls = input.required<DirectiveTreeData>();
readonly inspect = output<{node: FlatNode; directivePosition: DirectivePosition}>();
categoryOrder = [0, 1, 2];
readonly panels = computed<
{
title: string;
hidden: boolean;
controls: DirectiveTreeData;
documentation: string;
class: string;
}[]
>(() => {
return [
{
title: '@Inputs',
hidden: this.directiveInputControls().dataSource.data.length === 0,
controls: this.directiveInputControls(),
documentation: 'https://angular.dev/api/core/input',
class: 'cy-inputs',
},
{
title: '@Outputs',
hidden: this.directiveOutputControls().dataSource.data.length === 0,
controls: this.directiveOutputControls(),
documentation: 'https://angular.dev/api/core/output',
class: 'cy-outputs',
},
{
title: 'Properties',
hidden: this.directiveStateControls().dataSource.data.length === 0,
controls: this.directiveStateControls(),
documentation: 'https://angular.dev/guide/templates/property-binding',
class: 'cy-properties',
},
];
});
readonly controlsLoaded = computed(() => {
return (
!!this.directiveStateControls() &&
!!this.directiveOutputControls() &&
!!this.directiveInputControls()
);
});
updateValue({node, newValue}: {node: FlatNode; newValue: unknown}): void {
this.controller().updateValue(node, newValue);
}
drop(event: CdkDragDrop<any, any>): void {
moveItemInArray(this.categoryOrder, event.previousIndex, event.currentIndex);
}
handleInspect(node: FlatNode): void {
this.inspect.emit({
node,
directivePosition: this.controller().directivePosition,
});
}
}
@Component({
selector: 'ng-dependency-viewer',
template: `
<mat-accordion class="example-headers-align" multi>
<mat-expansion-panel>
<mat-expansion-panel-header collapsedHeight="35px" expandedHeight="35px">
<mat-panel-title>
<mat-chip-listbox>
<mat-chip
matTooltipPosition="left"
matTooltip="Dependency injection token"
(click)="$event.stopPropagation()"
>{{ dependency().token }}</mat-chip
>
</mat-chip-listbox>
</mat-panel-title>
<mat-panel-description>
<mat-chip-listbox>
<div class="di-flags">
@if (dependency().flags?.optional) {
<mat-chip [highlighted]="true" color="primary">Optional</mat-chip>
} @if (dependency().flags?.host) {
<mat-chip [highlighted]="true" color="primary">Host</mat-chip>
} @if (dependency().flags?.self) {
<mat-chip [highlighted]="true" color="primary">Self</mat-chip>
} @if (dependency().flags?.skipSelf) {
<mat-chip [highlighted]="true" color="primary">SkipSelf</mat-chip>
}
</div>
</mat-chip-listbox>
</mat-panel-description>
</mat-expansion-panel-header>
<ng-resolution-path [path]="dependency().resolutionPath"></ng-resolution-path>
</mat-expansion-panel>
</mat-accordion>
`,
styles: [
`
.di-flags {
display: flex;
flex-wrap: nowrap;
}
:host-context(.dark-theme) ng-resolution-path {
background: #1a1a1a;
}
ng-resolution-path {
border-top: 1px solid black;
display: block;
overflow-x: scroll;
background: #f3f3f3;
}
:host {
mat-chip {
--mdc-chip-container-height: 18px;
}
}
`,
],
standalone: true,
imports: [MatExpansionModule, MatChipsModule, MatTooltip, ResolutionPathComponent],
})
export class DependencyViewerComponent {
readonly dependency = input.required<SerializedInjectedService>();
}
@Component({
selector: 'ng-injected-services',
template: ` @for (dependency of dependencies(); track dependency.position[0]) {
<ng-dependency-viewer [dependency]="dependency" />
}`,
styles: [
`
ng-dependency-viewer {
border-bottom: 1px solid color-mix(in srgb, currentColor, #bdbdbd 85%);
display: block;
}
`,
],
standalone: true,
imports: [DependencyViewerComponent],
})
export class InjectedServicesComponent {
readonly controller = input.required<DirectivePropertyResolver>();
readonly dependencies = computed<SerializedInjectedService[]>(() => {
return this.controller().directiveMetadata?.dependencies ?? [];
});
}
| {
"end_byte": 6341,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-body.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-tree.component.html_0_1293 | @if (treeControl()) {
<mat-tree class="property-list" [dataSource]="dataSource()" [treeControl]="treeControl()">
<mat-tree-node matTreeNodePaddingIndent="14" *matTreeNodeDef="let node" matTreeNodePadding>
<span class="name non-expandable">{{ node.prop.name }}</span>:
@if (!node.prop.descriptor.editable) {
<ng-property-preview (inspect)="inspect.emit(node)" [node]="node"></ng-property-preview>
} @else {
<ng-property-editor
[key]="node.prop.name"
[initialValue]="node.prop.descriptor.value || node.prop.descriptor.preview"
[containerType]="node.prop.descriptor.containerType"
(updateValue)="handleUpdate(node, $event)"
/>
}
</mat-tree-node>
<mat-tree-node matTreeNodePaddingIndent="14" *matTreeNodeDef="let node; when: hasChild" matTreeNodePadding>
<div (click)="toggle(node)">
<mat-icon class="mat-icon-rtl-mirror">
{{ treeControl().isExpanded(node) ? 'expand_more' : 'chevron_right' }}
</mat-icon>
<span class="name">{{ node.prop.name }}</span>:
<span class="value">
{{ treeControl().isExpanded(node) ? '' : node.prop.descriptor.preview }}
</span>
</div>
</mat-tree-node>
</mat-tree>
}
| {
"end_byte": 1293,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-tree.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-tree.component.scss_0_953 | :host {
width: 100%;
display: block;
overflow: auto;
height: calc(100% - 24px);
mat-tree {
display: table;
}
::ng-deep {
.mat-tree-node {
min-height: 20px !important;
cursor: default;
font-family: Menlo, monospace;
.mat-icon {
font-size: 11px;
width: 8px;
height: 16px;
position: relative;
top: 6px;
}
}
}
}
.name {
margin-left: -9px;
}
.non-expandable {
margin-left: 18px;
}
.property-list {
margin: 5px 5px 5px 15px;
mat-tree-node {
.name {
color: #ce271e;
font-weight: 500;
}
}
}
:host-context(.dark-theme) {
.property-list {
.name {
color: #54c9bd !important;
}
}
}
.property-list mat-tree-node.disabled .name,
.disabled {
color: #333;
}
.arrow {
font-family: monospace;
font-size: 0.5em;
color: #6e6e6e;
}
:host ::ng-deep .mat-tree-node,
.mat-nested-tree-node {
font-size: 0.8em;
}
| {
"end_byte": 953,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-tree.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-editor.component.scss_0_557 | .editor {
cursor: text;
border: none;
outline: none;
min-width: 100px;
white-space: pre;
width: fit-content;
}
.editor-input {
background-color: #bbddfb;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05);
}
input {
width: fit-content;
font-family: Menlo, monospace;
font-weight: 500;
font-size: 1em;
border: none;
outline: none;
}
:host-context(.dark-theme) {
input {
color: #bcc5ce;
background-color: #202124;
}
.editor-input {
background-color: #454546;
box-shadow: 0 0 0 1px rgba(165, 165, 165, 0.05);
}
}
| {
"end_byte": 557,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-editor.component.scss"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-tree.component.ts_0_1877 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {FlatTreeControl} from '@angular/cdk/tree';
import {Component, input, output} from '@angular/core';
import {FlatNode} from '../../property-resolver/element-property-resolver';
import {PropertyDataSource} from '../../property-resolver/property-data-source';
import {MatIcon} from '@angular/material/icon';
import {PropertyEditorComponent} from './property-editor.component';
import {PropertyPreviewComponent} from './property-preview.component';
import {MatTree, MatTreeNode, MatTreeNodeDef, MatTreeNodePadding} from '@angular/material/tree';
@Component({
selector: 'ng-property-view-tree',
templateUrl: './property-view-tree.component.html',
styleUrls: ['./property-view-tree.component.scss'],
standalone: true,
imports: [
MatTree,
MatTreeNode,
MatTreeNodeDef,
MatTreeNodePadding,
PropertyPreviewComponent,
PropertyEditorComponent,
MatIcon,
],
})
export class PropertyViewTreeComponent {
readonly dataSource = input.required<PropertyDataSource>();
readonly treeControl = input.required<FlatTreeControl<FlatNode>>();
readonly updateValue = output<any>();
readonly inspect = output<any>();
hasChild = (_: number, node: FlatNode): boolean => node.expandable;
toggle(node: FlatNode): void {
if (this.treeControl().isExpanded(node)) {
this.treeControl().collapse(node);
return;
}
this.expand(node);
}
expand(node: FlatNode): void {
const {prop} = node;
if (!prop.descriptor.expandable) {
return;
}
this.treeControl().expand(node);
}
handleUpdate(node: FlatNode, newValue: unknown): void {
this.updateValue.emit({
node,
newValue,
});
}
}
| {
"end_byte": 1877,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-tree.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view.component.ts_0_1477 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, computed, inject, input, output} from '@angular/core';
import {DirectivePosition} from 'protocol';
import {ElementPropertyResolver, FlatNode} from '../../property-resolver/element-property-resolver';
import {PropertyViewBodyComponent} from './property-view-body.component';
import {PropertyViewHeaderComponent} from './property-view-header.component';
@Component({
selector: 'ng-property-view',
templateUrl: './property-view.component.html',
styleUrls: ['./property-view.component.scss'],
standalone: true,
imports: [PropertyViewHeaderComponent, PropertyViewBodyComponent],
})
export class PropertyViewComponent {
readonly directive = input.required<string>();
readonly inspect = output<{node: FlatNode; directivePosition: DirectivePosition}>();
readonly viewSource = output<void>();
private _nestedProps = inject(ElementPropertyResolver);
readonly controller = computed(() => this._nestedProps.getDirectiveController(this.directive()));
readonly directiveInputControls = computed(() => this.controller()?.directiveInputControls);
readonly directiveOutputControls = computed(() => this.controller()?.directiveOutputControls);
readonly directiveStateControls = computed(() => this.controller()?.directiveStateControls);
}
| {
"end_byte": 1477,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view.component.html_0_389 | <ng-property-view-header [directive]="directive()" (viewSource)="viewSource.emit()"></ng-property-view-header>
<ng-property-view-body
[controller]="controller()"
[directiveInputControls]="directiveInputControls()"
[directiveOutputControls]="directiveOutputControls()"
[directiveStateControls]="directiveStateControls()"
(inspect)="inspect.emit($event)"
></ng-property-view-body>
| {
"end_byte": 389,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-editor.component.ts_0_2332 | /**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
afterNextRender,
Component,
ElementRef,
effect,
input,
output,
signal,
viewChild,
} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {ContainerType} from 'protocol';
type EditorType = string | number | boolean;
type EditorResult = EditorType | Array<EditorType>;
enum PropertyEditorState {
Read,
Write,
}
const parseValue = (value: EditorResult): EditorResult => {
try {
return JSON.parse(value as any);
} catch {
return value.toString();
}
};
@Component({
templateUrl: './property-editor.component.html',
selector: 'ng-property-editor',
styleUrls: ['./property-editor.component.scss'],
standalone: true,
imports: [FormsModule],
})
export class PropertyEditorComponent {
readonly key = input.required<string>();
readonly initialValue = input.required<EditorResult>();
readonly containerType = input<ContainerType>();
readonly updateValue = output<EditorResult>();
readonly inputEl = viewChild<ElementRef<HTMLInputElement>>('inputEl');
readState = PropertyEditorState.Read;
writeState = PropertyEditorState.Write;
readonly valueToSubmit = signal<EditorResult | undefined>(undefined);
readonly currentPropertyState = signal(this.readState);
constructor() {
afterNextRender({
read: () => {
this.valueToSubmit.set(this.initialValue());
},
});
effect(() => {
const editor = this.inputEl()?.nativeElement;
if (editor && this.currentPropertyState() === this.writeState) {
editor.focus();
editor.select();
}
});
}
accept(): void {
const parsed = parseValue(this.valueToSubmit()!);
this.updateValue.emit(parsed);
this.currentPropertyState.set(this.readState);
}
reject(): void {
this.valueToSubmit.set(this.initialValue());
this.currentPropertyState.set(this.readState);
}
onClick(): void {
if (this.currentPropertyState() === this.readState) {
this.currentPropertyState.set(this.writeState);
}
}
onBlur(): void {
if (this.currentPropertyState() === this.writeState) {
this.accept();
}
}
}
| {
"end_byte": 2332,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-editor.component.ts"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-editor.component.html_0_899 | <div class="editor" (click)="onClick()">
<span class="state-container">
@switch (currentPropertyState()) {
@case (readState) {
<span>
@switch(containerType()) {
@case('WritableSignal') {
<span class="editable">Signal({{valueToSubmit()}})</span>
}
@default {
<span class="editable">{{ valueToSubmit() }}</span>
}
}
</span>
}
@case (writeState) {
<span>
<input
#inputEl
matInput
type="text"
class="editor-input editable"
(mousedown)="$event.stopPropagation()"
[(ngModel)]="valueToSubmit"
(keydown.enter)="accept()"
(keydown.escape)="reject()"
(blur)="onBlur()"
/>
</span>
}
}
</span>
</div>
| {
"end_byte": 899,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-editor.component.html"
} |
angular/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-header.component.html_0_164 | <mat-toolbar>
{{ directive() }}
<button matTooltip="Open source" (click)="handleViewSource($event)">
<mat-icon> code </mat-icon>
</button>
</mat-toolbar>
| {
"end_byte": 164,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-tab/property-view/property-view-header.component.html"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.