From eeb9e07f932c33c94d06fe5602ad00dead510928 Mon Sep 17 00:00:00 2001 From: Lukasz 'Severiaan' Grela Date: Wed, 26 Oct 2022 10:10:56 +0200 Subject: [PATCH 1/9] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c98f56d..1369a6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-json-editor-viewer", - "version": "1.0.7", + "version": "1.1.1", "description": "React JSON Editor and JSON Viewer", "main": "build/index.js", "scripts": { From 6249f70b2b9a0d22aea8979aa467f0be2f1a76ed Mon Sep 17 00:00:00 2001 From: Lukasz 'Severiaan' Grela Date: Wed, 26 Oct 2022 10:16:33 +0200 Subject: [PATCH 2/9] WIP: Add type selector --- src/lib/components/editor/Input.js | 69 +++++++++++++++++++++++++----- src/lib/util.js | 3 ++ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/lib/components/editor/Input.js b/src/lib/components/editor/Input.js index f41e1fb..f83a642 100644 --- a/src/lib/components/editor/Input.js +++ b/src/lib/components/editor/Input.js @@ -11,6 +11,8 @@ export default class Input extends React.Component { this.state = { hovering: false, editableInput: null, + type: props.type, + value: props.value, }; } @@ -26,10 +28,22 @@ export default class Input extends React.Component { this.setState({ editableInput: event.target.value }); }; + onTypeChanged = (event) => { + this.setState((state) => ({ ...state, type: event.target.value })); + }; + + onValueChanged = (event) => { + this.setState({ value: event.target.value }, () => { + if(this.props.label !== EDIT_KEY || this.state.type === "text") { + this.props.onChange(event) + } + }); + }; + onSaveElement = () => { let { saveElement, parent } = this.props; - let { editableInput } = this.state; - saveElement(parent, editableInput); + let { editableInput,type,value } = this.state; + saveElement(parent, editableInput, type,value); }; render() { @@ -37,9 +51,6 @@ export default class Input extends React.Component { marginLeft, marginBottom, label, - value, - type, - onChange, removeElement, parent, currentKey, @@ -47,6 +58,7 @@ export default class Input extends React.Component { styles, } = this.props; let style = merge({ marginLeft, marginBottom }, styles.row); + const { type, value } = this.state; return (
+ + +
- + {type === "object" && {"{}"}} + {type === "array" && {"[]"}} + {type === "null" && {"null"}} + {type === "boolean" && ( + + )} + {(type === "text" || type === "number") && ( + + )}