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