@@ -285,7 +285,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
285
285
rootElement . addEventListener ( 'mousedown' , this . _pointerDown , activeEventListenerOptions ) ;
286
286
rootElement . addEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
287
287
this . _handles . changes . pipe ( startWith ( null ) ) . subscribe ( ( ) =>
288
- toggleNativeDragInteractions ( rootElement , this . getChildHandles ( ) . length > 0 ) ) ;
288
+ toggleNativeDragInteractions ( rootElement , this . _getChildHandles ( ) . length > 0 ) ) ;
289
289
} ) ;
290
290
}
291
291
@@ -302,7 +302,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
302
302
if ( this . _isDragging ( ) ) {
303
303
// Since we move out the element to the end of the body while it's being
304
304
// dragged, we have to make sure that it's removed if it gets destroyed.
305
- this . _removeElement ( this . _rootElement ) ;
305
+ removeElement ( this . _rootElement ) ;
306
306
}
307
307
}
308
308
@@ -321,13 +321,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
321
321
}
322
322
323
323
/** Gets only handles that are not inside descendant `CdkDrag` instances. */
324
- private getChildHandles ( ) {
324
+ protected _getChildHandles ( ) {
325
325
return this . _handles . filter ( handle => handle . _parentDrag === this ) ;
326
326
}
327
327
328
328
/** Handler for the `mousedown`/`touchstart` events. */
329
329
_pointerDown = ( event : MouseEvent | TouchEvent ) => {
330
- const handles = this . getChildHandles ( ) ;
330
+ const handles = this . _getChildHandles ( ) ;
331
331
332
332
// Delegate the event based on whether it started from a handle or the element itself.
333
333
if ( handles . length ) {
@@ -351,7 +351,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
351
351
* @param referenceElement Element that started the drag sequence.
352
352
* @param event Browser event object that started the sequence.
353
353
*/
354
- private _initializeDragSequence ( referenceElement : HTMLElement , event : MouseEvent | TouchEvent ) {
354
+ protected _initializeDragSequence ( referenceElement : HTMLElement , event : MouseEvent | TouchEvent ) {
355
355
// Always stop propagation for the event that initializes
356
356
// the dragging sequence, in order to prevent it from potentially
357
357
// starting another sequence for a draggable parent somewhere up the DOM tree.
@@ -368,7 +368,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
368
368
}
369
369
370
370
// Abort if the user is already dragging or is using a mouse button other than the primary one.
371
- if ( this . _isDragging ( ) || ( ! this . _isTouchEvent ( event ) && event . button !== 0 ) ) {
371
+ if ( this . _isDragging ( ) || ( ! isTouchEvent ( event ) && event . button !== 0 ) ) {
372
372
return ;
373
373
}
374
374
@@ -395,7 +395,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
395
395
}
396
396
397
397
/** Starts the dragging sequence. */
398
- private _startDragSequence ( ) {
398
+ protected _startDragSequence ( ) {
399
399
// Emit the event on the item before the one on the container.
400
400
this . started . emit ( { source : this } ) ;
401
401
@@ -420,7 +420,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
420
420
}
421
421
422
422
/** Handler that is invoked when the user moves their pointer after they've initiated a drag. */
423
- private _pointerMove = ( event : MouseEvent | TouchEvent ) => {
423
+ protected _pointerMove = ( event : MouseEvent | TouchEvent ) => {
424
424
const pointerPosition = this . _getConstrainedPointerPosition ( event ) ;
425
425
426
426
if ( ! this . _hasStartedDragging ) {
@@ -474,7 +474,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
474
474
}
475
475
476
476
/** Handler that is invoked when the user lifts their pointer up, after initiating a drag. */
477
- private _pointerUp = ( ) => {
477
+ protected _pointerUp = ( ) => {
478
478
if ( ! this . _isDragging ( ) ) {
479
479
return ;
480
480
}
@@ -633,7 +633,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
633
633
const elementRect = this . _rootElement . getBoundingClientRect ( ) ;
634
634
const handleElement = referenceElement === this . _rootElement ? null : referenceElement ;
635
635
const referenceRect = handleElement ? handleElement . getBoundingClientRect ( ) : elementRect ;
636
- const point = this . _isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
636
+ const point = isTouchEvent ( event ) ? event . targetTouches [ 0 ] : event ;
637
637
const x = point . pageX - referenceRect . left - this . _scrollPosition . left ;
638
638
const y = point . pageY - referenceRect . top - this . _scrollPosition . top ;
639
639
@@ -690,19 +690,9 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
690
690
} ) ;
691
691
}
692
692
693
- /**
694
- * Helper to remove an element from the DOM and to do all the necessary null checks.
695
- * @param element Element to be removed.
696
- */
697
- private _removeElement ( element : HTMLElement | null ) {
698
- if ( element && element . parentNode ) {
699
- element . parentNode . removeChild ( element ) ;
700
- }
701
- }
702
-
703
693
/** Determines the point of the page that was touched by the user. */
704
694
private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
705
- const point = this . _isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
695
+ const point = isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
706
696
707
697
return {
708
698
x : point . pageX - this . _scrollPosition . left ,
@@ -724,15 +714,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
724
714
return point ;
725
715
}
726
716
727
- /** Determines whether an event is a touch event. */
728
- private _isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
729
- return event . type . startsWith ( 'touch' ) ;
730
- }
731
-
732
717
/** Destroys the preview element and its ViewRef. */
733
718
private _destroyPreview ( ) {
734
719
if ( this . _preview ) {
735
- this . _removeElement ( this . _preview ) ;
720
+ removeElement ( this . _preview ) ;
736
721
}
737
722
738
723
if ( this . _previewRef ) {
@@ -745,7 +730,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
745
730
/** Destroys the placeholder element and its ViewRef. */
746
731
private _destroyPlaceholder ( ) {
747
732
if ( this . _placeholder ) {
748
- this . _removeElement ( this . _placeholder ) ;
733
+ removeElement ( this . _placeholder ) ;
749
734
}
750
735
751
736
if ( this . _placeholderRef ) {
@@ -783,7 +768,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
783
768
}
784
769
785
770
/** Gets the root draggable element, based on the `rootElementSelector`. */
786
- private _getRootElement ( ) : HTMLElement {
771
+ protected _getRootElement ( ) : HTMLElement {
787
772
if ( this . rootElementSelector ) {
788
773
const selector = this . rootElementSelector ;
789
774
let currentElement = this . element . nativeElement . parentElement as HTMLElement | null ;
@@ -831,3 +816,18 @@ function deepCloneNode(node: HTMLElement): HTMLElement {
831
816
clone . removeAttribute ( 'id' ) ;
832
817
return clone ;
833
818
}
819
+
820
+ /**
821
+ * Helper to remove an element from the DOM and to do all the necessary null checks.
822
+ * @param element Element to be removed.
823
+ */
824
+ function removeElement ( element : HTMLElement | null ) {
825
+ if ( element && element . parentNode ) {
826
+ element . parentNode . removeChild ( element ) ;
827
+ }
828
+ }
829
+
830
+ /** Determines whether an event is a touch event. */
831
+ function isTouchEvent ( event : MouseEvent | TouchEvent ) : event is TouchEvent {
832
+ return event . type . startsWith ( 'touch' ) ;
833
+ }
0 commit comments