|
|
|
|
@ -33,6 +33,10 @@ import {
|
|
|
|
|
closeBracketsKeymap
|
|
|
|
|
} from '@codemirror/autocomplete'
|
|
|
|
|
import {lintKeymap} from '@codemirror/lint'
|
|
|
|
|
import { javascriptLanguage } from '@codemirror/lang-javascript'
|
|
|
|
|
import { cssLanguage } from '@codemirror/lang-css'
|
|
|
|
|
import { jsonLanguage } from '@codemirror/lang-json'
|
|
|
|
|
import { htmlLanguage } from '@codemirror/lang-html'
|
|
|
|
|
|
|
|
|
|
window.CodeMirrorBasic = {
|
|
|
|
|
// @codemirror/view
|
|
|
|
|
@ -64,6 +68,14 @@ window.CodeMirrorBasic = {
|
|
|
|
|
closeBracketsKeymap,
|
|
|
|
|
// @codemirror/lint
|
|
|
|
|
lintKeymap,
|
|
|
|
|
// @codemirror/lang-javascript
|
|
|
|
|
javascriptLanguage,
|
|
|
|
|
// @codemirror/lang-css
|
|
|
|
|
cssLanguage,
|
|
|
|
|
// @codemirror/lang-json
|
|
|
|
|
jsonLanguage,
|
|
|
|
|
// @codemirror/lang-html
|
|
|
|
|
htmlLanguage,
|
|
|
|
|
}` + "\n"
|
|
|
|
|
|
|
|
|
|
class Builder {
|
|
|
|
|
@ -85,6 +97,10 @@ class Builder {
|
|
|
|
|
"@codemirror/search",
|
|
|
|
|
"@codemirror/state",
|
|
|
|
|
"@codemirror/view",
|
|
|
|
|
"@codemirror/lang-html",
|
|
|
|
|
"@codemirror/lang-css",
|
|
|
|
|
"@codemirror/lang-json",
|
|
|
|
|
"@codemirror/lang-javascript",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
@ -345,6 +361,26 @@ class Editor extends HTMLElement {
|
|
|
|
|
`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function req(method, path, value = undefined) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const ch = new MessageChannel()
|
|
|
|
|
const port = ch.port1
|
|
|
|
|
port.onmessage = e => {
|
|
|
|
|
resolve(e.data)
|
|
|
|
|
port.close()
|
|
|
|
|
}
|
|
|
|
|
window.parent.postMessage(
|
|
|
|
|
(
|
|
|
|
|
method === 'get' ?
|
|
|
|
|
[method, path] :
|
|
|
|
|
[method, path, value]
|
|
|
|
|
),
|
|
|
|
|
'*',
|
|
|
|
|
[ch.port2]
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customElements.define('m-build-view', BuildView)
|
|
|
|
|
customElements.define('m-editor', Editor)
|
|
|
|
|
|
|
|
|
|
@ -359,6 +395,7 @@ class App {
|
|
|
|
|
|
|
|
|
|
async run() {
|
|
|
|
|
await this.build()
|
|
|
|
|
await this.save()
|
|
|
|
|
await this.display()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -374,6 +411,21 @@ class App {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async save() {
|
|
|
|
|
try {
|
|
|
|
|
const resp = await req(
|
|
|
|
|
'put',
|
|
|
|
|
'/editor-lib-codemirror/codemirror-bundle.js',
|
|
|
|
|
this.builder.code
|
|
|
|
|
)
|
|
|
|
|
if (resp.status !== 200) {
|
|
|
|
|
throw new Error(`save attempt returned ${resp.status}`)
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this.buildView.log(`${e}`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async display() {
|
|
|
|
|
await new Promise(r => setTimeout(() => r(), 500))
|
|
|
|
|
this.editor = document.createElement('m-editor')
|
|
|
|
|
|