gridstack 8.1.1 → 8.1.2

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 (154) hide show
  1. package/README.md +12 -11
  2. package/angular/.editorconfig +16 -0
  3. package/angular/.vscode/extensions.json +4 -0
  4. package/angular/.vscode/launch.json +20 -0
  5. package/angular/.vscode/tasks.json +42 -0
  6. package/{dist/ng → angular}/README.md +170 -154
  7. package/angular/README_build.md +27 -0
  8. package/angular/angular.json +132 -0
  9. package/angular/package.json +40 -0
  10. package/angular/projects/demo/.browserslistrc +16 -0
  11. package/angular/projects/demo/src/app/app.component.css +11 -0
  12. package/angular/projects/demo/src/app/app.component.html +78 -0
  13. package/angular/projects/demo/src/app/app.component.spec.ts +25 -0
  14. package/angular/projects/demo/src/app/app.component.ts +208 -0
  15. package/angular/projects/demo/src/app/app.module.ts +38 -0
  16. package/angular/projects/demo/src/app/dummy.component.ts +29 -0
  17. package/angular/projects/demo/src/app/ngFor.ts +131 -0
  18. package/angular/projects/demo/src/app/ngFor_cmd.ts +106 -0
  19. package/angular/projects/demo/src/app/simple.ts +46 -0
  20. package/angular/projects/demo/src/assets/.gitkeep +0 -0
  21. package/angular/projects/demo/src/environments/environment.prod.ts +3 -0
  22. package/angular/projects/demo/src/environments/environment.ts +16 -0
  23. package/angular/projects/demo/src/favicon.ico +0 -0
  24. package/angular/projects/demo/src/index.html +13 -0
  25. package/angular/projects/demo/src/main.ts +12 -0
  26. package/angular/projects/demo/src/polyfills.ts +53 -0
  27. package/angular/projects/demo/src/styles.css +4 -0
  28. package/angular/projects/demo/src/test.ts +26 -0
  29. package/angular/projects/demo/tsconfig.app.json +15 -0
  30. package/angular/projects/demo/tsconfig.spec.json +18 -0
  31. package/angular/projects/lib/README.md +24 -0
  32. package/angular/projects/lib/ng-package.json +7 -0
  33. package/angular/projects/lib/package.json +11 -0
  34. package/angular/projects/lib/src/lib/gridstack-item.component.ts +70 -0
  35. package/angular/projects/lib/src/lib/gridstack.component.ts +240 -0
  36. package/angular/projects/lib/src/lib/gridstack.module.ts +32 -0
  37. package/angular/projects/lib/src/public-api.ts +7 -0
  38. package/angular/projects/lib/src/test.ts +27 -0
  39. package/angular/projects/lib/tsconfig.lib.json +15 -0
  40. package/angular/projects/lib/tsconfig.lib.prod.json +10 -0
  41. package/angular/projects/lib/tsconfig.spec.json +17 -0
  42. package/dist/angular/README.md +170 -0
  43. package/dist/angular/esm2020/gridstack-angular.mjs +5 -0
  44. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +67 -0
  45. package/dist/angular/esm2020/lib/gridstack.component.mjs +233 -0
  46. package/dist/angular/esm2020/lib/gridstack.module.mjs +39 -0
  47. package/dist/angular/esm2020/public-api.mjs +7 -0
  48. package/dist/angular/fesm2015/gridstack-angular.mjs +346 -0
  49. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -0
  50. package/dist/angular/fesm2020/gridstack-angular.mjs +342 -0
  51. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -0
  52. package/dist/angular/index.d.ts +5 -0
  53. package/dist/{ng → angular/lib}/gridstack-item.component.d.ts +32 -29
  54. package/dist/{ng → angular/lib}/gridstack.component.d.ts +121 -118
  55. package/dist/angular/lib/gridstack.module.d.ts +10 -0
  56. package/dist/angular/package.json +31 -0
  57. package/dist/angular/public-api.d.ts +3 -0
  58. package/dist/angular/src/gridstack-item.component.ts +70 -0
  59. package/dist/angular/src/gridstack.component.ts +240 -0
  60. package/dist/angular/src/gridstack.module.ts +32 -0
  61. package/dist/dd-base-impl.d.ts +1 -1
  62. package/dist/dd-base-impl.js +1 -1
  63. package/dist/dd-base-impl.js.map +1 -1
  64. package/dist/dd-draggable.d.ts +1 -1
  65. package/dist/dd-draggable.js +1 -1
  66. package/dist/dd-draggable.js.map +1 -1
  67. package/dist/dd-droppable.d.ts +1 -1
  68. package/dist/dd-droppable.js +1 -1
  69. package/dist/dd-droppable.js.map +1 -1
  70. package/dist/dd-element.d.ts +1 -1
  71. package/dist/dd-element.js +1 -1
  72. package/dist/dd-element.js.map +1 -1
  73. package/dist/dd-gridstack.d.ts +1 -1
  74. package/dist/dd-gridstack.js +1 -1
  75. package/dist/dd-gridstack.js.map +1 -1
  76. package/dist/dd-manager.d.ts +1 -1
  77. package/dist/dd-manager.js +1 -1
  78. package/dist/dd-manager.js.map +1 -1
  79. package/dist/dd-resizable-handle.d.ts +1 -1
  80. package/dist/dd-resizable-handle.js +1 -1
  81. package/dist/dd-resizable-handle.js.map +1 -1
  82. package/dist/dd-resizable.d.ts +1 -1
  83. package/dist/dd-resizable.js +1 -1
  84. package/dist/dd-resizable.js.map +1 -1
  85. package/dist/dd-touch.d.ts +1 -1
  86. package/dist/dd-touch.js +1 -1
  87. package/dist/dd-touch.js.map +1 -1
  88. package/dist/es5/dd-base-impl.d.ts +1 -1
  89. package/dist/es5/dd-base-impl.js +1 -1
  90. package/dist/es5/dd-base-impl.js.map +1 -1
  91. package/dist/es5/dd-draggable.d.ts +1 -1
  92. package/dist/es5/dd-draggable.js +1 -1
  93. package/dist/es5/dd-draggable.js.map +1 -1
  94. package/dist/es5/dd-droppable.d.ts +1 -1
  95. package/dist/es5/dd-droppable.js +1 -1
  96. package/dist/es5/dd-droppable.js.map +1 -1
  97. package/dist/es5/dd-element.d.ts +1 -1
  98. package/dist/es5/dd-element.js +1 -1
  99. package/dist/es5/dd-element.js.map +1 -1
  100. package/dist/es5/dd-gridstack.d.ts +1 -1
  101. package/dist/es5/dd-gridstack.js +1 -1
  102. package/dist/es5/dd-gridstack.js.map +1 -1
  103. package/dist/es5/dd-manager.d.ts +1 -1
  104. package/dist/es5/dd-manager.js +1 -1
  105. package/dist/es5/dd-manager.js.map +1 -1
  106. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  107. package/dist/es5/dd-resizable-handle.js +1 -1
  108. package/dist/es5/dd-resizable-handle.js.map +1 -1
  109. package/dist/es5/dd-resizable.d.ts +1 -1
  110. package/dist/es5/dd-resizable.js +1 -1
  111. package/dist/es5/dd-resizable.js.map +1 -1
  112. package/dist/es5/dd-touch.d.ts +1 -1
  113. package/dist/es5/dd-touch.js +1 -1
  114. package/dist/es5/dd-touch.js.map +1 -1
  115. package/dist/es5/gridstack-all.js +1 -1
  116. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  117. package/dist/es5/gridstack-all.js.map +1 -1
  118. package/dist/es5/gridstack-engine.d.ts +1 -1
  119. package/dist/es5/gridstack-engine.js +1 -1
  120. package/dist/es5/gridstack-engine.js.map +1 -1
  121. package/dist/es5/gridstack-poly.js +1 -1
  122. package/dist/es5/gridstack.d.ts +1 -1
  123. package/dist/es5/gridstack.js +2 -2
  124. package/dist/es5/gridstack.js.map +1 -1
  125. package/dist/es5/types.d.ts +1 -1
  126. package/dist/es5/types.js +1 -1
  127. package/dist/es5/types.js.map +1 -1
  128. package/dist/es5/utils.d.ts +1 -1
  129. package/dist/es5/utils.js +1 -1
  130. package/dist/es5/utils.js.map +1 -1
  131. package/dist/gridstack-all.js +1 -1
  132. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  133. package/dist/gridstack-all.js.map +1 -1
  134. package/dist/gridstack-engine.d.ts +1 -1
  135. package/dist/gridstack-engine.js +1 -1
  136. package/dist/gridstack-engine.js.map +1 -1
  137. package/dist/gridstack.css +1 -1
  138. package/dist/gridstack.d.ts +1 -1
  139. package/dist/gridstack.js +2 -2
  140. package/dist/gridstack.js.map +1 -1
  141. package/dist/src/gridstack-extra.scss +3 -3
  142. package/dist/src/gridstack.scss +1 -1
  143. package/dist/types.d.ts +1 -1
  144. package/dist/types.js +1 -1
  145. package/dist/types.js.map +1 -1
  146. package/dist/utils.d.ts +1 -1
  147. package/dist/utils.js +1 -1
  148. package/dist/utils.js.map +1 -1
  149. package/doc/CHANGES.md +4 -1
  150. package/package.json +3 -3
  151. package/dist/ng/gridstack-item.component.js +0 -65
  152. package/dist/ng/gridstack-item.component.js.map +0 -1
  153. package/dist/ng/gridstack.component.js +0 -245
  154. package/dist/ng/gridstack.component.js.map +0 -1
package/README.md CHANGED
@@ -147,7 +147,7 @@ GridStack no longer requires external dependencies as of v1.0.0 (lodash was remo
147
147
 
148
148
  search for ['gridstack' under NPM](https://www.npmjs.com/search?q=gridstack&ranking=popularity) for latest, more to come...
149
149
 
150
- - **Angular**: we now ship out of the box with Angular wrapper components - see <a href="https://github.com/gridstack/gridstack.js/tree/master/demo/angular/src/app" target="_blank">Angular Demo</a>.
150
+ - **Angular**: we now ship out of the box with Angular wrapper components - see <a href="https://github.com/gridstack/gridstack.js/tree/master/angular" target="_blank">Angular Component</a>.
151
151
  - **Angular9**: [lb-gridstack](https://github.com/pfms84/lb-gridstack) Note: very old v0.3 gridstack instance so recommend for **concept ONLY if you wish to use directive instead**. teh code has been vented as I use components.
152
152
  - **AngularJS**: [gridstack-angular](https://github.com/kdietrich/gridstack-angular)
153
153
  - **Ember**: [ember-gridstack](https://github.com/yahoo/ember-gridstack)
@@ -219,7 +219,7 @@ See example: [2 grids demo](http://gridstack.github.io/gridstack.js/demo/two.htm
219
219
 
220
220
  If you need > 12 columns or want to generate the CSS manually you will need to generate CSS rules for `.grid-stack-item[gs-w="X"]` and `.grid-stack-item[gs-x="X"]`.
221
221
 
222
- For instance for 4-column grid you need to write CSS to be:
222
+ For instance for 4-column grid you need CSS to be:
223
223
 
224
224
  ```css
225
225
  .gs-4 > .grid-stack-item[gs-x="1"] { left: 25% }
@@ -232,30 +232,31 @@ For instance for 4-column grid you need to write CSS to be:
232
232
  .gs-4 > .grid-stack-item[gs-w="4"] { width: 100% }
233
233
  ```
234
234
 
235
- Better yet, here is a SASS code snippet, you can use sites like [sassmeister.com](https://www.sassmeister.com/) to generate the CSS for you instead:
235
+ Better yet, here is a SCSS code snippet, you can use sites like [sassmeister.com](https://www.sassmeister.com/) to generate the CSS for you instead:
236
236
 
237
- ```sass
237
+ ```scss
238
238
  $columns: 20;
239
239
  @function fixed($float) {
240
- @return calc(round($float * 100) / 100); // total 4 digits being %
240
+ @return round($float * 1000) / 1000; // total 2+3 digits being %
241
241
  }
242
242
  .gs-#{$columns} > .grid-stack-item {
243
243
 
244
- width: fixed(calc(100% / $columns));
244
+ width: fixed(100% / $columns);
245
245
 
246
246
  @for $i from 1 through $columns - 1 {
247
- &[gs-x='#{$i}'] { left: fixed(calc(100% / $columns) * $i); }
248
- &[gs-w='#{$i+1}'] { width: fixed(calc(100% / $columns) * ($i+1)); }
247
+ &[gs-x='#{$i}'] { left: fixed((100% / $columns) * $i); }
248
+ &[gs-w='#{$i+1}'] { width: fixed((100% / $columns) * ($i+1)); }
249
249
  }
250
250
  }
251
251
  ```
252
252
 
253
- you can also use the SASS [src/gridstack-extra.scss](https://github.com/gridstack/gridstack.js/tree/master/src/gridstack-extra.scss) included in NPM package and modify to add more columns.
253
+ you can also use the SCSS [src/gridstack-extra.scss](https://github.com/gridstack/gridstack.js/tree/master/src/gridstack-extra.scss) included in NPM package and modify to add more columns.
254
254
 
255
255
  Sample gulp command for 30 columns:
256
256
  ```js
257
257
  gulp.src('node_modules/gridstack/dist/src/gridstack-extra.scss')
258
- .pipe(replace('$gridstack-columns: 11 !default;','$gridstack-columns: 30;'))
258
+ .pipe(replace('$start: 2 !default;','$start: 30;'))
259
+ .pipe(replace('$end: 11 !default;','$end: 30;'))
259
260
  .pipe(sass({outputStyle: 'compressed'}))
260
261
  .pipe(rename({extname: '.min.css'}))
261
262
  .pipe(gulp.dest('dist/css'))
@@ -440,7 +441,7 @@ Possible breaking change if you use nested grid JSON format, or original Angular
440
441
  * `GridStackOptions.addRemoveCB` -> `GridStack.addRemoveCB` is now global instead of grid option
441
442
  * removed `GridStackOptions.dragInOptions` since `GridStack.setupDragIn()` has it replaced since 4.0
442
443
  * remove `GridStackOptions.minWidth` obsolete since 5.1, use `oneColumnSize` instead
443
- * CSS rules removed `.grid-stack` prefix for anything already gs based, 12 column (default) now uses `.grid-stack-12`, `gs-min|max_w|h` attribute no longer written (but read)
444
+ * CSS rules removed `.grid-stack` prefix for anything already gs based, 12 column (default) now uses `.gs-12`, extra.css is less than 1/4th it original size!, `gs-min|max_w|h` attribute no longer written (but read)
444
445
 
445
446
  # jQuery Application
446
447
 
@@ -0,0 +1,16 @@
1
+ # Editor configuration, see https://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.ts]
12
+ quote_type = single
13
+
14
+ [*.md]
15
+ max_line_length = off
16
+ trim_trailing_whitespace = false
@@ -0,0 +1,4 @@
1
+ {
2
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
3
+ "recommendations": ["angular.ng-template"]
4
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
3
+ "version": "0.2.0",
4
+ "configurations": [
5
+ {
6
+ "name": "ng serve",
7
+ "type": "pwa-chrome",
8
+ "request": "launch",
9
+ "preLaunchTask": "npm: start",
10
+ "url": "http://localhost:4200/"
11
+ },
12
+ {
13
+ "name": "ng test",
14
+ "type": "chrome",
15
+ "request": "launch",
16
+ "preLaunchTask": "npm: test",
17
+ "url": "http://localhost:9876/debug.html"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
3
+ "version": "2.0.0",
4
+ "tasks": [
5
+ {
6
+ "type": "npm",
7
+ "script": "start",
8
+ "isBackground": true,
9
+ "problemMatcher": {
10
+ "owner": "typescript",
11
+ "pattern": "$tsc",
12
+ "background": {
13
+ "activeOnStart": true,
14
+ "beginsPattern": {
15
+ "regexp": "(.*?)"
16
+ },
17
+ "endsPattern": {
18
+ "regexp": "bundle generation complete"
19
+ }
20
+ }
21
+ }
22
+ },
23
+ {
24
+ "type": "npm",
25
+ "script": "test",
26
+ "isBackground": true,
27
+ "problemMatcher": {
28
+ "owner": "typescript",
29
+ "pattern": "$tsc",
30
+ "background": {
31
+ "activeOnStart": true,
32
+ "beginsPattern": {
33
+ "regexp": "(.*?)"
34
+ },
35
+ "endsPattern": {
36
+ "regexp": "bundle generation complete"
37
+ }
38
+ }
39
+ }
40
+ }
41
+ ]
42
+ }
@@ -1,154 +1,170 @@
1
- # Angular wrapper
2
-
3
- The Angular [wrapper component](./gridstack.component.ts) <gridstack> is a better way to use Gridstack, but alternative raw [ngFor](./ngFor.ts) or [simple](./simple.ts) demos are also given.
4
-
5
- # Dynamic grid items
6
- this is the recommended way if you are going to have multiple grids (alow drag&drop between) or drag from toolbar to create items, or drag to remove items, etc...
7
-
8
- I.E. don't use Angular templating to create grid items as that is harder to sync when gridstack will also add/remove items.
9
-
10
- HTML
11
- ```html
12
- <gridstack [options]="gridOptions">
13
- </gridstack>
14
- ```
15
- Code
16
- ```ts
17
- import { GridStack, GridStackOptions } from 'gridstack';
18
- import { gsCreateNgComponents } from 'gridstack/dist/ng/gridstack.component';
19
-
20
- constructor() {
21
- // use the built in component creation code
22
- GridStack.addRemoveCB = gsCreateNgComponents;
23
- }
24
-
25
- // sample grid options and items to load...
26
- public gridOptions: GridStackOptions = {
27
- margin: 5,
28
- float: true,
29
- children: [ // or call load()/addWidget() with same data
30
- {x:0, y:0, minW:2, content:'Item 1'},
31
- {x:1, y:1, content:'Item 2'},
32
- {x:2, y:2, content:'Item 3'},
33
- ]
34
- }
35
- ```
36
-
37
- # More Complete example
38
- In this example will your actual custom angular components inside each grid item (instead of dummy html content)
39
-
40
- HTML
41
- ```html
42
- <gridstack [options]="gridOptions" (changeCB)="onChange($event)">
43
- <div empty-content>message when grid is empty</div>
44
- </gridstack>
45
- ```
46
-
47
- Code
48
- ```ts
49
- import { Component } from '@angular/core';
50
- import { GridStack, GridStackOptions } from 'gridstack';
51
- import { GridstackComponent, gsCreateNgComponents, NgGridStackWidget, nodesCB } from 'gridstack/dist/ng/gridstack.component';
52
-
53
- // some custom components
54
- @Component({
55
- selector: 'app-a',
56
- template: 'Comp A', // your real ng content goes in each component instead...
57
- })
58
- export class AComponent {
59
- }
60
-
61
- @Component({
62
- selector: 'app-b',
63
- template: 'Comp B',
64
- })
65
- export class BComponent {
66
- }
67
-
68
- // .... in your module for example
69
- constructor() {
70
- // register all our dynamic components created in the grid
71
- GridstackComponent.addComponentToSelectorType([AComponent, BComponent]);
72
- // set globally our method to create the right widget type
73
- GridStack.addRemoveCB = gsCreateNgComponents;
74
- GridStack.saveCB = gsSaveAdditionalNgInfo;
75
- }
76
-
77
- // and now our content will look like instead of dummy html content
78
- public gridOptions: NgGridStackOptions = {
79
- margin: 5,
80
- float: true,
81
- minRow: 1, // make space for empty message
82
- children: [ // or call load()/addWidget() with same data
83
- {x:0, y:0, minW:2, type:'app-a'},
84
- {x:1, y:1, type:'app-b'},
85
- {x:2, y:2, content:'plain html content'},
86
- ]
87
- }
88
-
89
- // called whenever items change size/position/etc.. see other events
90
- public onChange(data: nodesCB) {
91
- console.log('change ', data.nodes.length > 1 ? data.nodes : data.nodes[0]);
92
- }
93
- ```
94
-
95
- # ngFor with wrapper
96
- For simple case where you control the children creation (gridstack doesn't do create or re-parenting)
97
-
98
- HTML
99
- ```html
100
- <gridstack [options]="gridOptions" (changeCB)="onChange($event)">
101
- <gridstack-item *ngFor="let n of items; trackBy: identify" [options]="n">
102
- Item {{n.id}}
103
- </gridstack-item>
104
- </gridstack>
105
- ```
106
-
107
- Code
108
- ```javascript
109
- import { GridStackOptions, GridStackWidget } from 'gridstack';
110
- import { nodesCB } from 'gridstack/dist/ng/gridstack.component';
111
-
112
- /** sample grid options and items to load... */
113
- public gridOptions: GridStackOptions = {
114
- margin: 5,
115
- float: true,
116
- }
117
- public items: GridStackWidget[] = [
118
- {x:0, y:0, minW:2, id:'1'}, // must have unique id used for trackBy
119
- {x:1, y:1, id:'2'},
120
- {x:2, y:2, id:'3'},
121
- ];
122
-
123
- // called whenever items change size/position/etc..
124
- public onChange(data: nodesCB) {
125
- console.log('change ', data.nodes.length > 1 ? data.nodes : data.nodes[0]);
126
- }
127
-
128
- // ngFor unique node id to have correct match between our items used and GS
129
- public identify(index: number, w: GridStackWidget) {
130
- return w.id; // or use index if no id is set and you only modify at the end...
131
- }
132
- ```
133
-
134
- ## Demo
135
- You can see a fuller example at [app.component.ts](https://github.com/gridstack/gridstack.js/blob/master/demo/angular/src/app/app.component.ts)
136
-
137
- to build the demo, go to demo/angular and run `yarn` + `yarn start` and Navigate to `http://localhost:4200/`
138
-
139
- ## Caveats
140
-
141
- - This wrapper needs:
142
- - gridstack v8.0+ to run as it needs the latest changes (use older version to match gs versions)
143
- - Angular 13+ for dynamic createComponent() API
144
- - Code in now shipped starting with v8.0+ in dist/ng for people to use directly!
145
-
146
- ## *ngFor Caveats
147
- - This wrapper handles well ngFor loops, but if you're using a trackBy function (as I would recommend) and no element id change after an update,
148
- you must manually update the `GridstackItemComponent.option` directly - see [modifyNgFor()](./app.component.ts#L174) example.
149
- - The original client list of items is not updated to match **content** changes made by gridstack (TBD later), but adding new item or removing (as shown in demo) will update those new items. Client could use change/added/removed events to sync that list if they wish to do so.
150
-
151
-
152
- Would appreciate getting help doing the same for React and Vue (2 other popular frameworks)
153
-
154
- -Alain
1
+ # Angular wrapper
2
+
3
+ The Angular [wrapper component](projects/lib/src/lib/gridstack.component.ts) <gridstack> is a better way to use Gridstack, but alternative raw [ngFor](projects/demo/src/app/ngFor.ts) or [simple](projects/demo/src/app/simple.ts) demos are also given.
4
+
5
+ # Dynamic grid items
6
+ this is the recommended way if you are going to have multiple grids (alow drag&drop between) or drag from toolbar to create items, or drag to remove items, etc...
7
+
8
+ I.E. don't use Angular templating to create grid items as that is harder to sync when gridstack will also add/remove items.
9
+
10
+ HTML
11
+ ```html
12
+ <gridstack [options]="gridOptions">
13
+ </gridstack>
14
+ ```
15
+
16
+ CSS
17
+ ```css
18
+ @import "gridstack/dist/gridstack.min.css";
19
+
20
+ .grid-stack {
21
+ background: #FAFAD2;
22
+ }
23
+ .grid-stack-item-content {
24
+ text-align: center;
25
+ background-color: #18bc9c;
26
+ }
27
+ ```
28
+
29
+ in your module Code
30
+ ```ts
31
+ import { GridstackModule } from 'gridstack/dist/angular';
32
+
33
+ @NgModule({
34
+ imports: [GridstackModule, ...]
35
+ ...
36
+ bootstrap: [AppComponent]
37
+ })
38
+ export class AppModule { }
39
+ ```
40
+
41
+ Component Code
42
+ ```ts
43
+ import { GridStackOptions } from 'gridstack';
44
+
45
+ // sample grid options + items to load...
46
+ public gridOptions: GridStackOptions = {
47
+ margin: 5,
48
+ float: true,
49
+ children: [ // or call load()/addWidget() with same data
50
+ {x:0, y:0, minW:2, content:'Item 1'},
51
+ {x:1, y:1, content:'Item 2'},
52
+ {x:2, y:2, content:'Item 3'},
53
+ ]
54
+ }
55
+ ```
56
+
57
+ # More Complete example
58
+ In this example (build on previous one) will use your actual custom angular components inside each grid item (instead of dummy html content)
59
+
60
+ HTML
61
+ ```html
62
+ <gridstack [options]="gridOptions" (changeCB)="onChange($event)">
63
+ <div empty-content>message when grid is empty</div>
64
+ </gridstack>
65
+ ```
66
+
67
+ Code
68
+ ```ts
69
+ import { Component } from '@angular/core';
70
+ import { GridStack, GridStackOptions } from 'gridstack';
71
+ import { GridstackComponent, gsCreateNgComponents, NgGridStackWidget, nodesCB } from 'gridstack/dist/angular';
72
+
73
+ // some custom components
74
+ @Component({
75
+ selector: 'app-a',
76
+ template: 'Comp A', // your real ng content goes in each component instead...
77
+ })
78
+ export class AComponent {
79
+ }
80
+
81
+ @Component({
82
+ selector: 'app-b',
83
+ template: 'Comp B',
84
+ })
85
+ export class BComponent {
86
+ }
87
+
88
+ // .... in your module for example
89
+ constructor() {
90
+ // register all our dynamic components types created by the grid
91
+ GridstackComponent.addComponentToSelectorType([AComponent, BComponent]);
92
+ }
93
+
94
+ // now our content will use Components instead of dummy html content
95
+ public gridOptions: NgGridStackOptions = {
96
+ margin: 5,
97
+ float: true,
98
+ minRow: 1, // make space for empty message
99
+ children: [ // or call load()/addWidget() with same data
100
+ {x:0, y:0, minW:2, type:'app-a'},
101
+ {x:1, y:1, type:'app-b'},
102
+ {x:2, y:2, content:'plain html content'},
103
+ ]
104
+ }
105
+
106
+ // called whenever items change size/position/etc.. see other events
107
+ public onChange(data: nodesCB) {
108
+ console.log('change ', data.nodes.length > 1 ? data.nodes : data.nodes[0]);
109
+ }
110
+ ```
111
+
112
+ # ngFor with wrapper
113
+ For simple case where you control the children creation (gridstack doesn't do create or re-parenting)
114
+
115
+ HTML
116
+ ```html
117
+ <gridstack [options]="gridOptions" (changeCB)="onChange($event)">
118
+ <gridstack-item *ngFor="let n of items; trackBy: identify" [options]="n">
119
+ Item {{n.id}}
120
+ </gridstack-item>
121
+ </gridstack>
122
+ ```
123
+
124
+ Code
125
+ ```javascript
126
+ import { GridStackOptions, GridStackWidget } from 'gridstack';
127
+ import { nodesCB } from 'gridstack/dist/angular';
128
+
129
+ /** sample grid options and items to load... */
130
+ public gridOptions: GridStackOptions = {
131
+ margin: 5,
132
+ float: true,
133
+ }
134
+ public items: GridStackWidget[] = [
135
+ {x:0, y:0, minW:2, id:'1'}, // must have unique id used for trackBy
136
+ {x:1, y:1, id:'2'},
137
+ {x:2, y:2, id:'3'},
138
+ ];
139
+
140
+ // called whenever items change size/position/etc..
141
+ public onChange(data: nodesCB) {
142
+ console.log('change ', data.nodes.length > 1 ? data.nodes : data.nodes[0]);
143
+ }
144
+
145
+ // ngFor unique node id to have correct match between our items used and GS
146
+ public identify(index: number, w: GridStackWidget) {
147
+ return w.id; // or use index if no id is set and you only modify at the end...
148
+ }
149
+ ```
150
+
151
+ ## Demo
152
+ You can see a fuller example at [app.component.ts](src/app/app.component.ts)
153
+
154
+ to build the demo, go to angular/projects/demo and run `yarn` + `yarn start` and navigate to `http://localhost:4200/`
155
+
156
+ Code now shipped starting with v8.1.2+ in `dist/angular` for people to use directly! (source code under `dist/angular/src`)
157
+ ## Caveats
158
+
159
+ - This wrapper needs:
160
+ - gridstack v8 to run as it needs the latest changes (use older version that matches GS versions)
161
+ - Angular 13+ for dynamic createComponent() API
162
+
163
+ ## *ngFor Caveats
164
+ - This wrapper handles well ngFor loops, but if you're using a trackBy function (as I would recommend) and no element id change after an update,
165
+ you must manually update the `GridstackItemComponent.option` directly - see [modifyNgFor()](src/app/app.component.ts#L174) example.
166
+ - The original client list of items is not updated to match **content** changes made by gridstack (TBD later), but adding new item or removing (as shown in demo) will update those new items. Client could use change/added/removed events to sync that list if they wish to do so.
167
+
168
+ Would appreciate getting help doing the same for React and Vue (2 other popular frameworks)
169
+
170
+ -Alain
@@ -0,0 +1,27 @@
1
+ # GridstackLib
2
+
3
+ This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.2.10.
4
+
5
+ ## Development server
6
+
7
+ Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
8
+
9
+ ## Code scaffolding
10
+
11
+ Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12
+
13
+ ## Build
14
+
15
+ Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
16
+
17
+ ## Running unit tests
18
+
19
+ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20
+
21
+ ## Running end-to-end tests
22
+
23
+ Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
24
+
25
+ ## Further help
26
+
27
+ To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
@@ -0,0 +1,132 @@
1
+ {
2
+ "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3
+ "version": 1,
4
+ "newProjectRoot": "projects",
5
+ "projects": {
6
+ "lib": {
7
+ "projectType": "library",
8
+ "root": "projects/lib",
9
+ "sourceRoot": "projects/lib/src",
10
+ "prefix": "lib",
11
+ "architect": {
12
+ "build": {
13
+ "builder": "@angular-devkit/build-angular:ng-packagr",
14
+ "options": {
15
+ "project": "projects/lib/ng-package.json"
16
+ },
17
+ "configurations": {
18
+ "production": {
19
+ "tsConfig": "projects/lib/tsconfig.lib.prod.json"
20
+ },
21
+ "development": {
22
+ "tsConfig": "projects/lib/tsconfig.lib.json"
23
+ }
24
+ },
25
+ "defaultConfiguration": "production"
26
+ },
27
+ "test": {
28
+ "builder": "@angular-devkit/build-angular:karma",
29
+ "options": {
30
+ "main": "projects/lib/src/test.ts",
31
+ "tsConfig": "projects/lib/tsconfig.spec.json",
32
+ "karmaConfig": "projects/lib/karma.conf.js"
33
+ }
34
+ }
35
+ }
36
+ },
37
+ "demo": {
38
+ "projectType": "application",
39
+ "schematics": {},
40
+ "root": "projects/demo",
41
+ "sourceRoot": "projects/demo/src",
42
+ "prefix": "app",
43
+ "architect": {
44
+ "build": {
45
+ "builder": "@angular-devkit/build-angular:browser",
46
+ "options": {
47
+ "outputPath": "dist/demo",
48
+ "index": "projects/demo/src/index.html",
49
+ "main": "projects/demo/src/main.ts",
50
+ "polyfills": "projects/demo/src/polyfills.ts",
51
+ "tsConfig": "projects/demo/tsconfig.app.json",
52
+ "assets": [
53
+ "projects/demo/src/favicon.ico",
54
+ "projects/demo/src/assets"
55
+ ],
56
+ "styles": [
57
+ "projects/demo/src/styles.css"
58
+ ],
59
+ "scripts": []
60
+ },
61
+ "configurations": {
62
+ "production": {
63
+ "budgets": [
64
+ {
65
+ "type": "initial",
66
+ "maximumWarning": "500kb",
67
+ "maximumError": "1mb"
68
+ },
69
+ {
70
+ "type": "anyComponentStyle",
71
+ "maximumWarning": "2kb",
72
+ "maximumError": "4kb"
73
+ }
74
+ ],
75
+ "fileReplacements": [
76
+ {
77
+ "replace": "projects/demo/src/environments/environment.ts",
78
+ "with": "projects/demo/src/environments/environment.prod.ts"
79
+ }
80
+ ],
81
+ "outputHashing": "all"
82
+ },
83
+ "development": {
84
+ "buildOptimizer": false,
85
+ "optimization": false,
86
+ "vendorChunk": true,
87
+ "extractLicenses": false,
88
+ "sourceMap": true,
89
+ "namedChunks": true
90
+ }
91
+ },
92
+ "defaultConfiguration": "production"
93
+ },
94
+ "serve": {
95
+ "builder": "@angular-devkit/build-angular:dev-server",
96
+ "configurations": {
97
+ "production": {
98
+ "browserTarget": "demo:build:production"
99
+ },
100
+ "development": {
101
+ "browserTarget": "demo:build:development"
102
+ }
103
+ },
104
+ "defaultConfiguration": "development"
105
+ },
106
+ "extract-i18n": {
107
+ "builder": "@angular-devkit/build-angular:extract-i18n",
108
+ "options": {
109
+ "browserTarget": "demo:build"
110
+ }
111
+ },
112
+ "test": {
113
+ "builder": "@angular-devkit/build-angular:karma",
114
+ "options": {
115
+ "main": "projects/demo/src/test.ts",
116
+ "polyfills": "projects/demo/src/polyfills.ts",
117
+ "tsConfig": "projects/demo/tsconfig.spec.json",
118
+ "karmaConfig": "projects/demo/karma.conf.js",
119
+ "assets": [
120
+ "projects/demo/src/favicon.ico",
121
+ "projects/demo/src/assets"
122
+ ],
123
+ "styles": [
124
+ "projects/demo/src/styles.css"
125
+ ],
126
+ "scripts": []
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }