11<template >
22 <div class =" json" >
33 <v-jsoneditor ref =" jsonEditor" class =" json__editor" :options =" options" :plus =" false" height =" 446px" />
4- <div class =" json__button-group" >
4+ <div class =" json__button-group" :class = " {'--code': currentMode === 'code'} " >
55 <v-dialog v-model =" saveErrorDialog" width =" 500" >
66 <v-card >
77 <v-card-title class =" error" primary-title >
@@ -83,10 +83,12 @@ export default {
8383 origin: ' JsonPreview' ,
8484 activeFile: ' ' ,
8585 fileNameMap: {},
86+ currentMode: ' form' ,
8687 options: {
87- onChangeJSON: this .onEdit ,
88- mode: ' form' ,
89- onEvent: this .onEvent
88+ onChangeText: this .onEdit ,
89+ modes: [ ' form' , ' code' ],
90+ onEvent: this .onEvent ,
91+ onModeChange: this .onModeChange ,
9092 },
9193 };
9294 },
@@ -143,11 +145,27 @@ export default {
143145 * Handles JSON Editor changes
144146 */
145147 onEdit ($event ) {
146- this .checkErrors ($event, this .origin );
148+ let parsed;
149+
150+ // the code will work without this block, but the console.errors will fill up the console
151+ try {
152+ parsed = JSON .parse ($event);
153+ } catch {
154+ return ;
155+ }
156+
157+ this .checkErrors (parsed, this .origin );
158+
147159 if (this .jsonErrors ) {
148160 return ;
149161 }
150- EventBus .$emit (' json_update' , $event, this .origin );
162+ EventBus .$emit (' json_update' , parsed, this .origin );
163+ },
164+ /**
165+ * handles JSON viewer mode change (text or form)
166+ */
167+ onModeChange (newMode ) {
168+ this .currentMode = newMode;
151169 },
152170 /**
153171 * Handles the save caption event from app menu or keyboard shortcut
@@ -207,6 +225,10 @@ export default {
207225 const index = node .path [1 ];
208226 const indexDelta = index - this .currentIndex ;
209227
228+ if (this .currentIndex === index) {
229+ return ;
230+ }
231+
210232 if (this .activeFile === node .path [0 ]) {
211233 EventBus .$emit (' caption_move_index' , indexDelta, this .origin );
212234 return ;
@@ -320,6 +342,10 @@ export default {
320342
321343 const file = json[key];
322344
345+ if (! file) {
346+ return ;
347+ }
348+
323349 if (! Array .isArray (file)) {
324350 return ;
325351 }
@@ -376,6 +402,20 @@ $menu-height: 5.6rem;
376402 & __editor {
377403 width : 100% ;
378404 }
405+ .jsoneditor-contextmenu {
406+ .jsoneditor-menu {
407+ border-radius : 10px ;
408+ color : white ;
409+
410+ button {
411+ color : $white ;
412+
413+ & :hover {
414+ color : $black ;
415+ }
416+ }
417+ }
418+ }
379419
380420 .jsoneditor-menu {
381421 background-color : $accent ;
@@ -404,8 +444,6 @@ $menu-height: 5.6rem;
404444 }
405445
406446 & __errors {
407- position : relative ;
408- top : 2.25rem ;
409447 color : red ;
410448 }
411449
@@ -428,10 +466,15 @@ $menu-height: 5.6rem;
428466 & -group {
429467 display : flex ;
430468 width : 100% ;
469+ margin-top : 2.2rem ;
431470 min-height : 3.6rem ;
432471 align-items : center ;
433472 border-radius : 2rem ;
434473
474+ & .--code {
475+ margin-top : 5.2rem ;
476+ }
477+
435478 & >* {
436479 width : 50% ;
437480 }
0 commit comments