Skip to content

Commit 50d3d73

Browse files
committed
GridStackOptions casing, minWidth() fix
* fixed minWidth(), minHeight, maxHeight to set node value as well - see #1359 * correct GridStackOptions casing - see #1359 * rev 2.0.0-dev
1 parent d191a8d commit 50d3d73

File tree

9 files changed

+51
-67
lines changed

9 files changed

+51
-67
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ see [jsfiddle sample](https://jsfiddle.net/adumesny/jqhkry7g) as running example
149149

150150
## Requirements
151151

152-
Gridstack no longer requires external dependencies as of v1.0.0 (lodash was removed in v0.5.0 and jquery API in v1.0.0). All you need to include is `gridstack.all.js` and `gridstack.css` (layouts are done using CSS column based %).
152+
GridStack no longer requires external dependencies as of v1.0.0 (lodash was removed in v0.5.0 and jquery API in v1.0.0). All you need to include is `gridstack.all.js` and `gridstack.css` (layouts are done using CSS column based %).
153153

154154
## API Documentation
155155

@@ -365,7 +365,7 @@ make sure to read v1 migration first!
365365
366366
v2.x is a Typescript rewrite of 1.x, removing all jquery events, using classes and overall code cleanup to support ES6 modules. Your code might need to change from 1.x
367367
368-
1. In general methods that used no args (getter) vs setter can't be used in TS when the arguments differ (set/get are also not function calls so API would have changed). Instead we decided to have <b>all set methods return</b> `GridStack` to they can be chain-able (ex: `grid.float(true).cellHeight(10).column(6)`). Also legacy methods that used to take many parameters will now take a single object (typically `GridstackOptions` or `GridStackWidget`).
368+
1. In general methods that used no args (getter) vs setter can't be used in TS when the arguments differ (set/get are also not function calls so API would have changed). Instead we decided to have <b>all set methods return</b> `GridStack` to they can be chain-able (ex: `grid.float(true).cellHeight(10).column(6)`). Also legacy methods that used to take many parameters will now take a single object (typically `GridStackOptions` or `GridStackWidget`).
369369
370370
```
371371
`addWidget(el, x, y, width, height)` --> `addWidget(el, {with: 2})`

doc/CHANGES.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8-
- [2.0.0-dev (2020-09-07)](#200-dev-2020-09-07)
8+
- [2.0.0-dev](#200-dev)
9+
- [2.0.0 (2020-09-07)](#200-2020-09-07)
910
- [1.2.1 (2020-09-04)](#121-2020-09-04)
1011
- [1.2.0 (2020-08-01)](#120-2020-08-01)
1112
- [1.1.2 (2020-05-17)](#112-2020-05-17)
@@ -36,7 +37,12 @@ Change log
3637

3738
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3839

39-
## 2.0.0-dev (2020-09-07)
40+
## 2.0.0-dev
41+
42+
- fix `minWidth()`, `minHeight()`, `maxHeight()` to set node value as well [1359](https://github.com/gridstack/gridstack.js/issues/1359)
43+
- fix `GridStackOptions` spelling [1359](https://github.com/gridstack/gridstack.js/issues/1359)
44+
45+
## 2.0.0 (2020-09-07)
4046

4147
- re-write to native Typescript, removing all JQuery from main code and API (drag&drop plugin still using jqueryui for now)
4248
- add `getGridItems()` to return list of HTML grid items

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gridstack",
3-
"version": "2.0.0",
3+
"version": "2.0.0-dev",
44
"description": "TypeScript/Javascript lib for dashboard layout and creation, no external dependencies, with many wrappers (React, Angular, Ember, knockout...)",
55
"main": "./dist/gridstack.js",
66
"types": "./dist/gridstack.d.ts",

src/gridstack-dd.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack-dd.ts 2.0.0 @preserve
1+
// gridstack-dd.ts 2.0.0-dev @preserve
22

33
/**
44
* https://gridstackjs.com/
@@ -12,7 +12,7 @@ import { GridItemHTMLElement, DDDragInOpt } from './types';
1212

1313
/** Drag&Drop drop options */
1414
export type DDDropOpt = {
15-
/** function or class type that this grid will accept as dropped items (see GridstackOptions.acceptWidgets) */
15+
/** function or class type that this grid will accept as dropped items (see GridStackOptions.acceptWidgets) */
1616
accept?: (el: GridItemHTMLElement) => boolean;
1717
}
1818

src/gridstack-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack-engine.ts 2.0.0 @preserve
1+
// gridstack-engine.ts 2.0.0-dev @preserve
22

33
/**
44
* https://gridstackjs.com/

src/gridstack.ts

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack.ts 2.0.0 @preserve
1+
// gridstack.ts 2.0.0-dev @preserve
22

33
/**
44
* https://gridstackjs.com/
@@ -9,7 +9,7 @@ import './gridstack-poly.js';
99

1010
import { GridStackEngine } from './gridstack-engine';
1111
import { obsoleteOpts, obsoleteOptsDel, obsoleteAttr, obsolete, Utils } from './utils';
12-
import { GridItemHTMLElement, GridStackWidget, GridStackNode, GridstackOptions, numberOrString } from './types';
12+
import { GridItemHTMLElement, GridStackWidget, GridStackNode, GridStackOptions, numberOrString } from './types';
1313
import { GridStackDD } from './gridstack-dd';
1414

1515
// export all dependent file as well to make it easier for users to just import the main file
@@ -71,7 +71,7 @@ export class GridStack {
7171
* Note: the HTMLElement (of type GridHTMLElement) will store a `gridstack: GridStack` value that can be retrieve later
7272
* let grid = document.querySelector('.grid-stack').gridstack;
7373
*/
74-
public static init(options: GridstackOptions = {}, elOrString: GridStackElement = '.grid-stack'): GridStack {
74+
public static init(options: GridStackOptions = {}, elOrString: GridStackElement = '.grid-stack'): GridStack {
7575
let el = GridStack.getGridElement(elOrString);
7676
if (!el) {
7777
if (typeof elOrString === 'string') {
@@ -97,7 +97,7 @@ export class GridStack {
9797
* let grids = GridStack.initAll();
9898
* grids.forEach(...)
9999
*/
100-
public static initAll(options: GridstackOptions = {}, selector = '.grid-stack'): GridStack[] {
100+
public static initAll(options: GridStackOptions = {}, selector = '.grid-stack'): GridStack[] {
101101
let grids: GridStack[] = [];
102102
GridStack.getGridElements(selector).forEach(el => {
103103
if (!el.gridstack) {
@@ -125,7 +125,7 @@ export class GridStack {
125125
public engine: GridStackEngine;
126126

127127
/** grid options - public for classes to access, but use methods to modify! */
128-
public opts: GridstackOptions;
128+
public opts: GridStackOptions;
129129

130130
/** current drag&drop plugin being used */
131131
public dd: GridStackDD;
@@ -150,7 +150,7 @@ export class GridStack {
150150
* @param el
151151
* @param opts
152152
*/
153-
public constructor(el: GridHTMLElement, opts: GridstackOptions = {}) {
153+
public constructor(el: GridHTMLElement, opts: GridStackOptions = {}) {
154154
this.el = el; // exposed HTML element to the user
155155
opts = opts || {}; // handles null/undefined/0
156156

@@ -172,7 +172,7 @@ export class GridStack {
172172
let rowAttr = Utils.toNumber(el.getAttribute('data-gs-row'));
173173

174174
// elements attributes override any passed options (like CSS style) - merge the two together
175-
let defaults: GridstackOptions = {
175+
let defaults: GridStackOptions = {
176176
column: Utils.toNumber(el.getAttribute('data-gs-column')) || 12,
177177
minRow: rowAttr ? rowAttr : Utils.toNumber(el.getAttribute('data-gs-min-row')) || 0,
178178
maxRow: rowAttr ? rowAttr : Utils.toNumber(el.getAttribute('data-gs-max-row')) || 0,
@@ -429,7 +429,7 @@ export class GridStack {
429429
}
430430

431431
/**
432-
* Update current cell height - see `GridstackOptions.cellHeight` for format.
432+
* Update current cell height - see `GridStackOptions.cellHeight` for format.
433433
* This method rebuilds an internal CSS style sheet.
434434
* Note: You can expect performance issues if call this method too often.
435435
*
@@ -720,17 +720,7 @@ export class GridStack {
720720
* @param val A numeric value of the number of columns
721721
*/
722722
public maxWidth(els: GridStackElement, val: number): GridStack {
723-
this.getElements(els).forEach(el => {
724-
let node = el.gridstackNode;
725-
if (!node) { return }
726-
node.maxWidth = (val || undefined);
727-
if (val) {
728-
el.setAttribute('data-gs-max-width', String(val));
729-
} else {
730-
el.removeAttribute('data-gs-max-width');
731-
}
732-
});
733-
return this;
723+
return this._updateAttr(els, val, 'data-gs-max-width', 'maxWidth');
734724
}
735725

736726
/**
@@ -739,16 +729,7 @@ export class GridStack {
739729
* @param val A numeric value of the number of columns
740730
*/
741731
public minWidth(els: GridStackElement, val: number): GridStack {
742-
this.getElements(els).forEach(el => {
743-
let node = el.gridstackNode;
744-
if (!node) { return }
745-
if (val) {
746-
el.setAttribute('data-gs-min-width', String(val));
747-
} else {
748-
el.removeAttribute('data-gs-min-width');
749-
}
750-
});
751-
return this;
732+
return this._updateAttr(els, val, 'data-gs-min-width', 'minWidth');
752733
}
753734

754735
/**
@@ -757,16 +738,7 @@ export class GridStack {
757738
* @param val A numeric value of the number of rows
758739
*/
759740
public maxHeight(els: GridStackElement, val: number): GridStack {
760-
this.getElements(els).forEach(el => {
761-
let node = el.gridstackNode;
762-
if (!node) { return }
763-
if (val) {
764-
el.setAttribute('data-gs-max-height', String(val));
765-
} else {
766-
el.removeAttribute('data-gs-max-height');
767-
}
768-
});
769-
return this;
741+
return this._updateAttr(els, val, 'data-gs-max-height', 'maxHeight');
770742
}
771743

772744
/**
@@ -775,16 +747,7 @@ export class GridStack {
775747
* @param val A numeric value of the number of rows
776748
*/
777749
public minHeight(els: GridStackElement, val: number): GridStack {
778-
this.getElements(els).forEach(el => {
779-
let node = el.gridstackNode;
780-
if (!node) { return }
781-
if (val) {
782-
el.setAttribute('data-gs-min-height', String(val));
783-
} else {
784-
el.removeAttribute('data-gs-min-height');
785-
}
786-
});
787-
return this;
750+
return this._updateAttr(els, val, 'data-gs-min-height', 'minHeight');
788751
}
789752

790753
/**
@@ -1020,9 +983,9 @@ export class GridStack {
1020983
}
1021984

1022985
/**
1023-
* Updates the margins which will set all 4 sides at once - see `GridstackOptions.margin` for format options.
986+
* Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options.
1024987
* @param value new vertical margin value
1025-
* Note: you can instead use `marginTop | marginBottom | marginLeft | marginRight` GridstackOptions to set the sides separately.
988+
* Note: you can instead use `marginTop | marginBottom | marginLeft | marginRight` GridStackOptions to set the sides separately.
1026989
*/
1027990
public margin(value: numberOrString): GridStack {
1028991
let data = Utils.parseHeight(value);
@@ -1797,6 +1760,21 @@ export class GridStack {
17971760
return this;
17981761
}
17991762

1763+
/** @internal called to update an element(s) attributes and node values */
1764+
private _updateAttr(els: GridStackElement, val: number, attr: string, field: string): GridStack {
1765+
this.getElements(els).forEach(el => {
1766+
if (val) {
1767+
el.setAttribute(attr, String(val));
1768+
} else {
1769+
el.removeAttribute(attr);
1770+
}
1771+
if (el.gridstackNode) {
1772+
el.gridstackNode[field] = (val || undefined);
1773+
}
1774+
});
1775+
return this;
1776+
}
1777+
18001778
// legacy method renames
18011779
/** @internal */
18021780
private setGridWidth = obsolete(this, GridStack.prototype.column, 'setGridWidth', 'column', 'v0.5.3');

src/jq/gridstack-dd-jqueryui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// gridstack-dd-jqueryui.ts 2.0.0 @preserve
1+
// gridstack-dd-jqueryui.ts 2.0.0-dev @preserve
22

33
/** JQuery UI Drag&Drop plugin
44
* https://gridstackjs.com/

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// types.ts 2.0.0 @preserve
1+
// types.ts 2.0.0-dev @preserve
22

33
/**
44
* https://gridstackjs.com/
@@ -20,7 +20,7 @@ export interface GridItemHTMLElement extends HTMLElement {
2020
/**
2121
* Defines the options for a Grid
2222
*/
23-
export interface GridstackOptions {
23+
export interface GridStackOptions {
2424
/**
2525
* accept widgets dragged from other grids or from outside (default: `false`). Can be:
2626
* `true` (uses `'.grid-stack-item'` class filter) or `false`,
@@ -173,7 +173,7 @@ export interface GridstackOptions {
173173

174174

175175
/**
176-
* Gridstack Widget creation options
176+
* GridStack Widget creation options
177177
*/
178178
export interface GridStackWidget {
179179
/** widget position x (default?: 0) */

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// utils.ts 2.0.0 @preserve
1+
// utils.ts 2.0.0-dev @preserve
22

33
/**
44
* https://gridstackjs.com/
55
* (c) 2014-2020 Alain Dumesny, Dylan Weiss, Pavel Reznikov
66
* gridstack.js may be freely distributed under the MIT license.
77
*/
88

9-
import { GridStackWidget, GridStackNode, GridstackOptions, numberOrString } from './types';
9+
import { GridStackWidget, GridStackNode, GridStackOptions, numberOrString } from './types';
1010

1111
/** checks for obsolete method names */
1212
export function obsolete(self, f, oldName: string, newName: string, rev: string) {
@@ -20,7 +20,7 @@ export function obsolete(self, f, oldName: string, newName: string, rev: string)
2020
}
2121

2222
/** checks for obsolete grid options (can be used for any fields, but msg is about options) */
23-
export function obsoleteOpts(opts: GridstackOptions, oldName: string, newName: string, rev: string) {
23+
export function obsoleteOpts(opts: GridStackOptions, oldName: string, newName: string, rev: string) {
2424
if (opts[oldName] !== undefined) {
2525
opts[newName] = opts[oldName];
2626
console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + ' and has been replaced with `' +
@@ -29,7 +29,7 @@ export function obsoleteOpts(opts: GridstackOptions, oldName: string, newName: s
2929
}
3030

3131
/** checks for obsolete grid options which are gone */
32-
export function obsoleteOptsDel(opts: GridstackOptions, oldName: string, rev: string, info: string) {
32+
export function obsoleteOptsDel(opts: GridStackOptions, oldName: string, rev: string, info: string) {
3333
if (opts[oldName] !== undefined) {
3434
console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + info);
3535
}

0 commit comments

Comments
 (0)