Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78599e6

Browse files
authored
Merge pull request gridstack#1249 from adumesny/typescript
TS: packaging fix
2 parents eb4b745 + fc69a66 commit 78599e6

18 files changed

+139
-121
lines changed

.eslintignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dist/*.js
22
demo/*
33
spec/*
4-
src/jquery.js
5-
src/jquery-ui.js
4+
src/jq/jquery.js
5+
src/jq/jquery-ui.js

Gruntfile.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*eslint-disable camelcase */
22
module.exports = function(grunt) {
33
grunt.loadNpmTasks('grunt-sass');
4-
grunt.loadNpmTasks('grunt-contrib-cssmin');
4+
// grunt.loadNpmTasks('grunt-contrib-cssmin');
55
grunt.loadNpmTasks('grunt-contrib-copy');
66
grunt.loadNpmTasks('grunt-contrib-uglify');
77
grunt.loadNpmTasks('grunt-eslint');
@@ -16,7 +16,7 @@ module.exports = function(grunt) {
1616
sass: {
1717
options: {
1818
implementation: sass,
19-
sourceMap: true
19+
sourceMap: false
2020
},
2121
dist: {
2222
files: {
@@ -25,6 +25,7 @@ module.exports = function(grunt) {
2525
}
2626
}
2727
},
28+
/* very little gain
2829
cssmin: {
2930
dist: {
3031
options: {
@@ -37,21 +38,18 @@ module.exports = function(grunt) {
3738
}
3839
}
3940
},
41+
*/
4042
copy: {
4143
dist: {
4244
files: {
43-
/*
4445
'dist/gridstack-poly.js': ['src/gridstack-poly.js'],
45-
'dist/jquery.js': ['src/jquery.js'],
46-
'dist/jquery-ui.js': ['src/jquery-ui.js'],
47-
*/
46+
'dist/jq/jquery.js': ['src/jq/jquery.js'],
47+
'dist/jq/jquery-ui.js': ['src/jq/jquery-ui.js'],
4848
'dist/src/gridstack.scss': ['src/gridstack.scss'],
4949
'dist/src/gridstack-extra.scss': ['src/gridstack-extra.scss'],
5050
}
5151
}
5252
},
53-
54-
/*
5553
uglify: {
5654
options: {
5755
sourceMap: true,
@@ -62,14 +60,18 @@ module.exports = function(grunt) {
6260
},
6361
dist: {
6462
files: {
65-
//'dist/gridstack-poly.min.js': 'src/gridstack-poly.js',
66-
//'dist/jquery.min.js': 'src/jquery.js',
67-
//'dist/jquery-ui.min.js': 'src/jquery-ui.js'
63+
'dist/jq/jqueryui-gridstack-dragdrop-plugin.min.js': 'dist/jq/jqueryui-gridstack-dragdrop-plugin.js',
64+
'dist/jq/jquery.min.js': 'src/jq/jquery.js',
65+
'dist/jq/jquery-ui.min.js': 'src/jq/jquery-ui.js',
66+
67+
'dist/gridstack-dragdrop-plugin.min.js': 'dist/gridstack-dragdrop-plugin.js',
68+
'dist/gridstack-engine.min.js': 'dist/gridstack-engine.js',
69+
'dist/gridstack-poly.min.js': 'src/gridstack-poly.js',
70+
'dist/types.min.js': 'dist/types.js',
71+
'dist/utils.min.js': 'dist/utils.js',
6872
}
6973
}
7074
},
71-
*/
72-
7375
eslint: {
7476
target: ['*.js', 'src/*.js']
7577
},
@@ -116,7 +118,7 @@ module.exports = function(grunt) {
116118
});
117119

118120
grunt.registerTask('lint', ['eslint']);
119-
grunt.registerTask('default', ['sass', 'cssmin', /*'eslint',*/ 'copy', /*'uglify'*/]);
121+
grunt.registerTask('default', ['sass', /*'cssmin', 'eslint',*/ 'copy', 'uglify']);
120122
grunt.registerTask('e2e-test', ['connect', 'protractor_webdriver', 'protractor']);
121123
};
122124
/*eslint-enable camelcase */

demo/float.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
<link rel="stylesheet" href="demo.css"/>
1010
<script src="../dist/gridstack.all.js"></script>
11-
<!--
11+
<!-- need umd vs commonjs ? but then GridStack not found...
1212
<script src="../dist/utils.js"></script>
1313
<script src="../dist/gridstack-engine.js"></script>
14-
<script src="../src/jquery.js"></script>
1514
<script src="../dist/gridstack.js"></script>
16-
<script src="../src/jquery-ui.js"></script>
17-
<script src="../dist/jqueryui-gridstack-dragdrop-plugin.js"></script>
15+
<script src="../src/jq/jquery.js"></script>
16+
<script src="../src/jq/jquery-ui.js"></script>
17+
<script src="../dist/jq/jqueryui-gridstack-dragdrop-plugin.js"></script>
1818
-->
1919

2020
</head>

demo/two.html

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,12 @@ <h1>Two grids demo</h1>
8080
<div class="col-md-6">
8181
<a onClick="toggleFloat(this, 0)" class="btn btn-primary" href="#">float: false</a>
8282
<a onClick="compact(0)" class="btn btn-primary" href="#">Compact</a>
83-
<div class="grid-stack grid-stack-6">
84-
<div class="grid-stack-item">
85-
<div class="grid-stack-item-content"><button onClick="alert('clicked')">click</button></div>
86-
</div>
87-
</div>
83+
<div class="grid-stack grid-stack-6"></div>
8884
</div>
8985
<div class="col-md-6">
9086
<a onClick="toggleFloat(this, 1)" class="btn btn-primary" href="#">float: true</a>
9187
<a onClick="compact(1)" class="btn btn-primary" href="#">Compact</a>
92-
<div class="grid-stack grid-stack-6">
93-
</div>
88+
<div class="grid-stack grid-stack-6"></div>
9489
</div>
9590
</div>
9691
</div>
@@ -108,7 +103,7 @@ <h1>Two grids demo</h1>
108103
grids[1].float(true);
109104

110105
let items = [
111-
{x: 1, y: 0, width: 2, height: 2},
106+
{x: 0, y: 0, width: 2, height: 2},
112107
{x: 3, y: 1, width: 1, height: 2},
113108
{x: 4, y: 1, width: 1, height: 1},
114109
{x: 2, y: 3, width: 3, height: 1, maxWidth: 3, id: 'special', text: 'has maxWidth=3'},

doc/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ The Typescript `GridStackEvent` list all possible values, and nothing else is su
147147
Called when widgets are being added to a grid
148148

149149
```js
150-
grid.on('added', function(event: GridEvent, items: GridStackNode[]) {
150+
grid.on('added', function(event: Event, items: GridStackNode[]) {
151151
items.forEach(function(item) {...});
152152
});
153153
```
@@ -157,15 +157,15 @@ grid.on('added', function(event: GridEvent, items: GridStackNode[]) {
157157
Occurs when widgets change their position/size due to constrain or direct changes
158158

159159
```js
160-
grid.on('change', function(event: GridEvent, items: GridStackNode[]) {
160+
grid.on('change', function(event: Event, items: GridStackNode[]) {
161161
items.forEach(function(item) {...});
162162
});
163163
```
164164

165165
### disable(event)
166166

167167
```js
168-
grid.on('disable', function(event: GridEvent) {
168+
grid.on('disable', function(event: Event) {
169169
let grid: GridStack = event.target.gridstack;
170170
});
171171
```
@@ -175,15 +175,15 @@ grid.on('disable', function(event: GridEvent) {
175175
called when grid item is starting to be dragged
176176

177177
```js
178-
grid.on('dragstart', function(event: GridEvent, el: GridItemHTMLElement) {
178+
grid.on('dragstart', function(event: Event, el: GridItemHTMLElement) {
179179
});
180180
```
181181

182182
### dragstop(event, el)
183183
called after the user is done moving the item, with updated DOM attributes.
184184

185185
```js
186-
grid.on('dragstop', function(event: GridEvent, el: GridItemHTMLElement) {
186+
grid.on('dragstop', function(event: Event, el: GridItemHTMLElement) {
187187
let x = parseInt(el.getAttribute('data-gs-x')) || 0;
188188
// or all values...
189189
let node: GridStackNode = el.gridstackNode; // {x, y, width, height, id, ....}
@@ -195,7 +195,7 @@ grid.on('dragstop', function(event: GridEvent, el: GridItemHTMLElement) {
195195
called when an item has been dropped and accepted over a grid. If the item came from another grid, the previous widget node info will also be sent (but dom item long gone).
196196

197197
```js
198-
grid.on('dropped', function(event: GridEvent, previousWidget: GridStackNode, newWidget: GridStackNode) {
198+
grid.on('dropped', function(event: Event, previousWidget: GridStackNode, newWidget: GridStackNode) {
199199
console.log('Removed widget that was dragged out of grid:', previousWidget);
200200
console.log('Added widget in dropped grid:', newWidget);
201201
});
@@ -204,7 +204,7 @@ grid.on('dropped', function(event: GridEvent, previousWidget: GridStackNode, new
204204
### enable(event)
205205

206206
```js
207-
grid.on('enable', function(event: GridEvent) {
207+
grid.on('enable', function(event: Event) {
208208
let grid: GridStack = event.target.gridstack;
209209
});
210210
```
@@ -214,7 +214,7 @@ grid.on('enable', function(event: GridEvent) {
214214
Called when items are being removed from the grid
215215

216216
```js
217-
grid.on('removed', function(event: GridEvent, items: GridStackNode[]) {
217+
grid.on('removed', function(event: Event, items: GridStackNode[]) {
218218
items.forEach(function(item) {...});
219219
});
220220
```
@@ -224,7 +224,7 @@ grid.on('removed', function(event: GridEvent, items: GridStackNode[]) {
224224
called before the user starts resizing an item
225225

226226
```js
227-
grid.on('resizestart', function(event: GridEvent, el: GridItemHTMLElement) {
227+
grid.on('resizestart', function(event: Event, el: GridItemHTMLElement) {
228228
});
229229
```
230230

@@ -233,7 +233,7 @@ grid.on('resizestart', function(event: GridEvent, el: GridItemHTMLElement) {
233233
called after the user is done resizing the item, with updated DOM attributes.
234234

235235
```js
236-
grid.on('resizestop', function(event: GridEvent, el: GridItemHTMLElement) {
236+
grid.on('resizestop', function(event: Event, el: GridItemHTMLElement) {
237237
let width = parseInt(el.getAttribute('data-gs-width')) || 0;
238238
// or all values...
239239
let node: GridStackNode = el.gridstackNode; // {x, y, width, height, id, ....}

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function(config) {
1717

1818
// list of files / patterns to load in the browser
1919
files: [
20-
'src/*.ts',
20+
'src/**/*.ts',
2121
'spec/*-spec.ts',
2222
// 'spec/e2e/*-spec.js' issues with ReferenceError: `browser` & `element` is not defined
2323
],

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"url": "git+https://github.com/gridstack/gridstack.js.git"
1010
},
1111
"scripts": {
12-
"build": "yarn --no-progress && rm -rf dist/* && webpack && grunt && doctoc ./README.md && doctoc ./doc/README.md && doctoc ./doc/CHANGES.md",
12+
"build": "yarn --no-progress && rm -rf dist/* && webpack && tsc --stripInternal && grunt && doctoc ./README.md && doctoc ./doc/README.md && doctoc ./doc/CHANGES.md",
13+
"t": "tsc --stripInternal",
1314
"web": "rm -rf dist/* && webpack",
1415
"test": "yarn lint && karma start karma.conf.js",
1516
"lint": "tsc --noEmit && eslint src/*.ts",

spec/gridstack-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ describe('gridstack', function() {
14141414
});
14151415
it('add 3 single events', function() {
14161416
let grid = GridStack.init();
1417-
let fcn = (event: CustomEvent) => {};
1417+
let fcn = (event: Event) => {};
14181418
grid.on('added', fcn).on('enable', fcn).on('dragstart', fcn);
14191419
expect((grid as any)._gsEventHandler.enable).not.toBe(undefined);
14201420
grid.off('added').off('enable').off('dragstart');

src/gridstack-dragdrop-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/* eslint-disable @typescript-eslint/no-unused-vars */
99

1010
import { GridStack } from './gridstack';
11-
import { GridItemHTMLElement, GridStackNode, GridEvent } from './types';
11+
import { GridItemHTMLElement } from './types';
1212

1313
/** Drag&Drop drop options */
1414
export type DDDropOpt = {
@@ -22,7 +22,7 @@ export type DDOpts = 'enable' | 'disable' | 'destroy' | 'option' | string | {} |
2222
export type DDKey = 'minWidth' | 'minHeight' | string;
2323

2424
/** drag&drop events callbacks */
25-
export type DDCallback = (event: GridEvent, arg2: GridItemHTMLElement) => void;
25+
export type DDCallback = (event: Event, arg2: GridItemHTMLElement) => void;
2626

2727
/**
2828
* Base class for drag'n'drop plugin.

src/gridstack-engine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class GridStackEngine {
6262
return this;
6363
}
6464

65+
/** @internal */
6566
private _fixCollisions(node: GridStackNode): GridStackEngine {
6667
this._sortNodes(-1);
6768

@@ -125,11 +126,13 @@ export class GridStackEngine {
125126
/** float getter method */
126127
public get float(): boolean { return this._float || false; }
127128

129+
/** @internal */
128130
private _sortNodes(dir?: -1 | 1): GridStackEngine {
129131
this.nodes = Utils.sort(this.nodes, dir, this.column);
130132
return this;
131133
}
132134

135+
/** @internal */
133136
private _packNodes(): GridStackEngine {
134137
this._sortNodes();
135138

@@ -264,6 +267,7 @@ export class GridStackEngine {
264267
return this.nodes.filter(n => n._dirty);
265268
}
266269

270+
/** @internal */
267271
private _notify(nodes?: GridStackNode | GridStackNode[], detachNode?: boolean): GridStackEngine {
268272
if (this.batchMode) { return this }
269273
detachNode = (detachNode === undefined ? true : detachNode);
@@ -605,7 +609,7 @@ export class GridStackEngine {
605609
}
606610
}
607611

608-
// legacy method renames
612+
/** @internal legacy method renames */
609613
private getGridHeight = obsolete(this, GridStackEngine.prototype.getRow, 'getGridHeight', 'getRow', 'v1.0.0');
610614
}
611615

src/gridstack-poly.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* gridstack.js may be freely distributed under the MIT license.
77
*/
88

9+
/* eslint-disable prefer-rest-params */
10+
/* eslint-disable no-var */
11+
912
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
1013
(function () {
1114
if (typeof window.CustomEvent === "function") {

0 commit comments

Comments
 (0)