2021-12-10 02:37:01 +00: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-03-08 08:41:05 +00:00
|
|
|
/// <reference types="resize-observer-browser" />
|
2021-12-09 05:44:17 +00:00
|
|
|
import {AfterViewInit, Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
|
|
|
|
import {MatSlideToggleChange} from '@angular/material/slide-toggle';
|
|
|
|
|
import {MatTabNav} from '@angular/material/tabs';
|
|
|
|
|
import {Events, MessageBus, Route} from 'protocol';
|
|
|
|
|
import {Subscription} from 'rxjs';
|
|
|
|
|
|
|
|
|
|
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 18:40:18 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ng-devtools-tabs',
|
|
|
|
|
templateUrl: './devtools-tabs.component.html',
|
2020-03-29 03:28:36 +00:00
|
|
|
styleUrls: ['./devtools-tabs.component.scss'],
|
2020-01-27 18:40:18 +00:00
|
|
|
})
|
2021-02-13 10:22:04 +00:00
|
|
|
export class DevToolsTabsComponent implements OnInit, OnDestroy, AfterViewInit {
|
2021-12-09 05:44:17 +00:00
|
|
|
@Input() angularVersion: string|undefined = undefined;
|
2020-02-06 22:41:19 +00:00
|
|
|
@ViewChild(DirectiveExplorerComponent) directiveExplorer: DirectiveExplorerComponent;
|
2021-12-09 05:44:17 +00:00
|
|
|
@ViewChild('navBar', {static: true}) navbar: MatTabNav;
|
2021-02-13 10:22:04 +00:00
|
|
|
|
2021-12-09 05:44:17 +00:00
|
|
|
activeTab: 'Components'|'Profiler'|'Router Tree' = 'Components';
|
2020-01-27 18:40:18 +00:00
|
|
|
|
2020-08-08 20:43:42 +00:00
|
|
|
inspectorRunning = false;
|
2021-02-07 13:15:42 +00:00
|
|
|
routerTreeEnabled = false;
|
2021-04-28 22:50:06 +00:00
|
|
|
showCommentNodes = false;
|
2020-08-08 20:43:42 +00:00
|
|
|
|
|
|
|
|
private _currentThemeSubscription: Subscription;
|
|
|
|
|
currentTheme: Theme;
|
|
|
|
|
|
2021-03-11 05:41:50 +00:00
|
|
|
routes: Route[] = [];
|
|
|
|
|
|
2020-05-08 22:12:17 +00:00
|
|
|
constructor(
|
2021-12-09 05:44:17 +00:00
|
|
|
public tabUpdate: TabUpdate, public themeService: ThemeService,
|
|
|
|
|
private _messageBus: MessageBus<Events>,
|
|
|
|
|
private _applicationEnvironment: ApplicationEnvironment) {}
|
2020-04-02 23:23:03 +00:00
|
|
|
|
2020-08-08 20:43:42 +00:00
|
|
|
ngOnInit(): void {
|
2021-12-09 05:44:17 +00:00
|
|
|
this._currentThemeSubscription =
|
|
|
|
|
this.themeService.currentTheme.subscribe((theme) => (this.currentTheme = theme));
|
2021-03-11 05:41:50 +00:00
|
|
|
|
|
|
|
|
this._messageBus.on('updateRouterTree', (routes) => {
|
|
|
|
|
this.routes = routes || [];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get tabs(): string[] {
|
|
|
|
|
const alwaysShown = ['Components', 'Profiler'];
|
|
|
|
|
return this.routes.length === 0 ? alwaysShown : [...alwaysShown, 'Router Tree'];
|
2020-08-08 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-13 10:22:04 +00:00
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
this.navbar.disablePagination = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 20:43:42 +00:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
this._currentThemeSubscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 23:23:03 +00:00
|
|
|
get latestSHA(): string {
|
2021-12-01 06:13:17 +00:00
|
|
|
return this._applicationEnvironment.environment.LATEST_SHA.slice(0, 8);
|
2020-04-02 23:23:03 +00:00
|
|
|
}
|
2020-03-18 00:48:29 +00:00
|
|
|
|
2021-12-09 05:44:17 +00:00
|
|
|
changeTab(tab: 'Profiler'|'Components'|'Router Tree'): void {
|
2021-02-13 10:22:04 +00:00
|
|
|
this.activeTab = tab;
|
|
|
|
|
this.tabUpdate.notify();
|
2021-02-07 13:15:42 +00:00
|
|
|
if (tab === 'Router Tree') {
|
2021-03-04 04:43:18 +00:00
|
|
|
this._messageBus.emit('getRoutes');
|
2021-02-07 13:15:42 +00:00
|
|
|
}
|
2021-02-13 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-29 00:29:23 +00:00
|
|
|
toggleInspector(): void {
|
2020-02-06 22:41:19 +00:00
|
|
|
this.toggleInspectorState();
|
|
|
|
|
this.emitInspectorEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emitInspectorEvent(): void {
|
2020-01-27 18:40:18 +00:00
|
|
|
if (this.inspectorRunning) {
|
2020-03-18 00:48:29 +00:00
|
|
|
this._messageBus.emit('inspectorStart');
|
2021-03-13 02:18:56 +00:00
|
|
|
this.changeTab('Components');
|
2020-01-27 18:40:18 +00:00
|
|
|
} else {
|
2020-03-18 00:48:29 +00:00
|
|
|
this._messageBus.emit('inspectorEnd');
|
2020-04-14 22:27:59 +00:00
|
|
|
this._messageBus.emit('removeHighlightOverlay');
|
2020-01-27 18:40:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 22:41:19 +00:00
|
|
|
toggleInspectorState(): void {
|
|
|
|
|
this.inspectorRunning = !this.inspectorRunning;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 03:21:32 +00:00
|
|
|
toggleTimingAPI(change: MatSlideToggleChange): void {
|
2021-12-09 05:44:17 +00:00
|
|
|
change.checked ? this._messageBus.emit('enableTimingAPI') :
|
|
|
|
|
this._messageBus.emit('disableTimingAPI');
|
2020-05-07 03:21:32 +00:00
|
|
|
}
|
2020-01-27 18:40:18 +00:00
|
|
|
}
|