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.
- package/README.md +12 -11
- package/angular/.editorconfig +16 -0
- package/angular/.vscode/extensions.json +4 -0
- package/angular/.vscode/launch.json +20 -0
- package/angular/.vscode/tasks.json +42 -0
- package/{dist/ng → angular}/README.md +170 -154
- package/angular/README_build.md +27 -0
- package/angular/angular.json +132 -0
- package/angular/package.json +40 -0
- package/angular/projects/demo/.browserslistrc +16 -0
- package/angular/projects/demo/src/app/app.component.css +11 -0
- package/angular/projects/demo/src/app/app.component.html +78 -0
- package/angular/projects/demo/src/app/app.component.spec.ts +25 -0
- package/angular/projects/demo/src/app/app.component.ts +208 -0
- package/angular/projects/demo/src/app/app.module.ts +39 -0
- package/angular/projects/demo/src/app/dummy.component.ts +35 -0
- package/angular/projects/demo/src/app/ngFor.ts +131 -0
- package/angular/projects/demo/src/app/ngFor_cmd.ts +106 -0
- package/angular/projects/demo/src/app/simple.ts +46 -0
- package/angular/projects/demo/src/assets/.gitkeep +0 -0
- package/angular/projects/demo/src/environments/environment.prod.ts +3 -0
- package/angular/projects/demo/src/environments/environment.ts +16 -0
- package/angular/projects/demo/src/favicon.ico +0 -0
- package/angular/projects/demo/src/index.html +13 -0
- package/angular/projects/demo/src/main.ts +12 -0
- package/angular/projects/demo/src/polyfills.ts +53 -0
- package/angular/projects/demo/src/styles.css +4 -0
- package/angular/projects/demo/src/test.ts +26 -0
- package/angular/projects/demo/tsconfig.app.json +15 -0
- package/angular/projects/demo/tsconfig.spec.json +18 -0
- package/angular/projects/lib/README.md +24 -0
- package/angular/projects/lib/ng-package.json +7 -0
- package/angular/projects/lib/package.json +11 -0
- package/angular/projects/lib/src/lib/base-widget.ts +28 -0
- package/angular/projects/lib/src/lib/gridstack-item.component.ts +78 -0
- package/angular/projects/lib/src/lib/gridstack.component.ts +287 -0
- package/angular/projects/lib/src/lib/gridstack.module.ts +32 -0
- package/angular/projects/lib/src/public-api.ts +8 -0
- package/angular/projects/lib/src/test.ts +27 -0
- package/angular/projects/lib/tsconfig.lib.json +15 -0
- package/angular/projects/lib/tsconfig.lib.prod.json +10 -0
- package/angular/projects/lib/tsconfig.spec.json +17 -0
- package/dist/angular/README.md +170 -0
- package/dist/angular/esm2020/gridstack-angular.mjs +5 -0
- package/dist/angular/esm2020/lib/base-widget.mjs +30 -0
- package/dist/angular/esm2020/lib/gridstack-item.component.mjs +68 -0
- package/dist/angular/esm2020/lib/gridstack.component.mjs +278 -0
- package/dist/angular/esm2020/lib/gridstack.module.mjs +39 -0
- package/dist/angular/esm2020/public-api.mjs +8 -0
- package/dist/angular/fesm2015/gridstack-angular.mjs +418 -0
- package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -0
- package/dist/angular/fesm2020/gridstack-angular.mjs +413 -0
- package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -0
- package/dist/angular/index.d.ts +5 -0
- package/dist/angular/lib/base-widget.d.ts +16 -0
- package/dist/{ng → angular/lib}/gridstack-item.component.d.ts +37 -29
- package/dist/{ng → angular/lib}/gridstack.component.d.ts +129 -118
- package/dist/angular/lib/gridstack.module.d.ts +10 -0
- package/dist/angular/package.json +31 -0
- package/dist/angular/public-api.d.ts +4 -0
- package/dist/angular/src/base-widget.ts +28 -0
- package/dist/angular/src/gridstack-item.component.ts +78 -0
- package/dist/angular/src/gridstack.component.ts +287 -0
- package/dist/angular/src/gridstack.module.ts +32 -0
- package/dist/dd-base-impl.d.ts +1 -1
- package/dist/dd-base-impl.js +1 -1
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +1 -1
- package/dist/dd-draggable.js +1 -1
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +1 -1
- package/dist/dd-droppable.js +1 -1
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +1 -1
- package/dist/dd-element.js +1 -1
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +1 -1
- package/dist/dd-gridstack.js +1 -1
- package/dist/dd-gridstack.js.map +1 -1
- package/dist/dd-manager.d.ts +1 -1
- package/dist/dd-manager.js +1 -1
- package/dist/dd-manager.js.map +1 -1
- package/dist/dd-resizable-handle.d.ts +1 -1
- package/dist/dd-resizable-handle.js +1 -1
- package/dist/dd-resizable-handle.js.map +1 -1
- package/dist/dd-resizable.d.ts +1 -1
- package/dist/dd-resizable.js +1 -1
- package/dist/dd-resizable.js.map +1 -1
- package/dist/dd-touch.d.ts +1 -1
- package/dist/dd-touch.js +1 -1
- package/dist/dd-touch.js.map +1 -1
- package/dist/es5/dd-base-impl.d.ts +1 -1
- package/dist/es5/dd-base-impl.js +1 -1
- package/dist/es5/dd-base-impl.js.map +1 -1
- package/dist/es5/dd-draggable.d.ts +1 -1
- package/dist/es5/dd-draggable.js +1 -1
- package/dist/es5/dd-draggable.js.map +1 -1
- package/dist/es5/dd-droppable.d.ts +1 -1
- package/dist/es5/dd-droppable.js +1 -1
- package/dist/es5/dd-droppable.js.map +1 -1
- package/dist/es5/dd-element.d.ts +1 -1
- package/dist/es5/dd-element.js +1 -1
- package/dist/es5/dd-element.js.map +1 -1
- package/dist/es5/dd-gridstack.d.ts +1 -1
- package/dist/es5/dd-gridstack.js +1 -1
- package/dist/es5/dd-gridstack.js.map +1 -1
- package/dist/es5/dd-manager.d.ts +1 -1
- package/dist/es5/dd-manager.js +1 -1
- package/dist/es5/dd-manager.js.map +1 -1
- package/dist/es5/dd-resizable-handle.d.ts +1 -1
- package/dist/es5/dd-resizable-handle.js +1 -1
- package/dist/es5/dd-resizable-handle.js.map +1 -1
- package/dist/es5/dd-resizable.d.ts +1 -1
- package/dist/es5/dd-resizable.js +1 -1
- package/dist/es5/dd-resizable.js.map +1 -1
- package/dist/es5/dd-touch.d.ts +1 -1
- package/dist/es5/dd-touch.js +1 -1
- package/dist/es5/dd-touch.js.map +1 -1
- package/dist/es5/gridstack-all.js +1 -1
- package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/es5/gridstack-all.js.map +1 -1
- package/dist/es5/gridstack-engine.d.ts +1 -1
- package/dist/es5/gridstack-engine.js +1 -1
- package/dist/es5/gridstack-engine.js.map +1 -1
- package/dist/es5/gridstack-poly.js +1 -1
- package/dist/es5/gridstack.d.ts +8 -5
- package/dist/es5/gridstack.js +13 -7
- package/dist/es5/gridstack.js.map +1 -1
- package/dist/es5/types.d.ts +1 -1
- package/dist/es5/types.js +1 -1
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/utils.d.ts +1 -1
- package/dist/es5/utils.js +1 -1
- package/dist/es5/utils.js.map +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack-engine.d.ts +1 -1
- package/dist/gridstack-engine.js +1 -1
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack.css +1 -1
- package/dist/gridstack.d.ts +8 -5
- package/dist/gridstack.js +13 -7
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack-extra.scss +3 -3
- package/dist/src/gridstack.scss +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/doc/CHANGES.md +11 -1
- package/package.json +3 -3
- package/dist/ng/gridstack-item.component.js +0 -65
- package/dist/ng/gridstack-item.component.js.map +0 -1
- package/dist/ng/gridstack.component.js +0 -245
- 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,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.
|
|
Binary file
|
|
@@ -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,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,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
|
+
}
|