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 {animate, style, transition, trigger} from '@angular/animations';
|
2022-05-18 18:39:05 +03:00
|
|
|
import {Platform} from '@angular/cdk/platform';
|
|
|
|
|
import {DOCUMENT} from '@angular/common';
|
2024-02-27 09:12:43 -08:00
|
|
|
import {Component, Inject, OnDestroy, OnInit} from '@angular/core';
|
2021-12-09 00:44:17 -05:00
|
|
|
import {Events, MessageBus} from 'protocol';
|
|
|
|
|
import {interval} from 'rxjs';
|
|
|
|
|
|
|
|
|
|
import {ThemeService} from './theme-service';
|
2024-02-27 09:12:43 -08:00
|
|
|
import {MatTooltip} from '@angular/material/tooltip';
|
2024-01-19 22:52:14 +01:00
|
|
|
import {DevToolsTabsComponent} from './devtools-tabs/devtools-tabs.component';
|
2020-01-27 13:40:18 -05:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ng-devtools',
|
|
|
|
|
templateUrl: './devtools.component.html',
|
2020-03-28 23:28:36 -04:00
|
|
|
styleUrls: ['./devtools.component.scss'],
|
2020-02-04 10:34:34 -05:00
|
|
|
animations: [
|
2024-01-16 21:35:47 +00:00
|
|
|
trigger('enterAnimation', [
|
|
|
|
|
transition(':enter', [style({opacity: 0}), animate('200ms', style({opacity: 1}))]),
|
|
|
|
|
transition(':leave', [style({opacity: 1}), animate('200ms', style({opacity: 0}))]),
|
|
|
|
|
]),
|
2020-02-07 16:25:16 -05:00
|
|
|
],
|
2024-01-19 22:52:14 +01:00
|
|
|
standalone: true,
|
2024-02-27 09:12:43 -08:00
|
|
|
imports: [DevToolsTabsComponent, MatTooltip],
|
2020-01-27 13:40:18 -05:00
|
|
|
})
|
|
|
|
|
export class DevToolsComponent implements OnInit, OnDestroy {
|
2024-02-27 09:12:43 -08:00
|
|
|
angularExists: boolean | null = null;
|
2024-01-16 21:35:47 +00:00
|
|
|
angularVersion: string | boolean | undefined = undefined;
|
2021-02-25 05:34:39 -05:00
|
|
|
angularIsInDevMode = true;
|
2024-01-19 20:29:24 +01:00
|
|
|
hydration: boolean = false;
|
2023-12-04 20:44:53 +01:00
|
|
|
ivy!: boolean;
|
2020-03-17 17:48:29 -07:00
|
|
|
|
2022-05-18 18:39:05 +03:00
|
|
|
private readonly _firefoxStyleName = 'firefox_styles.css';
|
|
|
|
|
private readonly _chromeStyleName = 'chrome_styles.css';
|
2024-02-27 09:12:43 -08:00
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private _messageBus: MessageBus<Events>,
|
|
|
|
|
private _themeService: ThemeService,
|
|
|
|
|
private _platform: Platform,
|
|
|
|
|
@Inject(DOCUMENT) private _document: Document,
|
|
|
|
|
) {}
|
2020-01-27 13:40:18 -05:00
|
|
|
|
2020-04-16 16:32:12 -04:00
|
|
|
private _interval$ = interval(500).subscribe((attempt) => {
|
2024-02-27 09:12:43 -08:00
|
|
|
if (attempt === 10) {
|
|
|
|
|
this.angularExists = false;
|
2020-04-16 16:32:12 -04:00
|
|
|
}
|
|
|
|
|
this._messageBus.emit('queryNgAvailability');
|
|
|
|
|
});
|
2020-01-27 13:40:18 -05:00
|
|
|
|
2020-01-28 19:29:23 -05:00
|
|
|
ngOnInit(): void {
|
2021-02-25 05:34:39 -05:00
|
|
|
this._themeService.initializeThemeWatcher();
|
|
|
|
|
|
2024-01-19 20:29:24 +01:00
|
|
|
this._messageBus.once('ngAvailability', ({version, devMode, ivy, hydration}) => {
|
2024-02-27 09:12:43 -08:00
|
|
|
this.angularExists = !!version;
|
2020-01-29 12:10:57 -05:00
|
|
|
this.angularVersion = version;
|
2021-02-25 05:33:38 -05:00
|
|
|
this.angularIsInDevMode = devMode;
|
2020-04-20 13:13:18 -04:00
|
|
|
this.ivy = ivy;
|
2020-01-27 13:40:18 -05:00
|
|
|
this._interval$.unsubscribe();
|
2024-01-19 20:29:24 +01:00
|
|
|
this.hydration = hydration;
|
2020-01-27 13:40:18 -05:00
|
|
|
});
|
2022-05-18 18:39:05 +03:00
|
|
|
|
2024-01-16 21:35:47 +00:00
|
|
|
const browserStyleName = this._platform.FIREFOX
|
|
|
|
|
? this._firefoxStyleName
|
|
|
|
|
: this._chromeStyleName;
|
2022-05-18 18:39:05 +03:00
|
|
|
this._loadStyle(browserStyleName);
|
2020-01-27 13:40:18 -05:00
|
|
|
}
|
|
|
|
|
|
2020-04-17 14:59:26 -04:00
|
|
|
get majorAngularVersion(): number {
|
2020-03-20 11:54:37 -07:00
|
|
|
if (!this.angularVersion) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2020-04-20 13:13:18 -04:00
|
|
|
return parseInt(this.angularVersion.toString().split('.')[0], 10);
|
2020-02-07 13:39:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get supportedVersion(): boolean {
|
2020-04-20 13:13:18 -04:00
|
|
|
return (this.majorAngularVersion >= 9 || this.majorAngularVersion === 0) && this.ivy;
|
2020-02-07 13:39:15 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-18 18:39:05 +03:00
|
|
|
/** Add a style file in header based on fileName */
|
|
|
|
|
private _loadStyle(styleName: string) {
|
|
|
|
|
const head = this._document.getElementsByTagName('head')[0];
|
|
|
|
|
|
|
|
|
|
const style = this._document.createElement('link');
|
|
|
|
|
style.rel = 'stylesheet';
|
|
|
|
|
style.href = `./styles/${styleName}`;
|
|
|
|
|
|
|
|
|
|
head.appendChild(style);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 19:29:23 -05:00
|
|
|
ngOnDestroy(): void {
|
2020-01-27 13:40:18 -05:00
|
|
|
this._interval$.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
}
|