Implemented support for type 'string'

This commit is contained in:
jos 2016-07-31 14:41:28 +02:00
parent 38250a38ba
commit 49f0ed3e4f
2 changed files with 30 additions and 22 deletions

View File

@ -336,20 +336,20 @@ export default class JSONNode extends Component {
} }
handleChangeValue (event) { handleChangeValue (event) {
const value = JSONNode._getValueFromEvent(event) const value = this._getValueFromEvent(event)
this.props.events.onChangeValue(this.props.path, value) this.props.events.onChangeValue(this.props.path, value)
} }
handleClickValue (event) { handleClickValue (event) {
if (event.ctrlKey && event.button === 0) { // Ctrl+Left click if (event.ctrlKey && event.button === 0) { // Ctrl+Left click
JSONNode._openLinkIfUrl(event) this._openLinkIfUrl(event)
} }
} }
handleKeyDownValue (event) { handleKeyDownValue (event) {
if (event.ctrlKey && event.which === 13) { // Ctrl+Enter if (event.ctrlKey && event.which === 13) { // Ctrl+Enter
JSONNode._openLinkIfUrl(event) this._openLinkIfUrl(event)
} }
} }
@ -377,8 +377,8 @@ export default class JSONNode extends Component {
* @param event * @param event
* @private * @private
*/ */
static _openLinkIfUrl (event) { _openLinkIfUrl (event) {
const value = JSONNode._getValueFromEvent(event) const value = this._getValueFromEvent(event)
if (isUrl(value)) { if (isUrl(value)) {
event.preventDefault() event.preventDefault()
@ -388,11 +388,19 @@ export default class JSONNode extends Component {
} }
} }
static _getValueFromEvent (event) { /**
return stringConvert(unescapeHTML(getInnerText(event.target))) * Get the value of the target of an event, and convert it to it's type
* @param event
* @return {string | number | boolean | null}
* @private
*/
_getValueFromEvent (event) {
const stringValue = unescapeHTML(getInnerText(event.target))
return this.props.data.type === 'string'
? stringValue
: stringConvert(stringValue)
} }
/** /**
* Find the root DOM element of the JSONEditor * Find the root DOM element of the JSONEditor
* Search is done based on the CSS class 'jsoneditor' * Search is done based on the CSS class 'jsoneditor'

View File

@ -371,7 +371,7 @@ function jsonToData (path, json, expand) {
} }
else { else {
return { return {
type: 'json', type: 'value',
value: json value: json
} }
} }
@ -383,10 +383,11 @@ function jsonToData (path, json, expand) {
* @return {Object | Array | string | number | boolean | null} json * @return {Object | Array | string | number | boolean | null} json
*/ */
function dataToJson (data) { function dataToJson (data) {
if (data.type === 'array') { switch (data.type) {
case 'array':
return data.items.map(dataToJson) return data.items.map(dataToJson)
}
else if (data.type === 'object') { case 'object':
const object = {} const object = {}
data.props.forEach(prop => { data.props.forEach(prop => {
@ -394,9 +395,8 @@ function dataToJson (data) {
}) })
return object return object
}
else { default: // type 'string' or 'value'
// type 'value' or 'string'
return data.value return data.value
} }
} }