1
1
<template >
2
2
<div class =" json" >
3
3
<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'} " >
5
5
<v-dialog v-model =" saveErrorDialog" width =" 500" >
6
6
<v-card >
7
7
<v-card-title class =" error" primary-title >
@@ -83,10 +83,12 @@ export default {
83
83
origin: ' JsonPreview' ,
84
84
activeFile: ' ' ,
85
85
fileNameMap: {},
86
+ currentMode: ' form' ,
86
87
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 ,
90
92
},
91
93
};
92
94
},
@@ -143,11 +145,27 @@ export default {
143
145
* Handles JSON Editor changes
144
146
*/
145
147
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
+
147
159
if (this .jsonErrors ) {
148
160
return ;
149
161
}
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;
151
169
},
152
170
/**
153
171
* Handles the save caption event from app menu or keyboard shortcut
@@ -207,6 +225,10 @@ export default {
207
225
const index = node .path [1 ];
208
226
const indexDelta = index - this .currentIndex ;
209
227
228
+ if (this .currentIndex === index) {
229
+ return ;
230
+ }
231
+
210
232
if (this .activeFile === node .path [0 ]) {
211
233
EventBus .$emit (' caption_move_index' , indexDelta, this .origin );
212
234
return ;
@@ -320,6 +342,10 @@ export default {
320
342
321
343
const file = json[key];
322
344
345
+ if (! file) {
346
+ return ;
347
+ }
348
+
323
349
if (! Array .isArray (file)) {
324
350
return ;
325
351
}
@@ -376,6 +402,20 @@ $menu-height: 5.6rem;
376
402
& __editor {
377
403
width : 100% ;
378
404
}
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
+ }
379
419
380
420
.jsoneditor-menu {
381
421
background-color : $accent ;
@@ -404,8 +444,6 @@ $menu-height: 5.6rem;
404
444
}
405
445
406
446
& __errors {
407
- position : relative ;
408
- top : 2.25rem ;
409
447
color : red ;
410
448
}
411
449
@@ -428,10 +466,15 @@ $menu-height: 5.6rem;
428
466
& -group {
429
467
display : flex ;
430
468
width : 100% ;
469
+ margin-top : 2.2rem ;
431
470
min-height : 3.6rem ;
432
471
align-items : center ;
433
472
border-radius : 2rem ;
434
473
474
+ & .--code {
475
+ margin-top : 5.2rem ;
476
+ }
477
+
435
478
& >* {
436
479
width : 50% ;
437
480
}
0 commit comments