Implemented support for type 'string'
This commit is contained in:
parent
38250a38ba
commit
49f0ed3e4f
|
@ -336,20 +336,20 @@ export default class JSONNode extends Component {
|
|||
}
|
||||
|
||||
handleChangeValue (event) {
|
||||
const value = JSONNode._getValueFromEvent(event)
|
||||
const value = this._getValueFromEvent(event)
|
||||
|
||||
this.props.events.onChangeValue(this.props.path, value)
|
||||
}
|
||||
|
||||
handleClickValue (event) {
|
||||
if (event.ctrlKey && event.button === 0) { // Ctrl+Left click
|
||||
JSONNode._openLinkIfUrl(event)
|
||||
this._openLinkIfUrl(event)
|
||||
}
|
||||
}
|
||||
|
||||
handleKeyDownValue (event) {
|
||||
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
|
||||
* @private
|
||||
*/
|
||||
static _openLinkIfUrl (event) {
|
||||
const value = JSONNode._getValueFromEvent(event)
|
||||
_openLinkIfUrl (event) {
|
||||
const value = this._getValueFromEvent(event)
|
||||
|
||||
if (isUrl(value)) {
|
||||
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
|
||||
* Search is done based on the CSS class 'jsoneditor'
|
||||
|
|
14
src/Main.js
14
src/Main.js
|
@ -371,7 +371,7 @@ function jsonToData (path, json, expand) {
|
|||
}
|
||||
else {
|
||||
return {
|
||||
type: 'json',
|
||||
type: 'value',
|
||||
value: json
|
||||
}
|
||||
}
|
||||
|
@ -383,10 +383,11 @@ function jsonToData (path, json, expand) {
|
|||
* @return {Object | Array | string | number | boolean | null} json
|
||||
*/
|
||||
function dataToJson (data) {
|
||||
if (data.type === 'array') {
|
||||
switch (data.type) {
|
||||
case 'array':
|
||||
return data.items.map(dataToJson)
|
||||
}
|
||||
else if (data.type === 'object') {
|
||||
|
||||
case 'object':
|
||||
const object = {}
|
||||
|
||||
data.props.forEach(prop => {
|
||||
|
@ -394,9 +395,8 @@ function dataToJson (data) {
|
|||
})
|
||||
|
||||
return object
|
||||
}
|
||||
else {
|
||||
// type 'value' or 'string'
|
||||
|
||||
default: // type 'string' or 'value'
|
||||
return data.value
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue