-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Resizing issue #1530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resizing issue #1530
Changes from all commits
565b31a
1d3b40c
5ba15dc
84cec8d
2ec824c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import { DDResizableHandle } from './dd-resizable-handle'; | ||
| import { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl'; | ||
| import { DDUtils } from './dd-utils'; | ||
| import { Utils } from '../utils'; | ||
| import { DDUIData, Rect, Size } from '../types'; | ||
|
|
||
| // TODO: merge with DDDragOpt | ||
|
|
@@ -37,6 +38,12 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt | |
| /** @internal */ | ||
| private temporalRect: Rect; | ||
| /** @internal */ | ||
| private scrollY: number; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need that in JQ version as well ? |
||
| /** @internal */ | ||
| private scrolled: number; | ||
| /** @internal */ | ||
| private scrollEl: HTMLElement; | ||
| /** @internal */ | ||
| private startEvent: MouseEvent; | ||
| /** @internal value saved in the same order as _originStyleProp[] */ | ||
| private elOriginStyleVal: string[]; | ||
|
|
@@ -152,6 +159,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt | |
| /** @internal */ | ||
| private _resizeStart(event: MouseEvent): DDResizable { | ||
| this.originalRect = this.el.getBoundingClientRect(); | ||
| this.scrollEl = Utils.getScrollParent(this.el); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reset this in destroy() |
||
| this.scrollY = this.scrollEl.scrollTop; | ||
| this.startEvent = event; | ||
| this._setupHelper(); | ||
| this._applyChange(); | ||
|
|
@@ -166,6 +175,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt | |
|
|
||
| /** @internal */ | ||
| private _resizing(event: MouseEvent, dir: string): DDResizable { | ||
| this.scrolled = this.scrollEl.scrollTop - this.scrollY; | ||
| this.temporalRect = this._getChange(event, dir); | ||
| this._applyChange(); | ||
| const ev = DDUtils.initEvent<MouseEvent>(event, { type: 'resize', target: this.el }); | ||
|
|
@@ -188,6 +198,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt | |
| delete this.startEvent; | ||
| delete this.originalRect; | ||
| delete this.temporalRect; | ||
| delete this.scrollY; | ||
| delete this.scrolled; | ||
| return this; | ||
| } | ||
|
|
||
|
|
@@ -218,10 +230,11 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt | |
| const oEvent = this.startEvent; | ||
| const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out. | ||
| width: this.originalRect.width, | ||
| height: this.originalRect.height, | ||
| height: this.originalRect.height + this.scrolled, | ||
| left: this.originalRect.left, | ||
| top: this.originalRect.top | ||
| top: this.originalRect.top - this.scrolled | ||
| }; | ||
|
|
||
| const offsetH = event.clientX - oEvent.clientX; | ||
| const offsetV = event.clientY - oEvent.clientY; | ||
|
|
||
|
|
@@ -293,7 +306,13 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt | |
| private _ui = (): DDUIData => { | ||
| const containmentEl = this.el.parentElement; | ||
| const containmentRect = containmentEl.getBoundingClientRect(); | ||
| const rect = this.temporalRect || this.originalRect; | ||
| const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out. | ||
| width: this.originalRect.width, | ||
| height: this.originalRect.height + this.scrolled, | ||
| left: this.originalRect.left, | ||
| top: this.originalRect.top - this.scrolled | ||
| }; | ||
| const rect = this.temporalRect || newRect; | ||
| return { | ||
| position: { | ||
| left: rect.left - containmentRect.left, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,15 +280,15 @@ export class Utils { | |
|
|
||
| /** @internal */ | ||
| static getScrollParent(el: HTMLElement): HTMLElement { | ||
| let returnEl; | ||
| if (el === null) { | ||
| returnEl = null; | ||
| } else if (el.scrollHeight > el.clientHeight) { | ||
| returnEl = el; | ||
| if (el === null) return document.documentElement; | ||
| const style = getComputedStyle(el); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is getComputedStyle() better than checking the simple el.scrollHeight > el.clientHeight because you want to remember what parent MIGHT scroll later ? (in case you don't already scroll ?) - please add comment.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, also with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting. didn't think that would be possible... but I realize the call you have return the first that could scroll which is safer anyway... but always return the doc as least, which might not scroll so it should return NULL and have that be handled ideally...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly, the best option would be returning I was using the example
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And we need to manually prevent When I try to resize or drag and drop an item to the bottom my mouse continue on the screen bellow so
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well we have a if you want to take a stab at it that would be great.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take a look at this over the week (probably weekend, I'm quite busy right now) :) |
||
| const overflowRegex = /(auto|scroll)/; | ||
|
|
||
| if (overflowRegex.test(style.overflow + style.overflowY)) { | ||
| return el; | ||
| } else { | ||
| returnEl = this.getScrollParent(el.parentElement); | ||
| return this.getScrollParent(el.parentElement); | ||
| } | ||
| return returnEl; | ||
| } | ||
|
|
||
| /** @internal */ | ||
|
|
@@ -327,5 +327,31 @@ export class Utils { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @internal | ||
| * | ||
| * Function used to scroll the page. | ||
| * | ||
| * @param event `MouseEvent` that triggers the resize | ||
| * @param el `HTMLElement` that's being resized | ||
| * @param distance Distance to scroll | ||
| */ | ||
| static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void { | ||
| const scrollEl = this.getScrollParent(el); | ||
| const height = scrollEl.clientHeight; | ||
|
|
||
| const top = event.clientY < distance; | ||
adumesny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const bottom = event.clientY > height - distance; | ||
|
|
||
| if (top) { | ||
| // This also can be done with a timeout to keep scrolling while the mouse is | ||
| // in the scrolling zone. (will have smoother behavior) | ||
| scrollEl.scrollBy({ behavior: 'smooth', top: event.clientY - distance}); | ||
|
|
||
| } else if (bottom) { | ||
| scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - event.clientY)}); | ||
| } | ||
| } | ||
| } | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.