Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

Commit f79d2b1

Browse files
authored
Merge pull request #14 from hckhanh/jstree
Add JsTree plugin
2 parents 19036e1 + c285d0f commit f79d2b1

File tree

12 files changed

+230
-23
lines changed

12 files changed

+230
-23
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ node_modules
66
npm-debug.log*
77

88
# compiled files
9-
dist
9+
lib
10+
11+
# coverage directory used by tools like istanbul
12+
coverage

.npmignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# dependencies
2+
node_modules
3+
4+
# logs
5+
*.log
6+
npm-debug.log*
7+
8+
# coverage directory used by tools like istanbul
9+
coverage
10+
11+
# tests
12+
__tests__
13+
14+
# settings
15+
.vscode
16+
.babelrc
17+
.gitignore
18+
.npmignore
19+
.travis.yml
20+
gulpfile.js
21+
jsconfig.json
22+
webpack.config.js
23+
24+
# misc
25+
example
26+
src

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: node_js
2+
node_js:
3+
- "node"
4+
5+
sudo: false
6+
7+
cache:
8+
directories:
9+
- node_modules
10+
11+
before_install:
12+
- npm config set spin false
13+
14+
install:
15+
- npm install
16+
17+
script:
18+
- npm test
19+
20+
before_deploy:
21+
- npm run build
22+
23+
deploy:
24+
provider: npm
25+
api_key: $NPM_API_KEY
26+
on:
27+
tags: true

__tests__/react-tree-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import TestUtils from 'react-addons-test-utils';
4+
import ReactTree from '../src/react-tree';
5+
import { PROJECT_TREE } from '../example/project-tree'
6+
7+
describe('ReactTree', () => {
8+
it('should run be rendered', () => {
9+
const reactTree = TestUtils.renderIntoDocument(
10+
<ReactTree tree={PROJECT_TREE} />
11+
);
12+
13+
const reactTreeNode = ReactDOM.findDOMNode(reactTree);
14+
15+
expect(reactTreeNode.textContent).not.toBeNull();
16+
17+
});
18+
19+
it('should run the handle function of onChanged event', () => {
20+
const handleOnChanged = jest.fn();
21+
22+
const reactTree = TestUtils.renderIntoDocument(
23+
<ReactTree tree={PROJECT_TREE} onChanged={handleOnChanged} />
24+
);
25+
26+
expect(handleOnChanged).toBeCalled();
27+
});
28+
});

example/app.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
import ReactTree from '../lib/react-tree';
1+
import 'jstree/dist/themes/default/style.min.css';
2+
import 'jstree/dist/themes/default-dark/style.min.css';
3+
24
import ReactDOM from 'react-dom';
5+
import ReactTree from '../src/react-tree';
6+
import { PROJECT_TREE } from './project-tree';
7+
8+
class ExampleApp extends React.Component {
9+
constructor(props) {
10+
super(props);
11+
12+
this.state = { items: [] };
13+
14+
this.handleOnChanged = this.handleOnChanged.bind(this);
15+
}
16+
handleOnChanged(changedItems) {
17+
this.setState({
18+
items: changedItems.map(item => item.text).join(', ')
19+
});
20+
}
21+
22+
render() {
23+
return (
24+
<div>
25+
<ReactTree tree={PROJECT_TREE} onChanged={this.handleOnChanged} />
26+
<div>Selected items: {this.state.items}</div>
27+
</div>
28+
);
29+
}
30+
}
331

4-
ReactDOM.render(<ReactTree />, document.getElementById('app'));
32+
ReactDOM.render(<ExampleApp />, document.getElementById('app'));

example/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<html>
33

44
<head>
5-
<title>example react-tree</title>
5+
<title>Example App</title>
6+
<link rel="stylesheet" type="text/css" href="assets/styles.css">
67

78
<script src="https://fb.me/react-15.3.0.js"></script>
89
<script src="https://fb.me/react-dom-15.3.0.js"></script>
@@ -11,7 +12,7 @@
1112
<body>
1213
<div id="app"></div>
1314

14-
<script src="bundle.js"></script>
15+
<script src="assets/bundle.js"></script>
1516
</body>
1617

1718
</html>

example/project-tree.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export const PROJECT_TREE = [
2+
{
3+
text: '.vscode',
4+
state: {
5+
opened: true,
6+
selected: true
7+
},
8+
children: [
9+
{ text: 'settings.json', icon: 'jstree-file' }
10+
]
11+
},
12+
{
13+
text: 'example',
14+
state: {
15+
opened: true,
16+
},
17+
children: [
18+
{ text: 'app.js', icon: 'jstree-file' },
19+
{ text: 'index.html', icon: 'jstree-file' }
20+
]
21+
},
22+
{
23+
text: 'lib',
24+
state: {
25+
opened: true,
26+
},
27+
children: [
28+
{ text: 'react-tree.js', icon: 'jstree-file' }
29+
]
30+
},
31+
{
32+
text: 'node_modules',
33+
children: []
34+
},
35+
{ text: '.babelrc', icon: 'jstree-file' },
36+
{ text: '.gitignore', icon: 'jstree-file' },
37+
{ text: 'jsconfig.json', icon: 'jstree-file' },
38+
{ text: 'LICENSE', icon: 'jstree-file' },
39+
{ text: 'package.json', icon: 'jstree-file' },
40+
{ text: 'webpack.config.js', icon: 'jstree-file' }
41+
];

gulpfile.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const gulp = require('gulp');
2+
const babel = require('gulp-babel');
3+
4+
gulp.task('build', () => {
5+
return gulp.src('src/react-tree.js')
6+
.pipe(babel({
7+
presets: ['es2015', 'react']
8+
}))
9+
.pipe(gulp.dest('lib'));
10+
});

lib/react-tree.js

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

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "react-tree",
33
"version": "0.0.0",
44
"description": "The react component to present data as a tree",
5-
"main": ".",
5+
"main": "./lib/react-tree.js",
66
"scripts": {
77
"start": "webpack-dev-server --port=3000",
8-
"test": "."
8+
"test": "jest",
9+
"build": "gulp build"
910
},
1011
"repository": {
1112
"type": "git",
@@ -33,12 +34,20 @@
3334
"babel-loader": "^6.2.4",
3435
"babel-preset-es2015": "^6.13.2",
3536
"babel-preset-react": "^6.11.1",
36-
"jstree": "^3.3.1",
37+
"css-loader": "^0.23.1",
38+
"gulp": "^3.9.1",
39+
"gulp-babel": "^6.1.2",
40+
"jest-cli": "^14.1.0",
41+
"react-addons-test-utils": "^15.3.0",
3742
"webpack": "^1.13.1",
3843
"webpack-dev-server": "^1.14.1"
3944
},
4045
"dependencies": {
46+
"jstree": "^3.3.1",
4147
"react": "^15.3.0",
4248
"react-dom": "^15.3.0"
49+
},
50+
"jest": {
51+
"automock": false
4352
}
4453
}

0 commit comments

Comments
 (0)