@@ -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 = ( ) => {
518
+ protected _pointerUp = ( ) => {
519
519
if ( ! this . _isDragging ( ) ) {
520
520
return ;
521
521
}
@@ -678,7 +678,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
678
678
const elementRect = this . _rootElement . getBoundingClientRect ( ) ;
679
679
const handleElement = referenceElement === this . _rootElement ? null : referenceElement ;
680
680
const referenceRect = handleElement ? handleElement . getBoundingClientRect ( ) : elementRect ;
681
- const point = this . _isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
681
+ const point = isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
682
682
const x = point . pageX - referenceRect . left - this . _scrollPosition . left ;
683
683
const y = point . pageY - referenceRect . top - this . _scrollPosition . top ;
684
684
@@ -735,19 +735,9 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
735
735
} ) ;
736
736
}
737
737
738
- /**
739
- * Helper to remove an element from the DOM and to do all the necessary null checks.
740
- * @param element Element to be removed.
741
- */
742
- private _removeElement ( element : HTMLElement | null ) {
743
- if ( element && element . parentNode ) {
744
- element . parentNode . removeChild ( element ) ;
745
- }
746
- }
747
-
748
738
/** Determines the point of the page that was touched by the user. */
749
739
private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
750
- const point = this . _isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
740
+ const point = isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
751
741
752
742
return {
753
743
x : point . pageX - this . _scrollPosition . left ,
@@ -769,15 +759,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
769
759
return point ;
770
760
}
771
761
772
- /** Determines whether an event is a touch event. */
773
- private _isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
774
- return event . type . startsWith ( 'touch' ) ;
775
- }
776
-
777
762
/** Destroys the preview element and its ViewRef. */
778
763
private _destroyPreview ( ) {
779
764
if ( this . _preview ) {
780
- this . _removeElement ( this . _preview ) ;
765
+ removeElement ( this . _preview ) ;
781
766
}
782
767
783
768
if ( this . _previewRef ) {
@@ -790,7 +775,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
790
775
/** Destroys the placeholder element and its ViewRef. */
791
776
private _destroyPlaceholder ( ) {
792
777
if ( this . _placeholder ) {
793
- this . _removeElement ( this . _placeholder ) ;
778
+ removeElement ( this . _placeholder ) ;
794
779
}
795
780
796
781
if ( this . _placeholderRef ) {
@@ -828,7 +813,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
828
813
}
829
814
830
815
/** Gets the root draggable element, based on the `rootElementSelector`. */
831
- private _getRootElement ( ) : HTMLElement {
816
+ protected _getRootElement ( ) : HTMLElement {
832
817
if ( this . rootElementSelector ) {
833
818
const selector = this . rootElementSelector ;
834
819
let currentElement = this . element . nativeElement . parentElement as HTMLElement | null ;
@@ -876,3 +861,18 @@ function deepCloneNode(node: HTMLElement): HTMLElement {
876
861
clone . removeAttribute ( 'id' ) ;
877
862
return clone ;
878
863
}
864
+
865
+ /**
866
+ * Helper to remove an element from the DOM and to do all the necessary null checks.
867
+ * @param element Element to be removed.
868
+ */
869
+ function removeElement ( element : HTMLElement | null ) {
870
+ if ( element && element . parentNode ) {
871
+ element . parentNode . removeChild ( element ) ;
872
+ }
873
+ }
874
+
875
+ /** Determines whether an event is a touch event. */
876
+ function isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
877
+ return event . type . startsWith ( 'touch' ) ;
878
+ }
0 commit comments