@@ -154,6 +154,9 @@ export class DragRef<T = any> {
154
154
/** Pointer position at which the last change in the delta occurred. */
155
155
private _pointerPositionAtLastDirectionChange : Point ;
156
156
157
+ /** Position of the pointer at the last pointer event. */
158
+ private _lastKnownPointerPosition : Point ;
159
+
157
160
/**
158
161
* Root DOM node of the drag instance. This is the element that will
159
162
* be moved around as the user is dragging.
@@ -495,10 +498,10 @@ export class DragRef<T = any> {
495
498
496
499
/** Updates the item's sort order based on the last-known pointer position. */
497
500
_sortFromLastPointerPosition ( ) {
498
- const position = this . _pointerPositionAtLastDirectionChange ;
501
+ const position = this . _lastKnownPointerPosition ;
499
502
500
503
if ( position && this . _dropContainer ) {
501
- this . _updateActiveDropContainer ( this . _getConstrainedPointerPosition ( position ) ) ;
504
+ this . _updateActiveDropContainer ( this . _getConstrainedPointerPosition ( position ) , position ) ;
502
505
}
503
506
}
504
507
@@ -600,10 +603,11 @@ export class DragRef<T = any> {
600
603
601
604
const constrainedPointerPosition = this . _getConstrainedPointerPosition ( pointerPosition ) ;
602
605
this . _hasMoved = true ;
606
+ this . _lastKnownPointerPosition = pointerPosition ;
603
607
this . _updatePointerDirectionDelta ( constrainedPointerPosition ) ;
604
608
605
609
if ( this . _dropContainer ) {
606
- this . _updateActiveDropContainer ( constrainedPointerPosition ) ;
610
+ this . _updateActiveDropContainer ( constrainedPointerPosition , pointerPosition ) ;
607
611
} else {
608
612
const activeTransform = this . _activeTransform ;
609
613
activeTransform . x =
@@ -797,7 +801,8 @@ export class DragRef<T = any> {
797
801
this . _pickupPositionInElement = previewTemplate && previewTemplate . template &&
798
802
! previewTemplate . matchSize ? { x : 0 , y : 0 } :
799
803
this . _getPointerPositionInElement ( referenceElement , event ) ;
800
- const pointerPosition = this . _pickupPositionOnPage = this . _getPointerPositionOnPage ( event ) ;
804
+ const pointerPosition = this . _pickupPositionOnPage = this . _lastKnownPointerPosition =
805
+ this . _getPointerPositionOnPage ( event ) ;
801
806
this . _pointerDirectionDelta = { x : 0 , y : 0 } ;
802
807
this . _pointerPositionAtLastDirectionChange = { x : pointerPosition . x , y : pointerPosition . y } ;
803
808
this . _dragStartTime = Date . now ( ) ;
@@ -846,7 +851,7 @@ export class DragRef<T = any> {
846
851
* Updates the item's position in its drop container, or moves it
847
852
* into a new one, depending on its current drag position.
848
853
*/
849
- private _updateActiveDropContainer ( { x, y} : Point ) {
854
+ private _updateActiveDropContainer ( { x, y} : Point , { x : rawX , y : rawY } : Point ) {
850
855
// Drop container that draggable has been moved into.
851
856
let newContainer = this . _initialContainer . _getSiblingContainerFromPosition ( this , x , y ) ;
852
857
@@ -878,7 +883,7 @@ export class DragRef<T = any> {
878
883
} ) ;
879
884
}
880
885
881
- this . _dropContainer ! . _startScrollingIfNecessary ( x , y ) ;
886
+ this . _dropContainer ! . _startScrollingIfNecessary ( rawX , rawY ) ;
882
887
this . _dropContainer ! . _sortItem ( this , x , y , this . _pointerDirectionDelta ) ;
883
888
this . _preview . style . transform =
884
889
getTransform ( x - this . _pickupPositionInElement . x , y - this . _pickupPositionInElement . y ) ;
@@ -1053,13 +1058,13 @@ export class DragRef<T = any> {
1053
1058
1054
1059
/** Gets the pointer position on the page, accounting for any position constraints. */
1055
1060
private _getConstrainedPointerPosition ( point : Point ) : Point {
1056
- const constrainedPoint = this . constrainPosition ? this . constrainPosition ( point , this ) : point ;
1057
1061
const dropContainerLock = this . _dropContainer ? this . _dropContainer . lockAxis : null ;
1062
+ let { x, y} = this . constrainPosition ? this . constrainPosition ( point , this ) : point ;
1058
1063
1059
1064
if ( this . lockAxis === 'x' || dropContainerLock === 'x' ) {
1060
- constrainedPoint . y = this . _pickupPositionOnPage . y ;
1065
+ y = this . _pickupPositionOnPage . y ;
1061
1066
} else if ( this . lockAxis === 'y' || dropContainerLock === 'y' ) {
1062
- constrainedPoint . x = this . _pickupPositionOnPage . x ;
1067
+ x = this . _pickupPositionOnPage . x ;
1063
1068
}
1064
1069
1065
1070
if ( this . _boundaryRect ) {
@@ -1071,11 +1076,11 @@ export class DragRef<T = any> {
1071
1076
const minX = boundaryRect . left + pickupX ;
1072
1077
const maxX = boundaryRect . right - ( previewRect . width - pickupX ) ;
1073
1078
1074
- constrainedPoint . x = clamp ( constrainedPoint . x , minX , maxX ) ;
1075
- constrainedPoint . y = clamp ( constrainedPoint . y , minY , maxY ) ;
1079
+ x = clamp ( x , minX , maxX ) ;
1080
+ y = clamp ( y , minY , maxY ) ;
1076
1081
}
1077
1082
1078
- return constrainedPoint ;
1083
+ return { x , y } ;
1079
1084
}
1080
1085
1081
1086
@@ -1244,9 +1249,13 @@ export class DragRef<T = any> {
1244
1249
const scrollDifference = this . _parentPositions . handleScroll ( event ) ;
1245
1250
1246
1251
if ( scrollDifference ) {
1247
- // ClientRect dimensions are based on the page's scroll position so
1248
- // we have to update the cached boundary ClientRect if the user has scrolled.
1249
- if ( this . _boundaryRect ) {
1252
+ const target = event . target as Node ;
1253
+
1254
+ // ClientRect dimensions are based on the scroll position of the page and its parent node so
1255
+ // we have to update the cached boundary ClientRect if the user has scrolled. Check for
1256
+ // the `document` specifically since IE doesn't support `contains` on it.
1257
+ if ( this . _boundaryRect && ( target === this . _document ||
1258
+ ( target !== this . _boundaryElement && target . contains ( this . _boundaryElement ) ) ) ) {
1250
1259
adjustClientRect ( this . _boundaryRect , scrollDifference . top , scrollDifference . left ) ;
1251
1260
}
1252
1261
0 commit comments