@@ -12,8 +12,8 @@ import {
1212 SimpleChanges
1313} from '@angular/core' ;
1414
15- import { Subject } from 'rxjs' ;
16- import { takeUntil } from 'rxjs/operators' ;
15+ import { fromEvent , Observable , Subject } from 'rxjs' ;
16+ import { takeUntil , takeWhile , throttleTime } from 'rxjs/operators' ;
1717import { NgsgSortService } from './sort/sort/ngsg-sort.service' ;
1818import { NgsgSelectionService } from './mutliselect/ngsg-selection.service' ;
1919import { NgsgReflectService } from './sort/reflection/ngsg-reflect.service' ;
@@ -36,6 +36,7 @@ export class NgsgItemDirective implements OnInit, OnChanges, AfterViewInit, OnDe
3636
3737 private selected = false ;
3838 private destroy$ = new Subject ( ) ;
39+ private drag$ : Observable < Event > ;
3940
4041 constructor (
4142 public el : ElementRef ,
@@ -52,6 +53,18 @@ export class NgsgItemDirective implements OnInit, OnChanges, AfterViewInit, OnDe
5253 this . ngsgEventService . dropped$ . pipe (
5354 takeUntil ( this . destroy$ )
5455 ) . subscribe ( ( ) => this . selected = false ) ;
56+
57+ fromEvent < DragEvent > ( this . el . nativeElement , 'drag' ) . pipe (
58+ throttleTime ( 20 ) ,
59+ takeUntil ( this . destroy$ ) ,
60+ takeWhile ( ( ) => this . autoScroll )
61+ ) . subscribe ( ( ) => {
62+ this . scrollHelperService . scrollIfNecessary ( event , {
63+ top : this . scrollPointTop ,
64+ bottom : this . scrollPointBottom
65+ } , this . scrollSpeed ) ;
66+ }
67+ ) ;
5568 }
5669
5770 ngOnChanges ( changes : SimpleChanges ) : void {
@@ -91,16 +104,6 @@ export class NgsgItemDirective implements OnInit, OnChanges, AfterViewInit, OnDe
91104 this . sortService . sort ( this . el . nativeElement ) ;
92105 }
93106
94- @HostListener ( 'drag' , [ '$event' ] )
95- drag ( event ) : void {
96- if ( this . autoScroll ) {
97- this . scrollHelperService . scrollIfNecessary ( event , {
98- top : this . scrollPointTop ,
99- bottom : this . scrollPointBottom
100- } , this . scrollSpeed ) ;
101- }
102- }
103-
104107 @HostListener ( 'dragover' , [ '$event' ] )
105108 dragOver ( event ) : boolean {
106109 if ( event . preventDefault ) {
0 commit comments