Skip to content

Commit 5dc62fe

Browse files
authored
Merge pull request #2132 from adumesny/master
rev 7.1.2
2 parents 744f707 + 497a1fc commit 5dc62fe

25 files changed

+64
-42
lines changed

Gruntfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ module.exports = function(grunt) {
4242
'dist/es5/gridstack-poly.js': ['src/gridstack-poly.js'],
4343
'dist/src/gridstack.scss': ['src/gridstack.scss'],
4444
'dist/src/gridstack-extra.scss': ['src/gridstack-extra.scss'],
45+
'dist/angular/README.md': ['demo/angular/src/app/README.md'],
46+
'dist/angular/gridstack.component.ts': ['demo/angular/src/app/gridstack.component.ts'],
47+
'dist/angular/gridstack-item.component.ts': ['demo/angular/src/app/gridstack-item.component.ts'],
4548
}
4649
}
4750
},

demo/angular/src/app/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public gridOptions: GridStackOptions = {
1616
float: true,
1717
}
1818
public items: GridStackWidget[] = [
19-
{x:0, y:0, minW:2},
20-
{x:1, y:1},
21-
{x:2, y:2},
19+
{x:0, y:0, minW:2, id:'1'},
20+
{x:1, y:1, id:'2'},
21+
{x:2, y:2, id:'3'},
2222
];
2323

2424
// called whenever items change size/position/etc..
@@ -28,7 +28,7 @@ public onChange(data: nodesCB) {
2828

2929
// ngFor unique node id to have correct match between our items used and GS
3030
public identify(index: number, w: GridStackWidget) {
31-
return w.id;
31+
return w.id; // or use index if no id is set and you only modify at the end...
3232
}
3333
```
3434
HTML
@@ -50,3 +50,8 @@ to build the demo, go to demo/angular and run `yarn` + `yarn start` and Navigate
5050
- This wrapper needs v7.1.2+ to run as it needs the latest changes
5151
- This wrapper handles well ngFor loops, but if you're using a trackBy function (as I would recommend) and no element id change after an update, you must manually call the `Gridstack.update()` method directly.
5252
- The original client list of items is not updated to match **content** changes made by gridstack (TBD later), but adding new item or removing (as shown in demo) will update those new items. Client could use change/added/removed events to sync that list if they wish to do so now.
53+
- Code isn't compiled into a side lib to use right now - you need to copy those files for now. Let me know (slack) if you are using it...
54+
55+
thank you!
56+
Would appreciate getting help doing the same for React and Vue (2 other popular frameworks)
57+
- Alain

demo/angular/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<p><b>COMPONENT</b>: Most complete example that uses Component wrapper for grid and gridItem</p>
1717
<button (click)="add(grid)">add item</button>
1818
<button (click)="delete(grid)">remove item</button>
19-
<button (click)="change(grid)">modify item</button>
19+
<button (click)="modify(grid)">modify item</button>
2020
<button (click)="newLayout(grid)">new layout</button>
2121
<gridstack #grid [options]="gridOptions" (changeCB)="onChange($event)" (resizestopCB)="onResizeStop($event)">
2222
<gridstack-item *ngFor="let n of items; trackBy: identify" [options]="n">

demo/angular/src/app/app.component.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,25 @@ export class AppComponent {
4545
/**
4646
* CRUD TEST operations
4747
*/
48-
public add(comp: GridstackComponent) {
49-
// new array isn't required as Angular seem to detect changes to content
48+
public add(gridComp: GridstackComponent) {
49+
// new array isn't required as Angular detects changes to content with trackBy:identify()
5050
// this.items = [...this.items, { x:3, y:0, w:3, content:`item ${ids}`, id:String(ids++) }];
51-
this.items.push({ x:3, y:0, w:3, content:`item ${ids}`, id:String(ids++)});
51+
this.items.push({x:3, y:0, w:3, content:`item ${ids}`, id:String(ids++)});
5252
}
5353

54-
public delete(comp: GridstackComponent) {
54+
public delete(gridComp: GridstackComponent) {
5555
this.items.pop();
5656
}
5757

58-
public change(comp: GridstackComponent) {
59-
// this will not update the DOM nor trigger gridstackItems.changes for GS to auto-update, so call GS update() instead
58+
public modify(gridComp: GridstackComponent) {
59+
// this will not update the DOM nor trigger gridstackItems.changes for GS to auto-update, so set new option of the gridItem instead
6060
// this.items[0].w = 3;
61-
// comp.updateAll();
62-
const n = comp.grid?.engine.nodes[0];
63-
if (n?.el) comp.grid?.update(n.el, {w:3});
61+
const gridItem = gridComp.gridstackItems?.get(0);
62+
if (gridItem) gridItem.options = {w:3};
6463
}
6564

6665
/** test updating existing and creating new one */
67-
public newLayout(comp: GridstackComponent) {
66+
public newLayout(gridComp: GridstackComponent) {
6867
this.items = [
6968
{x:0, y:1, id:'1', minW:1, w:1}, // new size/constrain
7069
{x:1, y:1, id:'2'},
@@ -75,6 +74,6 @@ export class AppComponent {
7574

7675
// ngFor unique node id to have correct match between our items used and GS
7776
public identify(index: number, w: GridStackWidget) {
78-
return w.id;
77+
return w.id; // or use index if no id is set and you only modify at the end...
7978
}
8079
}

demo/angular/src/app/gridstack-item.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
/**
2+
* gridstack-item.component.ts 7.1.2
3+
* Copyright (c) 2022 Alain Dumesny - see GridStack root license
4+
*/
5+
16
import { ChangeDetectionStrategy, Component, ElementRef, Input } from '@angular/core';
27
import { GridItemHTMLElement, GridStackNode } from 'gridstack';
38

9+
/**
10+
* HTML Component Wrapper for gridstack items, in combination with GridstackComponent for parent grid
11+
*/
412
@Component({
513
selector: 'gridstack-item',
614
template: `
@@ -14,13 +22,15 @@ import { GridItemHTMLElement, GridStackNode } from 'gridstack';
1422
})
1523
export class GridstackItemComponent {
1624

17-
/** list of options for creating this item */
25+
/** list of options for creating/updating this item */
1826
@Input() public set options(val: GridStackNode) {
19-
val.el = this.element; // connect this element to options so we can convert to widget later
2027
if (this.element.gridstackNode?.grid) {
28+
// already built, do an update...
2129
this.element.gridstackNode.grid.update(this.element, val);
2230
} else {
23-
this._options = val; // store initial values (before we're built)
31+
// store our custom element in options so we can update it and not re-create a generic div!
32+
val.el = this.element;
33+
this._options = val;
2434
}
2535
}
2636
/** return the latest grid options (from GS once built, otherwise initial values) */

demo/angular/src/app/gridstack.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* gridstack.component.ts 7.1.2
3+
* Copyright (c) 2022 Alain Dumesny - see GridStack root license
4+
*/
5+
16
import { AfterContentInit, ChangeDetectionStrategy, Component, ContentChildren, ElementRef, EventEmitter, Input,
27
NgZone, OnDestroy, OnInit, Output, QueryList } from '@angular/core';
38
import { Subject } from 'rxjs';

demo/angular/src/app/ngFor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let ids = 1;
1414
<p><b>ngFor</b>: Example using Angular ngFor to loop through items and create DOM items. This track changes made to the array of items, waits for DOM rendering, then update GS</p>
1515
<button (click)="add()">add item</button>
1616
<button (click)="delete()">remove item</button>
17-
<button (click)="change()">modify item</button>
17+
<button (click)="modify()">modify item</button>
1818
<button (click)="newLayout()">new layout</button>
1919
<div class="grid-stack">
2020
<!-- using angular templating to create DOM, otherwise an easier way is to simply call grid.load(items)
@@ -107,7 +107,7 @@ export class AngularNgForTestComponent implements AfterViewInit {
107107
this.items.pop();
108108
}
109109

110-
public change() {
110+
public modify() {
111111
// this will only update the DOM attr (from the ngFor loop in our template above)
112112
// but not trigger gridstackItems.changes for GS to auto-update, so call GS update() instead
113113
// this.items[0].w = 2;

demo/angular/src/app/ngFor_cmd.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { GridItemHTMLElement, GridStack, GridStackWidget } from 'gridstack';
1414
<p><b>ngFor CMD</b>: Example using Angular ngFor to loop through items, but uses an explicity command to let us update GS (see automatic better way)</p>
1515
<button (click)="add()">add item</button>
1616
<button (click)="delete()">remove item</button>
17-
<button (click)="change()">modify item</button>
17+
<button (click)="modify()">modify item</button>
1818
<div class="grid-stack">
1919
<!-- using angular templating to create DOM, otherwise an easier way is to simply call grid.load(items) -->
2020
<div
@@ -94,7 +94,7 @@ export class AngularNgForCmdTestComponent implements AfterViewInit {
9494
}
9595

9696
// a change of a widget doesn´t change to amount of items in ngFor therefore we don´t need to do it through the zip function above
97-
public change() {
97+
public modify() {
9898
const updateEl = this.grid.getGridItems().find((el) => el.id === `${0}`);
9999
this.grid.update(updateEl!, { w: 2 });
100100
}

doc/CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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-
- [7.1.1-dev (TBD)](#711-dev-tbd)
8+
- [7.1.2 (2022-12-29)](#712-2022-12-29)
99
- [7.1.1 (2022-11-13)](#711-2022-11-13)
1010
- [7.1.0 (2022-10-23)](#710-2022-10-23)
1111
- [7.0.1 (2022-10-14)](#701-2022-10-14)
@@ -77,7 +77,7 @@ Change log
7777

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

80-
## 7.1.1-dev (TBD)
80+
## 7.1.2 (2022-12-29)
8181
* fix [#939](https://github.com/gridstack/gridstack.js/issues/2039) 'prototype' undefined error for dd-gridstack.js
8282
* add [#939](https://github.com/gridstack/gridstack.js/issues/2105) disable/enable are methods now recursive by default
8383
* add better `GridStackEventHandlerCallback` spelled out types

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": "7.1.1-dev",
3+
"version": "7.1.2",
44
"description": "TypeScript/JS lib for dashboard layout and creation, responsive, mobile support, no external dependencies, with many wrappers (React, Angular, Vue, Ember, knockout...)",
55
"main": "./dist/gridstack.js",
66
"types": "./dist/gridstack.d.ts",

src/dd-base-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-base-impl.ts 7.1.1-dev
2+
* dd-base-impl.ts 7.1.2
33
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-draggable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-draggable.ts 7.1.1-dev
2+
* dd-draggable.ts 7.1.2
33
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-droppable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-droppable.ts 7.1.1-dev
2+
* dd-droppable.ts 7.1.2
33
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-elements.ts 7.1.1-dev
2+
* dd-elements.ts 7.1.2
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-gridstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-gridstack.ts 7.1.1-dev
2+
* dd-gridstack.ts 7.1.2
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-manager.ts 7.1.1-dev
2+
* dd-manager.ts 7.1.2
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-resizable-handle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-resizable-handle.ts 7.1.1-dev
2+
* dd-resizable-handle.ts 7.1.2
33
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-resizable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* dd-resizable.ts 7.1.1-dev
2+
* dd-resizable.ts 7.1.2
33
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44
*/
55

src/dd-touch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* touch.ts 7.1.1-dev
2+
* touch.ts 7.1.2
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

src/gridstack-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gridstack-engine.ts 7.1.1-dev
2+
* gridstack-engine.ts 7.1.2
33
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44
*/
55

src/gridstack-poly.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gridstack-poly.ts 7.1.1-dev used for IE and older browser support (not supported in v2-v4.3.1, but again in v4.4)
2+
* gridstack-poly.ts 7.1.2 used for IE and older browser support (not supported in v2-v4.3.1, but again in v4.4)
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

src/gridstack.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gridstack SASS styles 7.1.1-dev
2+
* gridstack SASS styles 7.1.2
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

src/gridstack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* GridStack 7.1.1-dev
2+
* GridStack 7.1.2
33
* https://gridstackjs.com/
44
*
55
* Copyright (c) 2021-2022 Alain Dumesny
@@ -1614,7 +1614,7 @@ export class GridStack {
16141614
return this;
16151615
}
16161616

1617-
static GDRev = '7.1.1-dev';
1617+
static GDRev = '7.1.2';
16181618

16191619
/* ===========================================================================================
16201620
* drag&drop methods that used to be stubbed out and implemented in dd-gridstack.ts

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* types.ts 7.1.1-dev
2+
* types.ts 7.1.2
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* utils.ts 7.1.1-dev
2+
* utils.ts 7.1.2
33
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
44
*/
55

0 commit comments

Comments
 (0)