Skip to content

Commit 419b08d

Browse files
authored
Merge pull request #2743 from adumesny/master
resizing left from right most item works
2 parents 434fb9b + 7d0302c commit 419b08d

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Change log
117117
* fix: [#2734](https://github.com/gridstack/gridstack.js/bug/2734) rotate() JS error
118118
* fix: [#2741](https://github.com/gridstack/gridstack.js/pull/2741) resizeToContent JS error with nested grid
119119
* fix: [#2740](https://github.com/gridstack/gridstack.js/bug/2740) nested grid drag fix
120+
* fix: [#2730](https://github.com/gridstack/gridstack.js/bug/2730) resizing left from right most item works
120121

121122
## 10.3.0 (2024-06-26)
122123
* fix: [#2720](https://github.com/gridstack/gridstack.js/pull/2720) load() now creates widgets in order (used to be reverse due to old collision code)

src/dd-gridstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type DDDropOpt = {
1818
/** drag&drop options currently called from the main code, but others can be passed in grid options */
1919
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2020
export type DDOpts = 'enable' | 'disable' | 'destroy' | 'option' | string | any;
21-
export type DDKey = 'minWidth' | 'minHeight' | 'maxWidth' | 'maxHeight';
21+
export type DDKey = 'minWidth' | 'minHeight' | 'maxWidth' | 'maxHeight' | 'maxHeightMoveUp' | 'maxWidthMoveLeft';
2222
export type DDValue = number | string;
2323

2424
/** drag&drop events callbacks */

src/dd-resizable.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export interface DDResizableOpt {
1616
autoHide?: boolean;
1717
handles?: string;
1818
maxHeight?: number;
19+
maxHeightMoveUp?: number;
1920
maxWidth?: number;
21+
maxWidthMoveLeft?: number;
2022
minHeight?: number;
2123
minWidth?: number;
2224
start?: (event: Event, ui: DDUIData) => void;
@@ -254,20 +256,24 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
254256

255257
const offsetX = event.clientX - oEvent.clientX;
256258
const offsetY = this.sizeToContent ? 0 : event.clientY - oEvent.clientY; // prevent vert resize
259+
let moveLeft: boolean;
260+
let moveUp: boolean;
257261

258262
if (dir.indexOf('e') > -1) {
259263
newRect.width += offsetX;
260264
} else if (dir.indexOf('w') > -1) {
261265
newRect.width -= offsetX;
262266
newRect.left += offsetX;
267+
moveLeft = true;
263268
}
264269
if (dir.indexOf('s') > -1) {
265270
newRect.height += offsetY;
266271
} else if (dir.indexOf('n') > -1) {
267272
newRect.height -= offsetY;
268273
newRect.top += offsetY
274+
moveUp = true;
269275
}
270-
const constrain = this._constrainSize(newRect.width, newRect.height);
276+
const constrain = this._constrainSize(newRect.width, newRect.height, moveLeft, moveUp);
271277
if (Math.round(newRect.width) !== Math.round(constrain.width)) { // round to ignore slight round-off errors
272278
if (dir.indexOf('w') > -1) {
273279
newRect.left += newRect.width - constrain.width;
@@ -284,11 +290,12 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
284290
}
285291

286292
/** @internal constrain the size to the set min/max values */
287-
protected _constrainSize(oWidth: number, oHeight: number): Size {
288-
const maxWidth = this.option.maxWidth || Number.MAX_SAFE_INTEGER;
289-
const minWidth = this.option.minWidth / this.rectScale.x || oWidth;
290-
const maxHeight = this.option.maxHeight || Number.MAX_SAFE_INTEGER;
291-
const minHeight = this.option.minHeight / this.rectScale.y || oHeight;
293+
protected _constrainSize(oWidth: number, oHeight: number, moveLeft: boolean, moveUp: boolean): Size {
294+
const o = this.option;
295+
const maxWidth = (moveLeft ? o.maxWidthMoveLeft : o.maxWidth) || Number.MAX_SAFE_INTEGER;
296+
const minWidth = o.minWidth / this.rectScale.x || oWidth;
297+
const maxHeight = (moveUp ? o.maxHeightMoveUp : o.maxHeight) || Number.MAX_SAFE_INTEGER;
298+
const minHeight = o.minHeight / this.rectScale.y || oHeight;
292299
const width = Math.min(maxWidth, Math.max(minWidth, oWidth));
293300
const height = Math.min(maxHeight, Math.max(minHeight, oHeight));
294301
return { width, height };

src/gridstack.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,9 @@ export class GridStack {
25052505
dd.resizable(el, 'option', 'minWidth', cellWidth * Math.min(node.minW || 1, colLeft))
25062506
.resizable(el, 'option', 'minHeight', cellHeight * Math.min(node.minH || 1, rowLeft))
25072507
.resizable(el, 'option', 'maxWidth', cellWidth * Math.min(node.maxW || Number.MAX_SAFE_INTEGER, colLeft))
2508-
.resizable(el, 'option', 'maxHeight', cellHeight * Math.min(node.maxH || Number.MAX_SAFE_INTEGER, rowLeft));
2508+
.resizable(el, 'option', 'maxWidthMoveLeft', cellWidth * Math.min(node.maxW || Number.MAX_SAFE_INTEGER, node.x+node.w))
2509+
.resizable(el, 'option', 'maxHeight', cellHeight * Math.min(node.maxH || Number.MAX_SAFE_INTEGER, rowLeft))
2510+
.resizable(el, 'option', 'maxHeightMoveUp', cellHeight * Math.min(node.maxH || Number.MAX_SAFE_INTEGER, node.y+node.h));
25092511
}
25102512
}
25112513

0 commit comments

Comments
 (0)