Skip to content

Commit

Permalink
locked item can be moved/resized
Browse files Browse the repository at this point in the history
* fix gridstack#1767
* `locked` item can be user moved/resized just not pushed by other nodes (broke in 1.1.1)
* had incorrectly assume locked = noMove + noSize (user driven) but it's for layout only, so now you have complete choice.
  • Loading branch information
adumesny committed May 29, 2021
1 parent 3e430d0 commit 9734eff
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions demo/float.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1>Float grid demo</h1>
addEvents(grid);

let items = [
{x: 1, y: 1},
{x: 1, y: 1}, //, locked:true, content:"locked"},
{x: 2, y: 2, w: 3},
{x: 4, y: 2},
{x: 3, y: 1, h: 2},
Expand All @@ -44,8 +44,9 @@ <h1>Float grid demo</h1>
w: Math.round(1 + 3 * Math.random()),
h: Math.round(1 + 3 * Math.random())
};
n.content = String(count++);
n.content = n.content || String(count);
grid.addWidget(n);
count++;
};

toggleFloat = function() {
Expand Down
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Change log

* fix [#1760](https://github.com/gridstack/gridstack.js/issues/1760) `removable:true` working again (broke in 4.x)
* fix [#1761](https://github.com/gridstack/gridstack.js/issues/1761) `staticGrid(false)` will now enable drag in behavior (if set)
* fix [#1767](https://github.com/gridstack/gridstack.js/issues/1767) `locked` item can be user moved/resized again, just not pushed by other nodes (broke in 1.1.1)

## 4.2.3 (2021-5-8)

Expand Down
7 changes: 3 additions & 4 deletions src/gridstack-dd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
let dd = GridStackDD.get();

// check for disabled grid first
if (this.opts.staticGrid || node.locked ||
((node.noMove || this.opts.disableDrag) && (node.noResize || this.opts.disableResize))) {
if (this.opts.staticGrid || ((node.noMove || this.opts.disableDrag) && (node.noResize || this.opts.disableResize))) {
if (node._initDD) {
dd.remove(el); // nukes everything instead of just disable, will add some styles back next
delete node._initDD;
Expand Down Expand Up @@ -616,7 +615,7 @@ GridStack.prototype.movable = function(els: GridStackElement, val: boolean): Gri
if (this.opts.staticGrid) return this; // can't move a static grid!
GridStack.getElements(els).forEach(el => {
let node = el.gridstackNode;
if (!node || node.locked) return;
if (!node) return;
if (val) delete node.noMove; else node.noMove = true;
this._prepareDragDropByNode(node); // init DD if need be, and adjust
});
Expand All @@ -632,7 +631,7 @@ GridStack.prototype.resizable = function(els: GridStackElement, val: boolean): G
if (this.opts.staticGrid) return this; // can't resize a static grid!
GridStack.getElements(els).forEach(el => {
let node = el.gridstackNode;
if (!node || node.locked) return;
if (!node) return;
if (val) delete node.noResize; else node.noResize = true;
this._prepareDragDropByNode(node); // init DD if need be, and adjust
});
Expand Down
4 changes: 2 additions & 2 deletions src/gridstack-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export class GridStackEngine {
* In more complicated cases (maxRow) it will attempt at moving the item and fixing
* others in a clone first, then apply those changes if still within specs. */
public moveNodeCheck(node: GridStackNode, o: GridStackMoveOpts): boolean {
if (node.locked) return false;
// if (node.locked) return false;
if (!this.changedPosConstrain(node, o)) return false;
o.pack = true;

Expand Down Expand Up @@ -594,7 +594,7 @@ export class GridStackEngine {

/** return true if the passed in node was actually moved (checks for no-op and locked) */
public moveNode(node: GridStackNode, o: GridStackMoveOpts): boolean {
if (!node || node.locked || !o) return false;
if (!node || /*node.locked ||*/ !o) return false;
if (o.pack === undefined) o.pack = true;

// constrain the passed in values and check if we're still changing our node
Expand Down

0 comments on commit 9734eff

Please sign in to comment.