From b53d9e8a4e8b747b4bf4656b3c364b8bc2328a7b Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Fri, 8 May 2020 18:42:17 +0800 Subject: [PATCH] remove: plugins public file --- packages/plugins/public/index.html | 78 ------------------------- packages/plugins/public/js/editor.js | 69 ---------------------- packages/plugins/public/js/main.js | 55 ----------------- packages/plugins/public/js/message.js | 10 ---- packages/plugins/public/js/term.js | 54 ----------------- packages/plugins/public/js/websocket.js | 30 ---------- 6 files changed, 296 deletions(-) delete mode 100644 packages/plugins/public/index.html delete mode 100644 packages/plugins/public/js/editor.js delete mode 100644 packages/plugins/public/js/main.js delete mode 100644 packages/plugins/public/js/message.js delete mode 100644 packages/plugins/public/js/term.js delete mode 100644 packages/plugins/public/js/websocket.js diff --git a/packages/plugins/public/index.html b/packages/plugins/public/index.html deleted file mode 100644 index ca298ae3..00000000 --- a/packages/plugins/public/index.html +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - MiaoConsole 调试工具 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

欢迎使用 MiaoConsole 调试控制台

-
- 服务器地址 - - 连接 -
-
-
服务器日志 当前服务器类型: {{@type}}
-
-
-
-
- 正在加载 {{@type}} 类型定义 {{@classes.loaded}}/{{@classes.total}}({{~~(@classes.loaded/@classes.total*100)|percent}}%) -
-
-
-
代码编辑器
- - -
-
-
- - - \ No newline at end of file diff --git a/packages/plugins/public/js/editor.js b/packages/plugins/public/js/editor.js deleted file mode 100644 index b50a29ce..00000000 --- a/packages/plugins/public/js/editor.js +++ /dev/null @@ -1,69 +0,0 @@ -let editor -let monaco_path = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.18.1/min' -require.config({ paths: { 'vs': monaco_path + '/vs' } }); -window.MonacoEnvironment = { getWorkerUrl: () => proxy }; -let proxy = URL.createObjectURL(new Blob([`self.MonacoEnvironment = {baseUrl: '${monaco_path}/'}; -importScripts('${monaco_path}/vs/base/worker/workerMain.js');`], { type: 'text/javascript' })); - -function loadExtraLibs(ts_d_src, filter) { - let count = 0; - axios.get(`${ts_d_src}/index.d.ts`).then(async result => { - monaco.languages.typescript.javascriptDefaults.addExtraLib(result.data, 'file:///src/typings/index.d.ts') - let classes = result.data.split('\n').map(line => line.match(/.*\.\/(.*)".*/)).filter(line => line).map(dts => dts[1]) - if (filter) { - classes = classes.filter(line => filter(line)) - } - main.classes.total += classes.length - for (let fname of classes) { - if (count++ % 50 == 0) { await axios.get(`${ts_d_src}/${fname}`) } - loadExtraLib(`${ts_d_src}/${fname}`, `file:///src/typings/${fname}`) - } - }) -} - -function loadExtraLib(url, file) { - axios.get(url).then(result => monaco.languages.typescript.javascriptDefaults.addExtraLib(result.data, file)).finally(() => main.classes.loaded++) -} - -require(["vs/editor/editor.main"], async function() { - main.classes.total = 0 - main.classes.loaded = 0 - editor = monaco.editor.create(document.getElementById('editor'), { - value: '', - language: 'javascript', - automaticLayout: true, - scrollBeyondLastLine: false, - theme: 'vs-dark' - }); - main.load(editor) - editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function() { - main.save(editor) - }) - editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_R, function() { - main.send('execCode', getSelectContent(editor) || editor.getValue()) - }) - editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_E, function() { - main.send('execCommand', getSelectContent(editor)) - }) - editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_Q, function() { - main.switch(editor) - }) - loadExtraLibs(`https://cdn.jsdelivr.net/gh/circlecloud/ms@master/packages/types/dist/typings/jdk`, (line) => line.startsWith('java.lang')) - if (main.type !== 'unknow') { - loadExtraLibs(`https://cdn.jsdelivr.net/gh/circlecloud/ms@master/packages/types/dist/typings/${main.type}`) - } -}); -function getSelectContent(editor) { - let selInfo = editor.getSelection(); - if (selInfo.startLineNumber === selInfo.endLineNumber) { - return editor.getModel().getLineContent(selInfo.startLineNumber).substr(selInfo.startColumn - 1, selInfo.endColumn - selInfo.startColumn); - } else { - let first = editor.getModel().getLineContent(selInfo.startLineNumber).substr(selInfo.startColumn - 1) - let content = '\n' - for (let i = selInfo.startLineNumber + 1; i < selInfo.endLineNumber; i++) { - content += editor.getModel().getLineContent(i) + '\n' - } - let last = editor.getModel().getLineContent(selInfo.endLineNumber).substr(0, selInfo.endColumn - 1) - return first + content + last - } -} \ No newline at end of file diff --git a/packages/plugins/public/js/main.js b/packages/plugins/public/js/main.js deleted file mode 100644 index 3fce69e6..00000000 --- a/packages/plugins/public/js/main.js +++ /dev/null @@ -1,55 +0,0 @@ -var SPLIT_LINE = '\\M\\W\\S|T|S|S/L/T/' -let serverKey = 'MiaoScript:server' -let codeStorageKey = "MiaoScript:code:" -var main = avalon.define({ - $id: 'main', - server: window.localStorage.getItem(serverKey) || location.host, - type: 'unknow', - logs: '', - codes: ["default", "bukkit", "sponge", "bungee", "common", "test", "dev", "1", "2", "3", "4", "5", "6", "7", "8", "9"], - code: 'default', - classes: { - total: 0, - loaded: 0, - }, - precent: () => { - return classes.total - }, - log: (info) => { - info.split("\n").forEach((line) => { term.writeln(mcColor2ANSI(line + '§r')) }) - }, - send: (type, content) => { - if (!ws || ws.readyState != 1) { term.writeln('Please Connect to Server first!'); return; } - ws.send(`${type}${SPLIT_LINE}${content}`); - }, - connect: (event = { key: 'Enter' }) => { - if (event.key !== "Enter") { - return; - } - connectWebSocket() - }, - init: () => { - if (main.server) { - main.connect() - } - }, - load: (editor) => { - editor.setValue(window.localStorage.getItem(codeStorageKey + main.code) || '') - }, - save: (editor) => { - window.localStorage.setItem(codeStorageKey + main.code, editor.getValue()) - showMessenger('代码页 ' + main.code + ' 保存成功!') - }, - switch: (editor) => { - let index = main.codes.indexOf(main.code) + 1 - main.code = main.codes[index == main.codes.length ? 0 : index] - } -}); - -main.$watch('code', (now, old, name) => { - window.localStorage.setItem(codeStorageKey + old, editor.getValue()) - showMessenger('代码页 ' + old + ' 保存成功!') - editor.setValue(window.localStorage.getItem(codeStorageKey + now) || '// empty code page ' + now) -}) - -main.init() diff --git a/packages/plugins/public/js/message.js b/packages/plugins/public/js/message.js deleted file mode 100644 index 194d79f6..00000000 --- a/packages/plugins/public/js/message.js +++ /dev/null @@ -1,10 +0,0 @@ -$._messengerDefaults = { - extraClasses: 'messenger-fixed messenger-theme-future messenger-on-top messenger-on-right' -}; -var showMessenger = function(message, type) { - return Messenger().post({ - message: message, - type: type || 'info', - showClo6seButton: true - }); -}; diff --git a/packages/plugins/public/js/term.js b/packages/plugins/public/js/term.js deleted file mode 100644 index 03ca8014..00000000 --- a/packages/plugins/public/js/term.js +++ /dev/null @@ -1,54 +0,0 @@ -Terminal.applyAddon(fit); -var term = new Terminal(); -avalon.ready(() => { - term.open(document.getElementById('terminal')); - window.onresize = () => { - term.fit(); - } - window.onresize() -}) -term.on('data', (data) => { - if (data == '\r') { - term.writeln(data) - } -}); -term.attachCustomKeyEventHandler(e => { - if (e.ctrlKey && e.key == 'c' && term.hasSelection()) { - showMessenger('内容已复制到粘贴板') - return false; - } - if (e.ctrlKey && e.key == 'v') { - return false; - } - return true; -}) -var colorMap = [] -colorMap['0'] = '38;5;0' -colorMap['1'] = '38;5;4' -colorMap['2'] = '38;5;2' -colorMap['3'] = '38;5;6' -colorMap['4'] = '38;5;1' -colorMap['5'] = '38;5;5' -colorMap['6'] = '38;5;3' -colorMap['7'] = '38;5;7' -colorMap['8'] = '38;5;8' -colorMap['9'] = '38;5;12' -colorMap['a'] = '38;5;10' -colorMap['b'] = '38;5;14' -colorMap['c'] = '38;5;9' -colorMap['d'] = '38;5;13' -colorMap['e'] = '38;5;11' -colorMap['f'] = '38;5;15' -colorMap['r'] = '0' -colorMap['l'] = '1' -colorMap['n'] = '4' -var regexMap = [] -for (const c in colorMap) { - regexMap[colorMap[c]] = new RegExp(`§${c}`, "g") -} -function mcColor2ANSI(str) { - for (const regex in regexMap) { - str = str.replace(regexMap[regex], `\u001b[${regex}m`) - } - return str; -} \ No newline at end of file diff --git a/packages/plugins/public/js/websocket.js b/packages/plugins/public/js/websocket.js deleted file mode 100644 index 95d1f2da..00000000 --- a/packages/plugins/public/js/websocket.js +++ /dev/null @@ -1,30 +0,0 @@ -var ws; -function connectWebSocket() { - if (ws && ws.readyState == 1) { - ws.close() - } - window.localStorage.setItem(serverKey, main.server) - ws = new WebSocket(`${location.protocol == 'http:' ? 'ws' : 'wss'}://${main.server}/ws`) - ws.onmessage = (event) => { - const [type, obj] = event.data.split(SPLIT_LINE) - switch (type) { - case "log": - main.log(obj) - break; - case "type": - main.type = obj; - break; - } - } - ws.onopen = () => { - main.send("execDetect", "type"); - } - ws.onclose = (ev) => { - main.log(`Remote Server Close Connection... ${ev.code}`) - if (ev.code == 1006) { - setTimeout(() => { - main.connect() - }, 1000) - } - } -}