Skip to content

Commit 77a7d54

Browse files
committed
Merged branch develop into master
2 parents a4757fa + 6253b22 commit 77a7d54

File tree

16 files changed

+480
-120
lines changed

16 files changed

+480
-120
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ language: node_js
44

55
node_js:
66
- 6
7+
- 7
78

89
before_script:
910
- npm install -g gulp

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11

2+
# 1.2.0
3+
## Feature
4+
- Add possibility to edit 'function'
5+
- Add CircleCI build
6+
- Add Node 7 in TravisCI
7+
- Add CSS class on components
8+
- Add 'clear' button on demo for updates
9+
10+
## Fix
11+
- Fix render performance
12+
- Fix focus error on readOnly mode
13+
214
# 1.1.0
315
## Bug
416
- Fix reset to default in demo

README.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
React Editable Json Tree
22
========================
3-
[![Build Status](https://travis-ci.org/oxyno-zeta/react-editable-json-tree.svg?branch=master)](https://travis-ci.org/oxyno-zeta/react-editable-json-tree)[![npm](https://img.shields.io/npm/v/react-editable-json-tree.svg)]()
3+
[![Build Status](https://travis-ci.org/oxyno-zeta/react-editable-json-tree.svg?branch=master)](https://travis-ci.org/oxyno-zeta/react-editable-json-tree)[![Build Status](https://circleci.com/gh/oxyno-zeta/react-editable-json-tree.png)](https://circleci.com/gh/oxyno-zeta/react-editable-json-tree)[![npm](https://img.shields.io/npm/v/react-editable-json-tree.svg)]()
44

55
## Demo
66
Demo is available here : [Demo](https://oxyno-zeta.github.io/react-editable-json-tree/)
@@ -16,11 +16,12 @@ Demo is available here : [Demo](https://oxyno-zeta.github.io/react-editable-json
1616
- Style via function
1717
- Read only possibility
1818
- Call for global update and delta update
19+
- Possibility to give buttons, inputs, ... in parameters
1920

2021
## How to use
2122
### Install
2223
```bash
23-
npm install react-editable-json-tree
24+
npm install --save react-editable-json-tree
2425
```
2526

2627
### Example Usage
@@ -156,6 +157,7 @@ An example of return :
156157
addForm: {},
157158
}
158159
```
160+
You can see the actual used in `src/utils/styles.js`.
159161

160162
### addButtonElement
161163
| Key | Description | Type | Required | Default |
@@ -185,6 +187,76 @@ The library will add a `onClick` props on element.
185187

186188
The library will add a `placeholder`, `ref`, `defaultValue` props on element.
187189

190+
### textareaElement
191+
| Key | Description | Type | Required | Default |
192+
|:---------------:|:-----------------------------------------:|:-----------:|:--------:|:------------:|
193+
| textareaElement | Textarea Element to replace library one | Element | False | <textarea /> |
194+
195+
The library will add a `ref`, `defaultValue` props on element.
196+
197+
## Design
198+
The library provide CSS class on elements. All are prefixed by "rejt" to avoid conflict.
199+
To avoid being linked with a CSS file, the library will use the inline style.
200+
201+
Here is the list of classes by element and by deep and with basic element (on which it's applied).
202+
203+
### JsonTree
204+
* rejt-tree (div)
205+
206+
### JsonObject
207+
#### Collapsed
208+
* rejt-object-node (div)
209+
* rejt-name (span)
210+
* rejt-collapsed (span)
211+
* rejt-collapsed-text (span)
212+
* rejt-minus-menu (span)
213+
214+
#### Not Collapsed
215+
* rejt-object-node (div)
216+
* rejt-name (span)
217+
* rejt-not-collapsed (span)
218+
* rejt-not-collapsed-delimiter (span)
219+
* rejt-not-collapsed-list (ul)
220+
* rejt-not-collapsed-delimiter (span)
221+
* rejt-add-form (span)
222+
* rejt-plus-menu (span)
223+
* rejt-minus-menu (span)
224+
225+
### JsonArray
226+
#### Collapsed
227+
* rejt-array-node (div)
228+
* rejt-name (span)
229+
* rejt-collapsed (span)
230+
* rejt-collapsed-text (span)
231+
* rejt-minus-menu (span)
232+
233+
#### Not Collapsed
234+
* rejt-array-node (div)
235+
* rejt-name (span)
236+
* rejt-not-collapsed (span)
237+
* rejt-not-collapsed-delimiter (span)
238+
* rejt-not-collapsed-list (ul)
239+
* rejt-not-collapsed-delimiter (span)
240+
* rejt-add-form (span)
241+
* rejt-plus-menu (span)
242+
* rejt-minus-menu (span)
243+
244+
### JsonAddValue
245+
* rejt-add-value-node (span)
246+
247+
### JsonFunctionValue
248+
* rejt-function-value-node (li)
249+
* rejt-name (span)
250+
* rejt-edit-form (span)
251+
* rejt-value (span)
252+
* rejt-minus-menu (span)
253+
254+
### JsonValue
255+
* rejt-value-node (li)
256+
* rejt-name (span)
257+
* rejt-edit-form (span)
258+
* rejt-value (span)
259+
* rejt-minus-menu (span)
188260

189261
## Development
190262
### Serve

circle.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
machine:
2+
node:
3+
version: 7.1.0
4+
5+
6+
test:
7+
override:
8+
- gulp release
9+

dev/components/Body.jsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class Body extends Component {
6565
this.handleSubmit = this.handleSubmit.bind(this);
6666
this.handleResetToDefault = this.handleResetToDefault.bind(this);
6767
this.handleChangeReadOnly = this.handleChangeReadOnly.bind(this);
68+
this.handleClearGlobalUpdateString = this.handleClearGlobalUpdateString.bind(this);
69+
this.handleClearDeltaUpdateString = this.handleClearDeltaUpdateString.bind(this);
6870
}
6971

7072
onFullyUpdate(newJson) {
@@ -119,6 +121,18 @@ class Body extends Component {
119121
});
120122
}
121123

124+
handleClearGlobalUpdateString() {
125+
this.setState({
126+
globalUpdateString: '{}',
127+
});
128+
}
129+
130+
handleClearDeltaUpdateString() {
131+
this.setState({
132+
deltaUpdateString: '{}',
133+
});
134+
}
135+
122136
render() {
123137
const { json, deltaUpdateString, globalUpdateString, readOnly } = this.state;
124138

@@ -148,10 +162,22 @@ class Body extends Component {
148162
<table style={style1}>
149163
<thead>
150164
<tr>
151-
<th>Result</th>
152-
<th>Global Update</th>
153-
<th>Delta Update</th>
154-
<th>Put Your Json</th>
165+
<th>
166+
<span>Result</span>
167+
</th>
168+
<th>
169+
<span>
170+
Global Update <button onClick={this.handleClearGlobalUpdateString}>Clear</button>
171+
</span>
172+
</th>
173+
<th>
174+
<span>
175+
Delta Update <button onClick={this.handleClearDeltaUpdateString}>Clear</button>
176+
</span>
177+
</th>
178+
<th>
179+
<span>Put Your Json</span>
180+
</th>
155181
</tr>
156182
</thead>
157183
<tbody>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-editable-json-tree",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "React Editable Json Tree",
55
"main": "dist/JsonTree.js",
66
"scripts": {

src/JsonTree.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
import React, { Component, PropTypes } from 'react';
1010
import JsonNode from './components/JsonNode';
1111
import { value, object, array } from './utils/styles';
12-
import deltaTypes from './utils/deltaTypes';
13-
import objectTypes from './utils/objectTypes';
14-
15-
const { getObjectType } = objectTypes;
12+
import { ADD_DELTA_TYPE, REMOVE_DELTA_TYPE, UPDATE_DELTA_TYPE } from './utils/deltaTypes';
13+
import { getObjectType } from './utils/objectTypes';
1614

1715
/* ************************************* */
1816
/* ******** VARIABLES ******** */
@@ -30,6 +28,7 @@ const propTypes = {
3028
cancelButtonElement: PropTypes.element,
3129
editButtonElement: PropTypes.element,
3230
inputElement: PropTypes.element,
31+
textareaElement: PropTypes.element,
3332
};
3433
// Default props
3534
const defaultProps = {
@@ -94,6 +93,7 @@ class JsonTree extends Component {
9493
cancelButtonElement,
9594
editButtonElement,
9695
inputElement,
96+
textareaElement,
9797
} = this.props;
9898

9999
// Node type
@@ -114,12 +114,13 @@ class JsonTree extends Component {
114114
cancelButtonElement={cancelButtonElement}
115115
editButtonElement={editButtonElement}
116116
inputElement={inputElement}
117+
textareaElement={textareaElement}
117118
/>);
118119
} else {
119120
node = 'Data must be an Array or Object';
120121
}
121122

122-
return (<div>{node}</div>);
123+
return (<div className="rejt-tree">{node}</div>);
123124
}
124125
}
125126

@@ -132,4 +133,6 @@ JsonTree.defaultProps = defaultProps;
132133
/* ******** EXPORTS ******** */
133134
/* ************************************* */
134135
export { JsonTree };
135-
export { deltaTypes };
136+
export { ADD_DELTA_TYPE };
137+
export { REMOVE_DELTA_TYPE };
138+
export { UPDATE_DELTA_TYPE };

src/components/JsonAddValue.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,29 @@ class JsonAddValue extends Component {
9595
const cancelButtonElementLayout = React.cloneElement(cancelButtonElement, {
9696
onClick: handleCancel,
9797
});
98-
let result = null;
99-
if (onlyValue) {
100-
const inputElementValueLayout = React.cloneElement(inputElement, {
101-
placeholder: 'Value',
102-
ref: this.refInputValue,
103-
});
104-
result = (<span> {inputElementValueLayout} {cancelButtonElementLayout}{addButtonElementLayout}
105-
</span>);
106-
} else {
107-
const inputElementValueLayout = React.cloneElement(inputElement, {
108-
placeholder: 'Value',
109-
ref: this.refInputValue,
110-
});
111-
const inputElementKeyLayout = React.cloneElement(inputElement, {
98+
const inputElementValueLayout = React.cloneElement(inputElement, {
99+
placeholder: 'Value',
100+
ref: this.refInputValue,
101+
});
102+
let inputElementKeyLayout = null;
103+
let separatorElement = null;
104+
105+
if (!onlyValue) {
106+
inputElementKeyLayout = React.cloneElement(inputElement, {
112107
placeholder: 'Key',
113108
ref: this.refInputKey,
114109
});
115-
result = (<span> {inputElementKeyLayout}: {inputElementValueLayout} {cancelButtonElementLayout}
116-
{addButtonElementLayout}
117-
</span>);
110+
separatorElement = ':';
118111
}
119112

120113
const handlers = {
121114
esc: handleCancel,
122115
enter: this.onSubmit,
123116
};
124117

125-
return (<HotKeys component={'span'} handlers={handlers}>
126-
{result}
118+
return (<HotKeys className="rejt-add-value-node" component={'span'} handlers={handlers}>
119+
{inputElementKeyLayout} {separatorElement} {inputElementValueLayout} {cancelButtonElementLayout}
120+
{addButtonElementLayout}
127121
</HotKeys>);
128122
}
129123
}

0 commit comments

Comments
 (0)