diff --git a/Gruntfile.js b/Gruntfile.js index e5efd75ef..f2e5049e6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -38,7 +38,6 @@ module.exports = function(grunt) { copy: { dist: { files: { - 'dist/es5/gridstack-poly.js': ['src/gridstack-poly.js'], 'dist/src/gridstack.scss': ['src/gridstack.scss'], 'dist/angular/README.md': ['angular/README.md'], 'dist/angular/src/gridstack.component.ts': ['angular/projects/lib/src/lib/gridstack.component.ts'], diff --git a/README.md b/README.md index 326bec108..360721e91 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Alternatively (single combined file, notice the -all.js) in html ``` -**Note**: IE support was dropped in v2, but restored in v4.4 by an external contributor (I have no interest in testing+supporting obsolete browser so this likely will break again in the future). +**Note**: IE support was dropped in v2, but restored in v4.4 by an external contributor (I have no interest in testing+supporting obsolete browser so this likely will break again in the future) and DROPPED again in v12 (css variable needed). You can use the es5 files and polyfill (larger) for older browser instead. For example: ```html @@ -477,15 +477,18 @@ breaking change: **Breaking change:** +* V11 add new `GridStack.renderCB` that is called for you to create the widget content (entire GridStackWidget is passed so you can use id or some other field as logic) while GS creates the 2 needed parent divs + classes, unlike `GridStack.addRemoveCB` which doesn't create anything for you. Both can be handy for Angular/React/Vue frameworks. +* `addWidget(w: GridStackWidget)` is now the only supported format, no more string content passing. You will need to create content yourself as shown below, OR use `GridStack.createWidgetDivs()` to create parent divs, do the innerHtml, then call `makeWidget(el)` instead. * if your code relies on `GridStackWidget.content` with real HTML (like a few demos) it is up to you to do this: ```ts // NOTE: REAL apps would sanitize-html or DOMPurify before blinding setting innerHTML. see #2736 GridStack.renderCB = function(el: HTMLElement, w: GridStackNode) { el.innerHTML = w.content; }; + +// now you can create widgets like this again +let gridWidget = grid.addWidget({x, y, w, h, content: '
My html content
'}); ``` -* V11 add new `GridStack.renderCB` that is called for you to create the widget content (entire GridStackWidget is passed so you can use id or some other field as logic) while GS creates the 2 needed parent divs + classes, unlike `GridStack.addRemoveCB` which doesn't create anything for you. Both can be handy for Angular/React/Vue frameworks. -* `addWidget(w: GridStackWidget)` is now the only supported format, no more string content passing. You will need to create content yourself (`GridStack.createWidgetDivs()` can be used to create parent divs) then call `makeWidget(el)` instead. **Potential breaking change:** @@ -501,8 +504,10 @@ GridStack.renderCB = function(el: HTMLElement, w: GridStackNode) { * column and cell height code has been re-writen to use browser CSS variables, and we no longer need a tons of custom CSS classes! this fixes a long standing issue where people forget to include the right CSS for non 12 columns layouts, and a big speedup in many cases (many columns, or small cellHeight values). -**Breaking change:** -* `gridstack-extra.min.css` no longer exist, nor is custom column CSS needed. API/options hasn't changed. +**Potential breaking change:** +* `gridstack-extra.min.css` no longer exist, nor is custom column CSS classes needed. API/options hasn't changed. +* (v12.1) `ES5` folder content has been removed - was for IE support, which has been dropped. +* (v12.1) nested grid events are now sent to the main grid. You might have to adjust your workaround of this missing feature. nested.html demo has been adjusted. # jQuery Application diff --git a/angular/package.json b/angular/package.json index 8f175fb5c..073449b14 100644 --- a/angular/package.json +++ b/angular/package.json @@ -18,7 +18,7 @@ "@angular/platform-browser": "^14", "@angular/platform-browser-dynamic": "^14", "@angular/router": "^14", - "gridstack": "^12.0.0", + "gridstack": "^12.2.1", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" diff --git a/angular/projects/lib/src/lib/base-widget.ts b/angular/projects/lib/src/lib/base-widget.ts index 8a0208209..7847abf54 100644 --- a/angular/projects/lib/src/lib/base-widget.ts +++ b/angular/projects/lib/src/lib/base-widget.ts @@ -1,5 +1,5 @@ /** - * gridstack-item.component.ts 12.0.0 + * gridstack-item.component.ts 12.2.1 * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license */ diff --git a/angular/projects/lib/src/lib/gridstack-item.component.ts b/angular/projects/lib/src/lib/gridstack-item.component.ts index 33b6c151c..39278bb67 100644 --- a/angular/projects/lib/src/lib/gridstack-item.component.ts +++ b/angular/projects/lib/src/lib/gridstack-item.component.ts @@ -1,5 +1,5 @@ /** - * gridstack-item.component.ts 12.0.0 + * gridstack-item.component.ts 12.2.1 * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license */ diff --git a/angular/projects/lib/src/lib/gridstack.component.ts b/angular/projects/lib/src/lib/gridstack.component.ts index ca57473e5..9be73d2e4 100644 --- a/angular/projects/lib/src/lib/gridstack.component.ts +++ b/angular/projects/lib/src/lib/gridstack.component.ts @@ -1,10 +1,12 @@ /** - * gridstack.component.ts 12.0.0 + * gridstack.component.ts 12.2.1 * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license */ -import { AfterContentInit, Component, ContentChildren, ElementRef, EventEmitter, Input, - OnDestroy, OnInit, Output, QueryList, Type, ViewChild, ViewContainerRef, reflectComponentType, ComponentRef } from '@angular/core'; +import { + AfterContentInit, Component, ContentChildren, ElementRef, EventEmitter, Input, + OnDestroy, OnInit, Output, QueryList, Type, ViewChild, ViewContainerRef, reflectComponentType, ComponentRef +} from '@angular/core'; import { NgIf } from '@angular/common'; import { Subscription } from 'rxjs'; import { GridHTMLElement, GridItemHTMLElement, GridStack, GridStackNode, GridStackOptions, GridStackWidget } from 'gridstack'; @@ -124,6 +126,9 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy { if (!GridStack.saveCB) { GridStack.saveCB = gsSaveAdditionalNgInfo; } + if (!GridStack.updateCB) { + GridStack.updateCB = gsUpdateNgComponents; + } this.el._gridComp = this; } @@ -178,8 +183,14 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy { /** get all known events as easy to use Outputs for convenience */ protected hookEvents(grid?: GridStack) { if (!grid) return; + // nested grids don't have events in v12.1+ so skip + if (grid.parentGridNode) return; grid - .on('added', (event: Event, nodes: GridStackNode[]) => { this.checkEmpty(); this.addedCB.emit({event, nodes}); }) + .on('added', (event: Event, nodes: GridStackNode[]) => { + const gridComp = (nodes[0].grid?.el as GridCompHTMLElement)._gridComp || this; + gridComp.checkEmpty(); + this.addedCB.emit({event, nodes}); + }) .on('change', (event: Event, nodes: GridStackNode[]) => this.changeCB.emit({event, nodes})) .on('disable', (event: Event) => this.disableCB.emit({event})) .on('drag', (event: Event, el: GridItemHTMLElement) => this.dragCB.emit({event, el})) @@ -187,7 +198,11 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy { .on('dragstop', (event: Event, el: GridItemHTMLElement) => this.dragStopCB.emit({event, el})) .on('dropped', (event: Event, previousNode: GridStackNode, newNode: GridStackNode) => this.droppedCB.emit({event, previousNode, newNode})) .on('enable', (event: Event) => this.enableCB.emit({event})) - .on('removed', (event: Event, nodes: GridStackNode[]) => { this.checkEmpty(); this.removedCB.emit({event, nodes}); }) + .on('removed', (event: Event, nodes: GridStackNode[]) => { + const gridComp = (nodes[0].grid?.el as GridCompHTMLElement)._gridComp || this; + gridComp.checkEmpty(); + this.removedCB.emit({event, nodes}); + }) .on('resize', (event: Event, el: GridItemHTMLElement) => this.resizeCB.emit({event, el})) .on('resizestart', (event: Event, el: GridItemHTMLElement) => this.resizeStartCB.emit({event, el})) .on('resizestop', (event: Event, el: GridItemHTMLElement) => this.resizeStopCB.emit({event, el})) @@ -195,6 +210,8 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy { protected unhookEvents(grid?: GridStack) { if (!grid) return; + // nested grids don't have events in v12.1+ so skip + if (grid.parentGridNode) return; grid.off('added change disable drag dragstart dragstop dropped enable removed resize resizestart resizestop'); } } @@ -301,3 +318,12 @@ export function gsSaveAdditionalNgInfo(n: NgGridStackNode, w: NgGridStackWidget) //.... save any custom data } } + +/** + * track when widgeta re updated (rather than created) to make sure we de-serialize them as well + */ +export function gsUpdateNgComponents(n: NgGridStackNode) { + const w: NgGridStackWidget = n; + const gridItem = (n.el as GridItemCompHTMLElement)?._gridItemComp; + if (gridItem?.childWidget && w.input) gridItem.childWidget.deserialize(w); +} \ No newline at end of file diff --git a/angular/projects/lib/src/lib/gridstack.module.ts b/angular/projects/lib/src/lib/gridstack.module.ts index 5ef414d76..4e1e8bcba 100644 --- a/angular/projects/lib/src/lib/gridstack.module.ts +++ b/angular/projects/lib/src/lib/gridstack.module.ts @@ -1,5 +1,5 @@ /** - * gridstack.component.ts 12.0.0 + * gridstack.component.ts 12.2.1 * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license */ diff --git a/angular/projects/lib/src/lib/types.ts b/angular/projects/lib/src/lib/types.ts index d2daac99f..634de4cb8 100644 --- a/angular/projects/lib/src/lib/types.ts +++ b/angular/projects/lib/src/lib/types.ts @@ -1,5 +1,5 @@ /** - * gridstack-item.component.ts 12.0.0 + * gridstack-item.component.ts 12.2.1 * Copyright (c) 2025 Alain Dumesny - see GridStack root license */ diff --git a/angular/yarn.lock b/angular/yarn.lock index 6a4e9aece..53b0d63af 100644 --- a/angular/yarn.lock +++ b/angular/yarn.lock @@ -3752,10 +3752,10 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4, resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== -gridstack@^12.0.0: - version "12.0.0" - resolved "https://registry.yarnpkg.com/gridstack/-/gridstack-12.0.0.tgz#cb824410436573f480fc9e62c2e3fdf2fa536a9e" - integrity sha512-Wjfu7BtTb4NZqLpSEAJx+b9lBnfnXNgG2jUTVSD2g8NrHITrWgfk9eeHBqtDLVl2vtKQTzsSyy5lSyHAMcW2tA== +gridstack@^12.2.1: + version "12.2.1" + resolved "https://registry.yarnpkg.com/gridstack/-/gridstack-12.2.1.tgz#0e82e3d9d11e5229388d73bd57f8ef1a0e7059c4" + integrity sha512-xU69tThmmVxgMHTuM/z3rIKiiGm0zW4tcB6yRcuwiOUUBiwb3tslzFOrUjWz+PwaxoAW+JChT4fqOLl+oKAxZA== handle-thing@^2.0.0: version "2.0.1" @@ -3895,9 +3895,9 @@ http-proxy-agent@^5.0.0: debug "4" http-proxy-middleware@^2.0.3: - version "2.0.7" - resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.7.tgz#915f236d92ae98ef48278a95dedf17e991936ec6" - integrity sha512-fgVY8AV7qU7z/MmXJ/rxwbrtQH4jBQ9m7kp3llF0liB7glmFeVZFBepQb32T3y8n8k2+AEYuMPCpinYW+/CuRA== + version "2.0.9" + resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.9.tgz#e9e63d68afaa4eee3d147f39149ab84c0c2815ef" + integrity sha512-c1IyJYLYppU574+YI7R4QyX2ystMtVXZwIdzazUIPIJsHuWNd+mho2j+bKoHftndicGj9yh+xjd+l0yj7VeT1Q== dependencies: "@types/http-proxy" "^1.17.8" http-proxy "^1.18.1" diff --git a/demo/events.js b/demo/events.js index d32bbeb76..bca7ae3f8 100644 --- a/demo/events.js +++ b/demo/events.js @@ -1,59 +1,59 @@ function addEvents(grid, id) { - let g = (id !== undefined ? 'grid' + id + ' ' : ''); + let g = (id !== undefined ? 'grid' + id : ''); grid.on('added removed change', function(event, items) { let str = ''; items.forEach(function(item) { str += ' (' + item.x + ',' + item.y + ' ' + item.w + 'x' + item.h + ')'; }); - console.log(g + event.type + ' ' + items.length + ' items (x,y w h):' + str ); + console.log((g || items[0].grid.opts.id) + ' ' + event.type + ' ' + items.length + ' items (x,y w h):' + str ); }) .on('enable', function(event) { - let grid = event.target; - console.log(g + 'enable'); + let el = event.target; + console.log((g || el.gridstackNode.grid.opts.id) + ' enable'); }) .on('disable', function(event) { - let grid = event.target; - console.log(g + 'disable'); + let el = event.target; + console.log((g || el.gridstackNode.grid.opts.id) + ' disable'); }) .on('dragstart', function(event, el) { let n = el.gridstackNode; let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same let y = el.getAttribute('gs-y'); - console.log(g + 'dragstart ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')'); + console.log((g || el.gridstackNode.grid.opts.id) + ' dragstart ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')'); }) .on('drag', function(event, el) { let n = el.gridstackNode; let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same let y = el.getAttribute('gs-y'); - // console.log(g + 'drag ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')'); + // console.log((g || el.gridstackNode.grid.opts.id) + ' drag ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')'); }) .on('dragstop', function(event, el) { let n = el.gridstackNode; let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same let y = el.getAttribute('gs-y'); - console.log(g + 'dragstop ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')'); + console.log((g || el.gridstackNode.grid.opts.id) + ' dragstop ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')'); }) .on('dropped', function(event, previousNode, newNode) { if (previousNode) { - console.log(g + 'dropped - Removed widget from grid:', previousNode); + console.log((g || previousNode.grid.opts.id) + ' dropped - Removed widget from grid:', previousNode); } if (newNode) { - console.log(g + 'dropped - Added widget in grid:', newNode); + console.log((g || newNode.grid.opts.id) + ' dropped - Added widget in grid:', newNode); } }) .on('resizestart', function(event, el) { let n = el.gridstackNode; let rec = el.getBoundingClientRect(); - console.log(`${g} resizestart ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`); + console.log(`${g || el.gridstackNode.grid.opts.id} resizestart ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`); }) .on('resize', function(event, el) { let n = el.gridstackNode; let rec = el.getBoundingClientRect(); - console.log(`${g} resize ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`); + console.log(`${g || el.gridstackNode.grid.opts.id} resize ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`); }) .on('resizestop', function(event, el) { let n = el.gridstackNode; let rec = el.getBoundingClientRect(); - console.log(`${g} resizestop ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`); + console.log(`${g || el.gridstackNode.grid.opts.id} resizestop ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`); }); } \ No newline at end of file diff --git a/demo/nested.html b/demo/nested.html index 2f80b9e7d..d8a099c72 100644 --- a/demo/nested.html +++ b/demo/nested.html @@ -40,7 +40,7 @@

Nested grids demo

Load

- d + - - - + diff --git a/demo/web2.html b/demo/web2.html index 4c7e36e03..682816684 100644 --- a/demo/web2.html +++ b/demo/web2.html @@ -13,9 +13,7 @@ - - - +