diff --git a/index.html b/index.html index 44abdc6..9e0e77e 100644 --- a/index.html +++ b/index.html @@ -13,6 +13,7 @@ + @@ -55,6 +56,10 @@
+ + + + Select Examples: @@ -62,6 +67,13 @@ + + + Select Themes: + + + +
@@ -71,7 +83,10 @@
+ +
@@ -86,6 +101,15 @@
+
+ + +
+
+ +
diff --git a/json/themes.json b/json/themes.json new file mode 100644 index 0000000..d4a4460 --- /dev/null +++ b/json/themes.json @@ -0,0 +1,41 @@ +[ + "ambiance", + "chaos", + "chrome", + "clouds", + "clouds_midnight", + "cobalt", + "crimson_editor", + "dawn", + "dracula", + "dreamweaver", + "eclipse", + "github", + "gob", + "gruvbox", + "idle_fingers", + "iplastic", + "katzenmilch", + "kr_theme", + "kuroir", + "merbivore", + "merbivore_soft", + "mono_industrial", + "monokai", + "nord_dark", + "one_dark", + "pastel_on_dark", + "solarized_dark", + "solarized_light", + "sqlserver", + "terminal", + "textmate", + "tomorrow", + "tomorrow_night", + "tomorrow_night_blue", + "tomorrow_night_bright", + "tomorrow_night_eighties", + "twilight", + "vibrant_ink", + "xcode" +] \ No newline at end of file diff --git a/package.json b/package.json index a96b38b..121cd02 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "Kanon", + "name": "kanon", "version": "1.0.0", "description": "A live programming environment specialized for data structure programming.", "main": "app.js", @@ -29,7 +29,9 @@ "esprima": "3.1.3", "jquery": "3.6.0", "jquery-ui-dist": "1.12.1", + "js-beautify": "^1.14.0", "split-pane": "0.5.1", + "uncaught": "0.0.5", "vis": "4.17.0" }, "devDependencies": { diff --git a/src/css/problem-pane.css b/src/css/problem-pane.css new file mode 100644 index 0000000..ee19790 --- /dev/null +++ b/src/css/problem-pane.css @@ -0,0 +1,47 @@ +#problem-ball { + position: absolute; + right: 20px; + bottom: 20px; + color:#ffffff; + background: #ff2424; + font-size:1.5em; + text-align: center; + z-index: 2; + width: 30px; + height: 30px; + border-radius: 15px; + line-height: 30px; + border: none; + /* outline: none; */ +} + +#probem-panel{ + background-color: white; + width: inherit; + height: inherit; + top:0; + left: 0; + right:0; + bottom: 0; + position: absolute; + height: auto; + overflow-y: scroll; +} + +#close-button{ + left: 0; + top: 0; + display: none; + border:none; + background-color: transparent; + color: grey; + margin-top: 20px; + margin-bottom: 20px; + font-size: 1rem; + text-decoration: underline; +} + +#all-errors{ + display: none; + color:black; +} \ No newline at end of file diff --git a/src/import.js b/src/import.js index af6cdfe..c644df7 100644 --- a/src/import.js +++ b/src/import.js @@ -2,11 +2,15 @@ document.write('') document.write(''); document.write(''); document.write(''); +document.write('') +document.write('') document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); +document.write(''); +document.write(''); document.write(''); document.write(''); document.write(''); @@ -30,3 +34,5 @@ document.write(''); document.write(''); document.write(''); +document.write(''); +document.write(''); diff --git a/src/js/beautifyenable.js b/src/js/beautifyenable.js new file mode 100644 index 0000000..8d2c641 --- /dev/null +++ b/src/js/beautifyenable.js @@ -0,0 +1,15 @@ +__$__.beautify = ace.require("ace/ext/beautify"); +__$__.js_beautify = require("js-beautify").js; + +__$__.beautifyEnable = function(){ + // __$__.beautify.beautify(__$__.editor.getSession()); + __$__.val = editor.session.getValue(); + + __$__.array = __$__.val.split(/\n/); + __$__.array[0] = __$__.array[0].trim(); + __$__.val = __$__.array.join("\n"); + + //Actual beautify (prettify) + __$__.val = __$__.js_beautify(__$__.val); + __$__.editor.getSession().setValue(__$__.val); +} \ No newline at end of file diff --git a/src/js/editor.js b/src/js/editor.js index 1a2be47..e74b6b4 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -1,7 +1,10 @@ __$__.langTools = ace.require('ace/ext/language_tools'); +__$__.themes = ace.require("ace/ext/themelist"); __$__.Range = ace.require('ace/range').Range; __$__.editor = ace.edit("editor"); __$__.editor.setOption('enableBasicAutocompletion', true); +__$__.editor.setOption('enableSnippets', true); +__$__.editor.setOption('enableLiveAutocompletion', false); __$__.startAutocomplete = __$__.editor.keyBinding.$handlers[0].commands.startAutocomplete.exec; try { @@ -14,6 +17,7 @@ try { __$__.editor.setValue(''); } + __$__.editor.getSession().setMode('ace/mode/javascript'); // __$__.editor.getSession().setUseWorker(false); diff --git a/src/js/loadThemes.js b/src/js/loadThemes.js new file mode 100644 index 0000000..cf4bc30 --- /dev/null +++ b/src/js/loadThemes.js @@ -0,0 +1,54 @@ +var kindvalue = 0; + +__$__.createSelectBoxTheme = function () { + // The list of themes files on the server is kept in .json format. + + const path_themes = 'json/themes.json' + + function jsonToArray(data) { + var arr = []; + for (var i = 0; i < data.length; i++) { + arr.push(data[i]); + } + return arr; + } + + // Delete all old elements in the select box + let parentElement = document.getElementById("selectTheme"); + while (parentElement.firstChild) { + parentElement.removeChild(parentElement.firstChild); + } + + // Insert new nodes to the select box + function makeNodes(arr) { + for (var i = 0; i < arr.length; i++) { + let op = document.createElement("option"); + op.value = arr[i]; + op.text = arr[i]; + parentElement.appendChild(op); + } + } + + function getJSONFrom(path, callback) { + jQuery.getJSON(path, function (data) { + callback(data); + }); + } + + getJSONFrom(path_themes, function (data) { + var arr = jsonToArray(data); + makeNodes(arr); + }); + +}; + +__$__.pasteTheme = function () { + let selectedElement = jQuery("#selectTheme").val(); + + if (selectedElement) { + __$__.editor.setTheme('ace/theme/'+selectedElement); + } + else { + alert("Select one of the theme."); + } +} \ No newline at end of file diff --git a/src/js/problem-pane.js b/src/js/problem-pane.js new file mode 100644 index 0000000..46931e1 --- /dev/null +++ b/src/js/problem-pane.js @@ -0,0 +1,57 @@ +var errors_list = ""; + +__$__.getErrors = async function(e) { + + await new Promise((resolve, reject) => setTimeout(resolve, 1000)); + + let annotations = await __$__.editor.getSession().getAnnotations(); + + document.getElementById("problem-ball").innerText = annotations.length; + + for(var i=0; i" + annotations[i].type.toUpperCase() + "
" + annotations[i].text + "
" + + `

"; + } + + document.getElementById("all-errors").innerHTML = errors_list; + + for(var i=0; i