修复 monaco editor 加载

This commit is contained in:
purocean
2019-08-11 11:49:42 +08:00
parent f38e1e66a5
commit 2f6eb62c14
7 changed files with 40 additions and 35 deletions
+1 -1
View File
@@ -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",
+9
View File
@@ -4,6 +4,15 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Yank Note</title>
<script>
// 强制 monaco-editor 使用 浏览器模式
window.nodeRequire = window.require
window.nodeProcess = window.process
window.nodeModule = window.module
window.require = undefined
window.process = undefined
window.module = undefined
</script>
</head>
<body>
<div id="app"></div>
+8 -28
View File
@@ -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()
})
},
+2 -1
View File
@@ -6,8 +6,9 @@
<script>
import { mapState } from 'vuex'
import env from '@/lib/env'
const isElectron = !!(window && window.process && window.process.versions && window.process.versions['electron'])
const isElectron = env.isElectron
export default {
name: 'title-bar',
+12
View File
@@ -0,0 +1,12 @@
const nodeProcess = window && (window.process || window.nodeProcess)
const nodeModule = window && (window.module || window.nodeModule)
const nodeRequire = window && (window.require || window.nodeRequire)
const isElectron = !!(nodeProcess && nodeProcess.versions && nodeProcess.versions['electron'])
export default {
process: nodeProcess,
module: nodeModule,
require: nodeRequire,
isElectron
}
+4 -2
View File
@@ -1,4 +1,5 @@
import file from '@/lib/file'
import env from '@/lib/env'
const Plugin = md => {
const renderHtml = ({ file, content }) => {
@@ -119,15 +120,16 @@ const openInNewWindow = srcdoc => {
frame.frameBorder = '0'
frame.srcdoc = srcdoc
const isElectron = !!(window && window.process && window.process.versions && window.process.versions['electron'])
if (isElectron) {
if (env.isElectron) {
const json = JSON.stringify(frame.outerHTML)
opener.eval(`
document.title = '查看图形'
document.body.style.height = '100vh'
document.body.style.margin = '0'
document.body.innerHTML = ${json}
`)
} else {
opener.document.title = '查看图形'
opener.document.body.style.height = '100vh'
opener.document.body.style.margin = '0'
opener.document.body.appendChild(frame)
+4 -3
View File
@@ -4784,9 +4784,10 @@ mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@
dependencies:
minimist "0.0.8"
monaco-editor@^0.13.1:
version "0.13.1"
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.13.1.tgz#6b9ce20e4d1c945042d256825eb133cb23315a52"
monaco-editor@^0.17.1:
version "0.17.1"
resolved "https://registry.npm.taobao.org/monaco-editor/download/monaco-editor-0.17.1.tgz#8fbe96ca54bfa75262706e044f8f780e904aa45c"
integrity sha1-j76WylS/p1JicG4ET494DpBKpFw=
move-concurrently@^1.0.1:
version "1.0.1"