Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit e354ca3

Browse files
committed
refactor: remove private Angular APIs
1 parent b9745c6 commit e354ca3

21 files changed

+168
-121
lines changed

src/lib/api/core/base-adapter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class MockElementRef extends ElementRef {
2121
describe('BaseFxDirectiveAdapter class', () => {
2222
let component;
2323
beforeEach(() => {
24-
component = new BaseFxDirectiveAdapter('', {} as MediaMonitor, new MockElementRef(), {} as Renderer2); // tslint:disable-line:max-line-length
24+
component = new BaseFxDirectiveAdapter('', {} as MediaMonitor, new MockElementRef(), {} as Renderer2, {}); // tslint:disable-line:max-line-length
2525
});
2626
describe('cacheInput', () => {
2727
it('should call _cacheInputArray when source is an array', () => {

src/lib/api/core/base-adapter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
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-
import {ElementRef, Renderer2} from '@angular/core';
8+
import {ElementRef, Inject, Renderer2} from '@angular/core';
99

1010
import {BaseFxDirective} from './base';
1111
import {ResponsiveActivation} from './responsive-activation';
1212
import {MediaQuerySubscriber} from '../../media-query/media-change';
1313
import {MediaMonitor} from '../../media-query/media-monitor';
14+
import {DOCUMENT} from '@angular/common';
1415

1516

1617
/**
@@ -48,8 +49,9 @@ export class BaseFxDirectiveAdapter extends BaseFxDirective {
4849
constructor(protected _baseKey: string, // non-responsive @Input property name
4950
protected _mediaMonitor: MediaMonitor,
5051
protected _elementRef: ElementRef,
51-
protected _renderer: Renderer2) {
52-
super(_mediaMonitor, _elementRef, _renderer);
52+
protected _renderer: Renderer2,
53+
@Inject(DOCUMENT) _document: any) {
54+
super(_mediaMonitor, _elementRef, _renderer, _document);
5355
}
5456

5557
/**

src/lib/api/core/base.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {
9-
ElementRef, OnDestroy, SimpleChanges, OnChanges,
10-
SimpleChange, Renderer2
9+
ElementRef,
10+
OnDestroy,
11+
SimpleChanges,
12+
OnChanges,
13+
SimpleChange,
14+
Renderer2,
15+
Inject,
1116
} from '@angular/core';
1217

1318
import {buildLayoutCSS} from '../../utils/layout-validator';
@@ -16,12 +21,14 @@ import {
1621
lookupStyle,
1722
lookupInlineStyle,
1823
applyStyleToElement,
19-
applyStyleToElements, lookupAttributeValue
24+
applyStyleToElements,
25+
lookupAttributeValue,
2026
} from '../../utils/style-utils';
2127

2228
import {ResponsiveActivation, KeyOptions} from '../core/responsive-activation';
2329
import {MediaMonitor} from '../../media-query/media-monitor';
2430
import {MediaQuerySubscriber} from '../../media-query/media-change';
31+
import {DOCUMENT} from '@angular/common';
2532

2633
/** Abstract base class for the Layout API styling directives. */
2734
export abstract class BaseFxDirective implements OnDestroy, OnChanges {
@@ -63,7 +70,8 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
6370
*/
6471
constructor(protected _mediaMonitor: MediaMonitor,
6572
protected _elementRef: ElementRef,
66-
protected _renderer: Renderer2) {
73+
protected _renderer: Renderer2,
74+
@Inject(DOCUMENT) protected _document: any) {
6775
}
6876

6977
// *********************************************
@@ -133,7 +141,7 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
133141
* and optional restore it when the mediaQueries deactivate
134142
*/
135143
protected _getDisplayStyle(source: HTMLElement = this.nativeElement): string {
136-
return lookupStyle(source || this.nativeElement, 'display');
144+
return lookupStyle(this._document, source || this.nativeElement, 'display');
137145
}
138146

139147
/**
@@ -154,7 +162,7 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
154162
let value = 'row';
155163

156164
if (target) {
157-
value = lookupStyle(target, 'flex-direction') || 'row';
165+
value = lookupStyle(this._document, target, 'flex-direction') || 'row';
158166
let hasInlineValue = lookupInlineStyle(target, 'flex-direction');
159167

160168
if (!hasInlineValue && addIfMissing) {

src/lib/api/ext/class.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
Optional,
1818
Renderer2,
1919
SimpleChanges,
20-
Self, OnInit
20+
Self, OnInit, Inject
2121
} from '@angular/core';
22-
import {NgClass} from '@angular/common';
22+
import {DOCUMENT, NgClass} from '@angular/common';
2323

2424
import {BaseFxDirective} from '../core/base';
2525
import {BaseFxDirectiveAdapter} from '../core/base-adapter';
@@ -91,8 +91,9 @@ export class ClassDirective extends BaseFxDirective
9191
protected _keyValueDiffers: KeyValueDiffers,
9292
protected _ngEl: ElementRef,
9393
protected _renderer: Renderer2,
94-
@Optional() @Self() private _ngClassInstance: NgClass ) {
95-
super(monitor, _ngEl, _renderer);
94+
@Optional() @Self() private _ngClassInstance: NgClass,
95+
@Inject(DOCUMENT) protected _document: any ) {
96+
super(monitor, _ngEl, _renderer, _document);
9697
this._configureAdapters();
9798
}
9899

@@ -135,7 +136,7 @@ export class ClassDirective extends BaseFxDirective
135136
*/
136137
protected _configureAdapters() {
137138
this._base = new BaseFxDirectiveAdapter(
138-
'ngClass', this.monitor, this._ngEl, this._renderer
139+
'ngClass', this.monitor, this._ngEl, this._renderer, this._document
139140
);
140141
if (!this._ngClassInstance) {
141142
// Create an instance NgClass Directive instance only if `ngClass=""` has NOT been defined on

src/lib/api/ext/img-src.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
Input,
1212
OnInit,
1313
OnChanges,
14-
Renderer2
14+
Renderer2, Inject
1515
} from '@angular/core';
1616

1717
import {BaseFxDirective} from '../core/base';
1818
import {MediaMonitor} from '../../media-query/media-monitor';
19+
import {DOCUMENT} from '@angular/common';
1920

2021
/**
2122
* This directive provides a responsive API for the HTML <img> 'src' attribute
@@ -55,8 +56,11 @@ export class ImgSrcDirective extends BaseFxDirective implements OnInit, OnChange
5556
@Input('src.gt-lg') set srcGtLg(val) { this._cacheInput('srcGtLg', val); }
5657
/* tslint:enable */
5758

58-
constructor(elRef: ElementRef, renderer: Renderer2, monitor: MediaMonitor) {
59-
super(monitor, elRef, renderer);
59+
constructor(elRef: ElementRef,
60+
renderer: Renderer2,
61+
monitor: MediaMonitor,
62+
@Inject(DOCUMENT) document: any) {
63+
super(monitor, elRef, renderer, document);
6064
this._cacheInput('src', elRef.nativeElement.getAttribute('src') || '');
6165
}
6266

src/lib/api/ext/show-hide.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Renderer2,
1616
SimpleChanges,
1717
Self,
18-
Optional
18+
Optional, Inject
1919
} from '@angular/core';
2020

2121
import {Subscription} from 'rxjs/Subscription';
@@ -24,6 +24,7 @@ import {BaseFxDirective} from '../core/base';
2424
import {MediaChange} from '../../media-query/media-change';
2525
import {MediaMonitor} from '../../media-query/media-monitor';
2626
import {LayoutDirective} from '../flexbox/layout';
27+
import {DOCUMENT} from '@angular/common';
2728

2829
const FALSY = ['false', false, 0];
2930

@@ -104,9 +105,10 @@ export class ShowHideDirective extends BaseFxDirective implements OnInit, OnChan
104105
constructor(monitor: MediaMonitor,
105106
@Optional() @Self() protected _layout: LayoutDirective,
106107
protected elRef: ElementRef,
107-
protected renderer: Renderer2) {
108+
protected renderer: Renderer2,
109+
@Inject(DOCUMENT) _document: any) {
108110

109-
super(monitor, elRef, renderer);
111+
super(monitor, elRef, renderer, _document);
110112

111113
if (_layout) {
112114
/**

src/lib/api/ext/style.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
Renderer2,
1818
SecurityContext,
1919
Self,
20-
SimpleChanges, OnInit,
20+
SimpleChanges, OnInit, Inject,
2121
} from '@angular/core';
22-
import {NgStyle} from '@angular/common';
22+
import {DOCUMENT, NgStyle} from '@angular/common';
2323

2424
import {BaseFxDirective} from '../core/base';
2525
import {BaseFxDirectiveAdapter} from '../core/base-adapter';
@@ -89,9 +89,10 @@ export class StyleDirective extends BaseFxDirective
8989
protected _ngEl: ElementRef,
9090
protected _renderer: Renderer2,
9191
protected _differs: KeyValueDiffers,
92-
@Optional() @Self() private _ngStyleInstance: NgStyle) {
92+
@Optional() @Self() private _ngStyleInstance: NgStyle,
93+
@Inject(DOCUMENT) protected _document: any) {
9394

94-
super(monitor, _ngEl, _renderer);
95+
super(monitor, _ngEl, _renderer, _document);
9596
this._configureAdapters();
9697
}
9798

@@ -134,7 +135,7 @@ export class StyleDirective extends BaseFxDirective
134135
*/
135136
protected _configureAdapters() {
136137
this._base = new BaseFxDirectiveAdapter(
137-
'ngStyle', this.monitor, this._ngEl, this._renderer
138+
'ngStyle', this.monitor, this._ngEl, this._renderer, this._document
138139
);
139140
if ( !this._ngStyleInstance ) {
140141
// Create an instance NgClass Directive instance only if `ngClass=""` has NOT been

src/lib/api/flexbox/flex-align.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import {
1313
OnChanges,
1414
OnDestroy,
1515
Renderer2,
16-
SimpleChanges,
16+
SimpleChanges, Inject,
1717
} from '@angular/core';
1818

1919
import {BaseFxDirective} from '../core/base';
2020
import {MediaChange} from '../../media-query/media-change';
2121
import {MediaMonitor} from '../../media-query/media-monitor';
22+
import {DOCUMENT} from '@angular/common';
2223

2324
/**
2425
* 'flex-align' flexbox styling directive
@@ -54,8 +55,11 @@ export class FlexAlignDirective extends BaseFxDirective implements OnInit, OnCha
5455
@Input('fxFlexAlign.gt-lg') set alignGtLg(val) { this._cacheInput('alignGtLg', val); };
5556

5657
/* tslint:enable */
57-
constructor(monitor: MediaMonitor, elRef: ElementRef, renderer: Renderer2) {
58-
super(monitor, elRef, renderer);
58+
constructor(monitor: MediaMonitor,
59+
elRef: ElementRef,
60+
renderer: Renderer2,
61+
@Inject(DOCUMENT) document: any) {
62+
super(monitor, elRef, renderer, document);
5963
}
6064

6165

src/lib/api/flexbox/flex-fill.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
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-
import {Directive, ElementRef, Renderer2} from '@angular/core';
8+
import {Directive, ElementRef, Inject, Renderer2} from '@angular/core';
99

1010
import {MediaMonitor} from '../../media-query/media-monitor';
1111
import {BaseFxDirective} from '../core/base';
12+
import {DOCUMENT} from '@angular/common';
1213

1314
const FLEX_FILL_CSS = {
1415
'margin': 0,
@@ -29,8 +30,11 @@ const FLEX_FILL_CSS = {
2930
[fxFlexFill]
3031
`})
3132
export class FlexFillDirective extends BaseFxDirective {
32-
constructor(monitor: MediaMonitor, public elRef: ElementRef, public renderer: Renderer2) {
33-
super(monitor, elRef, renderer);
33+
constructor(monitor: MediaMonitor,
34+
public elRef: ElementRef,
35+
public renderer: Renderer2,
36+
@Inject(DOCUMENT) document: any) {
37+
super(monitor, elRef, renderer, document);
3438
this._applyStyleToElement(FLEX_FILL_CSS);
3539
}
3640
}

src/lib/api/flexbox/flex-offset.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Optional,
1616
Renderer2,
1717
SimpleChanges,
18-
SkipSelf
18+
SkipSelf, Inject
1919
} from '@angular/core';
2020

2121
import {Subscription} from 'rxjs/Subscription';
@@ -25,6 +25,7 @@ import {MediaChange} from '../../media-query/media-change';
2525
import {MediaMonitor} from '../../media-query/media-monitor';
2626
import {LayoutDirective} from './layout';
2727
import {isFlowHorizontal} from '../../utils/layout-validator';
28+
import {DOCUMENT} from '@angular/common';
2829

2930
/**
3031
* 'flex-offset' flexbox styling directive
@@ -60,8 +61,9 @@ export class FlexOffsetDirective extends BaseFxDirective implements OnInit, OnCh
6061
constructor(monitor: MediaMonitor,
6162
elRef: ElementRef,
6263
renderer: Renderer2,
63-
@Optional() @SkipSelf() protected _container: LayoutDirective ) {
64-
super(monitor, elRef, renderer);
64+
@Optional() @SkipSelf() protected _container: LayoutDirective,
65+
@Inject(DOCUMENT) document: any) {
66+
super(monitor, elRef, renderer, document);
6567

6668

6769
this.watchParentFlow();

src/lib/api/flexbox/flex-order.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import {
1313
OnChanges,
1414
OnDestroy,
1515
Renderer2,
16-
SimpleChanges,
16+
SimpleChanges, Inject,
1717
} from '@angular/core';
1818

1919
import {BaseFxDirective} from '../core/base';
2020
import {MediaChange} from '../../media-query/media-change';
2121
import {MediaMonitor} from '../../media-query/media-monitor';
22+
import {DOCUMENT} from '@angular/common';
2223

2324
/**
2425
* 'flex-order' flexbox styling directive
@@ -52,8 +53,11 @@ export class FlexOrderDirective extends BaseFxDirective implements OnInit, OnCha
5253
@Input('fxFlexOrder.lt-xl') set orderLtXl(val) { this._cacheInput('orderLtXl', val); };
5354

5455
/* tslint:enable */
55-
constructor(monitor: MediaMonitor, elRef: ElementRef, renderer: Renderer2) {
56-
super(monitor, elRef, renderer);
56+
constructor(monitor: MediaMonitor,
57+
elRef: ElementRef,
58+
renderer: Renderer2,
59+
@Inject(DOCUMENT) document: any) {
60+
super(monitor, elRef, renderer, document);
5761
}
5862

5963
// *********************************************

src/lib/api/flexbox/flex.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import {
99
Directive,
10-
ElementRef,
10+
ElementRef, Inject,
1111
Input,
1212
OnChanges,
1313
OnDestroy,
@@ -28,6 +28,7 @@ import {LayoutDirective} from './layout';
2828
import {LayoutWrapDirective} from './layout-wrap';
2929
import {validateBasis} from '../../utils/basis-validator';
3030
import {isFlowHorizontal} from '../../utils/layout-validator';
31+
import {DOCUMENT} from '@angular/common';
3132

3233

3334
/** Built-in aliases for different flex-basis values. */
@@ -86,9 +87,10 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
8687
elRef: ElementRef,
8788
renderer: Renderer2,
8889
@Optional() @SkipSelf() protected _container: LayoutDirective,
89-
@Optional() @SkipSelf() protected _wrap: LayoutWrapDirective) {
90+
@Optional() @SkipSelf() protected _wrap: LayoutWrapDirective,
91+
@Inject(DOCUMENT) _document: any) {
9092

91-
super(monitor, elRef, renderer);
93+
super(monitor, elRef, renderer, _document);
9294

9395
this._cacheInput('flex', '');
9496
this._cacheInput('shrink', 1);

src/lib/api/flexbox/layout-align.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
OnInit,
1515
Optional,
1616
Renderer2,
17-
SimpleChanges, Self,
17+
SimpleChanges, Self, Inject,
1818
} from '@angular/core';
1919
import {Subscription} from 'rxjs/Subscription';
2020
import {extendObject} from '../../utils/object-extend';
@@ -25,6 +25,7 @@ import {MediaMonitor} from '../../media-query/media-monitor';
2525

2626
import {LayoutDirective} from './layout';
2727
import {LAYOUT_VALUES, isFlowHorizontal} from '../../utils/layout-validator';
28+
import {DOCUMENT} from '@angular/common';
2829

2930
/**
3031
* 'layout-align' flexbox styling directive
@@ -68,8 +69,9 @@ export class LayoutAlignDirective extends BaseFxDirective implements OnInit, OnC
6869
constructor(
6970
monitor: MediaMonitor,
7071
elRef: ElementRef, renderer: Renderer2,
71-
@Optional() @Self() container: LayoutDirective) {
72-
super(monitor, elRef, renderer);
72+
@Optional() @Self() container: LayoutDirective,
73+
@Inject(DOCUMENT) document: any) {
74+
super(monitor, elRef, renderer, document);
7375

7476
if (container) { // Subscribe to layout direction changes
7577
this._layoutWatcher = container.layout$.subscribe(this._onLayoutChange.bind(this));

0 commit comments

Comments
 (0)