This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/elements/CodeMirror.ts

41 lines
1005 B
TypeScript
Raw Normal View History

2020-11-21 17:32:34 +00:00
import { customElement, html, LitElement, property } from "lit-element";
// @ts-ignore
import CodeMirror from "codemirror";
import "codemirror/addon/display/autorefresh";
import "codemirror/mode/xml/xml.js";
import "codemirror/mode/yaml/yaml.js";
import "codemirror/mode/python/python.js";
@customElement("pb-codemirror")
export class CodeMirrorTextarea extends LitElement {
@property()
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;
createRenderRoot() {
return this;
}
firstUpdated() {
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,
});
this.editor.on("blur", (e) => {
this.editor?.save();
});
}
}