Skip to content

Commit d8bb0a6

Browse files
committed
Merged branch develop into master
2 parents 443e35a + ead8d9a commit d8bb0a6

File tree

12 files changed

+287
-55
lines changed

12 files changed

+287
-55
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets":["es2015", "react"]
2+
"presets":["es2015", "stage-0", "react"]
33
}

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# 1.1.0
3+
## Bug
4+
- Fix reset to default in demo
5+
6+
## Feature
7+
- Add possibility to give add, cancel, edit buttons and input by props
8+
9+
## Code
10+
- Fix import : for js files, don't write '.js' in import
11+
- Add new babel plugin (stage-0)
12+
13+
# 1.0.1
14+
## Bug
15+
- Fix filename extensions in dist
16+
- Fix eslint conf for filenames
17+
18+
# 1.0.0
19+
First release !

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,35 @@ An example of return :
157157
}
158158
```
159159

160+
### addButtonElement
161+
| Key | Description | Type | Required | Default |
162+
|:----------------:|:-----------------------------------------:|:-----------:|:--------:|:---------------------:|
163+
| addButtonElement | Add button Element to replace library one | Element | False | <button>+</button> |
164+
165+
The library will add a `onClick` props on element.
166+
167+
### cancelButtonElement
168+
| Key | Description | Type | Required | Default |
169+
|:-------------------:|:--------------------------------------------:|:-----------:|:--------:|:---------------------:|
170+
| cancelButtonElement | Cancel button Element to replace library one | Element | False | <button>c</button> |
171+
172+
The library will add a `onClick` props on element.
173+
174+
### editButtonElement
175+
| Key | Description | Type | Required | Default |
176+
|:-----------------:|:------------------------------------------:|:-----------:|:--------:|:---------------------:|
177+
| editButtonElement | Edit button Element to replace library one | Element | False | <button>e</button> |
178+
179+
The library will add a `onClick` props on element.
180+
181+
### inputElement
182+
| Key | Description | Type | Required | Default |
183+
|:------------:|:-----------------------------------------:|:-----------:|:--------:|:------------:|
184+
| inputElement | Input Text Element to replace library one | Element | False | <input /> |
185+
186+
The library will add a `placeholder`, `ref`, `defaultValue` props on element.
187+
188+
160189
## Development
161190
### Serve
162191
```bash

dev/components/Body.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/* ******** IMPORTS ******** */
88
/* ************************************* */
99
import React, { Component } from 'react';
10+
import _ from 'lodash';
1011
import { JsonTree } from '../../src/JsonTree.js';
1112

1213
/* ************************************* */
@@ -49,7 +50,7 @@ class Body extends Component {
4950
constructor(props) {
5051
super(props);
5152
this.state = {
52-
json: defaultJson,
53+
json: _.cloneDeep(defaultJson),
5354
deltaUpdateString: '{}',
5455
globalUpdateString: '{}',
5556
textareaRef: null,
@@ -106,7 +107,7 @@ class Body extends Component {
106107

107108
handleResetToDefault() {
108109
this.setState({
109-
json: defaultJson,
110+
json: _.cloneDeep(defaultJson),
110111
});
111112
}
112113

gulp/bump.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Author: Alexandre Havrileck (Oxyno-zeta)
3+
* Date: 03/11/16
4+
* Licence: See Readme
5+
*/
6+
7+
8+
/* ************************************* */
9+
/* ******** REQUIRE ******** */
10+
/* ************************************* */
11+
const gulp = require('gulp');
12+
const bump = require('gulp-bump');
13+
14+
/* ************************************* */
15+
/* ******** PRIVATE FUNCTIONS ******** */
16+
/* ************************************* */
17+
18+
19+
/* ************************************* */
20+
/* ******** PUBLIC FUNCTIONS ******** */
21+
/* ************************************* */
22+
// MAJOR ('major') version when you make incompatible API changes
23+
// MINOR ('minor') version when you add functionality in a backwards-compatible manner
24+
// PATCH ('patch') version when you make backwards-compatible bug fixes.
25+
gulp.task('bump', ['bump:minor']);
26+
27+
gulp.task('bump:major', () => (
28+
gulp.src(['package.json'])
29+
.pipe(bump({
30+
type: 'major',
31+
}))
32+
.pipe(gulp.dest('./'))
33+
));
34+
35+
gulp.task('bump:minor', () => (
36+
gulp.src(['package.json'])
37+
.pipe(bump({
38+
type: 'minor',
39+
}))
40+
.pipe(gulp.dest('./'))
41+
));
42+
43+
gulp.task('bump:patch', () => (
44+
gulp.src(['package.json'])
45+
.pipe(bump({
46+
type: 'patch',
47+
}))
48+
.pipe(gulp.dest('./'))
49+
));

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-editable-json-tree",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "React Editable Json Tree",
55
"main": "dist/JsonTree.js",
66
"scripts": {
@@ -20,16 +20,19 @@
2020
"babel-preset-es2015": "^6.13.2",
2121
"babel-preset-react": "^6.11.1",
2222
"babel-preset-react-hmre": "^1.1.1",
23+
"babel-preset-stage-0": "^6.16.0",
2324
"body-parser": "^1.15.2",
2425
"del": "^2.2.2",
2526
"eslint": "^3.8.1",
2627
"eslint-config-airbnb": "^12.0.0",
27-
"eslint-plugin-import": "^2.0.1",
28+
"eslint-plugin-import": "^2.1.0",
2829
"eslint-plugin-jsx-a11y": "^2.2.3",
2930
"eslint-plugin-react": "^6.4.1",
3031
"gulp": "^3.9.1",
3132
"gulp-babel": "^6.1.2",
33+
"gulp-bump": "^2.5.0",
3234
"html-webpack-plugin": "^2.22.0",
35+
"lodash": "^4.16.6",
3336
"progress-bar-webpack-plugin": "^1.9.0",
3437
"react-hot-loader": "^1.3.0",
3538
"run-sequence": "^1.2.2",

src/JsonTree.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* ******** IMPORTS ******** */
88
/* ************************************* */
99
import React, { Component, PropTypes } from 'react';
10-
import JsonNode from './components/JsonNode.js';
10+
import JsonNode from './components/JsonNode';
1111
import { value, object, array } from './utils/styles';
1212
import deltaTypes from './utils/deltaTypes';
1313
import objectTypes from './utils/objectTypes';
@@ -26,6 +26,10 @@ const propTypes = {
2626
onDeltaUpdate: PropTypes.func,
2727
readOnly: PropTypes.bool,
2828
getStyle: PropTypes.func,
29+
addButtonElement: PropTypes.element,
30+
cancelButtonElement: PropTypes.element,
31+
editButtonElement: PropTypes.element,
32+
inputElement: PropTypes.element,
2933
};
3034
// Default props
3135
const defaultProps = {
@@ -81,7 +85,16 @@ class JsonTree extends Component {
8185

8286
render() {
8387
const { data, rootName } = this.state;
84-
const { isCollapsed, onDeltaUpdate, readOnly, getStyle } = this.props;
88+
const {
89+
isCollapsed,
90+
onDeltaUpdate,
91+
readOnly,
92+
getStyle,
93+
addButtonElement,
94+
cancelButtonElement,
95+
editButtonElement,
96+
inputElement,
97+
} = this.props;
8598

8699
// Node type
87100
const dataType = getObjectType(data);
@@ -97,6 +110,10 @@ class JsonTree extends Component {
97110
onDeltaUpdate={onDeltaUpdate}
98111
readOnly={readOnly}
99112
getStyle={getStyle}
113+
addButtonElement={addButtonElement}
114+
cancelButtonElement={cancelButtonElement}
115+
editButtonElement={editButtonElement}
116+
inputElement={inputElement}
100117
/>);
101118
} else {
102119
node = 'Data must be an Array or Object';

src/components/JsonAddValue.js

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/* ************************************* */
99
import React, { Component, PropTypes } from 'react';
1010
import { HotKeys } from 'react-hotkeys';
11-
import parse from '../utils/parse.js';
11+
import parse from '../utils/parse';
1212

1313
/* ************************************* */
1414
/* ******** VARIABLES ******** */
@@ -18,10 +18,16 @@ const propTypes = {
1818
handleAdd: PropTypes.func.isRequired,
1919
handleCancel: PropTypes.func.isRequired,
2020
onlyValue: PropTypes.bool,
21+
addButtonElement: PropTypes.element,
22+
cancelButtonElement: PropTypes.element,
23+
inputElement: PropTypes.element,
2124
};
2225
// Default props
2326
const defaultProps = {
2427
onlyValue: false,
28+
addButtonElement: <button>+</button>,
29+
cancelButtonElement: <button>c</button>,
30+
inputElement: <input />,
2531
};
2632

2733
/* ************************************* */
@@ -81,33 +87,41 @@ class JsonAddValue extends Component {
8187
}
8288

8389
render() {
84-
const { handleCancel, onlyValue } = this.props;
85-
86-
const handlers = {
87-
esc: handleCancel,
88-
enter: this.onSubmit,
89-
};
90+
const { handleCancel, onlyValue, addButtonElement, cancelButtonElement, inputElement } = this.props;
9091

92+
const addButtonElementLayout = React.cloneElement(addButtonElement, {
93+
onClick: this.onSubmit,
94+
});
95+
const cancelButtonElementLayout = React.cloneElement(cancelButtonElement, {
96+
onClick: handleCancel,
97+
});
9198
let result = null;
9299
if (onlyValue) {
93-
result = (<span> <input
94-
placeholder="Value"
95-
ref={this.refInputValue}
96-
/> <button onClick={handleCancel}>c</button>
97-
<button onClick={this.onSubmit}>+</button>
100+
const inputElementValueLayout = React.cloneElement(inputElement, {
101+
placeholder: 'Value',
102+
ref: this.refInputValue,
103+
});
104+
result = (<span> {inputElementValueLayout} {cancelButtonElementLayout}{addButtonElementLayout}
98105
</span>);
99106
} else {
100-
result = (<span> <input
101-
placeholder="Key"
102-
ref={this.refInputKey}
103-
/>: <input
104-
placeholder="Value"
105-
ref={this.refInputValue}
106-
/> <button onClick={handleCancel}>c</button>
107-
<button onClick={this.onSubmit}>+</button>
107+
const inputElementValueLayout = React.cloneElement(inputElement, {
108+
placeholder: 'Value',
109+
ref: this.refInputValue,
110+
});
111+
const inputElementKeyLayout = React.cloneElement(inputElement, {
112+
placeholder: 'Key',
113+
ref: this.refInputKey,
114+
});
115+
result = (<span> {inputElementKeyLayout}: {inputElementValueLayout} {cancelButtonElementLayout}
116+
{addButtonElementLayout}
108117
</span>);
109118
}
110119

120+
const handlers = {
121+
esc: handleCancel,
122+
enter: this.onSubmit,
123+
};
124+
111125
return (<HotKeys component={'span'} handlers={handlers}>
112126
{result}
113127
</HotKeys>);

src/components/JsonArray.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
/* ******** IMPORTS ******** */
88
/* ************************************* */
99
import React, { Component, PropTypes } from 'react';
10-
import JsonNode from './JsonNode.js';
11-
import JsonAddValue from './JsonAddValue.js';
12-
import objectTypes from '../utils/objectTypes.js';
13-
import { ADD_DELTA_TYPE, REMOVE_DELTA_TYPE, UPDATE_DELTA_TYPE } from '../utils/deltaTypes.js';
10+
import JsonNode from './JsonNode';
11+
import JsonAddValue from './JsonAddValue';
12+
import objectTypes from '../utils/objectTypes';
13+
import { ADD_DELTA_TYPE, REMOVE_DELTA_TYPE, UPDATE_DELTA_TYPE } from '../utils/deltaTypes';
1414

1515
const { getObjectType } = objectTypes;
1616

@@ -30,12 +30,13 @@ const propTypes = {
3030
readOnly: PropTypes.bool.isRequired,
3131
dataType: PropTypes.string,
3232
getStyle: PropTypes.func.isRequired,
33+
addButtonElement: PropTypes.element,
34+
cancelButtonElement: PropTypes.element,
35+
editButtonElement: PropTypes.element,
36+
inputElement: PropTypes.element,
3337
};
3438
// Default props
3539
const defaultProps = {
36-
collapsed: true,
37-
name: 'root',
38-
data: [],
3940
keyPath: [],
4041
deep: 0,
4142
};
@@ -219,7 +220,18 @@ class JsonArray extends Component {
219220

220221
renderNotCollapsed() {
221222
const { name, data, keyPath, deep, addFormVisible } = this.state;
222-
const { isCollapsed, handleRemove, onDeltaUpdate, readOnly, getStyle, dataType } = this.props;
223+
const {
224+
isCollapsed,
225+
handleRemove,
226+
onDeltaUpdate,
227+
readOnly,
228+
getStyle,
229+
dataType,
230+
addButtonElement,
231+
cancelButtonElement,
232+
editButtonElement,
233+
inputElement,
234+
} = this.props;
223235
const { minus, plus, delimiter, ul, addForm } = getStyle(name, data, keyPath, deep, dataType);
224236

225237
let minusElement = (deep !== 0) ? (<span onClick={handleRemove} style={minus}> - </span>) : null;
@@ -242,6 +254,10 @@ class JsonArray extends Component {
242254
onDeltaUpdate={onDeltaUpdate}
243255
readOnly={readOnly}
244256
getStyle={getStyle}
257+
addButtonElement={addButtonElement}
258+
cancelButtonElement={cancelButtonElement}
259+
editButtonElement={editButtonElement}
260+
inputElement={inputElement}
245261
/>);
246262

247263
const onlyValue = true;
@@ -250,6 +266,9 @@ class JsonArray extends Component {
250266
handleAdd={this.handleAddValueAdd}
251267
handleCancel={this.handleAddValueCancel}
252268
onlyValue={onlyValue}
269+
addButtonElement={addButtonElement}
270+
cancelButtonElement={cancelButtonElement}
271+
inputElement={inputElement}
253272
/></span>) :
254273
(<span><span onClick={this.handleAddMode} style={plus}> + </span> {minusElement}</span>);
255274
// Check if readOnly is activated

0 commit comments

Comments
 (0)