6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
10
- import { DOCUMENT } from '@angular/common' ;
11
9
import {
12
- ApplicationRef ,
13
10
ChangeDetectionStrategy ,
14
11
Component ,
15
- EnvironmentInjector ,
16
12
Inject ,
17
13
Injectable ,
18
14
NgZone ,
19
15
OnDestroy ,
20
16
ViewEncapsulation ,
21
17
WritableSignal ,
22
- createComponent ,
23
18
inject ,
24
19
signal ,
25
20
} from '@angular/core' ;
21
+ import { DOCUMENT } from '@angular/common' ;
22
+ import { normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
23
+ import { _CdkPrivateStyleLoader } from '@angular/cdk/private' ;
26
24
import { Observable , Observer , Subject , merge } from 'rxjs' ;
27
25
import type { DropListRef } from './drop-list-ref' ;
28
26
import type { DragRef } from './drag-ref' ;
@@ -33,9 +31,6 @@ const activeCapturingEventOptions = normalizePassiveListenerOptions({
33
31
capture : true ,
34
32
} ) ;
35
33
36
- /** Keeps track of the apps currently containing drag items. */
37
- const activeApps = new Set < ApplicationRef > ( ) ;
38
-
39
34
/**
40
35
* Component used to load the drag&drop reset styles.
41
36
* @docs -private
@@ -59,8 +54,7 @@ export class _ResetsLoader {}
59
54
@Injectable ( { providedIn : 'root' } )
60
55
export class DragDropRegistry < _ = unknown , __ = unknown > implements OnDestroy {
61
56
private _document : Document ;
62
- private _appRef = inject ( ApplicationRef ) ;
63
- private _environmentInjector = inject ( EnvironmentInjector ) ;
57
+ private _styleLoader = inject ( _CdkPrivateStyleLoader ) ;
64
58
65
59
/** Registered drop container instances. */
66
60
private _dropInstances = new Set < DropListRef > ( ) ;
@@ -169,7 +163,7 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy {
169
163
return ;
170
164
}
171
165
172
- this . _loadResets ( ) ;
166
+ this . _styleLoader . load ( _ResetsLoader ) ;
173
167
this . _activeDragInstances . update ( instances => [ ...instances , drag ] ) ;
174
168
175
169
if ( this . _activeDragInstances ( ) . length === 1 ) {
@@ -313,23 +307,4 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy {
313
307
314
308
this . _globalListeners . clear ( ) ;
315
309
}
316
-
317
- // TODO(crisbeto): abstract this away into something reusable.
318
- /** Loads the CSS resets needed for the module to work correctly. */
319
- private _loadResets ( ) {
320
- if ( ! activeApps . has ( this . _appRef ) ) {
321
- activeApps . add ( this . _appRef ) ;
322
-
323
- const componentRef = createComponent ( _ResetsLoader , {
324
- environmentInjector : this . _environmentInjector ,
325
- } ) ;
326
-
327
- this . _appRef . onDestroy ( ( ) => {
328
- activeApps . delete ( this . _appRef ) ;
329
- if ( activeApps . size === 0 ) {
330
- componentRef . destroy ( ) ;
331
- }
332
- } ) ;
333
- }
334
- }
335
310
}
0 commit comments