Skip to content

Commit 5ba15dc

Browse files
committed
review changes
1 parent 1d3b40c commit 5ba15dc

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

src/gridstack-dd.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,8 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
353353
this._gsEventHandler[event.type](event, target);
354354
}
355355

356-
// Saving `minRow` and adding new ones for resizing
356+
// Saving `minRow`
357357
minRow = this.opts.minRow;
358-
this.opts.minRow = this.getRow() + 100;
359-
this._updateContainerHeight();
360358

361359
this.engine.cleanNodes();
362360
this.engine.beginUpdate(node);
@@ -428,8 +426,17 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
428426
if (node._lastTriedX === x && node._lastTriedY === y) return;
429427
} else if (event.type === 'resize') {
430428
if (x < 0) return;
429+
// Addin an extra row if the item it's at the bottom of the layout
430+
if (node.y+node.h >= this.getRow()-1) {
431+
this.opts.minRow = this.getRow() + 1;
432+
this._updateContainerHeight();
433+
}
434+
431435
// Scrolling page if needed
432436
Utils.updateScrollResize(event as MouseEvent, el, cellHeight);
437+
// Restore minRow
438+
this.opts.minRow = minRow;
439+
433440
w = Math.round(ui.size.width / cellWidth);
434441
h = Math.round(ui.size.height / cellHeight);
435442
if (w === node.w && h === node.h) return;
@@ -491,10 +498,6 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
491498

492499
this.engine.endUpdate();
493500

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

src/h5/dd-resizable.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
4040
/** @internal */
4141
private scrollY: number;
4242
/** @internal */
43+
private scrolled: number;
44+
/** @internal */
4345
private startEvent: MouseEvent;
4446
/** @internal value saved in the same order as _originStyleProp[] */
4547
private elOriginStyleVal: string[];
@@ -156,7 +158,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
156158
private _resizeStart(event: MouseEvent): DDResizable {
157159
this.originalRect = this.el.getBoundingClientRect();
158160
const scrollEl = Utils.getScrollParent(this.el);
159-
this.scrollY = scrollEl === null ? 0 : scrollEl.scrollTop;
161+
this.scrollY = scrollEl ? scrollEl.scrollTop : 0;
160162
this.startEvent = event;
161163
this._setupHelper();
162164
this._applyChange();
@@ -171,6 +173,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
171173

172174
/** @internal */
173175
private _resizing(event: MouseEvent, dir: string): DDResizable {
176+
const scrollEl = Utils.getScrollParent(this.el);
177+
this.scrolled = scrollEl ? (scrollEl.scrollTop - this.scrollY) : this.scrollY;
174178
this.temporalRect = this._getChange(event, dir);
175179
this._applyChange();
176180
const ev = DDUtils.initEvent<MouseEvent>(event, { type: 'resize', target: this.el });
@@ -194,6 +198,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
194198
delete this.originalRect;
195199
delete this.temporalRect;
196200
delete this.scrollY;
201+
delete this.scrolled;
197202
return this;
198203
}
199204

@@ -222,13 +227,11 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
222227
/** @internal */
223228
private _getChange(event: MouseEvent, dir: string): Rect {
224229
const oEvent = this.startEvent;
225-
const scrollEl = Utils.getScrollParent(this.el);
226-
const scrolled = scrollEl === null ? 0 : (scrollEl.scrollTop - this.scrollY);
227230
const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
228231
width: this.originalRect.width,
229-
height: this.originalRect.height + scrolled,
232+
height: this.originalRect.height + this.scrolled,
230233
left: this.originalRect.left,
231-
top: this.originalRect.top - scrolled
234+
top: this.originalRect.top - this.scrolled
232235
};
233236

234237
const offsetH = event.clientX - oEvent.clientX;
@@ -300,14 +303,12 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
300303

301304
/** @internal */
302305
private _ui = (): DDUIData => {
303-
const scrollEl = Utils.getScrollParent(this.el);
304-
const scrolled = scrollEl === null ? 0 : (scrollEl.scrollTop - this.scrollY);
305306
const containmentRect = this.el.parentElement.getBoundingClientRect();
306307
const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
307308
width: this.originalRect.width,
308-
height: this.originalRect.height + scrolled,
309+
height: this.originalRect.height + this.scrolled,
309310
left: this.originalRect.left,
310-
top: this.originalRect.top - scrolled
311+
top: this.originalRect.top - this.scrolled
311312
};
312313
const rect = this.temporalRect || newRect;
313314
return {

src/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,18 @@ export class Utils {
328328
}
329329
}
330330

331-
/** @internal */
331+
/**
332+
* @internal
333+
*
334+
* Function used to scroll the page.
335+
*
336+
* @param event `MouseEvent` that triggers the resize
337+
* @param el `HTMLElement` that's being resized
338+
* @param distance Distance to scroll
339+
*/
332340
static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void {
333341
let scrollEl = this.getScrollParent(el);
334-
if (scrollEl === null) return;
342+
if (!scrollEl ) return;
335343

336344
//const width = scrollEl.clientWidth;
337345
const height = scrollEl.clientHeight;
@@ -343,9 +351,8 @@ export class Utils {
343351
// This also can be done with a timeout to keep scrolling while the mouse is
344352
// in the scrolling zone. (will have smoother behavior)
345353
scrollEl.scrollBy({ behavior: 'smooth', top: event.clientY - distance});
346-
}
347354

348-
if (bottom) {
355+
} else if (bottom) {
349356
scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - event.clientY)});
350357
}
351358
}

0 commit comments

Comments
 (0)