Skip to content

Commit 565b31a

Browse files
committed
Resizing issue
1 parent 20efe29 commit 565b31a

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

src/gridstack-dd.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
342342
// variables used/cashed between the 3 start/move/end methods, in addition to node passed above
343343
let cellWidth: number;
344344
let cellHeight: number;
345+
let minRow: number;
345346

346347
/** called when item starts moving/resizing */
347348
let onStartMoving = (event: Event, ui: DDUIData): void => {
@@ -352,6 +353,11 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
352353
this._gsEventHandler[event.type](event, target);
353354
}
354355

356+
// Saving `minRow` and adding new ones for resizing
357+
minRow = this.opts.minRow;
358+
this.opts.minRow = this.getRow() + 100;
359+
this._updateContainerHeight();
360+
355361
this.engine.cleanNodes();
356362
this.engine.beginUpdate(node);
357363
cellWidth = this.cellWidth();
@@ -422,6 +428,8 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
422428
if (node._lastTriedX === x && node._lastTriedY === y) return;
423429
} else if (event.type === 'resize') {
424430
if (x < 0) return;
431+
// Scrolling page if needed
432+
Utils.updateScrollResize(event as MouseEvent, el, cellHeight);
425433
w = Math.round(ui.size.width / cellWidth);
426434
h = Math.round(ui.size.height / cellHeight);
427435
if (w === node.w && h === node.h) return;
@@ -483,6 +491,10 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
483491

484492
this.engine.endUpdate();
485493

494+
// Removing lines rows added on `resizestart`
495+
this.opts.minRow = minRow;
496+
this._updateContainerHeight();
497+
486498
// if we re-sized a nested grid item, let the children resize as well
487499
if (event.type === 'resizestop') {
488500
this._resizeNestedGrids(target);

src/h5/dd-resizable.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { DDResizableHandle } from './dd-resizable-handle';
99
import { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';
1010
import { DDUtils } from './dd-utils';
11+
import { Utils } from '../utils';
1112
import { DDUIData, Rect, Size } from '../types';
1213

1314
// TODO: merge with DDDragOpt
@@ -37,6 +38,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
3738
/** @internal */
3839
private temporalRect: Rect;
3940
/** @internal */
41+
private scrollY: number;
42+
/** @internal */
4043
private startEvent: MouseEvent;
4144
/** @internal value saved in the same order as _originStyleProp[] */
4245
private elOriginStyleVal: string[];
@@ -152,6 +155,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
152155
/** @internal */
153156
private _resizeStart(event: MouseEvent): DDResizable {
154157
this.originalRect = this.el.getBoundingClientRect();
158+
const scrollEl = Utils.getScrollParent(this.el);
159+
this.scrollY = scrollEl === null ? 0 : scrollEl.scrollTop;
155160
this.startEvent = event;
156161
this._setupHelper();
157162
this._applyChange();
@@ -188,6 +193,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
188193
delete this.startEvent;
189194
delete this.originalRect;
190195
delete this.temporalRect;
196+
delete this.scrollY;
191197
return this;
192198
}
193199

@@ -216,12 +222,15 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
216222
/** @internal */
217223
private _getChange(event: MouseEvent, dir: string): Rect {
218224
const oEvent = this.startEvent;
225+
const scrollEl = Utils.getScrollParent(this.el);
226+
const scrolled = scrollEl === null ? 0 : (scrollEl.scrollTop - this.scrollY);
219227
const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
220228
width: this.originalRect.width,
221-
height: this.originalRect.height,
229+
height: this.originalRect.height + scrolled,
222230
left: this.originalRect.left,
223-
top: this.originalRect.top
231+
top: this.originalRect.top - scrolled
224232
};
233+
225234
const offsetH = event.clientX - oEvent.clientX;
226235
const offsetV = event.clientY - oEvent.clientY;
227236

@@ -291,9 +300,16 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
291300

292301
/** @internal */
293302
private _ui = (): DDUIData => {
294-
const containmentEl = this.el.parentElement;
295-
const containmentRect = containmentEl.getBoundingClientRect();
296-
const rect = this.temporalRect || this.originalRect;
303+
const scrollEl = Utils.getScrollParent(this.el);
304+
const scrolled = scrollEl === null ? 0 : (scrollEl.scrollTop - this.scrollY);
305+
const containmentRect = this.el.parentElement.getBoundingClientRect();
306+
const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
307+
width: this.originalRect.width,
308+
height: this.originalRect.height + scrolled,
309+
left: this.originalRect.left,
310+
top: this.originalRect.top - scrolled
311+
};
312+
const rect = this.temporalRect || newRect;
297313
return {
298314
position: {
299315
left: rect.left - containmentRect.left,

src/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,5 +327,27 @@ export class Utils {
327327
}
328328
}
329329
}
330+
331+
/** @internal */
332+
static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void {
333+
let scrollEl = this.getScrollParent(el);
334+
if (scrollEl === null) return;
335+
336+
//const width = scrollEl.clientWidth;
337+
const height = scrollEl.clientHeight;
338+
339+
const top = event.clientY < distance;
340+
const bottom = event.clientY > height - distance;
341+
342+
if (top) {
343+
// This also can be done with a timeout to keep scrolling while the mouse is
344+
// in the scrolling zone. (will have smoother behavior)
345+
scrollEl.scrollBy({ behavior: 'smooth', top: event.clientY - distance});
346+
}
347+
348+
if (bottom) {
349+
scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - event.clientY)});
350+
}
351+
}
330352
}
331353

0 commit comments

Comments
 (0)