diff --git a/src/jsoneditor/components/JSONNode.js b/src/jsoneditor/components/JSONNode.js index 50d7b6a..bf00592 100644 --- a/src/jsoneditor/components/JSONNode.js +++ b/src/jsoneditor/components/JSONNode.js @@ -95,7 +95,7 @@ export default class JSONNode extends PureComponent { const nodeStart = h('div', { key: 'node', onKeyDown: this.handleKeyDown, - 'data-selection-area': 'inside', + 'data-area': 'inside', className: 'jsoneditor-node jsoneditor-object' }, [ this.renderExpandButton(), @@ -129,7 +129,7 @@ export default class JSONNode extends PureComponent { childs = h('div', { key: 'childs', - 'data-selection-area': 'before', + 'data-area': 'before', className: 'jsoneditor-list' }, propsChilds) } @@ -137,8 +137,7 @@ export default class JSONNode extends PureComponent { childs = h('div', { key: 'childs', className: 'jsoneditor-list', - 'data-area': 'emptyBefore', // TODO: remove - 'data-selection-area': 'before' + 'data-area': 'before' }, this.renderEmpty('(empty object)') ) @@ -149,8 +148,7 @@ export default class JSONNode extends PureComponent { ? h('div', { key: 'node-end', className: 'jsoneditor-node-end', - 'data-selection-area': 'after', - 'data-area': 'empty', // TODO: remove + 'data-area': 'after', }, [ this.renderDelimiter('}', 'jsoneditor-delimiter-end', 'after-childs') ]) @@ -158,8 +156,7 @@ export default class JSONNode extends PureComponent { return h('div', { 'data-path': compileJSONPointer(this.state.path), - 'data-area': 'empty', // TODO: remove - 'data-selection-area': this.props.eson[EXPANDED] ? 'before-childs' : 'after', + 'data-area': this.props.eson[EXPANDED] ? 'before-childs' : 'after', className: this.getContainerClassName(this.props.eson[SELECTION]), // onMouseOver: this.handleMouseOver, // onMouseLeave: this.handleMouseLeave @@ -172,7 +169,7 @@ export default class JSONNode extends PureComponent { const nodeStart = h('div', { key: 'node', onKeyDown: this.handleKeyDown, - 'data-selection-area': 'inside', + 'data-area': 'inside', className: 'jsoneditor-node jsoneditor-array' }, [ this.renderExpandButton(), @@ -205,7 +202,7 @@ export default class JSONNode extends PureComponent { childs = h('div', { key: 'childs', - 'data-selection-area': 'before', + 'data-area': 'before', className: 'jsoneditor-list' }, items) } @@ -213,8 +210,7 @@ export default class JSONNode extends PureComponent { childs = h('div', { key: 'childs', className: 'jsoneditor-list', - 'data-selection-area': 'before', - 'data-area': 'emptyBefore' // TODO: remove data-area + 'data-area': 'before', }, this.renderEmpty('(empty array)') ) @@ -225,8 +221,7 @@ export default class JSONNode extends PureComponent { ? h('div', { key: 'node-end', className: 'jsoneditor-node-end', - 'data-selection-area': 'after', - 'data-area': 'empty'// TODO: remove data-area + 'data-area': 'after' }, [ this.renderDelimiter(']', 'jsoneditor-delimiter-end', 'after-childs') ]) @@ -234,8 +229,7 @@ export default class JSONNode extends PureComponent { return h('div', { 'data-path': compileJSONPointer(this.state.path), - 'data-area': 'empty', // TODO: remove data-area - 'data-selection-area': this.props.eson[EXPANDED] ? 'before-childs' : 'after', + 'data-area': this.props.eson[EXPANDED] ? 'before-childs' : 'after', className: this.getContainerClassName(this.props.eson[SELECTION]), // onMouseOver: this.handleMouseOver, // onMouseLeave: this.handleMouseLeave @@ -246,7 +240,7 @@ export default class JSONNode extends PureComponent { const node = h('div', { key: 'node', onKeyDown: this.handleKeyDown, - 'data-selection-area': 'inside', + 'data-area': 'inside', className: 'jsoneditor-node' }, [ this.renderPlaceholder(), @@ -260,8 +254,7 @@ export default class JSONNode extends PureComponent { return h('div', { 'data-path': compileJSONPointer(this.state.path), - 'data-area': 'empty', // TODO: remove - 'data-selection-area': 'after', + 'data-area': 'after', className: this.getContainerClassName(this.props.eson[SELECTION]), // onMouseOver: this.handleMouseOver, // onMouseLeave: this.handleMouseLeave @@ -276,12 +269,11 @@ export default class JSONNode extends PureComponent { renderEmpty (text) { return h('div', { 'data-path': compileJSONPointer(this.state.path) + '/-', - 'data-area': 'empty', // TODO: remove - 'data-selection-area': 'after', + 'data-area': 'after', className: 'jsoneditor-node-container' }, h('div', { className: 'jsoneditor-node', - 'data-selection-area': 'inside', + 'data-area': 'inside', onKeyDown: this.handleKeyDownAppend }, [ this.renderPlaceholder(), @@ -292,16 +284,14 @@ export default class JSONNode extends PureComponent { renderPlaceholder () { return h('div', { key: 'placeholder', - // 'data-area': dataArea, // TODO: remove - 'data-selection-area': 'before', + 'data-area': 'before', className: 'jsoneditor-button-placeholder' }) } - renderReadonly (text, title = null, dataArea = 'inside') { + renderReadonly (text, title = null) { return h('div', { key: 'readonly', - 'data-area': dataArea, // TODO: remove className: 'jsoneditor-readonly', title }, text) @@ -360,7 +350,7 @@ export default class JSONNode extends PureComponent { return h('div', { key: 'before-childs', className: 'jsoneditor-before-childs', - 'data-selection-area': 'before-childs' + 'data-area': 'before-childs' }) } @@ -373,15 +363,13 @@ export default class JSONNode extends PureComponent { return h('div', { key: 'separator', className: 'jsoneditor-delimiter', - 'data-area': 'value' // TODO: remove }, ':') } renderDelimiter (text, className = '', dataArea) { return h('div', { key: text, - 'data-area': 'value', // TODO: remove - 'data-selection-area': dataArea, + 'data-area': dataArea, className: 'jsoneditor-delimiter ' + className }, text) } @@ -564,7 +552,7 @@ export default class JSONNode extends PureComponent { return h('div', {key: 'expand', className: 'jsoneditor-button-container'}, h('button', { - 'data-selection-area': 'before', + 'data-area': 'before', className: className, onClick: this.handleExpand, title: diff --git a/src/jsoneditor/components/TreeMode.js b/src/jsoneditor/components/TreeMode.js index 514f468..e059aed 100644 --- a/src/jsoneditor/components/TreeMode.js +++ b/src/jsoneditor/components/TreeMode.js @@ -282,6 +282,7 @@ export default class TreeMode extends PureComponent { selection: this.state.selection, clipboard: this.state.clipboard, history: this.state.history, + historyIndex: this.state.historyIndex, mode: this.props.mode, modes: this.props.modes, @@ -884,18 +885,6 @@ export default class TreeMode extends PureComponent { return attr ? parseJSONPointer(attr.replace(/\/-$/, '')) : null } - /** - * Find JSON pointer from an HTML element - * @param {Element} element - * @return {ESONPointer | null} - */ - findJSONPointerFromElement (element) { - const path = this.findDataPathFromElement(element) - const area = (element && element.getAttribute && element.getAttribute('data-area')) || null - - return path ? { path, area } : null - } - /** * Find JSON pointer from an HTML element * @param {Element} element @@ -903,8 +892,8 @@ export default class TreeMode extends PureComponent { * @return {SelectionPointer | null} */ findSelectionPointerFromEvent (element, y) { - const areaParent = findParentWithAttribute(element, 'data-selection-area') - const area = areaParent ? areaParent.getAttribute('data-selection-area') : undefined + const areaParent = findParentWithAttribute(element, 'data-area') + const area = areaParent ? areaParent.getAttribute('data-area') : undefined const base = (area === 'before') ? document.elementFromPoint(element.getBoundingClientRect().right - 1, y) diff --git a/src/jsoneditor/components/menu/TreeModeMenu.js b/src/jsoneditor/components/menu/TreeModeMenu.js index ebe075a..cca60a9 100644 --- a/src/jsoneditor/components/menu/TreeModeMenu.js +++ b/src/jsoneditor/components/menu/TreeModeMenu.js @@ -34,6 +34,7 @@ export default class TreeModeMenu extends PureComponent { selection: PropTypes.object, clipboard: PropTypes.array, history: PropTypes.array, + historyIndex: PropTypes.number, mode: PropTypes.string.isRequired, modes: PropTypes.arrayOf(PropTypes.string), diff --git a/src/jsoneditor/eson.js b/src/jsoneditor/eson.js index 7d92ebd..c262611 100644 --- a/src/jsoneditor/eson.js +++ b/src/jsoneditor/eson.js @@ -416,34 +416,8 @@ export function findRootPath(selection) { return initial(parseJSONPointer(selection.after)) } - // TODO: handle area === 'before-childs' and area === 'after-childs' + // FIXME: handle area === 'before-childs' and area === 'after-childs' - - // TODO: cleanup - // if (selection.inside) { - // return initial(selection.inside) - // } - // else if (selection.after) { - // return initial(selection.after) - // } - // else if (selection.empty) { - // return initial(selection.empty) - // } - // else if (selection.emptyBefore) { - // return initial(selection.emptyBefore) - // } - // else { // selection.start and selection.end - // const sharedPath = findSharedPath(selection.start, selection.end) - // - // if (sharedPath.length === selection.start.length || - // sharedPath.length === selection.end.length) { - // // there is just one node selected, return it's parent - // return initial(sharedPath) - // } - // else { - // return sharedPath - // } - // } } /**