@@ -43,68 +43,70 @@ export class Draggable implements OnInit, OnDestroy {
43
43
44
44
ngOnInit ( ) : void {
45
45
46
- const mouseDrag : Observable < any > = this . mouseDown . flatMap ( ( mouseDownEvent : MouseEvent ) => {
46
+ const mouseDrag : Observable < any > = this . mouseDown
47
+ . filter ( ( ) => this . canDrag ( ) )
48
+ . flatMap ( ( mouseDownEvent : MouseEvent ) => {
47
49
48
- this . dragStart . next ( { x : 0 , y : 0 } ) ;
50
+ this . dragStart . next ( { x : 0 , y : 0 } ) ;
49
51
50
- if ( this . ghostDragEnabled ) {
51
- this . renderer . setElementStyle ( this . element . nativeElement , 'pointerEvents' , 'none' ) ;
52
- }
52
+ if ( this . ghostDragEnabled ) {
53
+ this . renderer . setElementStyle ( this . element . nativeElement , 'pointerEvents' , 'none' ) ;
54
+ }
53
55
54
- const currentDrag : Subject < any > = new Subject ( ) ;
56
+ const currentDrag : Subject < any > = new Subject ( ) ;
55
57
56
- this . draggableHelper . currentDrag . next ( currentDrag ) ;
58
+ this . draggableHelper . currentDrag . next ( currentDrag ) ;
57
59
58
- const mouseMove : Observable < Coordinates > = this . mouseMove
59
- . map ( ( mouseMoveEvent : MouseEvent ) => {
60
+ const mouseMove : Observable < Coordinates > = this . mouseMove
61
+ . map ( ( mouseMoveEvent : MouseEvent ) => {
60
62
61
- mouseMoveEvent . preventDefault ( ) ;
63
+ mouseMoveEvent . preventDefault ( ) ;
62
64
63
- return {
64
- currentDrag,
65
- x : mouseMoveEvent . clientX - mouseDownEvent . clientX ,
66
- y : mouseMoveEvent . clientY - mouseDownEvent . clientY
67
- } ;
65
+ return {
66
+ currentDrag,
67
+ x : mouseMoveEvent . clientX - mouseDownEvent . clientX ,
68
+ y : mouseMoveEvent . clientY - mouseDownEvent . clientY
69
+ } ;
68
70
69
- } )
70
- . map ( ( moveData : Coordinates ) => {
71
+ } )
72
+ . map ( ( moveData : Coordinates ) => {
71
73
72
- if ( this . dragSnapGrid . x ) {
73
- moveData . x = Math . floor ( moveData . x / this . dragSnapGrid . x ) * this . dragSnapGrid . x ;
74
- }
74
+ if ( this . dragSnapGrid . x ) {
75
+ moveData . x = Math . floor ( moveData . x / this . dragSnapGrid . x ) * this . dragSnapGrid . x ;
76
+ }
75
77
76
- if ( this . dragSnapGrid . y ) {
77
- moveData . y = Math . floor ( moveData . y / this . dragSnapGrid . y ) * this . dragSnapGrid . y ;
78
- }
78
+ if ( this . dragSnapGrid . y ) {
79
+ moveData . y = Math . floor ( moveData . y / this . dragSnapGrid . y ) * this . dragSnapGrid . y ;
80
+ }
79
81
80
- return moveData ;
81
- } )
82
- . map ( ( moveData : Coordinates ) => {
82
+ return moveData ;
83
+ } )
84
+ . map ( ( moveData : Coordinates ) => {
83
85
84
- if ( ! this . dragAxis . x ) {
85
- moveData . x = 0 ;
86
- }
86
+ if ( ! this . dragAxis . x ) {
87
+ moveData . x = 0 ;
88
+ }
87
89
88
- if ( ! this . dragAxis . y ) {
89
- moveData . y = 0 ;
90
- }
90
+ if ( ! this . dragAxis . y ) {
91
+ moveData . y = 0 ;
92
+ }
91
93
92
- return moveData ;
93
- } )
94
- . takeUntil ( Observable . merge ( this . mouseUp , this . mouseDown ) ) ;
94
+ return moveData ;
95
+ } )
96
+ . takeUntil ( Observable . merge ( this . mouseUp , this . mouseDown ) ) ;
95
97
96
- mouseMove . takeLast ( 1 ) . subscribe ( ( { x, y} ) => {
97
- this . dragEnd . next ( { x, y} ) ;
98
- currentDrag . complete ( ) ;
99
- this . setCssTransform ( '' ) ;
100
- if ( this . ghostDragEnabled ) {
101
- this . renderer . setElementStyle ( this . element . nativeElement , 'pointerEvents' , 'auto' ) ;
102
- }
103
- } ) ;
98
+ mouseMove . takeLast ( 1 ) . subscribe ( ( { x, y} ) => {
99
+ this . dragEnd . next ( { x, y} ) ;
100
+ currentDrag . complete ( ) ;
101
+ this . setCssTransform ( '' ) ;
102
+ if ( this . ghostDragEnabled ) {
103
+ this . renderer . setElementStyle ( this . element . nativeElement , 'pointerEvents' , 'auto' ) ;
104
+ }
105
+ } ) ;
104
106
105
- return mouseMove ;
107
+ return mouseMove ;
106
108
107
- } ) ;
109
+ } ) ;
108
110
109
111
mouseDrag . subscribe ( ( { x, y, currentDrag} ) => {
110
112
this . dragging . next ( { x, y} ) ;
@@ -154,4 +156,8 @@ export class Draggable implements OnInit, OnDestroy {
154
156
}
155
157
}
156
158
159
+ private canDrag ( ) : boolean {
160
+ return this . dragAxis . x || this . dragAxis . y ;
161
+ }
162
+
157
163
}
0 commit comments