Skip to content

Commit 716c2d6

Browse files
committed
TS: support for ES6 modules
* use webpack to bundle gridstack.all.js (all inclusive, works in browsers) * use tsc to compile each .TS into ES6 modules verified that you can now do this in a sample app import { GridStack } from 'gridstack'; import 'gridstack/dist/gridstack.css'; var grid = GridStack.init();
1 parent 6decc5d commit 716c2d6

File tree

9 files changed

+46
-53
lines changed

9 files changed

+46
-53
lines changed

Gruntfile.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function(grunt) {
22
grunt.loadNpmTasks('grunt-sass');
3-
// grunt.loadNpmTasks('grunt-contrib-cssmin');
3+
grunt.loadNpmTasks('grunt-contrib-cssmin');
44
grunt.loadNpmTasks('grunt-contrib-copy');
55
grunt.loadNpmTasks('grunt-contrib-uglify');
66
grunt.loadNpmTasks('grunt-eslint');
@@ -24,7 +24,6 @@ module.exports = function(grunt) {
2424
}
2525
}
2626
},
27-
/* very little gain
2827
cssmin: {
2928
dist: {
3029
options: {
@@ -37,7 +36,6 @@ module.exports = function(grunt) {
3736
}
3837
}
3938
},
40-
*/
4139
copy: {
4240
dist: {
4341
files: {
@@ -58,8 +56,8 @@ module.exports = function(grunt) {
5856
},
5957
dist: {
6058
files: {
61-
'dist/jq/jquery.min.js': 'src/jq/jquery.js',
62-
'dist/jq/jquery-ui.min.js': 'src/jq/jquery-ui.js',
59+
'dist/jq/jquery.js': 'src/jq/jquery.js',
60+
'dist/jq/jquery-ui.js': 'src/jq/jquery-ui.js',
6361
/*
6462
'dist/jq/gridstack-dd-jqueryui.min.js': 'dist/jq/gridstack-dd-jqueryui.js',
6563
'dist/gridstack-dd.min.js': 'dist/gridstack-dd.js',
@@ -84,7 +82,7 @@ module.exports = function(grunt) {
8482
},
8583
styles: {
8684
files: ['src/*.scss'],
87-
tasks: ['sass'/*, 'cssmin'*/],
85+
tasks: ['sass', 'cssmin'],
8886
options: {
8987
},
9088
}
@@ -118,6 +116,6 @@ module.exports = function(grunt) {
118116
});
119117

120118
grunt.registerTask('lint', ['eslint']);
121-
grunt.registerTask('default', ['sass', /*'cssmin', 'eslint',*/ 'copy', 'uglify']);
119+
grunt.registerTask('default', ['sass', 'cssmin', /*'eslint',*/ 'copy', 'uglify']);
122120
grunt.registerTask('e2e-test', ['connect', 'protractor_webdriver', 'protractor']);
123121
};

demo/two.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
<link rel="stylesheet" href="../dist/gridstack-extra.css"/>
1212

1313
<script src="../dist/gridstack.all.js"></script>
14-
<!--
15-
<script src="../dist/jq/jquery.min.js"></script>
16-
<script src="../dist/jq/jquery-ui.min.js"></script>
17-
<script src="../dist/gridstack.js"></script>
18-
<script src="../dist/jq/gridstack-dd-jqueryui.js"></script>
19-
-->
2014

2115
<style type="text/css">
2216
.grid-stack {
@@ -100,6 +94,7 @@ <h1>Two grids demo</h1>
10094
<script type="text/javascript">
10195
let options = {
10296
column: 6,
97+
cellHeight: 70,
10398
disableOneColumnMode: true,
10499
float: false,
105100
removable: '.trash',

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"url": "git+https://github.com/gridstack/gridstack.js.git"
1010
},
1111
"scripts": {
12-
"build": "yarn --no-progress && rm -rf dist/* && grunt && webpack && doctoc ./README.md && doctoc ./doc/README.md && doctoc ./doc/CHANGES.md",
12+
"build": "yarn --no-progress && rm -rf dist/* && grunt && webpack && tsc --stripInternal && doctoc ./README.md && doctoc ./doc/README.md && doctoc ./doc/CHANGES.md",
1313
"w": "rm -rf dist/* && grunt && webpack",
14-
"t": "rm -rf dist/* && tsc --stripInternal",
14+
"t": "rm -rf dist/* && grunt && tsc --stripInternal",
1515
"test": "yarn lint && karma start karma.conf.js",
1616
"lint": "tsc --noEmit && eslint src/*.ts",
1717
"reset": "rm -rf dist node_modules",
@@ -43,9 +43,11 @@
4343
},
4444
"homepage": "http://gridstack.github.io/gridstack.js/",
4545
"dependencies": {
46+
},
47+
"devDependencies": {
4648
"@types/jasmine": "^3.5.9",
47-
"@types/jquery": "^3.3.33",
48-
"@types/jqueryui": "^1.12.10",
49+
"@types/jquery": "^3.5.1",
50+
"@types/jqueryui": "^1.12.13",
4951
"@typescript-eslint/eslint-plugin": "^2.23.0",
5052
"@typescript-eslint/parser": "^2.23.0",
5153
"connect": "^3.7.0",

src/gridstack.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@
55
* (c) 2014-2020 Alain Dumesny, Dylan Weiss, Pavel Reznikov
66
* gridstack.js may be freely distributed under the MIT license.
77
*/
8+
import './gridstack-poly.js';
89

910
import { GridStackEngine } from './gridstack-engine';
1011
import { obsoleteOpts, obsoleteOptsDel, obsoleteAttr, obsolete, Utils } from './utils';
1112
import { GridItemHTMLElement, GridStackWidget, GridStackNode, GridstackOptions, numberOrString } from './types';
1213
import { GridStackDD } from './gridstack-dd';
1314

15+
// export all dependent file as well to make it easier for users to just import the main file
16+
export * from './types';
17+
export * from './utils';
18+
export * from './gridstack-engine';
19+
export * from './gridstack-dd';
20+
21+
// TEMPORARY import the jquery-ui drag&drop since we don't have alternative yet and don't expect users to create their own yet
22+
import './jq/gridstack-dd-jqueryui';
23+
export * from './jq/gridstack-dd-jqueryui';
24+
1425
export type GridStackElement = string | HTMLElement | GridItemHTMLElement;
1526

1627
export interface GridHTMLElement extends HTMLElement {

src/index.ts

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

src/jq/gridstack-dd-jqueryui.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { GridItemHTMLElement, DDDragInOpt } from '../types';
1212

1313
// TODO: TEMPORARY until can remove jquery-ui drag&drop and this class and use HTML5 instead !
1414
// see https://stackoverflow.com/questions/35345760/importing-jqueryui-with-typescript-and-requirejs
15-
import * as $ from './jquery.js';
16-
import './jquery-ui.js';
15+
import * as $ from './jquery';
16+
export { $ };
17+
export * from './jquery-ui';
1718

1819
/**
1920
* Jquery-ui based drag'n'drop plugin.
@@ -67,7 +68,7 @@ export class GridStackDDJQueryUI extends GridStackDD {
6768
}
6869

6970
public dragIn(el: GridStackElement, opts: DDDragInOpt): GridStackDD {
70-
let $el: JQuery = $(el);
71+
let $el: JQuery = $(el as any); // workaround Type 'string' is not assignable to type 'PlainObject<any>' - see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/29312
7172
$el.draggable(opts);
7273
return this;
7374
}
@@ -89,7 +90,7 @@ export class GridStackDDJQueryUI extends GridStackDD {
8990
}
9091

9192
public isDraggable(el: GridStackElement): boolean {
92-
let $el: JQuery = $(el);
93+
let $el: JQuery = $(el as any); // workaround Type 'string' is not assignable to type 'PlainObject<any>' - see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/29312
9394
return Boolean($el.data('ui-draggable'));
9495
}
9596

tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
"experimentalDecorators": true,
1111
"inlineSources": true,
1212
"lib": [ "es6", "es2015", "dom" ],
13-
"module": "commonjs",
13+
"module": "CommonJS",
1414
"noImplicitAny": false,
1515
"outDir": "./dist",
1616
"sourceMap": true,
1717
"strict": false,
18-
"target": "es5"
18+
"target": "ES6"
1919
},
2020
"exclude": [
21-
"./src/**/*.spec.ts"
21+
"./src/**/*.spec.ts",
22+
"./src/index.ts" // used for webpack all.js
23+
2224
],
2325
"include": [
2426
"./src/**/*.ts"

webpack.config.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@ const path = require('path');
22

33
module.exports = {
44
entry: {
5-
'gridstack.all': './src/index.ts',
6-
'gridstack': './src/gridstack.ts',
7-
/*
8-
'types': './src/types.ts',
9-
'utils': './src/utils.ts',
10-
'gridstack-engine': './src/gridstack-engine.ts',
11-
'gridstack-dd': './src/gridstack-dd.ts',
12-
'jq/gridstack-dd-jqueryui': './src/jq/gridstack-dd-jqueryui.ts',
13-
*/
5+
'gridstack.all': './src/gridstack.ts',
146
},
157
mode: 'production', // production vs development
168
devtool: 'source-map',

yarn.lock

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,24 @@
4646
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-3.5.9.tgz#43ca4566f0d9de23df1211ecf32a9b9f8c3a5923"
4747
integrity sha512-KNL2Fq6GRmty2j6+ZmueT/Z/dkctLNH+5DFoGHNDtcgt7yME9NZd8x2p81Yuea1Xux/qAryDd3zVLUoKpDz1TA==
4848

49-
"@types/jquery@*", "@types/jquery@^3.3.33":
49+
"@types/jquery@*":
5050
version "3.3.33"
5151
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.3.33.tgz#61d9cbd4004ffcdf6cf7e34720a87a5625a7d8e9"
5252
integrity sha512-U6IdXYGkfUI42SR79vB2Spj+h1Ly3J3UZjpd8mi943lh126TK7CB+HZOxGh2nM3IySor7wqVQdemD/xtydsBKA==
5353
dependencies:
5454
"@types/sizzle" "*"
5555

56-
"@types/jqueryui@^1.12.10":
57-
version "1.12.10"
58-
resolved "https://registry.yarnpkg.com/@types/jqueryui/-/jqueryui-1.12.10.tgz#39ebe4c391fb3b9f623521b4d803d9d4804883fa"
59-
integrity sha512-T8sctslWIiLl/2EHEQQfKCB92S9bMKBaeE3+iBRbSERMK/1gzyfqjaIEksduB4eUEsKq+Ji0Y+qVbiXQwI2Mwg==
56+
"@types/jquery@^3.5.1":
57+
version "3.5.1"
58+
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.1.tgz#cebb057acf5071c40e439f30e840c57a30d406c3"
59+
integrity sha512-Tyctjh56U7eX2b9udu3wG853ASYP0uagChJcQJXLUXEU6C/JiW5qt5dl8ao01VRj1i5pgXPAf8f1mq4+FDLRQg==
60+
dependencies:
61+
"@types/sizzle" "*"
62+
63+
"@types/jqueryui@^1.12.13":
64+
version "1.12.13"
65+
resolved "https://registry.yarnpkg.com/@types/jqueryui/-/jqueryui-1.12.13.tgz#1aa0507b4d1a75b03592d2126fbd6d2ea8e8c284"
66+
integrity sha512-IIOytTkwN6mBcJqi5SP8T8zqDGKy9hIpifQ0aGj1/ZjqshOoMo0yZdLp2uLIg7mQDJOwMCSC3EY1QZC/qZzvLQ==
6067
dependencies:
6168
"@types/jquery" "*"
6269

0 commit comments

Comments
 (0)