@@ -16,6 +16,12 @@ import {takeUntil} from 'rxjs/operators';
1616import { moveItemInArray } from './drag-utils' ;
1717import { DragDropRegistry } from './drag-drop-registry' ;
1818import { DragRefInternal as DragRef , Point } from './drag-ref' ;
19+ import {
20+ isPointerNearClientRect ,
21+ adjustClientRect ,
22+ getMutableClientRect ,
23+ isInsideClientRect ,
24+ } from './client-rect' ;
1925
2026/**
2127 * Proximity, as a ratio to width/height, at which a
@@ -446,7 +452,8 @@ export class DropListRef<T = any> {
446452 _sortItem ( item : DragRef , pointerX : number , pointerY : number ,
447453 pointerDelta : { x : number , y : number } ) : void {
448454 // Don't sort the item if sorting is disabled or it's out of range.
449- if ( this . sortingDisabled || ! isPointerNearClientRect ( this . _clientRect , pointerX , pointerY ) ) {
455+ if ( this . sortingDisabled ||
456+ ! isPointerNearClientRect ( this . _clientRect , DROP_PROXIMITY_THRESHOLD , pointerX , pointerY ) ) {
450457 return ;
451458 }
452459
@@ -540,7 +547,8 @@ export class DropListRef<T = any> {
540547 return ;
541548 }
542549
543- if ( isPointerNearClientRect ( position . clientRect , pointerX , pointerY ) ) {
550+ if ( isPointerNearClientRect ( position . clientRect , DROP_PROXIMITY_THRESHOLD ,
551+ pointerX , pointerY ) ) {
544552 [ verticalScrollDirection , horizontalScrollDirection ] = getElementScrollDirections (
545553 element as HTMLElement , position . clientRect , pointerX , pointerY ) ;
546554
@@ -921,35 +929,6 @@ export class DropListRef<T = any> {
921929}
922930
923931
924- /**
925- * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
926- * @param clientRect `ClientRect` that should be updated.
927- * @param top Amount to add to the `top` position.
928- * @param left Amount to add to the `left` position.
929- */
930- function adjustClientRect ( clientRect : ClientRect , top : number , left : number ) {
931- clientRect . top += top ;
932- clientRect . bottom = clientRect . top + clientRect . height ;
933-
934- clientRect . left += left ;
935- clientRect . right = clientRect . left + clientRect . width ;
936- }
937-
938- /**
939- * Checks whether the pointer coordinates are close to a ClientRect.
940- * @param rect ClientRect to check against.
941- * @param pointerX Coordinates along the X axis.
942- * @param pointerY Coordinates along the Y axis.
943- */
944- function isPointerNearClientRect ( rect : ClientRect , pointerX : number , pointerY : number ) : boolean {
945- const { top, right, bottom, left, width, height} = rect ;
946- const xThreshold = width * DROP_PROXIMITY_THRESHOLD ;
947- const yThreshold = height * DROP_PROXIMITY_THRESHOLD ;
948-
949- return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
950- pointerX > left - xThreshold && pointerX < right + xThreshold ;
951- }
952-
953932/**
954933 * Finds the index of an item that matches a predicate function. Used as an equivalent
955934 * of `Array.prototype.findIndex` which isn't part of the standard Google typings.
@@ -968,37 +947,6 @@ function findIndex<T>(array: T[],
968947 return - 1 ;
969948}
970949
971-
972- /**
973- * Checks whether some coordinates are within a `ClientRect`.
974- * @param clientRect ClientRect that is being checked.
975- * @param x Coordinates along the X axis.
976- * @param y Coordinates along the Y axis.
977- */
978- function isInsideClientRect ( clientRect : ClientRect , x : number , y : number ) {
979- const { top, bottom, left, right} = clientRect ;
980- return y >= top && y <= bottom && x >= left && x <= right ;
981- }
982-
983-
984- /** Gets a mutable version of an element's bounding `ClientRect`. */
985- function getMutableClientRect ( element : Element ) : ClientRect {
986- const clientRect = element . getBoundingClientRect ( ) ;
987-
988- // We need to clone the `clientRect` here, because all the values on it are readonly
989- // and we need to be able to update them. Also we can't use a spread here, because
990- // the values on a `ClientRect` aren't own properties. See:
991- // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
992- return {
993- top : clientRect . top ,
994- right : clientRect . right ,
995- bottom : clientRect . bottom ,
996- left : clientRect . left ,
997- width : clientRect . width ,
998- height : clientRect . height
999- } ;
1000- }
1001-
1002950/**
1003951 * Increments the vertical scroll position of a node.
1004952 * @param node Node whose scroll position should change.
0 commit comments