Skip to content

Commit

Permalink
disable/enable recursive by default
Browse files Browse the repository at this point in the history
* fix gridstack#2105
* disable/enable/setStatic/enableMove/enableResize now all take an optional recurse flag to update sub-grids
  • Loading branch information
adumesny committed Dec 27, 2022
1 parent b628f54 commit 188618f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/CHANGES.md
Expand Up @@ -79,6 +79,7 @@ Change log

## 7.1.1-dev (TBD)
* fix [#939](https://github.com/gridstack/gridstack.js/issues/2039) 'prototype' undefined error for dd-gridstack.js
* add [#939](https://github.com/gridstack/gridstack.js/issues/2105) disable/enable are methods now recursive by default

## 7.1.1 (2022-11-13)
* fix [#939](https://github.com/gridstack/gridstack.js/issues/939) editable elements focus (regression in v6). Thank you [@Gezdy](https://github.com/Gezdy)
Expand Down
39 changes: 27 additions & 12 deletions src/gridstack.ts
Expand Up @@ -1087,13 +1087,18 @@ export class GridStack {
* Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
* Also toggle the grid-stack-static class.
* @param val if true the grid become static.
* @param updateClass true (default) if css class gets updated
* @param recurse true (default) if sub-grids also get updated
*/
public setStatic(val: boolean, updateClass = true): GridStack {
public setStatic(val: boolean, updateClass = true, recurse = true): GridStack {
if (this.opts.staticGrid === val) return this;
this.opts.staticGrid = val;
this._setupRemoveDrop();
this._setupAcceptWidget();
this.engine.nodes.forEach(n => this._prepareDragDropByNode(n)); // either delete or init Drag&drop
this.engine.nodes.forEach(n => {
this._prepareDragDropByNode(n); // either delete or init Drag&drop
if (n.subGrid && recurse) (n.subGrid as GridStack).setStatic(val, updateClass, recurse);
});
if (updateClass) { this._setStaticClass(); }
return this;
}
Expand Down Expand Up @@ -1675,11 +1680,12 @@ export class GridStack {
* @example
* grid.enableMove(false);
* grid.enableResize(false);
* @param recurse true (default) if sub-grids also get updated
*/
public disable(): GridStack {
public disable(recurse = true): GridStack {
if (this.opts.staticGrid) return;
this.enableMove(false);
this.enableResize(false);// @ts-ignore
this.enableMove(false, recurse);
this.enableResize(false, recurse);// @ts-ignore
this._triggerEvent('disable');
return this;
}
Expand All @@ -1690,32 +1696,41 @@ export class GridStack {
* @example
* grid.enableMove(true);
* grid.enableResize(true);
* @param recurse true (default) if sub-grids also get updated
*/
public enable(): GridStack {
public enable(recurse = true): GridStack {
if (this.opts.staticGrid) return;
this.enableMove(true);
this.enableResize(true);// @ts-ignore
this.enableMove(true, recurse);
this.enableResize(true, recurse);// @ts-ignore
this._triggerEvent('enable');
return this;
}

/**
* Enables/disables widget moving. No-op for static grids.
* @param recurse true (default) if sub-grids also get updated
*/
public enableMove(doEnable: boolean): GridStack {
public enableMove(doEnable: boolean, recurse = true): GridStack {
if (this.opts.staticGrid) return this; // can't move a static grid!
this.opts.disableDrag = !doEnable; // FIRST before we update children as grid overrides #1658
this.engine.nodes.forEach(n => this.movable(n.el, doEnable));
this.engine.nodes.forEach(n => {
this.movable(n.el, doEnable);
if (n.subGrid && recurse) (n.subGrid as GridStack).enableMove(doEnable, recurse);
});
return this;
}

/**
* Enables/disables widget resizing. No-op for static grids.
* @param recurse true (default) if sub-grids also get updated
*/
public enableResize(doEnable: boolean): GridStack {
public enableResize(doEnable: boolean, recurse = true): GridStack {
if (this.opts.staticGrid) return this; // can't size a static grid!
this.opts.disableResize = !doEnable; // FIRST before we update children as grid overrides #1658
this.engine.nodes.forEach(n => this.resizable(n.el, doEnable));
this.engine.nodes.forEach(n => {
this.resizable(n.el, doEnable);
if (n.subGrid && recurse) (n.subGrid as GridStack).enableResize(doEnable, recurse);
});
return this;
}

Expand Down

0 comments on commit 188618f

Please sign in to comment.