gridstack 8.1.1 → 8.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 (158) 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 +39 -0
  16. package/angular/projects/demo/src/app/dummy.component.ts +35 -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/base-widget.ts +28 -0
  35. package/angular/projects/lib/src/lib/gridstack-item.component.ts +78 -0
  36. package/angular/projects/lib/src/lib/gridstack.component.ts +287 -0
  37. package/angular/projects/lib/src/lib/gridstack.module.ts +32 -0
  38. package/angular/projects/lib/src/public-api.ts +8 -0
  39. package/angular/projects/lib/src/test.ts +27 -0
  40. package/angular/projects/lib/tsconfig.lib.json +15 -0
  41. package/angular/projects/lib/tsconfig.lib.prod.json +10 -0
  42. package/angular/projects/lib/tsconfig.spec.json +17 -0
  43. package/dist/angular/README.md +170 -0
  44. package/dist/angular/esm2020/gridstack-angular.mjs +5 -0
  45. package/dist/angular/esm2020/lib/base-widget.mjs +30 -0
  46. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +68 -0
  47. package/dist/angular/esm2020/lib/gridstack.component.mjs +278 -0
  48. package/dist/angular/esm2020/lib/gridstack.module.mjs +39 -0
  49. package/dist/angular/esm2020/public-api.mjs +8 -0
  50. package/dist/angular/fesm2015/gridstack-angular.mjs +418 -0
  51. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -0
  52. package/dist/angular/fesm2020/gridstack-angular.mjs +413 -0
  53. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -0
  54. package/dist/angular/index.d.ts +5 -0
  55. package/dist/angular/lib/base-widget.d.ts +16 -0
  56. package/dist/{ng → angular/lib}/gridstack-item.component.d.ts +37 -29
  57. package/dist/{ng → angular/lib}/gridstack.component.d.ts +129 -118
  58. package/dist/angular/lib/gridstack.module.d.ts +10 -0
  59. package/dist/angular/package.json +31 -0
  60. package/dist/angular/public-api.d.ts +4 -0
  61. package/dist/angular/src/base-widget.ts +28 -0
  62. package/dist/angular/src/gridstack-item.component.ts +78 -0
  63. package/dist/angular/src/gridstack.component.ts +287 -0
  64. package/dist/angular/src/gridstack.module.ts +32 -0
  65. package/dist/dd-base-impl.d.ts +1 -1
  66. package/dist/dd-base-impl.js +1 -1
  67. package/dist/dd-base-impl.js.map +1 -1
  68. package/dist/dd-draggable.d.ts +1 -1
  69. package/dist/dd-draggable.js +1 -1
  70. package/dist/dd-draggable.js.map +1 -1
  71. package/dist/dd-droppable.d.ts +1 -1
  72. package/dist/dd-droppable.js +1 -1
  73. package/dist/dd-droppable.js.map +1 -1
  74. package/dist/dd-element.d.ts +1 -1
  75. package/dist/dd-element.js +1 -1
  76. package/dist/dd-element.js.map +1 -1
  77. package/dist/dd-gridstack.d.ts +1 -1
  78. package/dist/dd-gridstack.js +1 -1
  79. package/dist/dd-gridstack.js.map +1 -1
  80. package/dist/dd-manager.d.ts +1 -1
  81. package/dist/dd-manager.js +1 -1
  82. package/dist/dd-manager.js.map +1 -1
  83. package/dist/dd-resizable-handle.d.ts +1 -1
  84. package/dist/dd-resizable-handle.js +1 -1
  85. package/dist/dd-resizable-handle.js.map +1 -1
  86. package/dist/dd-resizable.d.ts +1 -1
  87. package/dist/dd-resizable.js +1 -1
  88. package/dist/dd-resizable.js.map +1 -1
  89. package/dist/dd-touch.d.ts +1 -1
  90. package/dist/dd-touch.js +1 -1
  91. package/dist/dd-touch.js.map +1 -1
  92. package/dist/es5/dd-base-impl.d.ts +1 -1
  93. package/dist/es5/dd-base-impl.js +1 -1
  94. package/dist/es5/dd-base-impl.js.map +1 -1
  95. package/dist/es5/dd-draggable.d.ts +1 -1
  96. package/dist/es5/dd-draggable.js +1 -1
  97. package/dist/es5/dd-draggable.js.map +1 -1
  98. package/dist/es5/dd-droppable.d.ts +1 -1
  99. package/dist/es5/dd-droppable.js +1 -1
  100. package/dist/es5/dd-droppable.js.map +1 -1
  101. package/dist/es5/dd-element.d.ts +1 -1
  102. package/dist/es5/dd-element.js +1 -1
  103. package/dist/es5/dd-element.js.map +1 -1
  104. package/dist/es5/dd-gridstack.d.ts +1 -1
  105. package/dist/es5/dd-gridstack.js +1 -1
  106. package/dist/es5/dd-gridstack.js.map +1 -1
  107. package/dist/es5/dd-manager.d.ts +1 -1
  108. package/dist/es5/dd-manager.js +1 -1
  109. package/dist/es5/dd-manager.js.map +1 -1
  110. package/dist/es5/dd-resizable-handle.d.ts +1 -1
  111. package/dist/es5/dd-resizable-handle.js +1 -1
  112. package/dist/es5/dd-resizable-handle.js.map +1 -1
  113. package/dist/es5/dd-resizable.d.ts +1 -1
  114. package/dist/es5/dd-resizable.js +1 -1
  115. package/dist/es5/dd-resizable.js.map +1 -1
  116. package/dist/es5/dd-touch.d.ts +1 -1
  117. package/dist/es5/dd-touch.js +1 -1
  118. package/dist/es5/dd-touch.js.map +1 -1
  119. package/dist/es5/gridstack-all.js +1 -1
  120. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  121. package/dist/es5/gridstack-all.js.map +1 -1
  122. package/dist/es5/gridstack-engine.d.ts +1 -1
  123. package/dist/es5/gridstack-engine.js +1 -1
  124. package/dist/es5/gridstack-engine.js.map +1 -1
  125. package/dist/es5/gridstack-poly.js +1 -1
  126. package/dist/es5/gridstack.d.ts +8 -5
  127. package/dist/es5/gridstack.js +13 -7
  128. package/dist/es5/gridstack.js.map +1 -1
  129. package/dist/es5/types.d.ts +1 -1
  130. package/dist/es5/types.js +1 -1
  131. package/dist/es5/types.js.map +1 -1
  132. package/dist/es5/utils.d.ts +1 -1
  133. package/dist/es5/utils.js +1 -1
  134. package/dist/es5/utils.js.map +1 -1
  135. package/dist/gridstack-all.js +1 -1
  136. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  137. package/dist/gridstack-all.js.map +1 -1
  138. package/dist/gridstack-engine.d.ts +1 -1
  139. package/dist/gridstack-engine.js +1 -1
  140. package/dist/gridstack-engine.js.map +1 -1
  141. package/dist/gridstack.css +1 -1
  142. package/dist/gridstack.d.ts +8 -5
  143. package/dist/gridstack.js +13 -7
  144. package/dist/gridstack.js.map +1 -1
  145. package/dist/src/gridstack-extra.scss +3 -3
  146. package/dist/src/gridstack.scss +1 -1
  147. package/dist/types.d.ts +1 -1
  148. package/dist/types.js +1 -1
  149. package/dist/types.js.map +1 -1
  150. package/dist/utils.d.ts +1 -1
  151. package/dist/utils.js +1 -1
  152. package/dist/utils.js.map +1 -1
  153. package/doc/CHANGES.md +11 -1
  154. package/package.json +3 -3
  155. package/dist/ng/gridstack-item.component.js +0 -65
  156. package/dist/ng/gridstack-item.component.js.map +0 -1
  157. package/dist/ng/gridstack.component.js +0 -245
  158. package/dist/ng/gridstack.component.js.map +0 -1
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Example using Angular ngFor to loop through items and create DOM items - this uses a custom command.
3
+ * NOTE: see the simpler and better (tracks all changes) angular-ng-for-test
4
+ */
5
+
6
+ import { Component, AfterViewInit, Input, ViewChildren, QueryList, ElementRef } from '@angular/core';
7
+ import { Subject, zip } from "rxjs";
8
+
9
+ import { GridItemHTMLElement, GridStack, GridStackWidget } from 'gridstack';
10
+
11
+ @Component({
12
+ selector: "angular-ng-for-cmd-test",
13
+ template: `
14
+ <p><b>ngFor CMD</b>: Example using Angular ngFor to loop through items, but uses an explicity command to let us update GS (see automatic better way)</p>
15
+ <button (click)="add()">add item</button>
16
+ <button (click)="delete()">remove item</button>
17
+ <button (click)="modify()">modify item</button>
18
+ <div class="grid-stack">
19
+ <!-- using angular templating to create DOM, otherwise an easier way is to simply call grid.load(items) -->
20
+ <div
21
+ *ngFor="let n of items; let i = index; trackBy: identify"
22
+ [id]="i"
23
+ class="grid-stack-item"
24
+ [attr.gs-x]="n.x"
25
+ [attr.gs-y]="n.y"
26
+ [attr.gs-w]="n.w"
27
+ [attr.gs-h]="n.h"
28
+ #gridStackItem
29
+ >
30
+ <div class="grid-stack-item-content">item {{ i }}</div>
31
+ </div>
32
+ </div>
33
+ `,
34
+ // gridstack.min.css and other custom styles should be included in global styles.scss or here
35
+ })
36
+ export class AngularNgForCmdTestComponent implements AfterViewInit {
37
+ /** list of HTML items that we track to know when the DOM has been updated to make/remove GS widgets */
38
+ @ViewChildren("gridStackItem") gridstackItems!: QueryList<ElementRef<GridItemHTMLElement>>;
39
+
40
+ /** set the items to display. */
41
+ @Input() public items: GridStackWidget[] = [
42
+ {x: 0, y: 0},
43
+ {x: 1, y: 1},
44
+ {x: 2, y: 2},
45
+ ];
46
+
47
+ private grid!: GridStack;
48
+ private widgetToMake: Subject<{
49
+ action: "add" | "remove" | "update";
50
+ id: number;
51
+ }> = new Subject(); // consider to use a state management like ngrx component store to do this
52
+
53
+ constructor() {}
54
+
55
+ // wait until after DOM is ready to init gridstack - can't be ngOnInit() as angular ngFor needs to run first!
56
+ public ngAfterViewInit() {
57
+ this.grid = GridStack.init({
58
+ margin: 5,
59
+ float: true,
60
+ });
61
+
62
+ // To sync dom manipulation done by Angular and widget manipulation done by gridstack we need to zip the observables
63
+ zip(this.gridstackItems.changes, this.widgetToMake).subscribe(
64
+ ([changedWidget, widgetToMake]) => {
65
+ if (widgetToMake.action === "add") {
66
+ this.grid.makeWidget(`#${widgetToMake.id}`);
67
+ } else if (widgetToMake.action === "remove") {
68
+ const id = String(widgetToMake.id);
69
+ // Note: DOM element has been removed by Angular already so look for it through the engine node list
70
+ const removeEl = this.grid.engine.nodes.find((n) => n.el?.id === id)?.el;
71
+ if (removeEl) this.grid.removeWidget(removeEl);
72
+ }
73
+ }
74
+ );
75
+
76
+ // TODO: the problem with this code is that our items list does NOT reflect changes made by GS (user directly changing,
77
+ // or conflict during initial layout) and believe the other ngFor example (which does track changes) is also cleaner
78
+ // as it doesn't require user creating special action commands nor track 'both' changes using zip().
79
+ // TODO: identify() uses index which is not guaranteed to match between invocations (insert/delete in
80
+ // middle of list instead of end as demo does)
81
+ }
82
+
83
+ /**
84
+ * CRUD operations
85
+ */
86
+ public add() {
87
+ this.items = [...this.items, { x: 3, y: 0, w: 3 }];
88
+ this.widgetToMake.next({ action: "add", id: this.items.length - 1 });
89
+ }
90
+
91
+ public delete() {
92
+ this.items.pop();
93
+ this.widgetToMake.next({ action: "remove", id: this.items.length });
94
+ }
95
+
96
+ // a change of a widget doesn´t change to amount of items in ngFor therefore we don´t need to do it through the zip function above
97
+ public modify() {
98
+ const updateEl = this.grid.getGridItems().find((el) => el.id === `${0}`);
99
+ this.grid.update(updateEl!, { w: 2 });
100
+ }
101
+
102
+ // ngFor lookup indexing
103
+ identify(index: number) {
104
+ return index;
105
+ }
106
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Simplest Angular Example using GridStack API directly
3
+ */
4
+ import { Component, OnInit } from '@angular/core';
5
+
6
+ import { GridStack, GridStackWidget } from 'gridstack';
7
+
8
+ @Component({
9
+ selector: 'angular-simple-test',
10
+ template: `
11
+ <p><b>SIMPLEST</b>: angular example using GridStack API directly, so not really using any angular construct per say other than waiting for DOM rendering</p>
12
+ <button (click)="add()">add item</button>
13
+ <button (click)="delete()">remove item</button>
14
+ <button (click)="change()">modify item</button>
15
+ <div class="grid-stack"></div>
16
+ `,
17
+ // gridstack.min.css and other custom styles should be included in global styles.scss
18
+ })
19
+ export class AngularSimpleComponent implements OnInit {
20
+ public items: GridStackWidget[] = [
21
+ { x: 0, y: 0, w: 9, h: 6, content: '0' },
22
+ { x: 9, y: 0, w: 3, h: 3, content: '1' },
23
+ { x: 9, y: 3, w: 3, h: 3, content: '2' },
24
+ ];
25
+ private grid!: GridStack;
26
+
27
+ constructor() {}
28
+
29
+ // simple div above doesn't require Angular to run, so init gridstack here
30
+ public ngOnInit() {
31
+ this.grid = GridStack.init({
32
+ cellHeight: 70,
33
+ })
34
+ .load(this.items); // and load our content directly (will create DOM)
35
+ }
36
+
37
+ public add() {
38
+ this.grid.addWidget({w: 3, content: 'new content'});
39
+ }
40
+ public delete() {
41
+ this.grid.removeWidget(this.grid.engine.nodes[0].el!);
42
+ }
43
+ public change() {
44
+ this.grid.update(this.grid.engine.nodes[0].el!, {w: 1});
45
+ }
46
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ export const environment = {
2
+ production: true
3
+ };
@@ -0,0 +1,16 @@
1
+ // This file can be replaced during build by using the `fileReplacements` array.
2
+ // `ng build` replaces `environment.ts` with `environment.prod.ts`.
3
+ // The list of file replacements can be found in `angular.json`.
4
+
5
+ export const environment = {
6
+ production: false
7
+ };
8
+
9
+ /*
10
+ * For easier debugging in development mode, you can import the following file
11
+ * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12
+ *
13
+ * This import should be commented out in production mode because it will have a negative impact
14
+ * on performance if an error is thrown.
15
+ */
16
+ // import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Demo</title>
6
+ <base href="/">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ <link rel="icon" type="image/x-icon" href="favicon.ico">
9
+ </head>
10
+ <body>
11
+ <app-root></app-root>
12
+ </body>
13
+ </html>
@@ -0,0 +1,12 @@
1
+ import { enableProdMode } from '@angular/core';
2
+ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3
+
4
+ import { AppModule } from './app/app.module';
5
+ import { environment } from './environments/environment';
6
+
7
+ if (environment.production) {
8
+ enableProdMode();
9
+ }
10
+
11
+ platformBrowserDynamic().bootstrapModule(AppModule)
12
+ .catch(err => console.error(err));
@@ -0,0 +1,53 @@
1
+ /**
2
+ * This file includes polyfills needed by Angular and is loaded before the app.
3
+ * You can add your own extra polyfills to this file.
4
+ *
5
+ * This file is divided into 2 sections:
6
+ * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7
+ * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8
+ * file.
9
+ *
10
+ * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11
+ * automatically update themselves. This includes recent versions of Safari, Chrome (including
12
+ * Opera), Edge on the desktop, and iOS and Chrome on mobile.
13
+ *
14
+ * Learn more in https://angular.io/guide/browser-support
15
+ */
16
+
17
+ /***************************************************************************************************
18
+ * BROWSER POLYFILLS
19
+ */
20
+
21
+ /**
22
+ * By default, zone.js will patch all possible macroTask and DomEvents
23
+ * user can disable parts of macroTask/DomEvents patch by setting following flags
24
+ * because those flags need to be set before `zone.js` being loaded, and webpack
25
+ * will put import in the top of bundle, so user need to create a separate file
26
+ * in this directory (for example: zone-flags.ts), and put the following flags
27
+ * into that file, and then add the following code before importing zone.js.
28
+ * import './zone-flags';
29
+ *
30
+ * The flags allowed in zone-flags.ts are listed here.
31
+ *
32
+ * The following flags will work for all browsers.
33
+ *
34
+ * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
35
+ * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
36
+ * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
37
+ *
38
+ * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
39
+ * with the following flag, it will bypass `zone.js` patch for IE/Edge
40
+ *
41
+ * (window as any).__Zone_enable_cross_context_check = true;
42
+ *
43
+ */
44
+
45
+ /***************************************************************************************************
46
+ * Zone JS is required by default for Angular itself.
47
+ */
48
+ import 'zone.js'; // Included with Angular CLI.
49
+
50
+
51
+ /***************************************************************************************************
52
+ * APPLICATION IMPORTS
53
+ */
@@ -0,0 +1,4 @@
1
+ /* re-use existing demo css file we already use for the plain demos - that include gridstack.css which is required */
2
+ @import "../../../../demo/demo.css";
3
+ /* required file for gridstack 2-11 column */
4
+ @import "../../../../dist/gridstack-extra.css";
@@ -0,0 +1,26 @@
1
+ // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2
+
3
+ import 'zone.js/testing';
4
+ import { getTestBed } from '@angular/core/testing';
5
+ import {
6
+ BrowserDynamicTestingModule,
7
+ platformBrowserDynamicTesting
8
+ } from '@angular/platform-browser-dynamic/testing';
9
+
10
+ declare const require: {
11
+ context(path: string, deep?: boolean, filter?: RegExp): {
12
+ <T>(id: string): T;
13
+ keys(): string[];
14
+ };
15
+ };
16
+
17
+ // First, initialize the Angular testing environment.
18
+ getTestBed().initTestEnvironment(
19
+ BrowserDynamicTestingModule,
20
+ platformBrowserDynamicTesting(),
21
+ );
22
+
23
+ // Then we find all the tests.
24
+ const context = require.context('./', true, /\.spec\.ts$/);
25
+ // And load the modules.
26
+ context.keys().forEach(context);
@@ -0,0 +1,15 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/app",
6
+ "types": []
7
+ },
8
+ "files": [
9
+ "src/main.ts",
10
+ "src/polyfills.ts"
11
+ ],
12
+ "include": [
13
+ "src/**/*.d.ts"
14
+ ]
15
+ }
@@ -0,0 +1,18 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/spec",
6
+ "types": [
7
+ "jasmine"
8
+ ]
9
+ },
10
+ "files": [
11
+ "src/test.ts",
12
+ "src/polyfills.ts"
13
+ ],
14
+ "include": [
15
+ "src/**/*.spec.ts",
16
+ "src/**/*.d.ts"
17
+ ]
18
+ }
@@ -0,0 +1,24 @@
1
+ # Gs
2
+
3
+ This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.2.0.
4
+
5
+ ## Code scaffolding
6
+
7
+ Run `ng generate component component-name --project gs` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project gs`.
8
+ > Note: Don't forget to add `--project gs` or else it will be added to the default project in your `angular.json` file.
9
+
10
+ ## Build
11
+
12
+ Run `ng build gs` to build the project. The build artifacts will be stored in the `dist/` directory.
13
+
14
+ ## Publishing
15
+
16
+ After building your library with `ng build gs`, go to the dist folder `cd dist/gs` and run `npm publish`.
17
+
18
+ ## Running unit tests
19
+
20
+ Run `ng test gs` to execute the unit tests via [Karma](https://karma-runner.github.io).
21
+
22
+ ## Further help
23
+
24
+ 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,7 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../../dist/angular",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "gridstack-angular",
3
+ "version": "8.2.0",
4
+ "peerDependencies": {
5
+ "@angular/common": "^14.2.0",
6
+ "@angular/core": "^14.2.0"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ }
11
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * gridstack-item.component.ts 8.2.0
3
+ * Copyright (c) 2022 Alain Dumesny - see GridStack root license
4
+ */
5
+
6
+ /**
7
+ * Base interface that all widgets need to implement in order for GridstackItemComponent to correctly save/load/delete/..
8
+ */
9
+
10
+ import { Injectable } from '@angular/core';
11
+ import { NgCompInputs, NgGridStackWidget } from './gridstack.component';
12
+
13
+ @Injectable()
14
+ export abstract class BaseWidget {
15
+ /**
16
+ * REDEFINE to return an object representing the data needed to re-create yourself, other than `selector` already handled.
17
+ * This should map directly to the @Input() fields of this objects on create, so a simple apply can be used on read
18
+ */
19
+ public serialize(): NgCompInputs | undefined { return; }
20
+
21
+ /**
22
+ * REDEFINE this if your widget needs to read from saved data and transform it to create itself - you do this for
23
+ * things that are not mapped directly into @Input() fields for example.
24
+ */
25
+ public deserialize(w: NgGridStackWidget) {
26
+ if (w.input) Object.assign(this, w.input);
27
+ }
28
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * gridstack-item.component.ts 8.2.0
3
+ * Copyright (c) 2022 Alain Dumesny - see GridStack root license
4
+ */
5
+
6
+ import { Component, ElementRef, Input, ViewChild, ViewContainerRef, OnDestroy, ComponentRef } from '@angular/core';
7
+ import { GridItemHTMLElement, GridStackNode } from 'gridstack';
8
+ import { BaseWidget } from './base-widget';
9
+
10
+ /** store element to Ng Class pointer back */
11
+ export interface GridItemCompHTMLElement extends GridItemHTMLElement {
12
+ _gridItemComp?: GridstackItemComponent;
13
+ }
14
+
15
+ /**
16
+ * HTML Component Wrapper for gridstack items, in combination with GridstackComponent for parent grid
17
+ */
18
+ @Component({
19
+ selector: 'gridstack-item',
20
+ template: `
21
+ <div class="grid-stack-item-content">
22
+ <!-- where dynamic items go based on component types, or sub-grids, etc...) -->
23
+ <ng-template #container></ng-template>
24
+ <!-- any static (defined in dom) content goes here -->
25
+ <ng-content></ng-content>
26
+ <!-- fallback HTML content from GridStackWidget content field if used instead -->
27
+ {{options.content}}
28
+ </div>`,
29
+ styles: [`
30
+ :host { display: block; }
31
+ `],
32
+ // changeDetection: ChangeDetectionStrategy.OnPush, // IFF you want to optimize and control when ChangeDetection needs to happen...
33
+ })
34
+ export class GridstackItemComponent implements OnDestroy {
35
+
36
+ /** container to append items dynamically */
37
+ @ViewChild('container', { read: ViewContainerRef, static: true}) public container?: ViewContainerRef;
38
+
39
+ /** ComponentRef of ourself - used by dynamic object to correctly get removed */
40
+ public ref: ComponentRef<GridstackItemComponent> | undefined;
41
+
42
+ /** child component so we can save/restore additional data to be saved along */
43
+ public childWidget: BaseWidget | undefined;
44
+
45
+ /** list of options for creating/updating this item */
46
+ @Input() public set options(val: GridStackNode) {
47
+ if (this.el.gridstackNode?.grid) {
48
+ // already built, do an update...
49
+ this.el.gridstackNode.grid.update(this.el, val);
50
+ } else {
51
+ // store our custom element in options so we can update it and not re-create a generic div!
52
+ this._options = {...val, el: this.el};
53
+ }
54
+ }
55
+ /** return the latest grid options (from GS once built, otherwise initial values) */
56
+ public get options(): GridStackNode {
57
+ return this.el.gridstackNode || this._options || {el: this.el};
58
+ }
59
+
60
+ private _options?: GridStackNode;
61
+
62
+ /** return the native element that contains grid specific fields as well */
63
+ public get el(): GridItemCompHTMLElement { return this.elementRef.nativeElement; }
64
+
65
+ /** clears the initial options now that we've built */
66
+ public clearOptions() {
67
+ delete this._options;
68
+ }
69
+
70
+ constructor(private readonly elementRef: ElementRef<GridItemHTMLElement>) {
71
+ this.el._gridItemComp = this;
72
+ }
73
+
74
+ public ngOnDestroy(): void {
75
+ delete this.ref;
76
+ delete this.el._gridItemComp;
77
+ }
78
+ }