@@ -6,15 +6,34 @@ let reevaluate = null;
6
6
const createElementComplex = ( containerNode , containerElem , indexOrKey , isArray , level , isRoot = false , parentArray ) => {
7
7
const wrapper = domUtils . create ( "div" , [ "container-wr" ] , null ) ;
8
8
const keyWrapper = domUtils . create ( "div" , [ ] , null ) ;
9
+ const valueWrapper = domUtils . create ( "div" , [ isRoot ? "root-wr" : null ] , { marginLeft : `${ level } rem` } ) ;
10
+
11
+ if ( ! isRoot ) {
12
+ const collapseButton = domUtils . createWithText ( "span" , "-" , [ ] , { cursor : "pointer" , marginRight : "5px" } ) ;
13
+ let hiding = false ;
14
+ collapseButton . addEventListener ( "click" , ( ) => {
15
+ if ( ! hiding ) {
16
+ valueWrapper . style . transform = "scaleY(0)" ;
17
+ collapseButton . textContent = "+" ;
18
+ } else {
19
+ valueWrapper . style . transform = "scaleY(1)" ;
20
+ collapseButton . textContent = "-" ;
21
+ }
22
+ hiding = ! hiding ;
23
+ } ) ;
24
+
25
+ keyWrapper . append ( collapseButton ) ;
26
+
27
+ }
9
28
keyWrapper . appendChild ( domUtils . createWithText ( "span" , isRoot ? "root: " : `${ indexOrKey } : ` , [ ] , null ) ) ;
10
29
keyWrapper . appendChild ( domUtils . createWithText ( "span" , isArray ? 'array' : 'object' , [ ] , { opacity : 0.6 } ) ) ;
11
30
12
31
let createKey = '' ;
13
32
let createValue = '' ;
14
33
let createType = "string" ;
15
34
16
-
17
35
const createWrapper = domUtils . create ( "div" , [ "create-row" ] , null ) ;
36
+
18
37
const valueInput = domUtils . input ( "Value" , '' , newVal => {
19
38
createValue = newVal ;
20
39
} ) ;
@@ -101,9 +120,9 @@ const createElementComplex = (containerNode, containerElem, indexOrKey, isArray,
101
120
} ) ;
102
121
alterBtn . style . display = "inline" ;
103
122
createWrapper . appendChild ( alterBtn ) ;
104
- }
123
+ }
105
124
keyWrapper . appendChild ( createWrapper ) ;
106
- const valueWrapper = domUtils . create ( "div" , [ isRoot ? "root-wr" : null ] , { marginLeft : ` ${ level } rem` } ) ;
125
+
107
126
wrapper . appendChild ( keyWrapper ) ;
108
127
wrapper . appendChild ( valueWrapper ) ;
109
128
return { wrapper, keyWrapper, valueWrapper} ;
@@ -163,7 +182,7 @@ const createElementSimple = (containerNode, containerElem, indexOrKey, isArray)
163
182
ev . stopPropagation ( ) ;
164
183
closeCurrentEdit ( ) ;
165
184
closeCurrentEdit = null ;
166
- } ) ;
185
+ } ) ;
167
186
const saveBtn = domUtils . button ( "Save" , ( ) => {
168
187
ev . stopPropagation ( ) ;
169
188
if ( key !== indexOrKey && ! isArray ) {
@@ -260,13 +279,29 @@ const advance = (node, elem, level, isRoot = false) => {
260
279
261
280
262
281
const createEditor = ( onParse ) => {
263
- const editorRoot = domUtils . create ( "div" , [ ] , { padding : "10px 15px" } , false ) ;
264
- const area = domUtils . create ( "textarea" , [ ] , { width : "100%" , height : "25vh" } , false ) ;
282
+ const editorRoot = domUtils . create ( "div" , [ ] , { padding : "10px 15px" , display : "flex" } , false ) ;
283
+ const buttonRow = domUtils . create ( "div" , [ ] , null , false ) ;
284
+ const area = domUtils . create ( "textarea" , [ ] , { width : "100%" , height : "20vh" , marginRight : "20px" } , false ) ;
265
285
const button = domUtils . button ( "parse" , ev => {
266
286
onParse ( area ) ;
267
287
} , false ) ;
288
+ let isDark = true ;
289
+ const theme = domUtils . button ( "Dark" , ev => {
290
+ if ( isDark ) {
291
+ ev . target . innerHTML = "<span>Light</span>" ;
292
+ window . document . body . classList . remove ( "dark-theme" ) ;
293
+ } else {
294
+ ev . target . innerHTML = "<span>Dark</span>" ;
295
+ window . document . body . classList . add ( "dark-theme" ) ;
296
+
297
+ }
298
+ isDark = ! isDark ;
299
+ } , false ) ;
300
+
268
301
editorRoot . appendChild ( area ) ;
269
- editorRoot . appendChild ( button ) ;
302
+ buttonRow . appendChild ( button ) ;
303
+ buttonRow . appendChild ( theme ) ;
304
+ editorRoot . appendChild ( buttonRow ) ;
270
305
return editorRoot ;
271
306
}
272
307
window . addEventListener ( "DOMContentLoaded" , ev => {
0 commit comments