Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit 679d0fb

Browse files
committed
Change to use gulp as the build system, rather than including static files. Change the file structure to make it work smoother. Update the README also
1 parent 378fbb2 commit 679d0fb

File tree

16 files changed

+145
-97
lines changed

16 files changed

+145
-97
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*.js
2-
*.js.map
31
typings
42
npm-debug.log
3+
dist/
4+
node_modules/

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ The demo included in this repo follows the [Angular 2 quick start](https://angul
1111
#### Setup
1212
----------
1313

14-
First you'll need to install [Node](http://nodejs.org). Then run:
14+
To use the Angular 2 Grid system, simply run `npm install angular2-grid` and then include NgGrid.ts into your typescript compilation. No more work needed!
15+
16+
If you want to help with development or try the demo, it's less simple, but not hard. First you'll need to install [Node](http://nodejs.org) and check out a copy of the repo. Then run:
1517

1618
```shell
17-
$ npm install -g tsd typescript
18-
$ tsd install angular2/
19-
$ tsc -m commonjs -t es5 -d --sourcemap --emitDecoratorMetadata --experimentalDecorators
19+
$ npm install --dev
20+
$ gulp build
2021
```
2122

22-
This will give you a fully compiled version of the demo that you can run using the HTTP server of your choice. Currently, it points to the following locations to get the required angular files:
23-
```
24-
- https://github.jspm.io/jmcriffey/[email protected]/traceur-runtime.js
25-
- https://jspm.io/[email protected]
26-
- https://code.angularjs.org/2.0.0-alpha.34/angular2.dev.js
27-
```
23+
This will give you a fully compiled version of the demo that you can run using the HTTP server of your choice.
24+
25+
You can also use `gulp watch` to compile the demo and have gulp watch for any changes.
26+
27+
NOTE: By default Angular 2 and System.js are not listed as actual dependencies, but as peer dependencies, so that npm doesn't install them on systems that just require the install file. If they are not installed, this could cause gulp to break. To fix this, run `npm install angular2 systemjs` and rerun the build command.
2828

2929
#### Config
3030
-----------

app.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"license": "MIT",
2323
"ignore": [
2424
"*",
25-
"!NgGrid.ts",
26-
"!NgGrid.css"
25+
"!src/NgGrid.ts",
26+
"!src/NgGrid.css"
2727
],
2828
"repository": {
2929
"type": "git",

gulpfile.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
var gulp = require('gulp');
2+
var typescript = require('gulp-typescript');
3+
var merge = require('merge2');
4+
5+
var tsProject = typescript.createProject({
6+
declarationFiles: true,
7+
module: 'system',
8+
target: 'ES5',
9+
emitDecoratorMetadata: true,
10+
experimentalDecorators: true
11+
});
12+
13+
var PATHS = {
14+
src: {
15+
ts: 'src/*.ts',
16+
html: 'src/*.html',
17+
css: 'src/*.css',
18+
},
19+
lib: [
20+
'node_modules/angular2/node_modules/traceur/bin/traceur-runtime.js',
21+
'node_modules/angular2/bundles/angular2.js',
22+
'node_modules/systemjs/dist/system-csp-production.js'
23+
],
24+
typings: 'node_modules/angular2/bundles/typings/angular2/angular2.d.ts'
25+
};
26+
27+
gulp.task('clean', function (done) {
28+
var del = require('del');
29+
del(['dist'], done);
30+
});
31+
32+
gulp.task('ts', function () {
33+
34+
var tsResult = gulp.src([PATHS.src.ts, PATHS.typings])
35+
.pipe(typescript(tsProject));
36+
37+
return merge([
38+
tsResult.js.pipe(gulp.dest('dist')),
39+
tsResult.dts.pipe(gulp.dest('src'))
40+
]);
41+
});
42+
43+
gulp.task('html', function () {
44+
return gulp.src(PATHS.src.html).pipe(gulp.dest('dist'));
45+
});
46+
47+
gulp.task('css', function () {
48+
return gulp.src(PATHS.src.css).pipe(gulp.dest('dist'));
49+
});
50+
51+
gulp.task('libs', function () {
52+
return gulp.src(PATHS.lib).pipe(gulp.dest('dist/lib'));
53+
});
54+
55+
gulp.task('build', function() {
56+
gulp.start('libs', 'html', 'css', 'ts');
57+
});
58+
59+
gulp.task('rebuild', ['clean'], function() {
60+
gulp.start('build');
61+
});
62+
63+
gulp.task('watch', ['build'], function () {
64+
gulp.watch(PATHS.src.ts, ['ts']);
65+
gulp.watch(PATHS.src.html, ['html']);
66+
gulp.watch(PATHS.src.css, ['css']);
67+
});
68+
69+
gulp.task('default', function() {
70+
gulp.start('build');
71+
});

index.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222
},
2323
"homepage": "https://github.com/BTMorton/angular2-grid",
2424
"peerDependencies": {
25-
"angular2": "2.0.0-alpha.35"
25+
"angular2": "2.0.0-alpha.35",
26+
"systemjs": "^0.18.17"
2627
},
2728
"files": [
28-
"NgGrid.ts",
29-
"NgGrid.css"
30-
]
29+
"src/NgGrid.ts",
30+
"src/NgGrid.css"
31+
],
32+
"devDependencies": {
33+
"del": "^1.2.1",
34+
"gulp": "^3.9.0",
35+
"gulp-typescript": "^2.8.1",
36+
"merge2": "^0.3.6",
37+
"typescript": "^1.5.3"
38+
}
3139
}
File renamed without changes.

NgGrid.d.ts renamed to src/NgGrid.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference path="typings/angular2/angular2.d.ts" />
21
import { ElementRef, Renderer, EventEmitter, DynamicComponentLoader, KeyValueDiffers } from 'angular2/angular2';
32
export declare class NgGrid {
43
private _differs;
@@ -56,7 +55,7 @@ export declare class NgGrid {
5655
y: number;
5756
};
5857
onCheck(): void;
59-
setMargins(margins: any): void;
58+
setMargins(margins: Array<string>): void;
6059
enableDrag(): void;
6160
disableDrag(): void;
6261
enableResize(): void;

NgGrid.ts renamed to src/NgGrid.ts

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="typings/angular2/angular2.d.ts" />
2-
31
import {Component, View, Directive, ElementRef, Renderer, EventEmitter, DynamicComponentLoader, Host, ViewEncapsulation, Type, ComponentRef, LifecycleEvent, KeyValueDiffer, KeyValueDiffers} from 'angular2/angular2';
42

53
@Directive({
@@ -46,7 +44,7 @@ export class NgGrid {
4644
private _draggingItem: NgGridItem = null;
4745
private _resizingItem: NgGridItem = null;
4846
private _resizeDirection: string = null;
49-
private _itemGrid = {1: {1: null}};
47+
private _itemGrid: Map<number, Map<number, NgGridItem>> = {1: {1: null}};
5048
private _containerWidth: number;
5149
private _containerHeight: number;
5250
private _maxCols:number = 0;
@@ -81,7 +79,7 @@ export class NgGrid {
8179
private _config = NgGrid.CONST_DEFAULT_CONFIG;
8280

8381
// [ng-grid] attribute handler
84-
set config(v) {
82+
set config(v: any) {
8583
this._config = v;
8684

8785
if (this._differ == null && v != null) {
@@ -99,7 +97,7 @@ export class NgGrid {
9997
}
10098

10199
// Public methods
102-
public setConfig(config): void {
100+
public setConfig(config: any): void {
103101
var maxColRowChanged = false;
104102
for (var x in config) {
105103
var val = config[x];
@@ -171,13 +169,13 @@ export class NgGrid {
171169
}
172170
}
173171

174-
for (var r = 1; r <= this._getMaxRow(); r++) {
172+
for (var r: number = 1; r <= this._getMaxRow(); r++) {
175173
if (this._itemGrid[r] != null) {
176-
for (var c = 1; c <= this._getMaxCol(); c++) {
174+
for (var c: number = 1; c <= this._getMaxCol(); c++) {
177175
if (this._itemGrid[r] != null && this._itemGrid[r][c] != null) {
178-
var item = this._itemGrid[r][c];
179-
var pos = item.getGridPosition();
180-
var dims = item.getSize();
176+
var item: NgGridItem = this._itemGrid[r][c];
177+
var pos: {'col': number, 'row': number} = item.getGridPosition();
178+
var dims: {'x': number, 'y': number} = item.getSize();
181179

182180
if ((this._maxCols > 0 && (pos.col + dims.x - 1) > this._maxCols) || (this._maxRows > 0 && (pos.row + dims.y - 1) > this._maxRows)) {
183181
this._removeFromGrid(item);
@@ -209,15 +207,15 @@ export class NgGrid {
209207
}
210208

211209
if (this._autoResize && this._maxCols > 0) {
212-
var maxWidth = this._ngEl.nativeElement.parentElement.getBoundingClientRect().width;
210+
var maxWidth: number = this._ngEl.nativeElement.parentElement.getBoundingClientRect().width;
213211

214-
var colWidth = Math.floor(maxWidth / this._maxCols);
212+
var colWidth: number = Math.floor(maxWidth / this._maxCols);
215213
colWidth -= (this.marginLeft + this.marginRight);
216214
this.colWidth = colWidth;
217215
} else if (this._autoResize && this._maxRows > 0) {
218-
var maxHeight = window.innerHeight;
216+
var maxHeight: number = window.innerHeight;
219217

220-
var rowHeight = Math.floor(maxHeight / this._maxRows);
218+
var rowHeight: number = Math.floor(maxHeight / this._maxRows);
221219
rowHeight -= (this.marginTop + this.marginBottom);
222220
this.rowHeight = rowHeight;
223221
}
@@ -246,7 +244,7 @@ export class NgGrid {
246244
}
247245
}
248246

249-
public setMargins(margins): void {
247+
public setMargins(margins: Array<string>): void {
250248
this.marginTop = parseInt(margins[0]);
251249
this.marginRight = margins.length >= 2 ? parseInt(margins[1]) : this.marginTop;
252250
this.marginBottom = margins.length >= 3 ? parseInt(margins[2]) : this.marginTop;
@@ -283,7 +281,7 @@ export class NgGrid {
283281
}
284282

285283
// Private methods
286-
private _onResize(e) {
284+
private _onResize(e: any): void {
287285
if (this._autoResize && this._maxCols > 0) {
288286
var maxWidth = this._ngEl.nativeElement.parentElement.getBoundingClientRect().width;
289287

@@ -306,9 +304,9 @@ export class NgGrid {
306304
}
307305

308306
private _applyChanges(changes: any): void {
309-
changes.forEachAddedItem((record) => { this._config[record.key] = record.currentValue; });
310-
changes.forEachChangedItem((record) => { this._config[record.key] = record.currentValue; });
311-
changes.forEachRemovedItem((record) => { delete this._config[record.key]; });
307+
changes.forEachAddedItem((record: any) => { this._config[record.key] = record.currentValue; });
308+
changes.forEachChangedItem((record: any) => { this._config[record.key] = record.currentValue; });
309+
changes.forEachRemovedItem((record: any) => { delete this._config[record.key]; });
312310
this.setConfig(this._config);
313311
}
314312

@@ -481,7 +479,7 @@ export class NgGrid {
481479

482480
this._draggingItem.setGridPosition(itemPos.col, itemPos.row);
483481
this._addToGrid(this._draggingItem);
484-
console.log("STOP", itemPos);
482+
485483
this._cascadeGrid();
486484

487485
this._draggingItem.stopMoving();
@@ -519,7 +517,7 @@ export class NgGrid {
519517
return { 'x': sizex, 'y': sizey };
520518
}
521519

522-
private _calculateGridSize(width, height): {x: number, y: number} {
520+
private _calculateGridSize(width: number, height: number): {x: number, y: number} {
523521
width += this.marginLeft + this.marginRight;
524522
height += this.marginTop + this.marginBottom;
525523

@@ -670,7 +668,6 @@ export class NgGrid {
670668
for (var c:number = 1; c <= this._getMaxCol(); c++) {
671669
if (this._itemGrid[r] == undefined) break;
672670
if (c < lowCol[r]) continue;
673-
console.log(r, c, lowCol);
674671

675672
if (this._itemGrid[r][c] != null) {
676673
var item = this._itemGrid[r][c];
@@ -891,7 +888,7 @@ export class NgGridItem {
891888
public resizeStop: EventEmitter = new EventEmitter();
892889

893890
// Default config
894-
private static CONST_DEFAULT_CONFIG = {
891+
private static CONST_DEFAULT_CONFIG: { 'col': number, 'row': number, 'sizex': number, 'sizey': number, 'dragHandle': string, 'resizeHandle': string } = {
895892
'col': 1,
896893
'row': 1,
897894
'sizex': 1,
@@ -918,7 +915,7 @@ export class NgGridItem {
918915
private _added: boolean = false;
919916

920917
// [ng-grid-item] handler
921-
set config(v) {
918+
set config(v: any) {
922919
var defaults = NgGridItem.CONST_DEFAULT_CONFIG;
923920

924921
for (var x in defaults)
@@ -947,11 +944,11 @@ export class NgGridItem {
947944
// Public methods
948945
public canDrag(e: any): boolean {
949946
if (this._dragHandle) {
950-
var foundHandle;
951-
var paths = e.path;
947+
var foundHandle: boolean;
948+
var paths: Array<any> = e.path;
952949
paths.pop(); // Get rid of #document
953950

954-
var last = null;
951+
var last: any = null;
955952

956953
for (var x in paths) {
957954
if (last !== null) {
@@ -972,11 +969,11 @@ export class NgGridItem {
972969

973970
public canResize(e: any): string {
974971
if (this._resizeHandle) {
975-
var foundHandle;
976-
var paths = e.path;
972+
var foundHandle: boolean;
973+
var paths: Array<any> = e.path;
977974
paths.pop(); // Get rid of #document
978975

979-
var last = null;
976+
var last: any = null;
980977

981978
for (var x in paths) {
982979
if (last !== null) {
@@ -1032,7 +1029,7 @@ export class NgGridItem {
10321029
}
10331030
}
10341031

1035-
public onDestroy() {
1032+
public onDestroy(): void {
10361033
if (this._added) this._ngGrid.removeItem(this);
10371034
}
10381035

@@ -1066,7 +1063,7 @@ export class NgGridItem {
10661063
}
10671064

10681065
// Setters
1069-
public setConfig(config): void {
1066+
public setConfig(config: any): void {
10701067
this._col = config.col;
10711068
this._row = config.row;
10721069
this._sizex = config.sizex;
@@ -1091,7 +1088,7 @@ export class NgGridItem {
10911088
this._col = col;
10921089
this._row = row;
10931090
this.gridPosition = {'col': this._col, 'row': this._row};
1094-
console.log(this.gridPosition);
1091+
10951092
this._recalculatePosition();
10961093

10971094
this.itemChange.next({'col': this._col, 'row': this._row, 'sizex': this._sizex, 'sizey': this._sizey});

0 commit comments

Comments
 (0)