remove codemirror-element
It's now a separate project
This commit is contained in:
parent
792af96170
commit
8800b4b11c
3 changed files with 0 additions and 106 deletions
|
@ -1,13 +0,0 @@
|
|||
NODE_BIN=node_modules/.bin
|
||||
|
||||
DEST=../thinks/static/thinks
|
||||
|
||||
$(DEST)/code-editor.mjs: code-editor.bundle.mjs
|
||||
cp $< $@
|
||||
|
||||
code-editor.terser.mjs: code-editor.bundle.mjs
|
||||
$(NODE_BIN)/terser --compress --mangle -- $< > $@
|
||||
|
||||
code-editor.bundle.mjs: code-editor.mjs
|
||||
$(NODE_BIN)/rollup $< -f es -p @rollup/plugin-node-resolve -o $@
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
import {basicSetup} from "codemirror";
|
||||
import {EditorView, keymap} from "@codemirror/view";
|
||||
import {EditorState} from "@codemirror/state";
|
||||
import {python} from "@codemirror/lang-python";
|
||||
import {r} from "codemirror-lang-r";
|
||||
import {vim} from "@replit/codemirror-vim";
|
||||
import {indentWithTab} from "@codemirror/commands";
|
||||
|
||||
window.EditorView = EditorView;
|
||||
|
||||
const languages = {
|
||||
'python': python,
|
||||
'r': r
|
||||
}
|
||||
|
||||
export function codemirror_editor(language, options) {
|
||||
const language_plugin = languages[language];
|
||||
|
||||
options = Object.assign({
|
||||
extensions: [
|
||||
vim(),
|
||||
basicSetup,
|
||||
keymap.of([indentWithTab]),
|
||||
EditorView.updateListener.of(update => {
|
||||
if(!options?.onChange || update.changes.desc.empty) {
|
||||
return;
|
||||
}
|
||||
options.onChange(update);
|
||||
})
|
||||
]
|
||||
}, options);
|
||||
|
||||
let editor = new EditorView(options);
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
export class CodeEditorElement extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.language = this.getAttribute('language') || '';
|
||||
const shadowRoot = this.attachShadow({mode: 'open'});
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.init_editor();
|
||||
}
|
||||
|
||||
init_editor() {
|
||||
const code = this.textContent;
|
||||
const code_tag = this.shadowRoot;
|
||||
|
||||
this.codeMirror = codemirror_editor(
|
||||
this.language,
|
||||
{
|
||||
doc: code,
|
||||
parent: code_tag,
|
||||
root: this.shadowRoot,
|
||||
onChange: update => this.onChange(update)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onChange() {
|
||||
const code = this.codeMirror.state.doc.toString();
|
||||
this.value = code;
|
||||
this.dispatchEvent(new CustomEvent('change'));
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("code-editor", CodeEditorElement);
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"name": "codemirror-element",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@codemirror/lang-python": "^6.1.2",
|
||||
"@replit/codemirror-vim": "^6.2.0",
|
||||
"@rollup/plugin-node-resolve": "^15.0.2",
|
||||
"codemirror": "^6.0.1",
|
||||
"codemirror-lang-r": "^0.1.0-2",
|
||||
"rollup": "^3.20.6",
|
||||
"terser": "^5.17.1"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue