gridstack 10.3.1 → 11.0.1

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