From afcf19bac58e5497073712efa5737ca130aea272 Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 5 Jan 2017 11:18:38 +0100 Subject: [PATCH] A bit more refactoring --- package.json | 3 ++- src/components/JSONNode.js | 52 ++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index ac36884..6935303 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "javascript-natural-sort": "0.7.1", "lodash": "4.17.2", "react": "15.4.1", - "react-dom": "15.4.1" + "react-dom": "15.4.1", + "react-scroll": "1.4.4" }, "devDependencies": { "ava": "0.17.0", diff --git a/src/components/JSONNode.js b/src/components/JSONNode.js index e7b2b45..09d06eb 100644 --- a/src/components/JSONNode.js +++ b/src/components/JSONNode.js @@ -1,7 +1,7 @@ // @flow weak import { createElement as h, Component } from 'react' -import { Element as ScrollElement } from 'react-scroll' +//import { Element as ScrollElement } from 'react-scroll' import ActionButton from './menu/ActionButton' import AppendActionButton from './menu/AppendActionButton' @@ -41,16 +41,15 @@ export default class JSONNode extends Component { renderJSONObject ({prop, index, data, options, events}) { const childCount = data.props.length - const contents = [ - h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-object'}, [ - this.renderExpandButton(), - this.renderActionMenuButton(), - this.renderProperty(prop, index, data, options), - this.renderReadonly(`{${childCount}}`, `Array containing ${childCount} items`), - this.renderError(data.error) - ]) - ] + const node = h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-object'}, [ + this.renderExpandButton(), + this.renderActionMenuButton(), + this.renderProperty(prop, index, data, options), + this.renderReadonly(`{${childCount}}`, `Array containing ${childCount} items`), + this.renderError(data.error) + ]) + let childs if (data.expanded) { if (data.props.length > 0) { const props = data.props.map(prop => { @@ -65,32 +64,31 @@ export default class JSONNode extends Component { ) }) - contents.push(h('ul', {key: 'props', className: 'jsoneditor-list'}, props)) + childs = h('ul', {key: 'childs', className: 'jsoneditor-list'}, props) } else { - contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'}, + childs = h('ul', {key: 'childs', className: 'jsoneditor-list'}, h('li', {}, this.renderAppend('(empty object)') ) - )) + ) } } - return h('div', {}, contents) + return h('div', {}, [node, childs]) } renderJSONArray ({prop, index, data, options, events}) { const childCount = data.items.length - const contents = [ - h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-array'}, [ - this.renderExpandButton(), - this.renderActionMenuButton(), - this.renderProperty(prop, index, data, options), - this.renderReadonly(`[${childCount}]`, `Array containing ${childCount} items`), - this.renderError(data.error) - ]) - ] + const node = h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-array'}, [ + this.renderExpandButton(), + this.renderActionMenuButton(), + this.renderProperty(prop, index, data, options), + this.renderReadonly(`[${childCount}]`, `Array containing ${childCount} items`), + this.renderError(data.error) + ]) + let childs if (data.expanded) { if (data.items.length > 0) { const items = data.items.map((child, index) => { @@ -104,18 +102,18 @@ export default class JSONNode extends Component { }) ) }) - contents.push(h('ul', {key: 'items', className: 'jsoneditor-list'}, items)) + childs = h('ul', {key: 'childs', className: 'jsoneditor-list'}, items) } else { - contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'}, + childs = h('ul', {key: 'childs', className: 'jsoneditor-list'}, h('li', {}, this.renderAppend('(empty array)') ) - )) + ) } } - return h('div', {}, contents) + return h('div', {}, [node, childs]) } renderJSONValue ({prop, index, data, options}) {