@@ -90,13 +90,21 @@ function editorListener(docName) {
9090 changes . push ( update . state . doc . toString ( ) ) ;
9191 debounce ( ( docName ) => {
9292 // set the global `doc` to the latest string from the editor
93- try {
94- const parsed = JSON . parse ( changes [ changes . length - 1 ] ) ;
95- this [ docName ] = parsed ;
93+ const latestChange = changes [ changes . length - 1 ] ;
94+ if ( latestChange === '' ) {
95+ this [ docName ] = '' ;
9696 this . parseError = '' ;
97- } catch ( err ) {
98- this . parseError = err . message ;
99- } ;
97+ setEditorValue ( readOnlyEditor , '' ) ;
98+ return ;
99+ } else {
100+ try {
101+ const parsed = JSON . parse ( latestChange ) ;
102+ this [ docName ] = parsed ;
103+ this . parseError = '' ;
104+ } catch ( err ) {
105+ this . parseError = err . message ;
106+ } ;
107+ }
100108 } , 1000 ) . call ( this , docName ) ;
101109 }
102110 } ) ;
@@ -249,7 +257,7 @@ const jsonLdHighlightTheme = EditorView.baseTheme({
249257function initEditor ( id , content , varName ) {
250258 return new EditorView ( {
251259 parent : document . getElementById ( id ) ,
252- doc : JSON . stringify ( content , null , 2 ) ,
260+ doc : ( content === 'object' ? JSON . stringify ( content , null , 2 ) : '' ) ,
253261 extensions : [
254262 basicSetup ,
255263 keymap . of ( [ indentWithTab ] ) ,
@@ -267,7 +275,7 @@ const language = new Compartment();
267275
268276const readOnlyEditor = new EditorView ( {
269277 parent : document . getElementById ( 'read-only-editor' ) ,
270- doc : `{}` ,
278+ doc : '' ,
271279 extensions : [
272280 basicSetup ,
273281 language . of ( json ( ) ) ,
@@ -302,7 +310,7 @@ function setEditorValue(_editor, doc, lang) {
302310}
303311
304312window . app = createApp ( {
305- doc : { } ,
313+ doc : '' ,
306314 contextDoc : { } ,
307315 frameDoc : { } ,
308316 tableQuads : { } ,
@@ -423,6 +431,7 @@ window.app = createApp({
423431 this . setOutputTab ( this . outputTab ) ;
424432 } ,
425433 async setOutputTab ( value ) {
434+ if ( ! value || ! this . doc ) return ;
426435 if ( value ) this . outputTab = value ;
427436 let context = this . contextDoc ;
428437 switch ( this . outputTab ) {
@@ -553,7 +562,7 @@ window.app = createApp({
553562 'frameDoc' ) ;
554563 } ,
555564 initMainEditor ( ) {
556- this . mainEditor = initEditor . call ( this , 'editor' , { } , 'doc' ) ;
565+ this . mainEditor = initEditor . call ( this , 'editor' , '' , 'doc' ) ;
557566 } ,
558567 copyContext ( ) {
559568 this . contextDoc = {
0 commit comments