Skip to content

Commit ab9c283

Browse files
committed
TS: v2.0.0-rc release candidate
1 parent 716c2d6 commit ab9c283

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
lines changed

README.md

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Join us on Slack: https://gridstackjs.troolee.com
3737
- [Custom columns CSS](#custom-columns-css)
3838
- [Override resizable/draggable options](#override-resizabledraggable-options)
3939
- [Touch devices support](#touch-devices-support)
40-
- [Migrating to v0.6.x](#migrating-to-v06x)
41-
- [Migrating to v1.0.0](#migrating-to-v100)
40+
- [Migrating to v0.6](#migrating-to-v06)
41+
- [Migrating to v1](#migrating-to-v1)
4242
- [jQuery Application](#jquery-application)
43-
- [Migrating to v2.0.0](#migrating-to-v200)
43+
- [Migrating to v2](#migrating-to-v2)
4444
- [Changes](#changes)
4545
- [The Team](#the-team)
4646

@@ -70,44 +70,66 @@ npm install --save gridstack
7070

7171
## Include
7272

73-
after you install:
73+
ES6 or Typescript
74+
75+
```js
76+
import { GridStack } from 'gridstack';
77+
import 'gridstack/dist/gridstack.css';
78+
```
79+
80+
legacy javascript
7481

7582
```js
7683
import 'gridstack/dist/gridstack.all.js';
7784
import 'gridstack/dist/gridstack.css';
7885
```
79-
* alternatively in html
86+
87+
alternatively in html
8088

8189
```html
8290
<link rel="stylesheet" href="node_modules/gridstack/dist/gridstack.min.css" />
8391
<script src="node_modules/gridstack/dist/gridstack.all.js"></script>
8492
```
8593

86-
* or using CDN (minimized):
94+
or using CDN (minimized):
8795

8896
```html
89-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gridstack@1.2.0/dist/gridstack.min.css" />
90-
<script src="https://cdn.jsdelivr.net/npm/gridstack@1.2.0/dist/gridstack.all.js"></script>
97+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gridstack@2.0.0-rc/dist/gridstack.min.css" />
98+
<script src="https://cdn.jsdelivr.net/npm/gridstack@2.0.0-rc/dist/gridstack.all.js"></script>
9199
```
92100

93-
if you need to debug, look at the git demo/ examples for non min includes.
101+
.map files are included for debugging purposes.
94102

95103
## Basic usage
96104

97105
creating items dynamically...
98106

99-
```html
107+
```js
108+
// ...in your HTML
100109
<div class="grid-stack"></div>
101110

102-
<script type="text/javascript">
103-
let grid = GridStack.init();
104-
grid.addWidget('<div><div class="grid-stack-item-content">Item 1</div></div>', {width: 2});
105-
</script>
111+
// ...in your script
112+
var grid = GridStack.init();
113+
grid.addWidget('<div><div class="grid-stack-item-content">Item 1</div></div>', {width: 2});
114+
```
115+
116+
... or creating from list
117+
118+
```js
119+
// using serialize data instead of .addWidget()
120+
const serializedData = [
121+
{x: 0, y: 0, width: 2, height: 2},
122+
{x: 2, y: 3, width: 3, height: 1},
123+
{x: 1, y: 3, width: 1, height: 1}
124+
];
125+
126+
grid.load(serializedData);
106127
```
107128

108129
... or DOM created items
109130

110-
```html
131+
```js
132+
// ...in your HTML
111133
<div class="grid-stack">
112134
<div class="grid-stack-item">
113135
<div class="grid-stack-item-content">Item 1</div>
@@ -117,9 +139,8 @@ creating items dynamically...
117139
</div>
118140
</div>
119141

120-
<script type="text/javascript">
121-
GridStack.init();
122-
</script>
142+
// ...in your script
143+
GridStack.init();
123144
```
124145

125146
see [jsfiddle sample](https://jsfiddle.net/adumesny/jqhkry7g) as running example too.
@@ -276,24 +297,24 @@ GridStack.init(options);
276297
If you're still experiencing issues on touch devices please check [#444](https://github.com/gridstack/gridstack.js/issues/444)
277298

278299

279-
## Migrating to v0.6.x
300+
## Migrating to v0.6
280301

281302
starting in 0.6.x `change` event are no longer sent (for pretty much most nodes!) when an item is just added/deleted unless it also changes other nodes (was incorrect and causing inefficiencies). You may need to track `added|removed` [events](https://github.com/gridstack/gridstack.js/tree/develop/doc#events) if you didn't and relied on the old broken behavior.
282303

283-
## Migrating to v1.0.0
304+
## Migrating to v1
284305

285306
v1.0.0 removed Jquery from the API and external dependencies, which will require some code changes. Here is a list of the changes:
286307

287-
1. see [Migrating to v0.6.x](#migrating-to-v06x) if you didn't already
308+
1. see [Migrating to v0.6](#migrating-to-v06) if you didn't already
288309

289-
2. your code only needs to include `gridstack.all.js` and `gristack.css` (don't include other JS) and is recommended you do that as internal dependencies will change over time. If you are jquery based, also see note below.
310+
2. your code only needs to include `gridstack.all.js` and `gristack.css` (don't include other JS) and is recommended you do that as internal dependencies will change over time. If you are jquery based, see [jquery app](#jquery-application) below.
290311

291312
3. code change:
292313

293314
**OLD** initializing code + adding a widget + adding an event:
294315
```js
295316
// initialization returned Jquery element, requiring second call to get GridStack var
296-
let grid = $('.grid-stack').gridstack(opts?).data('gridstack');
317+
var grid = $('.grid-stack').gridstack(opts?).data('gridstack');
297318

298319
// returned Jquery element
299320
grid.addWidget($('<div><div class="grid-stack-item-content"> test </div></div>'), undefined, undefined, 2, undefined, true);
@@ -302,13 +323,13 @@ grid.addWidget($('<div><div class="grid-stack-item-content"> test </div></div>')
302323
$('.grid-stack').on('added', function(e, items) {/* items contains info */});
303324

304325
// grid access after init
305-
let grid = $('.grid-stack').data('gridstack');
326+
var grid = $('.grid-stack').data('gridstack');
306327
```
307328
**NEW**
308329
```js
309330
// element identifier defaults to '.grid-stack', returns the grid
310-
// Note: for Typescript use window.GridStack.init() until next native TS version
311-
let grid = GridStack.init(opts?, element?);
331+
// Note: for Typescript use window.GridStack.init() until next native 2.x TS version
332+
var grid = GridStack.init(opts?, element?);
312333

313334
// returns DOM element
314335
grid.addWidget('<div><div class="grid-stack-item-content"> test </div></div>', {width: 2});
@@ -317,9 +338,9 @@ grid.addWidget('<div><div class="grid-stack-item-content"> test </div></div>', {
317338
grid.on('added', function(e, items) {/* items contains info */});
318339

319340
// grid access after init
320-
let grid = el.gridstack; // where el = document.querySelector('.grid-stack') or other ways...
341+
var grid = el.gridstack; // where el = document.querySelector('.grid-stack') or other ways...
321342
```
322-
Other vars/global changes
343+
Other changes
323344
```
324345
`GridStackUI` --> `GridStack`
325346
`GridStackUI.GridStackEngine` --> `GridStack.Engine`
@@ -332,22 +353,23 @@ Recommend looking at the [many samples](./demo) for more code examples.
332353
333354
### jQuery Application
334355
335-
We're working on implementing HTML5 drag'n'drop through the plugin system. Right now it is still jquery-ui based. Because of that we are still bundling `jquery` (3.5.1) + `jquery-ui` (1.12.1 minimal drag|drop|resize) internally in `gridstack.all.js`. IFF your app needs to bring your own version instead, you should **instead** include `gridstack-poly.min.js` (optional IE support) + `gridstack.min.js` + `gridstack.jQueryUI.min.js` after you import your JQ libs. But note that there are issue with jQuery and ES6 import (see [1306](https://github.com/gridstack/gridstack.js/issues/1306))
356+
We're working on implementing HTML5 drag'n'drop through the plugin system. Right now it is still jquery-ui based. Because of that we are still bundling `jquery` (3.5.1) + `jquery-ui` (1.12.1 minimal drag|drop|resize) internally in `gridstack.all.js`. IFF your app needs to bring your own version instead, you should **instead** include `gridstack-poly.min.js` (optional IE support) + `gridstack.min.js` + `gridstack.jQueryUI.min.js` after you import your JQ libs. But note that there are issue with jQuery and ES6 import (see [1306](https://github.com/gridstack/gridstack.js/issues/1306)).
357+
358+
Note: v2.0.-rc does not currently support importing GridStack Drag&Drop without also including our jquery + jqueryui. Still trying to figure how to make that bundle possible.
336359
337-
## Migrating to v2.0.0
360+
## Migrating to v2
338361
339-
make sure to read v1.0.0 migration first!
362+
make sure to read v1 migration first!
340363
341-
v2.x is a Typescript rewrite of 1.x, removing all jquery events, using classes and overall code cleanup. Your code might need to change from 1.x
364+
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
342365
343-
1. In general methods that used no args (getter) vs setter are not used in Typescript when the arguments differ.
344-
Also legacy methods that used to take many parameters will now take a single object (typically `GridstackOptions` or `GridStackWidget`).
366+
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`).
345367
346368
```
347-
removed `addWidget(el, x, y, width, ...)` --> use the widget options version instead `addWidget(el, {with, ...})`
369+
`addWidget(el, x, y, width, height)` --> `addWidget(el, {with: 2})`
348370
`float()` to get value --> `getFloat()`
349371
'cellHeight()` to get value --> `getCellHeight()`
350-
'verticalMargin' is now 'margin' grid options and applies to all 4 sides.
372+
'verticalMargin' is now 'margin' grid options and API that applies to all 4 sides.
351373
'verticalMargin()` to get value --> `getMargin()`
352374
```
353375

doc/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Change log
3737

3838
## 2.0.0-dev (upcoming)
3939

40-
- re-write to native Typescript, removing all JQuery from main code and API (drag&drop plugin still using for now which use latest v3.5.1)
40+
- re-write to native Typescript, removing all JQuery from main code and API (drag&drop plugin still using jqueryui for now)
4141
- add `getGridItems()` to return list of HTML grid items
4242
- add `{dragIn | dragInOptions}` grid attributes to handle external drag&drop items
4343
- add `save()` and `load()` to serialize grids from JSON, saving all attributes (not just w,h,x,y) [1286](https://github.com/gridstack/gridstack.js/issues/1286)

0 commit comments

Comments
 (0)