Skip to content

Commit 6405da9

Browse files
jelbournandrewseguin
authored andcommitted
feat(cdk): switch injectables to new scope API (#10301)
* feat(cdk): switch injectables to new scope API * Update rxjs version * Update CDK to new API * Fix TS 2.7 error. * Update package lock
1 parent c28549d commit 6405da9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3480
-4877
lines changed

package-lock.json

Lines changed: 3134 additions & 4614 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
"node": ">= 5.4.1"
2727
},
2828
"dependencies": {
29-
"@angular/animations": ">=6.0.0-beta.7 <7.0.0",
30-
"@angular/common": ">=6.0.0-beta.7 <7.0.0",
31-
"@angular/compiler": ">=6.0.0-beta.7 <7.0.0",
32-
"@angular/core": ">=6.0.0-beta.7 <7.0.0",
33-
"@angular/forms": ">=6.0.0-beta.7 <7.0.0",
34-
"@angular/platform-browser": ">=6.0.0-beta.7 <7.0.0",
29+
"@angular/animations": "6.0.0-beta.8",
30+
"@angular/common": "6.0.0-beta.8",
31+
"@angular/compiler": "6.0.0-beta.8",
32+
"@angular/core": "6.0.0-beta.8",
33+
"@angular/forms": "6.0.0-beta.8",
34+
"@angular/platform-browser": "6.0.0-beta.8",
3535
"core-js": "^2.4.1",
36-
"rxjs": "^5.5.5",
36+
"rxjs": "^5.5.7",
3737
"systemjs": "0.19.43",
3838
"tsickle": "^0.24.x",
3939
"tslib": "^1.7.1",
@@ -42,11 +42,11 @@
4242
"devDependencies": {
4343
"@angular-devkit/core": "^0.4.5",
4444
"@angular-devkit/schematics": "^0.4.5",
45-
"@angular/bazel": ">=6.0.0-beta.7 <7.0.0",
46-
"@angular/compiler-cli": ">=6.0.0-beta.7 <7.0.0",
47-
"@angular/http": ">=6.0.0-beta.7 <7.0.0",
48-
"@angular/platform-browser-dynamic": ">=6.0.0-beta.7 <7.0.0",
49-
"@angular/platform-server": ">=6.0.0-beta.7 <7.0.0",
45+
"@angular/bazel": "6.0.0-beta.8",
46+
"@angular/compiler-cli": "6.0.0-beta.8",
47+
"@angular/http": "6.0.0-beta.8",
48+
"@angular/platform-browser-dynamic": "6.0.0-beta.8",
49+
"@angular/platform-server": "6.0.0-beta.8",
5050
"@angular/router": ">=6.0.0-beta.7 <7.0.0",
5151
"@angular/upgrade": "^5.0.1",
5252
"@bazel/ibazel": "0.3.1",
@@ -126,7 +126,7 @@
126126
"tsconfig-paths": "^2.3.0",
127127
"tslint": "^5.9.1",
128128
"tsutils": "^2.6.0",
129-
"typescript": "~2.6.0",
129+
"typescript": "~2.7.0",
130130
"uglify-js": "^2.8.14",
131131
"web-animations-js": "^2.2.5"
132132
}

src/cdk/a11y/a11y-module.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,12 @@
99
import {PlatformModule} from '@angular/cdk/platform';
1010
import {CommonModule} from '@angular/common';
1111
import {NgModule} from '@angular/core';
12-
import {ARIA_DESCRIBER_PROVIDER, AriaDescriber} from './aria-describer/aria-describer';
13-
import {CdkMonitorFocus, FOCUS_MONITOR_PROVIDER} from './focus-monitor/focus-monitor';
14-
import {CdkTrapFocus, FocusTrapFactory} from './focus-trap/focus-trap';
15-
import {InteractivityChecker} from './interactivity-checker/interactivity-checker';
16-
import {LIVE_ANNOUNCER_PROVIDER} from './live-announcer/live-announcer';
12+
import {CdkMonitorFocus} from './focus-monitor/focus-monitor';
13+
import {CdkTrapFocus} from './focus-trap/focus-trap';
1714

1815
@NgModule({
1916
imports: [CommonModule, PlatformModule],
2017
declarations: [CdkTrapFocus, CdkMonitorFocus],
2118
exports: [CdkTrapFocus, CdkMonitorFocus],
22-
providers: [
23-
InteractivityChecker,
24-
FocusTrapFactory,
25-
AriaDescriber,
26-
LIVE_ANNOUNCER_PROVIDER,
27-
ARIA_DESCRIBER_PROVIDER,
28-
FOCUS_MONITOR_PROVIDER,
29-
]
3019
})
3120
export class A11yModule {}

src/cdk/a11y/aria-describer/aria-describer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable, Inject, InjectionToken, Optional, SkipSelf} from '@angular/core';
109
import {DOCUMENT} from '@angular/common';
10+
import {
11+
Inject,
12+
Injectable,
13+
InjectionToken,
14+
Optional,
15+
SkipSelf,
16+
} from '@angular/core';
1117
import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference';
1218

19+
1320
/**
1421
* Interface used to register message elements and keep a count of how many registrations have
1522
* the same message and the reference to the message element used for the `aria-describedby`.
@@ -46,7 +53,7 @@ let messagesContainer: HTMLElement | null = null;
4653
* content.
4754
* @docs-private
4855
*/
49-
@Injectable()
56+
@Injectable({providedIn: 'root'})
5057
export class AriaDescriber {
5158
private _document: Document;
5259

@@ -204,12 +211,13 @@ export class AriaDescriber {
204211

205212
}
206213

207-
/** @docs-private */
214+
215+
/** @docs-private @deprecated @deletion-target 7.0.0 */
208216
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
209217
return parentDispatcher || new AriaDescriber(_document);
210218
}
211219

212-
/** @docs-private */
220+
/** @docs-private @deprecated @deletion-target 7.0.0 */
213221
export const ARIA_DESCRIBER_PROVIDER = {
214222
// If there is already an AriaDescriber available, use that. Otherwise, provide a new one.
215223
provide: AriaDescriber,

src/cdk/a11y/focus-monitor/focus-monitor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
89
import {Platform, supportsPassiveEventListeners} from '@angular/cdk/platform';
910
import {
1011
Directive,
@@ -39,7 +40,7 @@ type MonitoredElementInfo = {
3940

4041

4142
/** Monitors mouse and keyboard events to determine the cause of focus events. */
42-
@Injectable()
43+
@Injectable({providedIn: 'root'})
4344
export class FocusMonitor implements OnDestroy {
4445
/** The focus origin that the next focus event is a result of. */
4546
private _origin: FocusOrigin = null;
@@ -380,13 +381,13 @@ export class CdkMonitorFocus implements OnDestroy {
380381
}
381382
}
382383

383-
/** @docs-private */
384+
/** @docs-private @deprecated @deletion-target 7.0.0 */
384385
export function FOCUS_MONITOR_PROVIDER_FACTORY(
385386
parentDispatcher: FocusMonitor, ngZone: NgZone, platform: Platform) {
386387
return parentDispatcher || new FocusMonitor(ngZone, platform);
387388
}
388389

389-
/** @docs-private */
390+
/** @docs-private @deprecated @deletion-target 7.0.0 */
390391
export const FOCUS_MONITOR_PROVIDER = {
391392
// If there is already a FocusMonitor available, use that. Otherwise, provide a new one.
392393
provide: FocusMonitor,

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {DOCUMENT} from '@angular/common';
911
import {
12+
AfterContentInit,
1013
Directive,
1114
ElementRef,
15+
Inject,
16+
Injectable,
1217
Input,
1318
NgZone,
1419
OnDestroy,
15-
AfterContentInit,
16-
Injectable,
17-
Inject,
1820
} from '@angular/core';
19-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
2021
import {take} from 'rxjs/operators/take';
2122
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
22-
import {DOCUMENT} from '@angular/common';
2323

2424

2525
/**
@@ -278,7 +278,7 @@ export class FocusTrap {
278278

279279

280280
/** Factory that allows easy instantiation of focus traps. */
281-
@Injectable()
281+
@Injectable({providedIn: 'root'})
282282
export class FocusTrapFactory {
283283
private _document: Document;
284284

src/cdk/a11y/interactivity-checker/interactivity-checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable} from '@angular/core';
109
import {Platform} from '@angular/cdk/platform';
10+
import {Injectable} from '@angular/core';
1111

1212

1313
// The InteractivityChecker leans heavily on the ally.js accessibility utilities.
@@ -18,7 +18,7 @@ import {Platform} from '@angular/cdk/platform';
1818
* Utility for checking the interactivity of an element, such as whether is is focusable or
1919
* tabbable.
2020
*/
21-
@Injectable()
21+
@Injectable({providedIn: 'root'})
2222
export class InteractivityChecker {
2323

2424
constructor(private _platform: Platform) {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {InjectionToken} from '@angular/core';
10+
11+
// The token for the live announcer element is defined in a separate file from LiveAnnouncer
12+
// as a workaround for https://github.com/angular/angular/issues/22559
13+
14+
export const LIVE_ANNOUNCER_ELEMENT_TOKEN =
15+
new InjectionToken<HTMLElement | null>('liveAnnouncerElement', {
16+
providedIn: 'root',
17+
factory: () => null,
18+
});

src/cdk/a11y/live-announcer/live-announcer.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import {inject, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing';
21
import {Component} from '@angular/core';
2+
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
33
import {By} from '@angular/platform-browser';
4-
import {LiveAnnouncer, LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer';
54
import {A11yModule} from '../index';
5+
import {LiveAnnouncer} from './live-announcer';
6+
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';
67

78

89
describe('LiveAnnouncer', () => {

src/cdk/a11y/live-announcer/live-announcer.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {DOCUMENT} from '@angular/common';
910
import {
11+
Inject,
1012
Injectable,
11-
InjectionToken,
13+
OnDestroy,
1214
Optional,
13-
Inject,
15+
Provider,
1416
SkipSelf,
15-
OnDestroy,
1617
} from '@angular/core';
17-
import {DOCUMENT} from '@angular/common';
18+
import {LIVE_ANNOUNCER_ELEMENT_TOKEN} from './live-announcer-token';
1819

1920

20-
export const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken<HTMLElement>('liveAnnouncerElement');
21-
2221
/** Possible politeness levels. */
2322
export type AriaLivePoliteness = 'off' | 'polite' | 'assertive';
2423

25-
@Injectable()
24+
@Injectable({providedIn: 'root'})
2625
export class LiveAnnouncer implements OnDestroy {
27-
private _liveElement: Element;
26+
private readonly _liveElement: Element;
2827

2928
constructor(
3029
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
@@ -81,14 +80,15 @@ export class LiveAnnouncer implements OnDestroy {
8180

8281
}
8382

84-
/** @docs-private */
83+
84+
/** @docs-private @deprecated @deletion-target 7.0.0 */
8585
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
8686
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
8787
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
8888
}
8989

90-
/** @docs-private */
91-
export const LIVE_ANNOUNCER_PROVIDER = {
90+
/** @docs-private @deprecated @deletion-target 7.0.0 */
91+
export const LIVE_ANNOUNCER_PROVIDER: Provider = {
9292
// If there is already a LiveAnnouncer available, use that. Otherwise, provide a new one.
9393
provide: LiveAnnouncer,
9494
deps: [

src/cdk/a11y/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from './key-manager/list-key-manager';
1212
export * from './focus-trap/focus-trap';
1313
export * from './interactivity-checker/interactivity-checker';
1414
export * from './live-announcer/live-announcer';
15+
export * from './live-announcer/live-announcer-token';
1516
export * from './focus-monitor/focus-monitor';
1617
export * from './fake-mousedown';
1718
export * from './a11y-module';

src/cdk/accordion/accordion-module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
*/
88

99
import {NgModule} from '@angular/core';
10-
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections';
1110
import {CdkAccordion} from './accordion';
1211
import {CdkAccordionItem} from './accordion-item';
1312

13+
1414
@NgModule({
1515
exports: [CdkAccordion, CdkAccordionItem],
1616
declarations: [CdkAccordion, CdkAccordionItem],
17-
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
1817
})
1918
export class CdkAccordionModule {}

src/cdk/bidi/BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22
load("@angular//:index.bzl", "ng_module")
3+
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
4+
35

46
ng_module(
57
name = "bidi",
@@ -8,3 +10,30 @@ ng_module(
810
deps = ["@rxjs"],
911
tsconfig = ":tsconfig-build.json",
1012
)
13+
14+
ts_library(
15+
name = "bidi_test_sources",
16+
testonly = 1,
17+
srcs = glob(["**/*.spec.ts"]),
18+
deps = [
19+
":bidi",
20+
"@rxjs",
21+
],
22+
tsconfig = ":tsconfig-build.json",
23+
)
24+
25+
ts_web_test(
26+
name = "unit_tests",
27+
bootstrap = [
28+
"//:web_test_bootstrap_scripts",
29+
],
30+
31+
# Do not sort
32+
deps = [
33+
"//:tslib_bundle",
34+
"//:angular_bundles",
35+
"//:angular_test_bundles",
36+
"//test:angular_test_init",
37+
":bidi_test_sources",
38+
],
39+
)

src/cdk/bidi/bidi-module.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@
77
*/
88

99
import {NgModule} from '@angular/core';
10-
import {DOCUMENT} from '@angular/common';
1110
import {Dir} from './dir';
12-
import {DIR_DOCUMENT, Directionality} from './directionality';
1311

1412

1513
@NgModule({
1614
exports: [Dir],
1715
declarations: [Dir],
18-
providers: [
19-
{provide: DIR_DOCUMENT, useExisting: DOCUMENT},
20-
Directionality,
21-
]
2216
})
2317
export class BidiModule { }

src/cdk/bidi/dir-document-token.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {DOCUMENT} from '@angular/common';
10+
import {inject, InjectionToken} from '@angular/core';
11+
12+
13+
/**
14+
* Injection token used to inject the document into Directionality.
15+
* This is used so that the value can be faked in tests.
16+
*
17+
* We can't use the real document in tests because changing the real `dir` causes geometry-based
18+
* tests in Safari to fail.
19+
*
20+
* We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
21+
* themselves use things like `querySelector` in test code.
22+
*
23+
* This token is defined in a separate file from Directionality as a workaround for
24+
* https://github.com/angular/angular/issues/22559
25+
*
26+
* @docs-private
27+
*/
28+
export const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {
29+
providedIn: 'root',
30+
factory: () => inject(DOCUMENT),
31+
});

0 commit comments

Comments
 (0)