Skip to content

Commit e661d65

Browse files
committed
add button to hide the code editor
1 parent 6c74547 commit e661d65

File tree

5 files changed

+113
-71
lines changed

5 files changed

+113
-71
lines changed

public/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ svg {
8989
color: #101820;
9090
}
9191

92+
.top-bar button#hide-editor.active {
93+
color: #606060;
94+
}
95+
9296
.editor {
9397
display: flex;
9498
flex-flow: row wrap;

public/app.js

Lines changed: 62 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ <h1>Litecanvas</h1>
8888
/>
8989
</svg>
9090
</a>
91+
<button
92+
type="button"
93+
id="hide-editor"
94+
title="Hide the code editor"
95+
aria-label="Hide the code editor"
96+
hidden
97+
>
98+
<svg
99+
xmlns="http://www.w3.org/2000/svg"
100+
fill="none"
101+
stroke="currentColor"
102+
stroke-width="1.5"
103+
role="img"
104+
width="24"
105+
height="24"
106+
>
107+
<path
108+
d="M12 4.5v15m-7.875 0h15.75c.621 0 1.125-.504 1.125-1.125V5.625c0-.621-.504-1.125-1.125-1.125H4.125C3.504 4.5 3 5.004 3 5.625v12.75c0 .621.504 1.125 1.125 1.125Z"
109+
/>
110+
</svg>
111+
</button>
91112
<button
92113
type="button"
93114
id="share"
@@ -122,7 +143,6 @@ <h1>Litecanvas</h1>
122143
height="24"
123144
stroke-width="1.5"
124145
stroke="currentColor"
125-
class="w-6 h-6"
126146
>
127147
<path
128148
stroke-linecap="round"

public/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "2.31.0";
2+
const version = "2.32.0";
33

44
const precacheResources = [
55
"/",

src/index.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const playButton = $("#play");
6464
const stopButton = $("#stop");
6565
const shareButton = $("#share");
6666
const copyButton = $("#copy");
67+
const hideEditor = $("#hide-editor");
6768
/** @type {HTMLIFrameElement} */
6869
const iframe = $("#frame");
6970
const iframeOverlay = $("#frame-overlay");
@@ -102,11 +103,12 @@ shareButton.addEventListener("click", (evt) => {
102103
"Your browser not support this feature. Consider installing Firefox or Chrome."
103104
);
104105
}
105-
const code = codeEditor.state.doc.toString();
106+
const code = window.codeEditor.state.doc.toString();
106107
const url =
107108
location.origin + "?c=" + encodeURIComponent(compressString(code));
108109

109-
if (url.length > 2048) {
110+
if (url.length > 2000) {
111+
console.log("Your too long URL:", url);
110112
return alert("Code too long to encode in URL");
111113
}
112114

@@ -127,7 +129,7 @@ copyButton.addEventListener("click", (evt) => {
127129
"Your browser not support this feature. Consider installing Firefox or Chrome."
128130
);
129131
}
130-
const code = codeEditor.state.doc.toString();
132+
const code = window.codeEditor.state.doc.toString();
131133

132134
navigator.clipboard.writeText(code).then(
133135
() => {},
@@ -138,12 +140,23 @@ copyButton.addEventListener("click", (evt) => {
138140
);
139141
});
140142

143+
hideEditor.addEventListener("click", (evt) => {
144+
if (code.hasAttribute("hidden")) {
145+
code.removeAttribute("hidden");
146+
hideEditor.classList.remove("active");
147+
} else {
148+
code.setAttribute("hidden", true);
149+
hideEditor.classList.add("active");
150+
}
151+
iframe.focus();
152+
});
153+
141154
function runCode() {
142155
iframe.src = "preview.html"; // reload the iframe
143156
}
144157

145158
iframe.addEventListener("load", () => {
146-
const code = codeEditor.state.doc.toString();
159+
const code = window.codeEditor.state.doc.toString();
147160
iframe.contentDocument.querySelector("#code").innerHTML = code;
148161
});
149162

@@ -220,13 +233,14 @@ iframeOverlay.onmousedown = iframeOverlay.ontouchstart = (evt) => {
220233
if (evt.target === iframeOverlay) {
221234
hide(iframeOverlay);
222235
iframe.focus();
223-
return;
224236
}
225237
};
226238

227239
window.addEventListener("click", (evt) => {
228240
if (evt.target === iframeOverlay) return;
229241
if (evt.target === playButton) return;
242+
if (evt.target === hideEditor) return;
243+
230244
show(iframeOverlay);
231245
iframe.blur();
232246
});
@@ -291,7 +305,10 @@ if (config.autosave) {
291305
}
292306

293307
function saveCode() {
294-
localStorage.setItem("litecanvas_code", codeEditor.state.doc.toString());
308+
localStorage.setItem(
309+
"litecanvas_code",
310+
window.codeEditor.state.doc.toString()
311+
);
295312
}
296313

297314
function loadFromStorage() {
@@ -303,7 +320,7 @@ function resetStorage() {
303320
}
304321

305322
if (isMobile) {
306-
mobileBar(codeEditor);
323+
mobileBar(window.codeEditor);
307324
}
308325

309326
window.isUpdateAvailable = new Promise(function (resolve) {
@@ -353,6 +370,7 @@ window.isUpdateAvailable.then((isAvailable) => {
353370

354371
if (!smallScreen) {
355372
show(iframeOverlay);
373+
show(hideEditor);
356374
if (autoplay) runCode();
357375
} else {
358376
show(playButton);

0 commit comments

Comments
 (0)