2021-12-09 21:37:01 -05:00
|
|
|
/**
|
|
|
|
|
* @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.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2021-12-09 00:44:17 -05:00
|
|
|
import {AfterViewInit, Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
2023-12-04 20:44:53 +01:00
|
|
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
2023-08-30 18:41:16 -04:00
|
|
|
import {MatTabNav} from '@angular/material/tabs';
|
2021-12-09 00:44:17 -05:00
|
|
|
import {Events, MessageBus, Route} from 'protocol';
|
|
|
|
|
|
|
|
|
|
import {ApplicationEnvironment} from '../application-environment/index';
|
|
|
|
|
import {Theme, ThemeService} from '../theme-service';
|
|
|
|
|
|
|
|
|
|
import {DirectiveExplorerComponent} from './directive-explorer/directive-explorer.component';
|
|
|
|
|
import {TabUpdate} from './tab-update/index';
|
2020-01-27 13:40:18 -05:00
|
|
|
|
2024-01-16 21:35:47 +00:00
|
|
|
type Tabs = 'Components' | 'Profiler' | 'Router Tree' | 'Injector Tree';
|
2023-12-04 22:19:43 +01:00
|
|
|
|
2020-01-27 13:40:18 -05:00
|
|
|
@Component({
|
|
|
|
|
selector: 'ng-devtools-tabs',
|
|
|
|
|
templateUrl: './devtools-tabs.component.html',
|
2020-03-28 23:28:36 -04:00
|
|
|
styleUrls: ['./devtools-tabs.component.scss'],
|
2020-01-27 13:40:18 -05:00
|
|
|
})
|
2023-12-04 20:44:53 +01:00
|
|
|
export class DevToolsTabsComponent implements OnInit, AfterViewInit {
|
2024-01-16 21:35:47 +00:00
|
|
|
@Input() angularVersion: string | undefined = undefined;
|
2023-12-04 20:44:53 +01:00
|
|
|
@ViewChild(DirectiveExplorerComponent) directiveExplorer!: DirectiveExplorerComponent;
|
|
|
|
|
@ViewChild('navBar', {static: true}) navbar!: MatTabNav;
|
2021-02-13 05:22:04 -05:00
|
|
|
|
2023-12-04 22:19:43 +01:00
|
|
|
activeTab: Tabs = 'Components';
|
2020-01-27 13:40:18 -05:00
|
|
|
|
2020-08-08 16:43:42 -04:00
|
|
|
inspectorRunning = false;
|
2021-02-07 08:15:42 -05:00
|
|
|
routerTreeEnabled = false;
|
2021-04-28 15:50:06 -07:00
|
|
|
showCommentNodes = false;
|
2023-08-30 18:41:16 -04:00
|
|
|
timingAPIEnabled = false;
|
2020-08-08 16:43:42 -04:00
|
|
|
|
2023-12-04 20:44:53 +01:00
|
|
|
currentTheme!: Theme;
|
2020-08-08 16:43:42 -04:00
|
|
|
|
2021-03-11 00:41:50 -05:00
|
|
|
routes: Route[] = [];
|
|
|
|
|
|
2020-05-08 15:12:17 -07:00
|
|
|
constructor(
|
2024-01-16 21:35:47 +00:00
|
|
|
public tabUpdate: TabUpdate,
|
|
|
|
|
public themeService: ThemeService,
|
|
|
|
|
private _messageBus: MessageBus<Events>,
|
|
|
|
|
private _applicationEnvironment: ApplicationEnvironment,
|
2023-12-04 20:44:53 +01:00
|
|
|
) {
|
2024-01-16 21:35:47 +00:00
|
|
|
this.themeService.currentTheme
|
|
|
|
|
.pipe(takeUntilDestroyed())
|
|
|
|
|
.subscribe((theme) => (this.currentTheme = theme));
|
2021-03-11 00:41:50 -05:00
|
|
|
|
|
|
|
|
this._messageBus.on('updateRouterTree', (routes) => {
|
|
|
|
|
this.routes = routes || [];
|
|
|
|
|
});
|
2023-12-04 20:44:53 +01:00
|
|
|
}
|
2023-08-30 18:41:16 -04:00
|
|
|
|
2023-12-04 20:44:53 +01:00
|
|
|
ngOnInit(): void {
|
2023-08-30 18:41:16 -04:00
|
|
|
this.navbar.stretchTabs = false;
|
2021-03-11 00:41:50 -05:00
|
|
|
}
|
|
|
|
|
|
2023-12-04 22:19:43 +01:00
|
|
|
get tabs(): Tabs[] {
|
|
|
|
|
const alwaysShown: Tabs[] = ['Components', 'Profiler', 'Injector Tree'];
|
2021-03-11 00:41:50 -05:00
|
|
|
return this.routes.length === 0 ? alwaysShown : [...alwaysShown, 'Router Tree'];
|
2020-08-08 16:43:42 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-13 05:22:04 -05:00
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
this.navbar.disablePagination = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 19:23:03 -04:00
|
|
|
get latestSHA(): string {
|
2021-12-01 01:13:17 -05:00
|
|
|
return this._applicationEnvironment.environment.LATEST_SHA.slice(0, 8);
|
2020-04-02 19:23:03 -04:00
|
|
|
}
|
2020-03-17 17:48:29 -07:00
|
|
|
|
2023-12-04 22:19:43 +01:00
|
|
|
changeTab(tab: Tabs): void {
|
2021-02-13 05:22:04 -05:00
|
|
|
this.activeTab = tab;
|
|
|
|
|
this.tabUpdate.notify();
|
2021-02-07 08:15:42 -05:00
|
|
|
if (tab === 'Router Tree') {
|
2021-03-03 23:43:18 -05:00
|
|
|
this._messageBus.emit('getRoutes');
|
2021-02-07 08:15:42 -05:00
|
|
|
}
|
2021-02-13 05:22:04 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-28 19:29:23 -05:00
|
|
|
toggleInspector(): void {
|
2020-02-06 17:41:19 -05:00
|
|
|
this.toggleInspectorState();
|
|
|
|
|
this.emitInspectorEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emitInspectorEvent(): void {
|
2020-01-27 13:40:18 -05:00
|
|
|
if (this.inspectorRunning) {
|
2020-03-17 17:48:29 -07:00
|
|
|
this._messageBus.emit('inspectorStart');
|
2020-01-27 13:40:18 -05:00
|
|
|
} else {
|
2020-03-17 17:48:29 -07:00
|
|
|
this._messageBus.emit('inspectorEnd');
|
2020-04-14 18:27:59 -04:00
|
|
|
this._messageBus.emit('removeHighlightOverlay');
|
2020-01-27 13:40:18 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 17:41:19 -05:00
|
|
|
toggleInspectorState(): void {
|
|
|
|
|
this.inspectorRunning = !this.inspectorRunning;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 18:41:16 -04:00
|
|
|
toggleTimingAPI(): void {
|
|
|
|
|
this.timingAPIEnabled = !this.timingAPIEnabled;
|
2024-01-16 21:35:47 +00:00
|
|
|
this.timingAPIEnabled
|
|
|
|
|
? this._messageBus.emit('enableTimingAPI')
|
|
|
|
|
: this._messageBus.emit('disableTimingAPI');
|
2020-05-06 23:21:32 -04:00
|
|
|
}
|
2020-01-27 13:40:18 -05:00
|
|
|
}
|