gridstack 12.1.1 → 12.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +5 -2
  2. package/dist/angular/esm2020/gridstack-angular.mjs +4 -4
  3. package/dist/angular/esm2020/index.mjs +8 -8
  4. package/dist/angular/esm2020/lib/base-widget.mjs +34 -34
  5. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +56 -56
  6. package/dist/angular/esm2020/lib/gridstack.component.mjs +319 -307
  7. package/dist/angular/esm2020/lib/gridstack.module.mjs +31 -31
  8. package/dist/angular/esm2020/lib/types.mjs +6 -6
  9. package/dist/angular/fesm2015/gridstack-angular.mjs +433 -420
  10. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  11. package/dist/angular/fesm2020/gridstack-angular.mjs +424 -412
  12. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  13. package/dist/angular/index.d.ts +5 -5
  14. package/dist/angular/lib/base-widget.d.ts +18 -18
  15. package/dist/angular/lib/gridstack-item.component.d.ts +37 -37
  16. package/dist/angular/lib/gridstack.component.d.ts +121 -117
  17. package/dist/angular/lib/gridstack.module.d.ts +8 -8
  18. package/dist/angular/lib/types.d.ts +24 -24
  19. package/dist/angular/src/base-widget.ts +1 -1
  20. package/dist/angular/src/gridstack-item.component.ts +1 -1
  21. package/dist/angular/src/gridstack.component.ts +17 -3
  22. package/dist/angular/src/gridstack.module.ts +1 -1
  23. package/dist/dd-base-impl.d.ts +1 -1
  24. package/dist/dd-base-impl.js +1 -1
  25. package/dist/dd-base-impl.js.map +1 -1
  26. package/dist/dd-draggable.d.ts +1 -1
  27. package/dist/dd-draggable.js +2 -2
  28. package/dist/dd-draggable.js.map +1 -1
  29. package/dist/dd-droppable.d.ts +1 -1
  30. package/dist/dd-droppable.js +1 -1
  31. package/dist/dd-droppable.js.map +1 -1
  32. package/dist/dd-element.d.ts +1 -1
  33. package/dist/dd-element.js +1 -1
  34. package/dist/dd-element.js.map +1 -1
  35. package/dist/dd-gridstack.d.ts +1 -1
  36. package/dist/dd-gridstack.js +1 -1
  37. package/dist/dd-gridstack.js.map +1 -1
  38. package/dist/dd-manager.d.ts +1 -1
  39. package/dist/dd-manager.js +1 -1
  40. package/dist/dd-manager.js.map +1 -1
  41. package/dist/dd-resizable-handle.d.ts +1 -1
  42. package/dist/dd-resizable-handle.js +1 -1
  43. package/dist/dd-resizable-handle.js.map +1 -1
  44. package/dist/dd-resizable.d.ts +1 -1
  45. package/dist/dd-resizable.js +1 -1
  46. package/dist/dd-resizable.js.map +1 -1
  47. package/dist/dd-touch.d.ts +1 -1
  48. package/dist/dd-touch.js +1 -1
  49. package/dist/dd-touch.js.map +1 -1
  50. package/dist/gridstack-all.js +1 -1
  51. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  52. package/dist/gridstack-all.js.map +1 -1
  53. package/dist/gridstack-engine.d.ts +1 -1
  54. package/dist/gridstack-engine.js +1 -1
  55. package/dist/gridstack-engine.js.map +1 -1
  56. package/dist/gridstack.css +1 -2
  57. package/dist/gridstack.d.ts +3 -1
  58. package/dist/gridstack.js +11 -12
  59. package/dist/gridstack.js.map +1 -1
  60. package/dist/gridstack.min.css +1 -1
  61. package/dist/src/gridstack.scss +1 -2
  62. package/dist/types.d.ts +1 -1
  63. package/dist/types.js +1 -1
  64. package/dist/types.js.map +1 -1
  65. package/dist/utils.d.ts +1 -1
  66. package/dist/utils.js +1 -1
  67. package/dist/utils.js.map +1 -1
  68. package/doc/CHANGES.md +9 -0
  69. package/package.json +1 -1
@@ -3,83 +3,83 @@ import { Injectable, ViewContainerRef, Component, ViewChild, Input, EventEmitter
3
3
  import { NgIf } from '@angular/common';
4
4
  import { GridStack } from 'gridstack';
5
5
 
6
- /**
7
- * gridstack-item.component.ts 12.1.1
8
- * Copyright (c) 2025 Alain Dumesny - see GridStack root license
6
+ /**
7
+ * gridstack-item.component.ts 12.2.0
8
+ * Copyright (c) 2025 Alain Dumesny - see GridStack root license
9
9
  */
10
10
 
11
- /**
12
- * gridstack-item.component.ts 12.1.1
13
- * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
14
- */
15
- class BaseWidget {
16
- /**
17
- * REDEFINE to return an object representing the data needed to re-create yourself, other than `selector` already handled.
18
- * This should map directly to the @Input() fields of this objects on create, so a simple apply can be used on read
19
- */
20
- serialize() { return; }
21
- /**
22
- * REDEFINE this if your widget needs to read from saved data and transform it to create itself - you do this for
23
- * things that are not mapped directly into @Input() fields for example.
24
- */
25
- deserialize(w) {
26
- // save full description for meta data
27
- this.widgetItem = w;
28
- if (!w)
29
- return;
30
- if (w.input)
31
- Object.assign(this, w.input);
32
- }
33
- }
34
- BaseWidget.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: BaseWidget, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
35
- BaseWidget.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: BaseWidget });
36
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: BaseWidget, decorators: [{
37
- type: Injectable
11
+ /**
12
+ * gridstack-item.component.ts 12.2.0
13
+ * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
14
+ */
15
+ class BaseWidget {
16
+ /**
17
+ * REDEFINE to return an object representing the data needed to re-create yourself, other than `selector` already handled.
18
+ * This should map directly to the @Input() fields of this objects on create, so a simple apply can be used on read
19
+ */
20
+ serialize() { return; }
21
+ /**
22
+ * REDEFINE this if your widget needs to read from saved data and transform it to create itself - you do this for
23
+ * things that are not mapped directly into @Input() fields for example.
24
+ */
25
+ deserialize(w) {
26
+ // save full description for meta data
27
+ this.widgetItem = w;
28
+ if (!w)
29
+ return;
30
+ if (w.input)
31
+ Object.assign(this, w.input);
32
+ }
33
+ }
34
+ BaseWidget.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: BaseWidget, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
35
+ BaseWidget.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: BaseWidget });
36
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: BaseWidget, decorators: [{
37
+ type: Injectable
38
38
  }] });
39
39
 
40
- /**
41
- * gridstack-item.component.ts 12.1.1
42
- * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
43
- */
44
- /**
45
- * HTML Component Wrapper for gridstack items, in combination with GridstackComponent for parent grid
46
- */
47
- class GridstackItemComponent {
48
- constructor(elementRef) {
49
- this.elementRef = elementRef;
50
- this.el._gridItemComp = this;
51
- }
52
- /** list of options for creating/updating this item */
53
- set options(val) {
54
- const grid = this.el.gridstackNode?.grid;
55
- if (grid) {
56
- // already built, do an update...
57
- grid.update(this.el, val);
58
- }
59
- else {
60
- // store our custom element in options so we can update it and not re-create a generic div!
61
- this._options = { ...val, el: this.el };
62
- }
63
- }
64
- /** return the latest grid options (from GS once built, otherwise initial values) */
65
- get options() {
66
- return this.el.gridstackNode || this._options || { el: this.el };
67
- }
68
- /** return the native element that contains grid specific fields as well */
69
- get el() { return this.elementRef.nativeElement; }
70
- /** clears the initial options now that we've built */
71
- clearOptions() {
72
- delete this._options;
73
- }
74
- ngOnDestroy() {
75
- this.clearOptions();
76
- delete this.childWidget;
77
- delete this.el._gridItemComp;
78
- delete this.container;
79
- delete this.ref;
80
- }
81
- }
82
- GridstackItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackItemComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
40
+ /**
41
+ * gridstack-item.component.ts 12.2.0
42
+ * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
43
+ */
44
+ /**
45
+ * HTML Component Wrapper for gridstack items, in combination with GridstackComponent for parent grid
46
+ */
47
+ class GridstackItemComponent {
48
+ constructor(elementRef) {
49
+ this.elementRef = elementRef;
50
+ this.el._gridItemComp = this;
51
+ }
52
+ /** list of options for creating/updating this item */
53
+ set options(val) {
54
+ const grid = this.el.gridstackNode?.grid;
55
+ if (grid) {
56
+ // already built, do an update...
57
+ grid.update(this.el, val);
58
+ }
59
+ else {
60
+ // store our custom element in options so we can update it and not re-create a generic div!
61
+ this._options = { ...val, el: this.el };
62
+ }
63
+ }
64
+ /** return the latest grid options (from GS once built, otherwise initial values) */
65
+ get options() {
66
+ return this.el.gridstackNode || this._options || { el: this.el };
67
+ }
68
+ /** return the native element that contains grid specific fields as well */
69
+ get el() { return this.elementRef.nativeElement; }
70
+ /** clears the initial options now that we've built */
71
+ clearOptions() {
72
+ delete this._options;
73
+ }
74
+ ngOnDestroy() {
75
+ this.clearOptions();
76
+ delete this.childWidget;
77
+ delete this.el._gridItemComp;
78
+ delete this.container;
79
+ delete this.ref;
80
+ }
81
+ }
82
+ GridstackItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackItemComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
83
83
  GridstackItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: GridstackItemComponent, isStandalone: true, selector: "gridstack-item", inputs: { options: "options" }, viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: `
84
84
  <div class="grid-stack-item-content">
85
85
  <!-- where dynamic items go based on component selector (recommended way), or sub-grids, etc...) -->
@@ -88,9 +88,9 @@ GridstackItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0",
88
88
  <ng-content></ng-content>
89
89
  <!-- fallback HTML content from GridStackWidget.content if used instead (not recommended) -->
90
90
  {{options.content}}
91
- </div>`, isInline: true, styles: [":host{display:block}\n"] });
92
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackItemComponent, decorators: [{
93
- type: Component,
91
+ </div>`, isInline: true, styles: [":host{display:block}\n"] });
92
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackItemComponent, decorators: [{
93
+ type: Component,
94
94
  args: [{ selector: 'gridstack-item', template: `
95
95
  <div class="grid-stack-item-content">
96
96
  <!-- where dynamic items go based on component selector (recommended way), or sub-grids, etc...) -->
@@ -99,164 +99,167 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
99
99
  <ng-content></ng-content>
100
100
  <!-- fallback HTML content from GridStackWidget.content if used instead (not recommended) -->
101
101
  {{options.content}}
102
- </div>`, standalone: true, styles: [":host{display:block}\n"] }]
103
- }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { container: [{
104
- type: ViewChild,
105
- args: ['container', { read: ViewContainerRef, static: true }]
106
- }], options: [{
107
- type: Input
102
+ </div>`, standalone: true, styles: [":host{display:block}\n"] }]
103
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { container: [{
104
+ type: ViewChild,
105
+ args: ['container', { read: ViewContainerRef, static: true }]
106
+ }], options: [{
107
+ type: Input
108
108
  }] } });
109
109
 
110
- /**
111
- * gridstack.component.ts 12.1.1
112
- * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
113
- */
114
- /**
115
- * HTML Component Wrapper for gridstack, in combination with GridstackItemComponent for the items
116
- */
117
- class GridstackComponent {
118
- constructor(elementRef) {
119
- this.elementRef = elementRef;
120
- /** individual list of GridStackEvent callbacks handlers as output
121
- * otherwise use this.grid.on('name1 name2 name3', callback) to handle multiple at once
122
- * see https://github.com/gridstack/gridstack.js/blob/master/demo/events.js#L4
123
- *
124
- * Note: camel casing and 'CB' added at the end to prevent @angular-eslint/no-output-native
125
- * eg: 'change' would trigger the raw CustomEvent so use different name.
126
- */
127
- this.addedCB = new EventEmitter();
128
- this.changeCB = new EventEmitter();
129
- this.disableCB = new EventEmitter();
130
- this.dragCB = new EventEmitter();
131
- this.dragStartCB = new EventEmitter();
132
- this.dragStopCB = new EventEmitter();
133
- this.droppedCB = new EventEmitter();
134
- this.enableCB = new EventEmitter();
135
- this.removedCB = new EventEmitter();
136
- this.resizeCB = new EventEmitter();
137
- this.resizeStartCB = new EventEmitter();
138
- this.resizeStopCB = new EventEmitter();
139
- // set globally our method to create the right widget type
140
- if (!GridStack.addRemoveCB) {
141
- GridStack.addRemoveCB = gsCreateNgComponents;
142
- }
143
- if (!GridStack.saveCB) {
144
- GridStack.saveCB = gsSaveAdditionalNgInfo;
145
- }
146
- this.el._gridComp = this;
147
- }
148
- /** initial options for creation of the grid */
149
- set options(o) {
150
- if (this._grid) {
151
- this._grid.updateOptions(o);
152
- }
153
- else {
154
- this._options = o;
155
- }
156
- }
157
- /** return the current running options */
158
- get options() { return this._grid?.opts || this._options || {}; }
159
- /** return the native element that contains grid specific fields as well */
160
- get el() { return this.elementRef.nativeElement; }
161
- /** return the GridStack class */
162
- get grid() { return this._grid; }
163
- /** add a list of ng Component to be mapped to selector */
164
- static addComponentToSelectorType(typeList) {
165
- typeList.forEach(type => GridstackComponent.selectorToType[GridstackComponent.getSelector(type)] = type);
166
- }
167
- /** return the ng Component selector */
168
- static getSelector(type) {
169
- return reflectComponentType(type).selector;
170
- }
171
- ngOnInit() {
172
- // init ourself before any template children are created since we track them below anyway - no need to double create+update widgets
173
- this.loaded = !!this.options?.children?.length;
174
- this._grid = GridStack.init(this._options, this.el);
175
- delete this._options; // GS has it now
176
- this.checkEmpty();
177
- }
178
- /** wait until after all DOM is ready to init gridstack children (after angular ngFor and sub-components run first) */
179
- ngAfterContentInit() {
180
- // track whenever the children list changes and update the layout...
181
- this._sub = this.gridstackItems?.changes.subscribe(() => this.updateAll());
182
- // ...and do this once at least unless we loaded children already
183
- if (!this.loaded)
184
- this.updateAll();
185
- this.hookEvents(this.grid);
186
- }
187
- ngOnDestroy() {
188
- this.unhookEvents(this._grid);
189
- this._sub?.unsubscribe();
190
- this._grid?.destroy();
191
- delete this._grid;
192
- delete this.el._gridComp;
193
- delete this.container;
194
- delete this.ref;
195
- }
196
- /**
197
- * called when the TEMPLATE (not recommended) list of items changes - get a list of nodes and
198
- * update the layout accordingly (which will take care of adding/removing items changed by Angular)
199
- */
200
- updateAll() {
201
- if (!this.grid)
202
- return;
203
- const layout = [];
204
- this.gridstackItems?.forEach(item => {
205
- layout.push(item.options);
206
- item.clearOptions();
207
- });
208
- this.grid.load(layout); // efficient that does diffs only
209
- }
210
- /** check if the grid is empty, if so show alternative content */
211
- checkEmpty() {
212
- if (!this.grid)
213
- return;
214
- this.isEmpty = !this.grid.engine.nodes.length;
215
- }
216
- /** get all known events as easy to use Outputs for convenience */
217
- hookEvents(grid) {
218
- if (!grid)
219
- return;
220
- // nested grids don't have events in v12.1+ so skip
221
- if (grid.parentGridNode)
222
- return;
223
- grid
224
- .on('added', (event, nodes) => {
225
- const gridComp = nodes[0].grid?.el._gridComp || this;
226
- gridComp.checkEmpty();
227
- this.addedCB.emit({ event, nodes });
228
- })
229
- .on('change', (event, nodes) => this.changeCB.emit({ event, nodes }))
230
- .on('disable', (event) => this.disableCB.emit({ event }))
231
- .on('drag', (event, el) => this.dragCB.emit({ event, el }))
232
- .on('dragstart', (event, el) => this.dragStartCB.emit({ event, el }))
233
- .on('dragstop', (event, el) => this.dragStopCB.emit({ event, el }))
234
- .on('dropped', (event, previousNode, newNode) => this.droppedCB.emit({ event, previousNode, newNode }))
235
- .on('enable', (event) => this.enableCB.emit({ event }))
236
- .on('removed', (event, nodes) => {
237
- const gridComp = nodes[0].grid?.el._gridComp || this;
238
- gridComp.checkEmpty();
239
- this.removedCB.emit({ event, nodes });
240
- })
241
- .on('resize', (event, el) => this.resizeCB.emit({ event, el }))
242
- .on('resizestart', (event, el) => this.resizeStartCB.emit({ event, el }))
243
- .on('resizestop', (event, el) => this.resizeStopCB.emit({ event, el }));
244
- }
245
- unhookEvents(grid) {
246
- if (!grid)
247
- return;
248
- // nested grids don't have events in v12.1+ so skip
249
- if (grid.parentGridNode)
250
- return;
251
- grid.off('added change disable drag dragstart dragstop dropped enable removed resize resizestart resizestop');
252
- }
253
- }
254
- /**
255
- * stores the selector -> Type mapping, so we can create items dynamically from a string.
256
- * Unfortunately Ng doesn't provide public access to that mapping.
257
- */
258
- GridstackComponent.selectorToType = {};
259
- GridstackComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
110
+ /**
111
+ * gridstack.component.ts 12.2.0
112
+ * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
113
+ */
114
+ /**
115
+ * HTML Component Wrapper for gridstack, in combination with GridstackItemComponent for the items
116
+ */
117
+ class GridstackComponent {
118
+ constructor(elementRef) {
119
+ this.elementRef = elementRef;
120
+ /** individual list of GridStackEvent callbacks handlers as output
121
+ * otherwise use this.grid.on('name1 name2 name3', callback) to handle multiple at once
122
+ * see https://github.com/gridstack/gridstack.js/blob/master/demo/events.js#L4
123
+ *
124
+ * Note: camel casing and 'CB' added at the end to prevent @angular-eslint/no-output-native
125
+ * eg: 'change' would trigger the raw CustomEvent so use different name.
126
+ */
127
+ this.addedCB = new EventEmitter();
128
+ this.changeCB = new EventEmitter();
129
+ this.disableCB = new EventEmitter();
130
+ this.dragCB = new EventEmitter();
131
+ this.dragStartCB = new EventEmitter();
132
+ this.dragStopCB = new EventEmitter();
133
+ this.droppedCB = new EventEmitter();
134
+ this.enableCB = new EventEmitter();
135
+ this.removedCB = new EventEmitter();
136
+ this.resizeCB = new EventEmitter();
137
+ this.resizeStartCB = new EventEmitter();
138
+ this.resizeStopCB = new EventEmitter();
139
+ // set globally our method to create the right widget type
140
+ if (!GridStack.addRemoveCB) {
141
+ GridStack.addRemoveCB = gsCreateNgComponents;
142
+ }
143
+ if (!GridStack.saveCB) {
144
+ GridStack.saveCB = gsSaveAdditionalNgInfo;
145
+ }
146
+ if (!GridStack.updateCB) {
147
+ GridStack.updateCB = gsUpdateNgComponents;
148
+ }
149
+ this.el._gridComp = this;
150
+ }
151
+ /** initial options for creation of the grid */
152
+ set options(o) {
153
+ if (this._grid) {
154
+ this._grid.updateOptions(o);
155
+ }
156
+ else {
157
+ this._options = o;
158
+ }
159
+ }
160
+ /** return the current running options */
161
+ get options() { return this._grid?.opts || this._options || {}; }
162
+ /** return the native element that contains grid specific fields as well */
163
+ get el() { return this.elementRef.nativeElement; }
164
+ /** return the GridStack class */
165
+ get grid() { return this._grid; }
166
+ /** add a list of ng Component to be mapped to selector */
167
+ static addComponentToSelectorType(typeList) {
168
+ typeList.forEach(type => GridstackComponent.selectorToType[GridstackComponent.getSelector(type)] = type);
169
+ }
170
+ /** return the ng Component selector */
171
+ static getSelector(type) {
172
+ return reflectComponentType(type).selector;
173
+ }
174
+ ngOnInit() {
175
+ // init ourself before any template children are created since we track them below anyway - no need to double create+update widgets
176
+ this.loaded = !!this.options?.children?.length;
177
+ this._grid = GridStack.init(this._options, this.el);
178
+ delete this._options; // GS has it now
179
+ this.checkEmpty();
180
+ }
181
+ /** wait until after all DOM is ready to init gridstack children (after angular ngFor and sub-components run first) */
182
+ ngAfterContentInit() {
183
+ // track whenever the children list changes and update the layout...
184
+ this._sub = this.gridstackItems?.changes.subscribe(() => this.updateAll());
185
+ // ...and do this once at least unless we loaded children already
186
+ if (!this.loaded)
187
+ this.updateAll();
188
+ this.hookEvents(this.grid);
189
+ }
190
+ ngOnDestroy() {
191
+ this.unhookEvents(this._grid);
192
+ this._sub?.unsubscribe();
193
+ this._grid?.destroy();
194
+ delete this._grid;
195
+ delete this.el._gridComp;
196
+ delete this.container;
197
+ delete this.ref;
198
+ }
199
+ /**
200
+ * called when the TEMPLATE (not recommended) list of items changes - get a list of nodes and
201
+ * update the layout accordingly (which will take care of adding/removing items changed by Angular)
202
+ */
203
+ updateAll() {
204
+ if (!this.grid)
205
+ return;
206
+ const layout = [];
207
+ this.gridstackItems?.forEach(item => {
208
+ layout.push(item.options);
209
+ item.clearOptions();
210
+ });
211
+ this.grid.load(layout); // efficient that does diffs only
212
+ }
213
+ /** check if the grid is empty, if so show alternative content */
214
+ checkEmpty() {
215
+ if (!this.grid)
216
+ return;
217
+ this.isEmpty = !this.grid.engine.nodes.length;
218
+ }
219
+ /** get all known events as easy to use Outputs for convenience */
220
+ hookEvents(grid) {
221
+ if (!grid)
222
+ return;
223
+ // nested grids don't have events in v12.1+ so skip
224
+ if (grid.parentGridNode)
225
+ return;
226
+ grid
227
+ .on('added', (event, nodes) => {
228
+ const gridComp = nodes[0].grid?.el._gridComp || this;
229
+ gridComp.checkEmpty();
230
+ this.addedCB.emit({ event, nodes });
231
+ })
232
+ .on('change', (event, nodes) => this.changeCB.emit({ event, nodes }))
233
+ .on('disable', (event) => this.disableCB.emit({ event }))
234
+ .on('drag', (event, el) => this.dragCB.emit({ event, el }))
235
+ .on('dragstart', (event, el) => this.dragStartCB.emit({ event, el }))
236
+ .on('dragstop', (event, el) => this.dragStopCB.emit({ event, el }))
237
+ .on('dropped', (event, previousNode, newNode) => this.droppedCB.emit({ event, previousNode, newNode }))
238
+ .on('enable', (event) => this.enableCB.emit({ event }))
239
+ .on('removed', (event, nodes) => {
240
+ const gridComp = nodes[0].grid?.el._gridComp || this;
241
+ gridComp.checkEmpty();
242
+ this.removedCB.emit({ event, nodes });
243
+ })
244
+ .on('resize', (event, el) => this.resizeCB.emit({ event, el }))
245
+ .on('resizestart', (event, el) => this.resizeStartCB.emit({ event, el }))
246
+ .on('resizestop', (event, el) => this.resizeStopCB.emit({ event, el }));
247
+ }
248
+ unhookEvents(grid) {
249
+ if (!grid)
250
+ return;
251
+ // nested grids don't have events in v12.1+ so skip
252
+ if (grid.parentGridNode)
253
+ return;
254
+ grid.off('added change disable drag dragstart dragstop dropped enable removed resize resizestart resizestop');
255
+ }
256
+ }
257
+ /**
258
+ * stores the selector -> Type mapping, so we can create items dynamically from a string.
259
+ * Unfortunately Ng doesn't provide public access to that mapping.
260
+ */
261
+ GridstackComponent.selectorToType = {};
262
+ GridstackComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
260
263
  GridstackComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: GridstackComponent, isStandalone: true, selector: "gridstack", inputs: { options: "options", isEmpty: "isEmpty" }, outputs: { addedCB: "addedCB", changeCB: "changeCB", disableCB: "disableCB", dragCB: "dragCB", dragStartCB: "dragStartCB", dragStopCB: "dragStopCB", droppedCB: "droppedCB", enableCB: "enableCB", removedCB: "removedCB", resizeCB: "resizeCB", resizeStartCB: "resizeStartCB", resizeStopCB: "resizeStopCB" }, queries: [{ propertyName: "gridstackItems", predicate: GridstackItemComponent }], viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: `
261
264
  <!-- content to show when when grid is empty, like instructions on how to add widgets -->
262
265
  <ng-content select="[empty-content]" *ngIf="isEmpty"></ng-content>
@@ -264,9 +267,9 @@ GridstackComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", ver
264
267
  <ng-template #container></ng-template>
265
268
  <!-- where template items go -->
266
269
  <ng-content></ng-content>
267
- `, isInline: true, styles: [":host{display:block}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
268
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackComponent, decorators: [{
269
- type: Component,
270
+ `, isInline: true, styles: [":host{display:block}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
271
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackComponent, decorators: [{
272
+ type: Component,
270
273
  args: [{ selector: 'gridstack', template: `
271
274
  <!-- content to show when when grid is empty, like instructions on how to add widgets -->
272
275
  <ng-content select="[empty-content]" *ngIf="isEmpty"></ng-content>
@@ -274,189 +277,198 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
274
277
  <ng-template #container></ng-template>
275
278
  <!-- where template items go -->
276
279
  <ng-content></ng-content>
277
- `, standalone: true, imports: [NgIf], styles: [":host{display:block}\n"] }]
278
- }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { gridstackItems: [{
279
- type: ContentChildren,
280
- args: [GridstackItemComponent]
281
- }], container: [{
282
- type: ViewChild,
283
- args: ['container', { read: ViewContainerRef, static: true }]
284
- }], options: [{
285
- type: Input
286
- }], isEmpty: [{
287
- type: Input
288
- }], addedCB: [{
289
- type: Output
290
- }], changeCB: [{
291
- type: Output
292
- }], disableCB: [{
293
- type: Output
294
- }], dragCB: [{
295
- type: Output
296
- }], dragStartCB: [{
297
- type: Output
298
- }], dragStopCB: [{
299
- type: Output
300
- }], droppedCB: [{
301
- type: Output
302
- }], enableCB: [{
303
- type: Output
304
- }], removedCB: [{
305
- type: Output
306
- }], resizeCB: [{
307
- type: Output
308
- }], resizeStartCB: [{
309
- type: Output
310
- }], resizeStopCB: [{
311
- type: Output
312
- }] } });
313
- /**
314
- * can be used when a new item needs to be created, which we do as a Angular component, or deleted (skip)
315
- **/
316
- function gsCreateNgComponents(host, n, add, isGrid) {
317
- if (add) {
318
- //
319
- // create the component dynamically - see https://angular.io/docs/ts/latest/cookbook/dynamic-component-loader.html
320
- //
321
- if (!host)
322
- return;
323
- if (isGrid) {
324
- // TODO: figure out how to create ng component inside regular Div. need to access app injectors...
325
- // if (!container) {
326
- // const hostElement: Element = host;
327
- // const environmentInjector: EnvironmentInjector;
328
- // grid = createComponent(GridstackComponent, {environmentInjector, hostElement})?.instance;
329
- // }
330
- const gridItemComp = host.parentElement?._gridItemComp;
331
- if (!gridItemComp)
332
- return;
333
- // check if gridItem has a child component with 'container' exposed to create under..
334
- const container = gridItemComp.childWidget?.container || gridItemComp.container;
335
- const gridRef = container?.createComponent(GridstackComponent);
336
- const grid = gridRef?.instance;
337
- if (!grid)
338
- return;
339
- grid.ref = gridRef;
340
- grid.options = n;
341
- return grid.el;
342
- }
343
- else {
344
- const gridComp = host._gridComp;
345
- const gridItemRef = gridComp?.container?.createComponent(GridstackItemComponent);
346
- const gridItem = gridItemRef?.instance;
347
- if (!gridItem)
348
- return;
349
- gridItem.ref = gridItemRef;
350
- // define what type of component to create as child, OR you can do it GridstackItemComponent template, but this is more generic
351
- const selector = n.selector;
352
- const type = selector ? GridstackComponent.selectorToType[selector] : undefined;
353
- if (type) {
354
- // shared code to create our selector component
355
- const createComp = () => {
356
- const childWidget = gridItem.container?.createComponent(type)?.instance;
357
- // if proper BaseWidget subclass, save it and load additional data
358
- if (childWidget && typeof childWidget.serialize === 'function' && typeof childWidget.deserialize === 'function') {
359
- gridItem.childWidget = childWidget;
360
- childWidget.deserialize(n);
361
- }
362
- };
363
- const lazyLoad = n.lazyLoad || n.grid?.opts?.lazyLoad && n.lazyLoad !== false;
364
- if (lazyLoad) {
365
- if (!n.visibleObservable) {
366
- n.visibleObservable = new IntersectionObserver(([entry]) => {
367
- if (entry.isIntersecting) {
368
- n.visibleObservable?.disconnect();
369
- delete n.visibleObservable;
370
- createComp();
371
- }
372
- });
373
- window.setTimeout(() => n.visibleObservable?.observe(gridItem.el)); // wait until callee sets position attributes
374
- }
375
- }
376
- else
377
- createComp();
378
- }
379
- return gridItem.el;
380
- }
381
- }
382
- else {
383
- //
384
- // REMOVE - have to call ComponentRef:destroy() for dynamic objects to correctly remove themselves
385
- // Note: this will destroy all children dynamic components as well: gridItem -> childWidget
386
- //
387
- if (isGrid) {
388
- const grid = n.el?._gridComp;
389
- if (grid?.ref)
390
- grid.ref.destroy();
391
- else
392
- grid?.ngOnDestroy();
393
- }
394
- else {
395
- const gridItem = n.el?._gridItemComp;
396
- if (gridItem?.ref)
397
- gridItem.ref.destroy();
398
- else
399
- gridItem?.ngOnDestroy();
400
- }
401
- }
402
- return;
403
- }
404
- /**
405
- * called for each item in the grid - check if additional information needs to be saved.
406
- * Note: since this is options minus gridstack protected members using Utils.removeInternalForSave(),
407
- * this typically doesn't need to do anything. However your custom Component @Input() are now supported
408
- * using BaseWidget.serialize()
409
- */
410
- function gsSaveAdditionalNgInfo(n, w) {
411
- const gridItem = n.el?._gridItemComp;
412
- if (gridItem) {
413
- const input = gridItem.childWidget?.serialize();
414
- if (input) {
415
- w.input = input;
416
- }
417
- return;
418
- }
419
- // else check if Grid
420
- const grid = n.el?._gridComp;
421
- if (grid) {
422
- //.... save any custom data
423
- }
280
+ `, standalone: true, imports: [NgIf], styles: [":host{display:block}\n"] }]
281
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { gridstackItems: [{
282
+ type: ContentChildren,
283
+ args: [GridstackItemComponent]
284
+ }], container: [{
285
+ type: ViewChild,
286
+ args: ['container', { read: ViewContainerRef, static: true }]
287
+ }], options: [{
288
+ type: Input
289
+ }], isEmpty: [{
290
+ type: Input
291
+ }], addedCB: [{
292
+ type: Output
293
+ }], changeCB: [{
294
+ type: Output
295
+ }], disableCB: [{
296
+ type: Output
297
+ }], dragCB: [{
298
+ type: Output
299
+ }], dragStartCB: [{
300
+ type: Output
301
+ }], dragStopCB: [{
302
+ type: Output
303
+ }], droppedCB: [{
304
+ type: Output
305
+ }], enableCB: [{
306
+ type: Output
307
+ }], removedCB: [{
308
+ type: Output
309
+ }], resizeCB: [{
310
+ type: Output
311
+ }], resizeStartCB: [{
312
+ type: Output
313
+ }], resizeStopCB: [{
314
+ type: Output
315
+ }] } });
316
+ /**
317
+ * can be used when a new item needs to be created, which we do as a Angular component, or deleted (skip)
318
+ **/
319
+ function gsCreateNgComponents(host, n, add, isGrid) {
320
+ if (add) {
321
+ //
322
+ // create the component dynamically - see https://angular.io/docs/ts/latest/cookbook/dynamic-component-loader.html
323
+ //
324
+ if (!host)
325
+ return;
326
+ if (isGrid) {
327
+ // TODO: figure out how to create ng component inside regular Div. need to access app injectors...
328
+ // if (!container) {
329
+ // const hostElement: Element = host;
330
+ // const environmentInjector: EnvironmentInjector;
331
+ // grid = createComponent(GridstackComponent, {environmentInjector, hostElement})?.instance;
332
+ // }
333
+ const gridItemComp = host.parentElement?._gridItemComp;
334
+ if (!gridItemComp)
335
+ return;
336
+ // check if gridItem has a child component with 'container' exposed to create under..
337
+ const container = gridItemComp.childWidget?.container || gridItemComp.container;
338
+ const gridRef = container?.createComponent(GridstackComponent);
339
+ const grid = gridRef?.instance;
340
+ if (!grid)
341
+ return;
342
+ grid.ref = gridRef;
343
+ grid.options = n;
344
+ return grid.el;
345
+ }
346
+ else {
347
+ const gridComp = host._gridComp;
348
+ const gridItemRef = gridComp?.container?.createComponent(GridstackItemComponent);
349
+ const gridItem = gridItemRef?.instance;
350
+ if (!gridItem)
351
+ return;
352
+ gridItem.ref = gridItemRef;
353
+ // define what type of component to create as child, OR you can do it GridstackItemComponent template, but this is more generic
354
+ const selector = n.selector;
355
+ const type = selector ? GridstackComponent.selectorToType[selector] : undefined;
356
+ if (type) {
357
+ // shared code to create our selector component
358
+ const createComp = () => {
359
+ const childWidget = gridItem.container?.createComponent(type)?.instance;
360
+ // if proper BaseWidget subclass, save it and load additional data
361
+ if (childWidget && typeof childWidget.serialize === 'function' && typeof childWidget.deserialize === 'function') {
362
+ gridItem.childWidget = childWidget;
363
+ childWidget.deserialize(n);
364
+ }
365
+ };
366
+ const lazyLoad = n.lazyLoad || n.grid?.opts?.lazyLoad && n.lazyLoad !== false;
367
+ if (lazyLoad) {
368
+ if (!n.visibleObservable) {
369
+ n.visibleObservable = new IntersectionObserver(([entry]) => {
370
+ if (entry.isIntersecting) {
371
+ n.visibleObservable?.disconnect();
372
+ delete n.visibleObservable;
373
+ createComp();
374
+ }
375
+ });
376
+ window.setTimeout(() => n.visibleObservable?.observe(gridItem.el)); // wait until callee sets position attributes
377
+ }
378
+ }
379
+ else
380
+ createComp();
381
+ }
382
+ return gridItem.el;
383
+ }
384
+ }
385
+ else {
386
+ //
387
+ // REMOVE - have to call ComponentRef:destroy() for dynamic objects to correctly remove themselves
388
+ // Note: this will destroy all children dynamic components as well: gridItem -> childWidget
389
+ //
390
+ if (isGrid) {
391
+ const grid = n.el?._gridComp;
392
+ if (grid?.ref)
393
+ grid.ref.destroy();
394
+ else
395
+ grid?.ngOnDestroy();
396
+ }
397
+ else {
398
+ const gridItem = n.el?._gridItemComp;
399
+ if (gridItem?.ref)
400
+ gridItem.ref.destroy();
401
+ else
402
+ gridItem?.ngOnDestroy();
403
+ }
404
+ }
405
+ return;
406
+ }
407
+ /**
408
+ * called for each item in the grid - check if additional information needs to be saved.
409
+ * Note: since this is options minus gridstack protected members using Utils.removeInternalForSave(),
410
+ * this typically doesn't need to do anything. However your custom Component @Input() are now supported
411
+ * using BaseWidget.serialize()
412
+ */
413
+ function gsSaveAdditionalNgInfo(n, w) {
414
+ const gridItem = n.el?._gridItemComp;
415
+ if (gridItem) {
416
+ const input = gridItem.childWidget?.serialize();
417
+ if (input) {
418
+ w.input = input;
419
+ }
420
+ return;
421
+ }
422
+ // else check if Grid
423
+ const grid = n.el?._gridComp;
424
+ if (grid) {
425
+ //.... save any custom data
426
+ }
427
+ }
428
+ /**
429
+ * track when widgeta re updated (rather than created) to make sure we de-serialize them as well
430
+ */
431
+ function gsUpdateNgComponents(n) {
432
+ const w = n;
433
+ const gridItem = n.el?._gridItemComp;
434
+ if (gridItem?.childWidget && w.input)
435
+ gridItem.childWidget.deserialize(w);
424
436
  }
425
437
 
426
- /**
427
- * gridstack.component.ts 12.1.1
428
- * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
429
- */
430
- // @deprecated use GridstackComponent and GridstackItemComponent as standalone components
431
- class GridstackModule {
432
- }
433
- GridstackModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
434
- GridstackModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, imports: [GridstackItemComponent,
435
- GridstackComponent], exports: [GridstackItemComponent,
436
- GridstackComponent] });
437
- GridstackModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, imports: [GridstackItemComponent,
438
- GridstackComponent] });
439
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, decorators: [{
440
- type: NgModule,
441
- args: [{
442
- imports: [
443
- GridstackItemComponent,
444
- GridstackComponent,
445
- ],
446
- exports: [
447
- GridstackItemComponent,
448
- GridstackComponent,
449
- ],
450
- }]
438
+ /**
439
+ * gridstack.component.ts 12.2.0
440
+ * Copyright (c) 2022-2024 Alain Dumesny - see GridStack root license
441
+ */
442
+ // @deprecated use GridstackComponent and GridstackItemComponent as standalone components
443
+ class GridstackModule {
444
+ }
445
+ GridstackModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
446
+ GridstackModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, imports: [GridstackItemComponent,
447
+ GridstackComponent], exports: [GridstackItemComponent,
448
+ GridstackComponent] });
449
+ GridstackModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, imports: [GridstackItemComponent,
450
+ GridstackComponent] });
451
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: GridstackModule, decorators: [{
452
+ type: NgModule,
453
+ args: [{
454
+ imports: [
455
+ GridstackItemComponent,
456
+ GridstackComponent,
457
+ ],
458
+ exports: [
459
+ GridstackItemComponent,
460
+ GridstackComponent,
461
+ ],
462
+ }]
451
463
  }] });
452
464
 
453
- /*
454
- * Public API Surface of gridstack-angular
465
+ /*
466
+ * Public API Surface of gridstack-angular
455
467
  */
456
468
 
457
- /**
458
- * Generated bundle index. Do not edit.
469
+ /**
470
+ * Generated bundle index. Do not edit.
459
471
  */
460
472
 
461
- export { BaseWidget, GridstackComponent, GridstackItemComponent, GridstackModule, gsCreateNgComponents, gsSaveAdditionalNgInfo };
473
+ export { BaseWidget, GridstackComponent, GridstackItemComponent, GridstackModule, gsCreateNgComponents, gsSaveAdditionalNgInfo, gsUpdateNgComponents };
462
474
  //# sourceMappingURL=gridstack-angular.mjs.map