@@ -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 ) {
@@ -509,7 +509,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
509
509
}
510
510
511
511
/** Handler that is invoked when the user lifts their pointer up, after initiating a drag. */
512
- private _pointerUp = ( ) => {
512
+ protected _pointerUp = ( ) => {
513
513
if ( ! this . _isDragging ( ) ) {
514
514
return ;
515
515
}
@@ -672,7 +672,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
672
672
const elementRect = this . _rootElement . getBoundingClientRect ( ) ;
673
673
const handleElement = referenceElement === this . _rootElement ? null : referenceElement ;
674
674
const referenceRect = handleElement ? handleElement . getBoundingClientRect ( ) : elementRect ;
675
- const point = this . _isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
675
+ const point = isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
676
676
const x = point . pageX - referenceRect . left - this . _scrollPosition . left ;
677
677
const y = point . pageY - referenceRect . top - this . _scrollPosition . top ;
678
678
@@ -729,19 +729,9 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
729
729
} ) ;
730
730
}
731
731
732
- /**
733
- * Helper to remove an element from the DOM and to do all the necessary null checks.
734
- * @param element Element to be removed.
735
- */
736
- private _removeElement ( element : HTMLElement | null ) {
737
- if ( element && element . parentNode ) {
738
- element . parentNode . removeChild ( element ) ;
739
- }
740
- }
741
-
742
732
/** Determines the point of the page that was touched by the user. */
743
733
private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
744
- const point = this . _isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
734
+ const point = isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
745
735
746
736
return {
747
737
x : point . pageX - this . _scrollPosition . left ,
@@ -763,15 +753,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
763
753
return point ;
764
754
}
765
755
766
- /** Determines whether an event is a touch event. */
767
- private _isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
768
- return event . type . startsWith ( 'touch' ) ;
769
- }
770
-
771
756
/** Destroys the preview element and its ViewRef. */
772
757
private _destroyPreview ( ) {
773
758
if ( this . _preview ) {
774
- this . _removeElement ( this . _preview ) ;
759
+ removeElement ( this . _preview ) ;
775
760
}
776
761
777
762
if ( this . _previewRef ) {
@@ -784,7 +769,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
784
769
/** Destroys the placeholder element and its ViewRef. */
785
770
private _destroyPlaceholder ( ) {
786
771
if ( this . _placeholder ) {
787
- this . _removeElement ( this . _placeholder ) ;
772
+ removeElement ( this . _placeholder ) ;
788
773
}
789
774
790
775
if ( this . _placeholderRef ) {
@@ -822,7 +807,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
822
807
}
823
808
824
809
/** Gets the root draggable element, based on the `rootElementSelector`. */
825
- private _getRootElement ( ) : HTMLElement {
810
+ protected _getRootElement ( ) : HTMLElement {
826
811
if ( this . rootElementSelector ) {
827
812
const selector = this . rootElementSelector ;
828
813
let currentElement = this . element . nativeElement . parentElement as HTMLElement | null ;
@@ -870,3 +855,18 @@ function deepCloneNode(node: HTMLElement): HTMLElement {
870
855
clone . removeAttribute ( 'id' ) ;
871
856
return clone ;
872
857
}
858
+
859
+ /**
860
+ * Helper to remove an element from the DOM and to do all the necessary null checks.
861
+ * @param element Element to be removed.
862
+ */
863
+ function removeElement ( element : HTMLElement | null ) {
864
+ if ( element && element . parentNode ) {
865
+ element . parentNode . removeChild ( element ) ;
866
+ }
867
+ }
868
+
869
+ /** Determines whether an event is a touch event. */
870
+ function isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
871
+ return event . type . startsWith ( 'touch' ) ;
872
+ }
0 commit comments