2020-12-01 16:27:19 +00:00
|
|
|
import { customElement, LitElement, property } from "lit-element";
|
2020-11-21 17:32:34 +00:00
|
|
|
|
|
|
|
import CodeMirror from "codemirror";
|
|
|
|
import "codemirror/addon/display/autorefresh";
|
|
|
|
import "codemirror/mode/xml/xml.js";
|
|
|
|
import "codemirror/mode/yaml/yaml.js";
|
2021-02-03 20:58:30 +00:00
|
|
|
import "codemirror/mode/javascript/javascript.js";
|
2020-11-21 17:32:34 +00:00
|
|
|
import "codemirror/mode/python/python.js";
|
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
@customElement("ak-codemirror")
|
2020-11-21 17:32:34 +00:00
|
|
|
export class CodeMirrorTextarea extends LitElement {
|
2020-12-02 14:44:40 +00:00
|
|
|
@property({type: Boolean})
|
2020-12-01 08:15:41 +00:00
|
|
|
readOnly = false;
|
2020-11-21 17:32:34 +00:00
|
|
|
|
|
|
|
@property()
|
2020-12-01 08:15:41 +00:00
|
|
|
mode = "yaml";
|
2020-11-21 17:32:34 +00:00
|
|
|
|
|
|
|
editor?: CodeMirror.EditorFromTextArea;
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
createRenderRoot() : ShadowRoot | Element {
|
2020-11-21 17:32:34 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
firstUpdated(): void {
|
2020-11-21 17:32:34 +00:00
|
|
|
const textarea = this.querySelector("textarea");
|
|
|
|
if (!textarea) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.editor = CodeMirror.fromTextArea(textarea, {
|
|
|
|
mode: this.mode,
|
2020-11-21 19:48:49 +00:00
|
|
|
theme: "monokai",
|
2020-11-21 17:32:34 +00:00
|
|
|
lineNumbers: false,
|
|
|
|
readOnly: this.readOnly,
|
|
|
|
autoRefresh: true,
|
|
|
|
});
|
2020-12-01 16:27:19 +00:00
|
|
|
this.editor.on("blur", () => {
|
2020-11-21 17:32:34 +00:00
|
|
|
this.editor?.save();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|