From 52c88e6028a2b42b0c12bab26dc1be16689b90de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2020 20:09:59 +0000 Subject: [PATCH 1/2] Bump node-fetch from 2.6.0 to 2.6.1 Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1. - [Release notes](https://github.com/bitinn/node-fetch/releases) - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1) Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index a0536064b..a3a876413 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5519,9 +5519,9 @@ node-fetch-npm@^2.0.2: safe-buffer "^5.1.1" node-fetch@^2.3.0, node-fetch@^2.5.0: - version "2.6.0" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" - integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA== + version "2.6.1" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" + integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== node-gyp@^5.0.2: version "5.0.7" From 9a25bf8924652f0766a5bb17619f0af41bdfb7ea Mon Sep 17 00:00:00 2001 From: Cameron Toy Date: Wed, 28 Oct 2020 21:47:48 -0700 Subject: [PATCH 2/2] added optional drag image offset added drag offset to findScrollTarget made drag offset optional added optional drag offset --- packages/dragdrop/src/index.ts | 56 ++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/packages/dragdrop/src/index.ts b/packages/dragdrop/src/index.ts index ce5481fdb..af7b0a99a 100644 --- a/packages/dragdrop/src/index.ts +++ b/packages/dragdrop/src/index.ts @@ -144,6 +144,8 @@ class Drag implements IDisposable { this.proposedAction = options.proposedAction || 'copy'; this.supportedActions = options.supportedActions || 'all'; this.source = options.source || null; + this._dragAdjustX = options.dragAdjustX || 0; + this._dragAdjustY = options.dragAdjustY || 0; } /** @@ -233,6 +235,9 @@ class Drag implements IDisposable { return this._promise; } + this._dragOffsetX = (this._dragAdjustX) ? this._dragAdjustX - clientX : 0; + this._dragOffsetY = (this._dragAdjustY) ? this._dragAdjustY - clientY : 0; + // Install the document listeners for the drag object. this._addListeners(); @@ -291,8 +296,8 @@ class Drag implements IDisposable { return; } let style = this.dragImage.style; - style.top = `${clientY}px`; - style.left = `${clientX}px`; + style.top = `${clientY + this.dragOffsetY}px`; + style.left = `${clientX + this.dragOffsetX}px`; } /** @@ -311,7 +316,7 @@ class Drag implements IDisposable { // Move the drag image to the specified client position. This is // performed *after* dispatching to prevent unnecessary reflows. - this.moveDragImage(event.clientX, event.clientY); + this.moveDragImage(event.clientX + this.dragOffsetX, event.clientY + this.dragOffsetY); } /** @@ -405,7 +410,7 @@ class Drag implements IDisposable { */ private _updateDragScroll(event: MouseEvent): void { // Find the scroll target under the mouse. - let target = Private.findScrollTarget(event); + let target = Private.findScrollTarget(event, this.dragOffsetX, this.dragOffsetY); // Bail if there is nothing to scroll. if (!this._scrollTarget && !target) { @@ -601,6 +606,14 @@ class Drag implements IDisposable { requestAnimationFrame(this._onScrollFrame); }; + get dragOffsetX(): number { + return this._dragOffsetX; + } + + get dragOffsetY(): number { + return this._dragOffsetY; + } + private _disposed = false; private _dropAction: DropAction = 'none'; private _override: IDisposable | null = null; @@ -609,6 +622,10 @@ class Drag implements IDisposable { private _promise: Promise | null = null; private _scrollTarget: Private.IScrollTarget | null = null; private _resolve: ((value: DropAction) => void) | null = null; + private _dragAdjustX: number; + private _dragAdjustY: number; + private _dragOffsetX: number; + private _dragOffsetY: number; } @@ -681,6 +698,20 @@ namespace Drag { * The default value is `null`. */ source?: any; + + /** + * How many pixels to offset the drag/image in the x direction. + * + * The default value is 0. + */ + dragAdjustX?: number; + + /** + * How many pixels to offset the drag/image in the y direction. + * + * The default value is 0. + */ + dragAdjustY?: number; } /** @@ -797,12 +828,18 @@ namespace Private { /** * Find the drag scroll target under the mouse, if any. + * + * @param event - The mouse event related to the action. + * + * @param dragOffsetX - the number of pixels to offset the drag in the x direction. + * + * @param dragOffsetY - the number of pixels to offset the drag in the y direction. */ export - function findScrollTarget(event: MouseEvent): IScrollTarget | null { + function findScrollTarget(event: MouseEvent, dragOffsetX?: number, dragOffsetY?: number): IScrollTarget | null { // Look up the client mouse position. - let x = event.clientX; - let y = event.clientY; + const x = event.clientX + (dragOffsetX !== undefined ? dragOffsetX : 0); + const y = event.clientY + (dragOffsetY !== undefined ? dragOffsetY : 0); // Get the element under the mouse. let element: Element | null = document.elementFromPoint(x, y); @@ -810,6 +847,7 @@ namespace Private { // Search for a scrollable target based on the mouse position. // The null assert in third clause of for-loop is required due to: // https://github.com/Microsoft/TypeScript/issues/14143 + for (; element; element = element!.parentElement) { // Ignore elements which are not marked as scrollable. let scrollable = element.hasAttribute('data-lm-dragscroll'); @@ -1174,8 +1212,8 @@ namespace Private { // Initialize the mouse event data. dragEvent.initMouseEvent( type, true, true, window, 0, - event.screenX, event.screenY, - event.clientX, event.clientY, + event.screenX + drag.dragOffsetX, event.screenY + drag.dragOffsetY, + event.clientX + drag.dragOffsetX, event.clientY + drag.dragOffsetY, event.ctrlKey, event.altKey, event.shiftKey, event.metaKey, event.button, related