Skip to content

Commit

Permalink
Merge pull request #2700 from adumesny/master
Browse files Browse the repository at this point in the history
prevent 'r' rotation to items that can't resize (2)
  • Loading branch information
adumesny authored Jun 13, 2024
2 parents 06e558b + 4114425 commit b057075
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dd-draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
grid.engine.restoreInitial();
this._mouseUp(this.mouseDownEvent);
} else if (e.key === 'r' || e.key === 'R') {
if (n.w === n.h) return;
if (!Utils.canBeRotated(n)) return;
n._origRotate = n._origRotate || {...n._orig}; // store the real orig size in case we Esc after doing rotation
delete n._moving; // force rotate to happen (move waits for >50% coverage otherwise)
grid.setAnimation(false) // immediate rotate so _getDragOffset() gets the right dom size below
Expand Down
2 changes: 1 addition & 1 deletion src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ export class GridStack {
public rotate(els: GridStackElement, relative?: Position): GridStack {
GridStack.getElements(els).forEach(el => {
let n = el.gridstackNode;
if (!n || n.w === n.h || n.locked || n.noResize || n.grid?.opts.disableResize || (n.minW && n.minW === n.maxW) || (n.minH && n.minH === n.maxH)) return;
if (!Utils.canBeRotated(n)) return;
const rot: GridStackWidget = { w: n.h, h: n.w, minH: n.minW, minW: n.minH, maxH: n.maxW, maxW: n.maxH };
// if given an offset, adjust x/y by column/row bounds when user presses 'r' during dragging
if (relative) {
Expand Down
7 changes: 6 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,9 @@ export class Utils {
// }
// return el.contains(target);
// }
}

/** true if the item can be rotated (checking for prop, not space available) */
public static canBeRotated(n: GridStackNode): boolean {
return !(!n || n.w === n.h || n.locked || n.noResize || n.grid?.opts.disableResize || (n.minW && n.minW === n.maxW) || (n.minH && n.minH === n.maxH));
}
}

0 comments on commit b057075

Please sign in to comment.