From 2f6eb62c14bd9240be688b7ddb2cbdd06be91d45 Mon Sep 17 00:00:00 2001 From: purocean Date: Sun, 11 Aug 2019 11:49:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20monaco=20editor=20?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 2 +- frontend/public/index.html | 9 ++++++ frontend/src/components/MonacoEditor.vue | 36 ++++++------------------ frontend/src/components/TitleBar.vue | 3 +- frontend/src/lib/env.js | 12 ++++++++ frontend/src/plugins/DrawioPlugin.js | 6 ++-- frontend/yarn.lock | 7 +++-- 7 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 frontend/src/lib/env.js diff --git a/frontend/package.json b/frontend/package.json index 4025b0e0..84f83d85 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,7 +24,7 @@ "markdown-it-multimd-table": "^3.1.3", "markdown-it-task-lists": "^2.1.1", "mime-types": "^2.1.24", - "monaco-editor": "^0.13.1", + "monaco-editor": "^0.17.1", "normalize.css": "^8.0.1", "socket.io-client": "^2.2.0", "transliteration": "^2.1.3", diff --git a/frontend/public/index.html b/frontend/public/index.html index 752ef369..86dff2a2 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -4,6 +4,15 @@ Yank Note +
diff --git a/frontend/src/components/MonacoEditor.vue b/frontend/src/components/MonacoEditor.vue index ba2ad82d..d872db94 100644 --- a/frontend/src/components/MonacoEditor.vue +++ b/frontend/src/components/MonacoEditor.vue @@ -6,9 +6,6 @@ import dayjs from 'dayjs' import TurndownService from 'turndown' -const isElectron = !!(window && window.process && window.process.versions && window.process.versions['electron']) -const appPath = isElectron && window.require('electron').remote.app.getAppPath().replace(/dist$/, '') -const pathModule = isElectron && window.require('path') const keys = {} export default { @@ -22,20 +19,14 @@ export default { } }, mounted () { - if (isElectron && !window.amdRequire) { - const amdLoader = window.require(pathModule.resolve(appPath, 'dist/static/vs/loader.js')) - window.amdRequire = amdLoader.require - this.onGotAmdLoader() + if (!window.require) { + const loaderScript = document.createElement('script') + loaderScript.type = 'text/javascript' + loaderScript.src = 'vs/loader.js' + loaderScript.addEventListener('load', this.onGotAmdLoader) + document.body.appendChild(loaderScript) } else { - if (!window.require) { - const loaderScript = document.createElement('script') - loaderScript.type = 'text/javascript' - loaderScript.src = 'vs/loader.js' - loaderScript.addEventListener('load', this.onGotAmdLoader) - document.body.appendChild(loaderScript) - } else { - this.onGotAmdLoader() - } + this.onGotAmdLoader() } window.addEventListener('keydown', this.recordKeys, true) @@ -60,18 +51,7 @@ export default { } }, onGotAmdLoader () { - const xrequire = isElectron ? window.amdRequire : window.require - if (isElectron) { - const uriFromPath = path => { - let pathName = pathModule.resolve(path).replace(/\\/g, '/') - if (pathName.length > 0 && pathName.charAt(0) !== '/') { - pathName = '/' + pathName - } - return encodeURI('file://' + pathName) - } - xrequire.config({ baseUrl: uriFromPath(pathModule.join(appPath, 'dist/static')) }) - } - xrequire(['vs/editor/editor.main'], () => { + window.require(['vs/editor/editor.main'], () => { this.initMonaco() }) }, diff --git a/frontend/src/components/TitleBar.vue b/frontend/src/components/TitleBar.vue index 80001d88..8ea7bd80 100644 --- a/frontend/src/components/TitleBar.vue +++ b/frontend/src/components/TitleBar.vue @@ -6,8 +6,9 @@