8
8
9
9
import { HighContrastModeDetector } from '@angular/cdk/a11y' ;
10
10
import { BidiModule } from '@angular/cdk/bidi' ;
11
- import { inject , Inject , InjectionToken , NgModule , Optional } from '@angular/core' ;
12
- import { VERSION as CDK_VERSION } from '@angular/cdk' ;
13
- import { DOCUMENT } from '@angular/common' ;
14
- import { Platform , _isTestEnvironment } from '@angular/cdk/platform' ;
15
- import { VERSION } from '../version' ;
11
+ import { inject , InjectionToken , NgModule } from '@angular/core' ;
12
+ import { _isTestEnvironment } from '@angular/cdk/platform' ;
16
13
17
- /** @docs -private */
18
- export function MATERIAL_SANITY_CHECKS_FACTORY ( ) : SanityChecks {
19
- return true ;
20
- }
21
-
22
- /** Injection token that configures whether the Material sanity checks are enabled. */
14
+ /**
15
+ * Injection token that configures whether the Material sanity checks are enabled.
16
+ * @deprecated No longer used and will be removed.
17
+ * @breaking -change 21.0.0
18
+ */
23
19
export const MATERIAL_SANITY_CHECKS = new InjectionToken < SanityChecks > ( 'mat-sanity-checks' , {
24
20
providedIn : 'root' ,
25
- factory : MATERIAL_SANITY_CHECKS_FACTORY ,
21
+ factory : ( ) => true ,
26
22
} ) ;
27
23
28
24
/**
29
25
* Possible sanity checks that can be enabled. If set to
30
26
* true/false, all checks will be enabled/disabled.
27
+ * @deprecated No longer used and will be removed.
28
+ * @breaking -change 21.0.0
31
29
*/
32
30
export type SanityChecks = boolean | GranularSanityChecks ;
33
31
34
- /** Object that can be used to configure the sanity checks granularly. */
32
+ /**
33
+ * Object that can be used to configure the sanity checks granularly.
34
+ * @deprecated No longer used and will be removed.
35
+ * @breaking -change 21.0.0
36
+ */
35
37
export interface GranularSanityChecks {
36
38
doctype : boolean ;
37
39
theme : boolean ;
@@ -43,109 +45,19 @@ export interface GranularSanityChecks {
43
45
* components. This includes Bidi, etc.
44
46
*
45
47
* This module should be imported to each top-level component module (e.g., MatTabsModule).
48
+ * @deprecated No longer used and will be removed.
49
+ * @breaking -change 21.0.0
46
50
*/
47
51
@NgModule ( {
48
52
imports : [ BidiModule ] ,
49
53
exports : [ BidiModule ] ,
50
54
} )
51
55
export class MatCommonModule {
52
- /** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */
53
- private _hasDoneGlobalChecks = false ;
56
+ constructor ( ...args : any [ ] ) ;
54
57
55
- constructor (
56
- highContrastModeDetector : HighContrastModeDetector ,
57
- @Optional ( ) @Inject ( MATERIAL_SANITY_CHECKS ) private _sanityChecks : SanityChecks ,
58
- @Inject ( DOCUMENT ) private _document : Document ,
59
- ) {
58
+ constructor ( ) {
60
59
// While A11yModule also does this, we repeat it here to avoid importing A11yModule
61
60
// in MatCommonModule.
62
- highContrastModeDetector . _applyBodyHighContrastModeCssClasses ( ) ;
63
-
64
- if ( ! this . _hasDoneGlobalChecks ) {
65
- this . _hasDoneGlobalChecks = true ;
66
-
67
- if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
68
- // Inject in here so the reference to `Platform` can be removed in production mode.
69
- const platform = inject ( Platform , { optional : true } ) ;
70
-
71
- if ( this . _checkIsEnabled ( 'doctype' ) ) {
72
- _checkDoctypeIsDefined ( this . _document ) ;
73
- }
74
-
75
- if ( this . _checkIsEnabled ( 'theme' ) ) {
76
- _checkThemeIsPresent ( this . _document , ! ! platform ?. isBrowser ) ;
77
- }
78
-
79
- if ( this . _checkIsEnabled ( 'version' ) ) {
80
- _checkCdkVersionMatch ( ) ;
81
- }
82
- }
83
- }
84
- }
85
-
86
- /** Gets whether a specific sanity check is enabled. */
87
- private _checkIsEnabled ( name : keyof GranularSanityChecks ) : boolean {
88
- if ( _isTestEnvironment ( ) ) {
89
- return false ;
90
- }
91
-
92
- if ( typeof this . _sanityChecks === 'boolean' ) {
93
- return this . _sanityChecks ;
94
- }
95
-
96
- return ! ! this . _sanityChecks [ name ] ;
97
- }
98
- }
99
-
100
- /** Checks that the page has a doctype. */
101
- function _checkDoctypeIsDefined ( doc : Document ) : void {
102
- if ( ! doc . doctype ) {
103
- console . warn (
104
- 'Current document does not have a doctype. This may cause ' +
105
- 'some Angular Material components not to behave as expected.' ,
106
- ) ;
107
- }
108
- }
109
-
110
- /** Checks that a theme has been included. */
111
- function _checkThemeIsPresent ( doc : Document , isBrowser : boolean ) : void {
112
- // We need to assert that the `body` is defined, because these checks run very early
113
- // and the `body` won't be defined if the consumer put their scripts in the `head`.
114
- if ( ! doc . body || ! isBrowser ) {
115
- return ;
116
- }
117
-
118
- const testElement = doc . createElement ( 'div' ) ;
119
- testElement . classList . add ( 'mat-theme-loaded-marker' ) ;
120
- doc . body . appendChild ( testElement ) ;
121
-
122
- const computedStyle = getComputedStyle ( testElement ) ;
123
-
124
- // In some situations the computed style of the test element can be null. For example in
125
- // Firefox, the computed style is null if an application is running inside of a hidden iframe.
126
- // See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397
127
- if ( computedStyle && computedStyle . display !== 'none' ) {
128
- console . warn (
129
- 'Could not find Angular Material core theme. Most Material ' +
130
- 'components may not work as expected. For more info refer ' +
131
- 'to the theming guide: https://material.angular.io/guide/theming' ,
132
- ) ;
133
- }
134
-
135
- testElement . remove ( ) ;
136
- }
137
-
138
- /** Checks whether the Material version matches the CDK version. */
139
- function _checkCdkVersionMatch ( ) : void {
140
- if ( VERSION . full !== CDK_VERSION . full ) {
141
- console . warn (
142
- 'The Angular Material version (' +
143
- VERSION . full +
144
- ') does not match ' +
145
- 'the Angular CDK version (' +
146
- CDK_VERSION . full +
147
- ').\n' +
148
- 'Please ensure the versions of these two packages exactly match.' ,
149
- ) ;
61
+ inject ( HighContrastModeDetector ) . _applyBodyHighContrastModeCssClasses ( ) ;
150
62
}
151
63
}
0 commit comments