Skip to content

Commit bb6885f

Browse files
committed
objects can now be collapsed and finally added and made a dark theme default
1 parent 17c4b30 commit bb6885f

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link type="text/css" href="style.css" rel="stylesheet" />
77
</head>
88

9-
<body>
9+
<body class="dark-theme">
1010
<div id="root">
1111
<div class="input-wrapper">
1212
</div>

js/index.js

+42-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,34 @@ let reevaluate = null;
66
const createElementComplex = (containerNode, containerElem, indexOrKey, isArray, level, isRoot = false, parentArray) => {
77
const wrapper = domUtils.create("div", ["container-wr"], null);
88
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+
}
928
keyWrapper.appendChild(domUtils.createWithText("span", isRoot ? "root: " : `${indexOrKey}: `, [], null));
1029
keyWrapper.appendChild(domUtils.createWithText("span", isArray ? 'array' : 'object', [], {opacity: 0.6}));
1130

1231
let createKey = '';
1332
let createValue = '';
1433
let createType = "string";
1534

16-
1735
const createWrapper = domUtils.create("div", ["create-row"], null);
36+
1837
const valueInput = domUtils.input("Value", '', newVal => {
1938
createValue = newVal;
2039
});
@@ -101,9 +120,9 @@ const createElementComplex = (containerNode, containerElem, indexOrKey, isArray,
101120
});
102121
alterBtn.style.display = "inline";
103122
createWrapper.appendChild(alterBtn);
104-
}
123+
}
105124
keyWrapper.appendChild(createWrapper);
106-
const valueWrapper = domUtils.create("div", [isRoot ? "root-wr" : null], {marginLeft: `${level}rem`});
125+
107126
wrapper.appendChild(keyWrapper);
108127
wrapper.appendChild(valueWrapper);
109128
return {wrapper, keyWrapper, valueWrapper};
@@ -163,7 +182,7 @@ const createElementSimple = (containerNode, containerElem, indexOrKey, isArray)
163182
ev.stopPropagation();
164183
closeCurrentEdit();
165184
closeCurrentEdit = null;
166-
});
185+
});
167186
const saveBtn = domUtils.button("Save", () => {
168187
ev.stopPropagation();
169188
if (key !== indexOrKey && !isArray) {
@@ -260,13 +279,29 @@ const advance = (node, elem, level, isRoot = false) => {
260279

261280

262281
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);
265285
const button = domUtils.button("parse", ev => {
266286
onParse(area);
267287
}, 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+
268301
editorRoot.appendChild(area);
269-
editorRoot.appendChild(button);
302+
buttonRow.appendChild(button);
303+
buttonRow.appendChild(theme);
304+
editorRoot.appendChild(buttonRow);
270305
return editorRoot;
271306
}
272307
window.addEventListener("DOMContentLoaded", ev => {

style.css

+31-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ select {
3535

3636
}
3737
.browser-root {
38-
width: 95vw;
39-
height: 55vh;
38+
width: 98vw;
39+
height: 70vh;
4040
margin: 0 auto;
4141
border: 2px solid black;
4242
padding: 4px;
@@ -82,3 +82,32 @@ select {
8282
.valtype-number {
8383
color: green;
8484
}
85+
.dark-theme {
86+
background: #212121;
87+
}
88+
.dark-theme input, .dark-theme textarea {
89+
background: #2e2e2e;
90+
color: #cecece;
91+
}
92+
.dark-theme span, .dark-theme div {
93+
color: #cecece;
94+
}
95+
.dark-theme .browser-root {
96+
background: #2e2e2e;
97+
}
98+
.dark-theme .btn, .dark-theme select {
99+
background: #4e4e4e;
100+
}
101+
.dark-theme .btn span, .dark-theme select {
102+
color: #eaeaea;
103+
}
104+
105+
.dark-theme .valtype-null, .dark-theme .valtype-boolean {
106+
color: #b12fb1;
107+
}
108+
.dark-theme .valtype-string {
109+
color: #2f94ff;
110+
}
111+
.dark-theme .valtype-number {
112+
color: #00dd12;
113+
}

0 commit comments

Comments
 (0)