Compare commits

..

No commits in common. '4f08777c0570f1cd5aab9255b8112b24b1b27009' and '3496d7b38d8bc3cc6be7b892e6a220a464c66e6b' have entirely different histories.

165
app.js

@ -8,11 +8,7 @@ import {
lineNumbers, highlightActiveLineGutter,
EditorView
} from '@codemirror/view'
import {
EditorState,
Compartment,
StateEffect
} from '@codemirror/state'
import {EditorState} from '@codemirror/state'
import {
defaultHighlightStyle,
syntaxHighlighting,
@ -37,55 +33,45 @@ 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
keymap, highlightSpecialChars,
drawSelection, highlightActiveLine, dropCursor,
rectangularSelection, crosshairCursor,
lineNumbers, highlightActiveLineGutter,
EditorView,
// @codemirror/state
EditorState,
Compartment,
StateEffect,
// @codemirror/language
defaultHighlightStyle,
syntaxHighlighting,
indentOnInput,
bracketMatching,
foldGutter,
foldKeymap,
// @codemirror/commands
defaultKeymap,
history,
historyKeymap,
// @codemirror/search
searchKeymap,
highlightSelectionMatches,
// @codemirror/autocomplete
autocompletion,
completionKeymap,
closeBrackets,
closeBracketsKeymap,
// @codemirror/lint
lintKeymap,
// @codemirror/lang-javascript
javascriptLanguage,
// @codemirror/lang-css
cssLanguage,
// @codemirror/lang-json
jsonLanguage,
// @codemirror/lang-html
htmlLanguage,
}` + "\n"
console.log('loading file')
const basicSetup = (() => [
lineNumbers(),
highlightActiveLineGutter(),
highlightSpecialChars(),
history(),
foldGutter(),
drawSelection(),
dropCursor(),
EditorState.allowMultipleSelections.of(true),
indentOnInput(),
syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
bracketMatching(),
closeBrackets(),
autocompletion(),
rectangularSelection(),
crosshairCursor(),
highlightActiveLine(),
highlightSelectionMatches(),
keymap.of([
...closeBracketsKeymap,
...defaultKeymap,
...searchKeymap,
...historyKeymap,
...foldKeymap,
...completionKeymap,
...lintKeymap
])
])()
window.editorLib = {
basicSetup,
EditorView
}`
class Builder {
// any URL that supports pkg/path o pkg@version/path
// any URL that supports pkg/path or pkg@version/path
baseUrl = 'https://unpkg.com'
scripts = {
'@rollup/browser': {
@ -103,9 +89,6 @@ class Builder {
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@codemirror/lang-html",
"@codemirror/lang-css",
"@codemirror/lang-json",
"@codemirror/lang-javascript",
]
@ -237,8 +220,6 @@ class Builder {
new TextEncoder().encode(this.code)
)
this.log(`built ${this.sha}`)
const raw = new TextEncoder().encode(this.code)
this.log(`${raw.byteLength} bytes`)
}
}
@ -303,38 +284,8 @@ class Editor extends HTMLElement {
}
connectedCallback() {
const cm = window.CodeMirrorBasic
const basicSetup = [
cm.lineNumbers(),
cm.highlightActiveLineGutter(),
cm.highlightSpecialChars(),
cm.history(),
cm.foldGutter(),
cm.drawSelection(),
cm.dropCursor(),
cm.EditorState.allowMultipleSelections.of(true),
cm.indentOnInput(),
cm.syntaxHighlighting(
cm.defaultHighlightStyle, {fallback: true}
),
cm.bracketMatching(),
cm.closeBrackets(),
cm.autocompletion(),
cm.rectangularSelection(),
cm.crosshairCursor(),
cm.highlightActiveLine(),
cm.highlightSelectionMatches(),
cm.keymap.of([
...cm.closeBracketsKeymap,
...cm.defaultKeymap,
...cm.searchKeymap,
...cm.historyKeymap,
...cm.foldKeymap,
...cm.completionKeymap,
...cm.lintKeymap
]),
]
this.view = new cm.EditorView({
const {EditorView, basicSetup} = window.editorLib
this.view = new EditorView({
doc: '',
extensions: [
basicSetup,
@ -367,26 +318,6 @@ 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)
@ -401,7 +332,6 @@ class App {
async run() {
await this.build()
await this.save()
await this.display()
}
@ -412,21 +342,8 @@ class App {
s.type = 'module'
s.textContent = this.builder.code
document.head.append(s)
} catch (e) {
this.buildView.log(`${e}`)
}
}
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}`)
}
this.buildView.log('skipped appending code')
//this.buildView.log(this.builder.code)
} catch (e) {
this.buildView.log(`${e}`)
}

File diff suppressed because one or more lines are too long

@ -1,12 +0,0 @@
<!doctype html>
<html>
<head>
<title>CodeMirror Build</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Security-Policy" content="default-src unpkg.com 'self' 'unsafe-inline' 'unsafe-eval'">
<link rel="stylesheet" href="/editor-lib-codemirror/style.css">
</head>
<body>
<script src="/editor-lib-codemirror/app.js"></script>
</body>
</html>
Loading…
Cancel
Save