@@ -332,7 +332,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
332
332
rootElement . addEventListener ( 'mousedown' , this . _pointerDown , activeEventListenerOptions ) ;
333
333
rootElement . addEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
334
334
this . _handles . changes . pipe ( startWith ( null ) ) . subscribe ( ( ) =>
335
- toggleNativeDragInteractions ( rootElement , this . getChildHandles ( ) . length > 0 ) ) ;
335
+ toggleNativeDragInteractions ( rootElement , this . _getChildHandles ( ) . length > 0 ) ) ;
336
336
} ) ;
337
337
}
338
338
@@ -349,7 +349,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
349
349
if ( this . _isDragging ( ) ) {
350
350
// Since we move out the element to the end of the body while it's being
351
351
// dragged, we have to make sure that it's removed if it gets destroyed.
352
- this . _removeElement ( this . _rootElement ) ;
352
+ removeElement ( this . _rootElement ) ;
353
353
}
354
354
}
355
355
@@ -368,13 +368,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
368
368
}
369
369
370
370
/** Gets only handles that are not inside descendant `CdkDrag` instances. */
371
- private getChildHandles ( ) {
371
+ protected _getChildHandles ( ) {
372
372
return this . _handles . filter ( handle => handle . _parentDrag === this ) ;
373
373
}
374
374
375
375
/** Handler for the `mousedown`/`touchstart` events. */
376
376
_pointerDown = ( event : MouseEvent | TouchEvent ) => {
377
- const handles = this . getChildHandles ( ) ;
377
+ const handles = this . _getChildHandles ( ) ;
378
378
379
379
// Delegate the event based on whether it started from a handle or the element itself.
380
380
if ( handles . length ) {
@@ -398,16 +398,16 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
398
398
* @param referenceElement Element that started the drag sequence.
399
399
* @param event Browser event object that started the sequence.
400
400
*/
401
- private _initializeDragSequence ( referenceElement : HTMLElement , event : MouseEvent | TouchEvent ) {
401
+ protected _initializeDragSequence ( referenceElement : HTMLElement , event : MouseEvent | TouchEvent ) {
402
402
// Always stop propagation for the event that initializes
403
403
// the dragging sequence, in order to prevent it from potentially
404
404
// starting another sequence for a draggable parent somewhere up the DOM tree.
405
405
event . stopPropagation ( ) ;
406
406
407
407
const isDragging = this . _isDragging ( ) ;
408
- const isTouchEvent = this . _isTouchEvent ( event ) ;
409
- const isAuxiliaryMouseButton = ! isTouchEvent && ( event as MouseEvent ) . button !== 0 ;
410
- const isSyntheticEvent = ! isTouchEvent && this . _lastTouchEventTime &&
408
+ const wasTouchEvent = isTouchEvent ( event ) ;
409
+ const isAuxiliaryMouseButton = ! wasTouchEvent && ( event as MouseEvent ) . button !== 0 ;
410
+ const isSyntheticEvent = ! wasTouchEvent && this . _lastTouchEventTime &&
411
411
this . _lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date . now ( ) ;
412
412
413
413
// If the event started from an element with the native HTML drag&drop, it'll interfere
@@ -453,11 +453,11 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
453
453
}
454
454
455
455
/** Starts the dragging sequence. */
456
- private _startDragSequence ( event : MouseEvent | TouchEvent ) {
456
+ protected _startDragSequence ( event : MouseEvent | TouchEvent ) {
457
457
// Emit the event on the item before the one on the container.
458
458
this . started . emit ( { source : this } ) ;
459
459
460
- if ( this . _isTouchEvent ( event ) ) {
460
+ if ( isTouchEvent ( event ) ) {
461
461
this . _lastTouchEventTime = Date . now ( ) ;
462
462
}
463
463
@@ -482,7 +482,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
482
482
}
483
483
484
484
/** Handler that is invoked when the user moves their pointer after they've initiated a drag. */
485
- private _pointerMove = ( event : MouseEvent | TouchEvent ) => {
485
+ protected _pointerMove = ( event : MouseEvent | TouchEvent ) => {
486
486
if ( ! this . _hasStartedDragging ) {
487
487
const pointerPosition = this . _getPointerPositionOnPage ( event ) ;
488
488
const distanceX = Math . abs ( pointerPosition . x - this . _pickupPositionOnPage . x ) ;
@@ -551,7 +551,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
551
551
}
552
552
553
553
/** Handler that is invoked when the user lifts their pointer up, after initiating a drag. */
554
- private _pointerUp = ( event : MouseEvent | TouchEvent ) => {
554
+ protected _pointerUp = ( event : MouseEvent | TouchEvent ) => {
555
555
if ( ! this . _isDragging ( ) ) {
556
556
return ;
557
557
}
@@ -721,7 +721,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
721
721
const elementRect = this . _rootElement . getBoundingClientRect ( ) ;
722
722
const handleElement = referenceElement === this . _rootElement ? null : referenceElement ;
723
723
const referenceRect = handleElement ? handleElement . getBoundingClientRect ( ) : elementRect ;
724
- const point = this . _isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
724
+ const point = isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
725
725
const x = point . pageX - referenceRect . left - this . _scrollPosition . left ;
726
726
const y = point . pageY - referenceRect . top - this . _scrollPosition . top ;
727
727
@@ -778,20 +778,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
778
778
} ) ;
779
779
}
780
780
781
- /**
782
- * Helper to remove an element from the DOM and to do all the necessary null checks.
783
- * @param element Element to be removed.
784
- */
785
- private _removeElement ( element : HTMLElement | null ) {
786
- if ( element && element . parentNode ) {
787
- element . parentNode . removeChild ( element ) ;
788
- }
789
- }
790
-
791
781
/** Determines the point of the page that was touched by the user. */
792
782
private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
793
783
// `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
794
- const point = this . _isTouchEvent ( event ) ? ( event . touches [ 0 ] || event . changedTouches [ 0 ] ) : event ;
784
+ const point = isTouchEvent ( event ) ? ( event . touches [ 0 ] || event . changedTouches [ 0 ] ) : event ;
795
785
796
786
return {
797
787
x : point . pageX - this . _scrollPosition . left ,
@@ -826,15 +816,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
826
816
return point ;
827
817
}
828
818
829
- /** Determines whether an event is a touch event. */
830
- private _isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
831
- return event . type . startsWith ( 'touch' ) ;
832
- }
833
-
834
819
/** Destroys the preview element and its ViewRef. */
835
820
private _destroyPreview ( ) {
836
821
if ( this . _preview ) {
837
- this . _removeElement ( this . _preview ) ;
822
+ removeElement ( this . _preview ) ;
838
823
}
839
824
840
825
if ( this . _previewRef ) {
@@ -847,7 +832,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
847
832
/** Destroys the placeholder element and its ViewRef. */
848
833
private _destroyPlaceholder ( ) {
849
834
if ( this . _placeholder ) {
850
- this . _removeElement ( this . _placeholder ) ;
835
+ removeElement ( this . _placeholder ) ;
851
836
}
852
837
853
838
if ( this . _placeholderRef ) {
@@ -885,7 +870,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
885
870
}
886
871
887
872
/** Gets the root draggable element, based on the `rootElementSelector`. */
888
- private _getRootElement ( ) : HTMLElement {
873
+ protected _getRootElement ( ) : HTMLElement {
889
874
const element = this . element . nativeElement ;
890
875
const rootElement = this . rootElementSelector ?
891
876
getClosestMatchingAncestor ( element , this . rootElementSelector ) : null ;
@@ -950,3 +935,18 @@ function getClosestMatchingAncestor(element: HTMLElement, selector: string) {
950
935
currentElement = currentElement . parentElement ;
951
936
}
952
937
}
938
+
939
+ /**
940
+ * Helper to remove an element from the DOM and to do all the necessary null checks.
941
+ * @param element Element to be removed.
942
+ */
943
+ function removeElement ( element : HTMLElement | null ) {
944
+ if ( element && element . parentNode ) {
945
+ element . parentNode . removeChild ( element ) ;
946
+ }
947
+ }
948
+
949
+ /** Determines whether an event is a touch event. */
950
+ function isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
951
+ return event . type . startsWith ( 'touch' ) ;
952
+ }
0 commit comments