1- import { Directive , ElementRef , Inject , Input , OnDestroy , OnInit , Renderer2 } from '@angular/core' ;
2- import { NodeDraggableService } from './node-draggable.service' ;
3- import { CapturedNode } from './captured-node' ;
4- import { Tree } from '../tree' ;
1+ import { Directive , ElementRef , Inject , Input , OnDestroy , OnInit , Renderer2 } from '@angular/core' ;
2+ import { NodeDraggableService } from './node-draggable.service' ;
3+ import { CapturedNode } from './captured-node' ;
4+ import { Tree } from '../tree' ;
55
66@Directive ( {
77 selector : '[nodeDraggable]'
88} )
99export class NodeDraggableDirective implements OnDestroy , OnInit {
1010 public static DATA_TRANSFER_STUB_DATA = 'some browsers enable drag-n-drop only when dataTransfer has data' ;
1111
12- @Input ( )
13- public nodeDraggable : ElementRef ;
12+ @Input ( ) public nodeDraggable : ElementRef ;
1413
15- @Input ( )
16- public tree : Tree ;
14+ @Input ( ) public tree : Tree ;
1715
1816 private nodeNativeElement : HTMLElement ;
1917 private disposersForDragListeners : Function [ ] = [ ] ;
2018
21- public constructor ( @Inject ( ElementRef ) public element : ElementRef ,
22- @Inject ( NodeDraggableService ) private nodeDraggableService : NodeDraggableService ,
23- @Inject ( Renderer2 ) private renderer : Renderer2 ) {
19+ public constructor (
20+ @Inject ( ElementRef ) public element : ElementRef ,
21+ @Inject ( NodeDraggableService ) private nodeDraggableService : NodeDraggableService ,
22+ @Inject ( Renderer2 ) private renderer : Renderer2
23+ ) {
2424 this . nodeNativeElement = element . nativeElement ;
2525 }
2626
2727 public ngOnInit ( ) : void {
2828 if ( ! this . tree . isStatic ( ) ) {
2929 this . renderer . setAttribute ( this . nodeNativeElement , 'draggable' , 'true' ) ;
30- this . disposersForDragListeners . push ( this . renderer . listen ( this . nodeNativeElement , 'dragenter' , this . handleDragEnter . bind ( this ) ) ) ;
31- this . disposersForDragListeners . push ( this . renderer . listen ( this . nodeNativeElement , 'dragover' , this . handleDragOver . bind ( this ) ) ) ;
32- this . disposersForDragListeners . push ( this . renderer . listen ( this . nodeNativeElement , 'dragstart' , this . handleDragStart . bind ( this ) ) ) ;
33- this . disposersForDragListeners . push ( this . renderer . listen ( this . nodeNativeElement , 'dragleave' , this . handleDragLeave . bind ( this ) ) ) ;
34- this . disposersForDragListeners . push ( this . renderer . listen ( this . nodeNativeElement , 'drop' , this . handleDrop . bind ( this ) ) ) ;
35- this . disposersForDragListeners . push ( this . renderer . listen ( this . nodeNativeElement , 'dragend' , this . handleDragEnd . bind ( this ) ) ) ;
30+ this . disposersForDragListeners . push (
31+ this . renderer . listen ( this . nodeNativeElement , 'dragenter' , this . handleDragEnter . bind ( this ) )
32+ ) ;
33+ this . disposersForDragListeners . push (
34+ this . renderer . listen ( this . nodeNativeElement , 'dragover' , this . handleDragOver . bind ( this ) )
35+ ) ;
36+ this . disposersForDragListeners . push (
37+ this . renderer . listen ( this . nodeNativeElement , 'dragstart' , this . handleDragStart . bind ( this ) )
38+ ) ;
39+ this . disposersForDragListeners . push (
40+ this . renderer . listen ( this . nodeNativeElement , 'dragleave' , this . handleDragLeave . bind ( this ) )
41+ ) ;
42+ this . disposersForDragListeners . push (
43+ this . renderer . listen ( this . nodeNativeElement , 'drop' , this . handleDrop . bind ( this ) )
44+ ) ;
45+ this . disposersForDragListeners . push (
46+ this . renderer . listen ( this . nodeNativeElement , 'dragend' , this . handleDragEnd . bind ( this ) )
47+ ) ;
3648 }
3749 }
3850
@@ -90,9 +102,7 @@ export class NodeDraggableDirective implements OnDestroy, OnInit {
90102
91103 private isDropPossible ( e : DragEvent ) : boolean {
92104 const capturedNode = this . nodeDraggableService . getCapturedNode ( ) ;
93- return capturedNode
94- && capturedNode . canBeDroppedAt ( this . nodeDraggable )
95- && this . containsElementAt ( e ) ;
105+ return capturedNode && capturedNode . canBeDroppedAt ( this . nodeDraggable ) && this . containsElementAt ( e ) ;
96106 }
97107
98108 private handleDragEnd ( e : DragEvent ) : any {
@@ -101,7 +111,7 @@ export class NodeDraggableDirective implements OnDestroy, OnInit {
101111 }
102112
103113 private containsElementAt ( e : DragEvent ) : boolean {
104- const { x = e . clientX , y = e . clientY } = e ;
114+ const { x = e . clientX , y = e . clientY } = e ;
105115 return this . nodeNativeElement . contains ( document . elementFromPoint ( x , y ) ) ;
106116 }
107117
0 commit comments