From 43ac095898592d9a3e71b67d943b9c6905d5ea3a Mon Sep 17 00:00:00 2001 From: Kat21 Date: Thu, 18 Apr 2024 08:53:45 -0500 Subject: [PATCH] DevEnv improvements, faster initial page load --- index.html | 13 ------ pkgs/apps/DevEnv.js | 97 ++++++++++++++++++++++++++++++++++++++++++--- style.css | 6 ++- 3 files changed, 96 insertions(+), 20 deletions(-) diff --git a/index.html b/index.html index 6f5d56e..de2699d 100644 --- a/index.html +++ b/index.html @@ -36,19 +36,6 @@ type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jshashes/1.0.8/hashes.min.js" > - - diff --git a/pkgs/apps/DevEnv.js b/pkgs/apps/DevEnv.js index 3f1fc79..50b04cd 100644 --- a/pkgs/apps/DevEnv.js +++ b/pkgs/apps/DevEnv.js @@ -120,7 +120,7 @@ export default { DvWindow = new Win({ title: Root.Lib.getString("systemApp_DevEnv"), content: - '
DevEnv is loading external libraries, please wait...
', + '
DevEnv is loading external libraries, please wait...
', width: 540, height: 420, pid: Root.PID, @@ -139,6 +139,44 @@ export default { }, }); + wrapper = DvWindow.window.querySelector(".win-content"); + + function loadScript(url, scriptId) { + return new Promise((resolve) => { + if (Html.qs('script[id="' + scriptId + '"]')) { + return resolve(false); + } + + new Html("script") + .attr({ id: scriptId, src: url }) + .on("load", () => { + resolve(true); + }) + .appendTo("head"); + }); + } + + let counter = new Html("div") + .text("0 / 5") + .appendTo(wrapper.querySelector(".col")); + + let count = 0; + function increaseCount() { + count++; + counter.text(`${count} / 5`); + } + + await loadScript( + "https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ace.min.js", + "ace" + ); + increaseCount(); + await loadScript( + "https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ext-language_tools.js", + "ace_language_tools" + ); + increaseCount(); + // import * as prettier from "https://unpkg.com/prettier@3.2.4/standalone.mjs"; // import prettierPluginBabel from "https://unpkg.com/prettier@3.2.4/plugins/babel.mjs"; // import prettierPluginEsTree from "https://unpkg.com/prettier@3.2.4/plugins/estree.mjs"; @@ -146,12 +184,15 @@ export default { const prettier = await import( "https://unpkg.com/prettier@3.2.4/standalone.mjs" ); + increaseCount(); const prettierPluginBabel = ( await import("https://unpkg.com/prettier@3.2.4/plugins/babel.mjs") ).default; + increaseCount(); const prettierPluginEsTree = ( await import("https://unpkg.com/prettier@3.2.4/plugins/estree.mjs") ).default; + increaseCount(); console.log(prettier, prettierPluginBabel, prettierPluginEsTree); @@ -267,6 +308,23 @@ export default { }, prettify: async () => { try { + if ( + currentDocument.path.endsWith(".js") === false && + currentDocument.path.endsWith(".ts") === false && + currentDocument.path.endsWith(".app") === false && + currentDocument.path !== "" + ) { + modal( + new Html("div").appendMany( + new Html("span").html( + "You currently cannot format a file of this type. Use .js, .ts, or .app file extensions for formatting support." + ) + ), + true, + Root.Lib.getString("error") + ); + return; + } const formatted = await prettier.format(editor.getValue(), { parser: "babel", plugins: [prettierPluginBabel, prettierPluginEsTree], @@ -278,7 +336,7 @@ export default { } catch (e) { modal( new Html("div").appendMany( - new Html("span").text("Something went wrong when formatting"), + new Html("span").text("An error occurred while formatting:"), new Html("pre").text(e.message) ), true, @@ -606,7 +664,6 @@ export default { window.addEventListener("keydown", keyBindHandler); - wrapper = DvWindow.window.querySelector(".win-content"); wrapper.innerHTML = ""; wrapper.classList.add("col", "o-h", "h-100"); @@ -615,15 +672,33 @@ export default { dirty: false, }; - const updateTitle = (_) => - (DvWindow.window.querySelector(".win-titlebar .title").innerText = `${ + const updateTitle = (_) => { + // Display title + DvWindow.window.querySelector(".win-titlebar .title").innerText = `${ currentDocument.dirty === true ? "•" : "" } DevEnv - ${ currentDocument.path === "" ? "Untitled" : currentDocument.path.split("/").pop() - }`.trim()); + }`.trim(); + // Correct language mode + if (currentDocument.path === "") { + editor.session.setMode("ace/mode/typescript"); + } else { + const dots = currentDocument.path.split("."); + if (dots.length > 0) { + let currentFileExtension = dots.pop(); + if (currentFileExtension in appFileTypes) { + editor.session.setMode( + `ace/mode/${appFileTypes[currentFileExtension]}` + ); + } else { + editor.session.setMode("ace/mode/plain_text"); + } + } + } + }; function newDocument(path, content) { currentDocument.path = path; currentDocument.dirty = false; @@ -676,6 +751,16 @@ export default { const MenuBar = await Root.Lib.loadComponent("MenuBar"); + const appFileTypes = { + app: "typescript", + css: "css", + html: "html", + pml: "html", + xml: "xml", + js: "typescript", + }; + const defaultFileType = null; + // let extensionsList = []; function makeSidebar() { diff --git a/style.css b/style.css index df2fcc8..d814244 100644 --- a/style.css +++ b/style.css @@ -1405,7 +1405,7 @@ ul { } .ace-tm .ace_constant { - color: rgb(197, 6, 11); + color: rgb(6, 156, 197); } .ace-tm .ace_constant.ace_buildin { @@ -1466,6 +1466,10 @@ ul { color: rgb(128, 159, 191); } +.ace-tm .ace_tag { + color: rgb(128, 159, 191) !important; +} + .ace-tm .ace_constant.ace_numeric { color: #b5cea8; }