@@ -434,6 +434,29 @@ export class DragRef<T = any> {
434434 this . _dropContainer = container ;
435435 }
436436
437+ /**
438+ * Gets the current position in pixels the draggable outside of a drop container.
439+ */
440+ getFreeDragPosition ( ) : Readonly < Point > {
441+ return { x : this . _passiveTransform . x , y : this . _passiveTransform . y } ;
442+ }
443+
444+ /**
445+ * Sets the current position in pixels the draggable outside of a drop container.
446+ * @param value New position to be set.
447+ */
448+ setFreeDragPosition ( value : Point ) : this {
449+ this . _activeTransform = { x : 0 , y : 0 } ;
450+ this . _passiveTransform . x = value . x ;
451+ this . _passiveTransform . y = value . y ;
452+
453+ if ( ! this . _dropContainer ) {
454+ this . _applyRootElementTransform ( value . x , value . y ) ;
455+ }
456+
457+ return this ;
458+ }
459+
437460 /** Unsubscribes from the global subscriptions. */
438461 private _removeSubscriptions ( ) {
439462 this . _pointerMoveSubscription . unsubscribe ( ) ;
@@ -527,13 +550,8 @@ export class DragRef<T = any> {
527550 constrainedPointerPosition . x - this . _pickupPositionOnPage . x + this . _passiveTransform . x ;
528551 activeTransform . y =
529552 constrainedPointerPosition . y - this . _pickupPositionOnPage . y + this . _passiveTransform . y ;
530- const transform = getTransform ( activeTransform . x , activeTransform . y ) ;
531553
532- // Preserve the previous `transform` value, if there was one. Note that we apply our own
533- // transform before the user's, because things like rotation can affect which direction
534- // the element will be translated towards.
535- this . _rootElement . style . transform = this . _initialTransform ?
536- transform + ' ' + this . _initialTransform : transform ;
554+ this . _applyRootElementTransform ( activeTransform . x , activeTransform . y ) ;
537555
538556 // Apply transform as attribute if dragging and svg element to work for IE
539557 if ( typeof SVGElement !== 'undefined' && this . _rootElement instanceof SVGElement ) {
@@ -660,12 +678,6 @@ export class DragRef<T = any> {
660678 return ;
661679 }
662680
663- // Cache the previous transform amount only after the first drag sequence, because
664- // we don't want our own transforms to stack on top of each other.
665- if ( this . _initialTransform == null ) {
666- this . _initialTransform = this . _rootElement . style . transform || '' ;
667- }
668-
669681 // If we've got handles, we need to disable the tap highlight on the entire root element,
670682 // otherwise iOS will still add it, even though all the drag interactions on the handle
671683 // are disabled.
@@ -990,6 +1002,26 @@ export class DragRef<T = any> {
9901002 element . removeEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
9911003 }
9921004
1005+ /**
1006+ * Applies a `transform` to the root element, taking into account any existing transforms on it.
1007+ * @param x New transform value along the X axis.
1008+ * @param y New transform value along the Y axis.
1009+ */
1010+ private _applyRootElementTransform ( x : number , y : number ) {
1011+ const transform = getTransform ( x , y ) ;
1012+
1013+ // Cache the previous transform amount only after the first drag sequence, because
1014+ // we don't want our own transforms to stack on top of each other.
1015+ if ( this . _initialTransform == null ) {
1016+ this . _initialTransform = this . _rootElement . style . transform || '' ;
1017+ }
1018+
1019+ // Preserve the previous `transform` value, if there was one. Note that we apply our own
1020+ // transform before the user's, because things like rotation can affect which direction
1021+ // the element will be translated towards.
1022+ this . _rootElement . style . transform = this . _initialTransform ?
1023+ transform + ' ' + this . _initialTransform : transform ;
1024+ }
9931025}
9941026
9951027/** Point on the page or within an element. */
0 commit comments