@@ -310,7 +310,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
310
310
rootElement . addEventListener ( 'mousedown' , this . _pointerDown , activeEventListenerOptions ) ;
311
311
rootElement . addEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
312
312
this . _handles . changes . pipe ( startWith ( null ) ) . subscribe ( ( ) =>
313
- toggleNativeDragInteractions ( rootElement , this . getChildHandles ( ) . length > 0 ) ) ;
313
+ toggleNativeDragInteractions ( rootElement , this . _getChildHandles ( ) . length > 0 ) ) ;
314
314
} ) ;
315
315
}
316
316
@@ -327,7 +327,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
327
327
if ( this . _isDragging ( ) ) {
328
328
// Since we move out the element to the end of the body while it's being
329
329
// dragged, we have to make sure that it's removed if it gets destroyed.
330
- this . _removeElement ( this . _rootElement ) ;
330
+ removeElement ( this . _rootElement ) ;
331
331
}
332
332
}
333
333
@@ -346,13 +346,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
346
346
}
347
347
348
348
/** Gets only handles that are not inside descendant `CdkDrag` instances. */
349
- private getChildHandles ( ) {
349
+ protected _getChildHandles ( ) {
350
350
return this . _handles . filter ( handle => handle . _parentDrag === this ) ;
351
351
}
352
352
353
353
/** Handler for the `mousedown`/`touchstart` events. */
354
354
_pointerDown = ( event : MouseEvent | TouchEvent ) => {
355
- const handles = this . getChildHandles ( ) ;
355
+ const handles = this . _getChildHandles ( ) ;
356
356
357
357
// Delegate the event based on whether it started from a handle or the element itself.
358
358
if ( handles . length ) {
@@ -376,16 +376,16 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
376
376
* @param referenceElement Element that started the drag sequence.
377
377
* @param event Browser event object that started the sequence.
378
378
*/
379
- private _initializeDragSequence ( referenceElement : HTMLElement , event : MouseEvent | TouchEvent ) {
379
+ protected _initializeDragSequence ( referenceElement : HTMLElement , event : MouseEvent | TouchEvent ) {
380
380
// Always stop propagation for the event that initializes
381
381
// the dragging sequence, in order to prevent it from potentially
382
382
// starting another sequence for a draggable parent somewhere up the DOM tree.
383
383
event . stopPropagation ( ) ;
384
384
385
385
const isDragging = this . _isDragging ( ) ;
386
- const isTouchEvent = this . _isTouchEvent ( event ) ;
387
- const isAuxiliaryMouseButton = ! isTouchEvent && ( event as MouseEvent ) . button !== 0 ;
388
- const isSyntheticEvent = ! isTouchEvent && this . _lastTouchEventTime &&
386
+ const wasTouchEvent = isTouchEvent ( event ) ;
387
+ const isAuxiliaryMouseButton = ! wasTouchEvent && ( event as MouseEvent ) . button !== 0 ;
388
+ const isSyntheticEvent = ! wasTouchEvent && this . _lastTouchEventTime &&
389
389
this . _lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date . now ( ) ;
390
390
391
391
// If the event started from an element with the native HTML drag&drop, it'll interfere
@@ -426,11 +426,11 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
426
426
}
427
427
428
428
/** Starts the dragging sequence. */
429
- private _startDragSequence ( event : MouseEvent | TouchEvent ) {
429
+ protected _startDragSequence ( event : MouseEvent | TouchEvent ) {
430
430
// Emit the event on the item before the one on the container.
431
431
this . started . emit ( { source : this } ) ;
432
432
433
- if ( this . _isTouchEvent ( event ) ) {
433
+ if ( isTouchEvent ( event ) ) {
434
434
this . _lastTouchEventTime = Date . now ( ) ;
435
435
}
436
436
@@ -455,7 +455,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
455
455
}
456
456
457
457
/** Handler that is invoked when the user moves their pointer after they've initiated a drag. */
458
- private _pointerMove = ( event : MouseEvent | TouchEvent ) => {
458
+ protected _pointerMove = ( event : MouseEvent | TouchEvent ) => {
459
459
const pointerPosition = this . _getConstrainedPointerPosition ( event ) ;
460
460
461
461
if ( ! this . _hasStartedDragging ) {
@@ -515,7 +515,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
515
515
}
516
516
517
517
/** Handler that is invoked when the user lifts their pointer up, after initiating a drag. */
518
- private _pointerUp = ( event : MouseEvent | TouchEvent ) => {
518
+ protected _pointerUp = ( event : MouseEvent | TouchEvent ) => {
519
519
if ( ! this . _isDragging ( ) ) {
520
520
return ;
521
521
}
@@ -681,7 +681,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
681
681
const elementRect = this . _rootElement . getBoundingClientRect ( ) ;
682
682
const handleElement = referenceElement === this . _rootElement ? null : referenceElement ;
683
683
const referenceRect = handleElement ? handleElement . getBoundingClientRect ( ) : elementRect ;
684
- const point = this . _isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
684
+ const point = isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
685
685
const x = point . pageX - referenceRect . left - this . _scrollPosition . left ;
686
686
const y = point . pageY - referenceRect . top - this . _scrollPosition . top ;
687
687
@@ -738,19 +738,9 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
738
738
} ) ;
739
739
}
740
740
741
- /**
742
- * Helper to remove an element from the DOM and to do all the necessary null checks.
743
- * @param element Element to be removed.
744
- */
745
- private _removeElement ( element : HTMLElement | null ) {
746
- if ( element && element . parentNode ) {
747
- element . parentNode . removeChild ( element ) ;
748
- }
749
- }
750
-
751
741
/** Determines the point of the page that was touched by the user. */
752
742
private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
753
- const point = this . _isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
743
+ const point = isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
754
744
755
745
return {
756
746
x : point . pageX - this . _scrollPosition . left ,
@@ -772,15 +762,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
772
762
return point ;
773
763
}
774
764
775
- /** Determines whether an event is a touch event. */
776
- private _isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
777
- return event . type . startsWith ( 'touch' ) ;
778
- }
779
-
780
765
/** Destroys the preview element and its ViewRef. */
781
766
private _destroyPreview ( ) {
782
767
if ( this . _preview ) {
783
- this . _removeElement ( this . _preview ) ;
768
+ removeElement ( this . _preview ) ;
784
769
}
785
770
786
771
if ( this . _previewRef ) {
@@ -793,7 +778,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
793
778
/** Destroys the placeholder element and its ViewRef. */
794
779
private _destroyPlaceholder ( ) {
795
780
if ( this . _placeholder ) {
796
- this . _removeElement ( this . _placeholder ) ;
781
+ removeElement ( this . _placeholder ) ;
797
782
}
798
783
799
784
if ( this . _placeholderRef ) {
@@ -831,7 +816,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
831
816
}
832
817
833
818
/** Gets the root draggable element, based on the `rootElementSelector`. */
834
- private _getRootElement ( ) : HTMLElement {
819
+ protected _getRootElement ( ) : HTMLElement {
835
820
if ( this . rootElementSelector ) {
836
821
const selector = this . rootElementSelector ;
837
822
let currentElement = this . element . nativeElement . parentElement as HTMLElement | null ;
@@ -881,3 +866,18 @@ function deepCloneNode(node: HTMLElement): HTMLElement {
881
866
clone . removeAttribute ( 'id' ) ;
882
867
return clone ;
883
868
}
869
+
870
+ /**
871
+ * Helper to remove an element from the DOM and to do all the necessary null checks.
872
+ * @param element Element to be removed.
873
+ */
874
+ function removeElement ( element : HTMLElement | null ) {
875
+ if ( element && element . parentNode ) {
876
+ element . parentNode . removeChild ( element ) ;
877
+ }
878
+ }
879
+
880
+ /** Determines whether an event is a touch event. */
881
+ function isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
882
+ return event . type . startsWith ( 'touch' ) ;
883
+ }
0 commit comments