|
|
@ -34,44 +34,40 @@ import { |
|
|
} from '@codemirror/autocomplete' |
|
|
} from '@codemirror/autocomplete' |
|
|
import {lintKeymap} from '@codemirror/lint' |
|
|
import {lintKeymap} from '@codemirror/lint' |
|
|
|
|
|
|
|
|
console.log('loading file') |
|
|
window.CodeMirrorBasic = { |
|
|
|
|
|
// @codemirror/view
|
|
|
const basicSetup = (() => [ |
|
|
keymap, highlightSpecialChars, |
|
|
lineNumbers(), |
|
|
drawSelection, highlightActiveLine, dropCursor, |
|
|
highlightActiveLineGutter(), |
|
|
rectangularSelection, crosshairCursor, |
|
|
highlightSpecialChars(), |
|
|
lineNumbers, highlightActiveLineGutter, |
|
|
history(), |
|
|
EditorView, |
|
|
foldGutter(), |
|
|
// @codemirror/state
|
|
|
drawSelection(), |
|
|
EditorState, |
|
|
dropCursor(), |
|
|
// @codemirror/language
|
|
|
EditorState.allowMultipleSelections.of(true), |
|
|
defaultHighlightStyle, |
|
|
indentOnInput(), |
|
|
syntaxHighlighting, |
|
|
syntaxHighlighting(defaultHighlightStyle, {fallback: true}), |
|
|
indentOnInput, |
|
|
bracketMatching(), |
|
|
bracketMatching, |
|
|
closeBrackets(), |
|
|
foldGutter, |
|
|
autocompletion(), |
|
|
foldKeymap, |
|
|
rectangularSelection(), |
|
|
// @codemirror/commands
|
|
|
crosshairCursor(), |
|
|
defaultKeymap, |
|
|
highlightActiveLine(), |
|
|
history, |
|
|
highlightSelectionMatches(), |
|
|
historyKeymap, |
|
|
keymap.of([ |
|
|
// @codemirror/search
|
|
|
...closeBracketsKeymap, |
|
|
searchKeymap, |
|
|
...defaultKeymap, |
|
|
highlightSelectionMatches, |
|
|
...searchKeymap, |
|
|
// @codemirror/autocomplete
|
|
|
...historyKeymap, |
|
|
autocompletion, |
|
|
...foldKeymap, |
|
|
completionKeymap, |
|
|
...completionKeymap, |
|
|
closeBrackets, |
|
|
...lintKeymap |
|
|
closeBracketsKeymap, |
|
|
]) |
|
|
// @codemirror/lint
|
|
|
])() |
|
|
lintKeymap, |
|
|
|
|
|
}` + "\n"
|
|
|
window.editorLib = { |
|
|
|
|
|
basicSetup, |
|
|
|
|
|
EditorView |
|
|
|
|
|
}` |
|
|
|
|
|
|
|
|
|
|
|
class Builder { |
|
|
class Builder { |
|
|
// any URL that supports pkg/path or pkg@version/path
|
|
|
// any URL that supports pkg/path o pkg@version/path
|
|
|
baseUrl = 'https://unpkg.com' |
|
|
baseUrl = 'https://unpkg.com' |
|
|
scripts = { |
|
|
scripts = { |
|
|
'@rollup/browser': { |
|
|
'@rollup/browser': { |
|
|
@ -89,7 +85,6 @@ class Builder { |
|
|
"@codemirror/search", |
|
|
"@codemirror/search", |
|
|
"@codemirror/state", |
|
|
"@codemirror/state", |
|
|
"@codemirror/view", |
|
|
"@codemirror/view", |
|
|
"@codemirror/lang-javascript", |
|
|
|
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
constructor() { |
|
|
constructor() { |
|
|
@ -220,6 +215,8 @@ class Builder { |
|
|
new TextEncoder().encode(this.code) |
|
|
new TextEncoder().encode(this.code) |
|
|
) |
|
|
) |
|
|
this.log(`built ${this.sha}`) |
|
|
this.log(`built ${this.sha}`) |
|
|
|
|
|
const raw = new TextEncoder().encode(this.code) |
|
|
|
|
|
this.log(`${raw.byteLength} bytes`) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -284,8 +281,38 @@ class Editor extends HTMLElement { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
connectedCallback() { |
|
|
connectedCallback() { |
|
|
const {EditorView, basicSetup} = window.editorLib |
|
|
const cm = window.CodeMirrorBasic |
|
|
this.view = new EditorView({ |
|
|
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({ |
|
|
doc: '', |
|
|
doc: '', |
|
|
extensions: [ |
|
|
extensions: [ |
|
|
basicSetup, |
|
|
basicSetup, |
|
|
@ -342,8 +369,6 @@ class App { |
|
|
s.type = 'module' |
|
|
s.type = 'module' |
|
|
s.textContent = this.builder.code |
|
|
s.textContent = this.builder.code |
|
|
document.head.append(s) |
|
|
document.head.append(s) |
|
|
this.buildView.log('skipped appending code') |
|
|
|
|
|
//this.buildView.log(this.builder.code)
|
|
|
|
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
this.buildView.log(`${e}`) |
|
|
this.buildView.log(`${e}`) |
|
|
} |
|
|
} |
|
|
|