@@ -29,28 +29,32 @@ class Source extends React.Component {
2929 valid : isValid ( source ) ,
3030 } ;
3131 }
32+
3233 UNSAFE_componentWillReceiveProps = ( nextProps ) => {
3334 const source = JSON . stringify ( nextProps . source , null , 2 ) ;
3435 this . setState ( {
3536 source,
3637 valid : isValid ( source ) ,
3738 } ) ;
3839 }
40+
3941 onChange = ( newValue ) => {
4042 this . setState ( { source : newValue } ) ;
4143 }
44+
4245 onBeforeChange = ( editor , data , value ) => {
43- // const { onChange } = this.props;
44- // const parsed = isValid(value );
46+ const { onChange } = this . props ;
47+ const parsed = isValid ( editor ) ;
4548
46- // this.setState({
47- // valid: parsed,
48- // source: value ,
49- // });
50- // if (parsed && onChange) {
51- // onChange(parsed);
52- // }
49+ this . setState ( {
50+ valid : parsed ,
51+ source : editor ,
52+ } ) ;
53+ if ( parsed && onChange ) {
54+ onChange ( parsed ) ;
55+ }
5356 }
57+
5458 render ( ) {
5559 const { source, valid } = this . state ;
5660 const { classes, title } = this . props ;
@@ -59,7 +63,7 @@ class Source extends React.Component {
5963 < div className = { classes . root } >
6064 < div className = { classNames ( classes . ctr , { [ classes . invalid ] : ! valid } ) } >
6165 < div >
62- { /* <Icon fontSize className={classes.icon} /> */ }
66+ < Icon fontSize = { 'default' } className = { classes . icon } />
6367 < div className = { classes . title } >
6468 < p > { title } </ p >
6569 </ div >
@@ -68,13 +72,14 @@ class Source extends React.Component {
6872 < AceEditor
6973 mode = 'json'
7074 theme = 'textmate'
71- value = { this . state . source }
72- onChange = { this . onChange }
75+ value = { source }
76+ onChange = { this . onBeforeChange }
7377 name = 'ace_editor_1'
7478 editorProps = { { $blockScrolling : true } }
7579 showPrintMargin
7680 showGutter
7781 highlightActiveLine
82+ width = { title === 'JSONSchema' ? '100%' : 500 }
7883 setOptions = { {
7984 enableBasicAutocompletion : true ,
8085 enableLiveAutocompletion : true ,
0 commit comments