Rename CodeJarEditor to CodeEditor.
This commit is contained in:
parent
a776930590
commit
b4ba1bc63a
|
@ -2,23 +2,23 @@ import { Component, JSX, createRef } from "preact";
|
||||||
import { CodeJar as _CodeJar } from "codejar";
|
import { CodeJar as _CodeJar } from "codejar";
|
||||||
import { highlightElement } from "prismjs";
|
import { highlightElement } from "prismjs";
|
||||||
|
|
||||||
interface CodeJarProps {
|
interface CodeEditorProps {
|
||||||
language: string;
|
language: string;
|
||||||
tabSize: number;
|
tabSize: number;
|
||||||
code: string;
|
code: string;
|
||||||
onUpdate: (code: string) => void;
|
onUpdate: (code: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CodeJarEditor extends Component<CodeJarProps, unknown> {
|
export class CodeEditor extends Component<CodeEditorProps, unknown> {
|
||||||
editorRef = createRef<HTMLDivElement>();
|
editorRef = createRef<HTMLDivElement>();
|
||||||
jar = createRef<_CodeJar | null>();
|
jar = createRef<_CodeJar | null>();
|
||||||
|
|
||||||
highlighter(e: HTMLElement, pos?: unknown): void {
|
highlighter(e: HTMLElement): void {
|
||||||
highlightElement(e);
|
highlightElement(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
this.jar.current = _CodeJar(this.editorRef.current, this.highlighter, {
|
this.jar.current = _CodeJar(this.editorRef.current, (e) => this.highlighter(e), {
|
||||||
tab: " ".repeat(this.props.tabSize),
|
tab: " ".repeat(this.props.tabSize),
|
||||||
window: window,
|
window: window,
|
||||||
});
|
});
|
||||||
|
@ -36,7 +36,7 @@ export class CodeJarEditor extends Component<CodeJarProps, unknown> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: CodeJarProps): void {
|
componentDidUpdate(prevProps: CodeEditorProps): void {
|
||||||
if (!this.jar.current) return;
|
if (!this.jar.current) return;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -49,6 +49,8 @@ export class CodeJarEditor extends Component<CodeJarProps, unknown> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
return <div class={"editor language-" + this.props.language} ref={this.editorRef} />;
|
return (
|
||||||
|
<div class={"editor line-numbers language-" + this.props.language} ref={this.editorRef} />
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import { CodeJarEditor } from "../../../elements/CodeJar/CodeJarEditor";
|
import { CodeEditor } from "../../../elements/CodeEditor";
|
||||||
import { Component, JSX, render } from "preact";
|
import { Component, JSX, render } from "preact";
|
||||||
import { Page } from "../../../types/Page";
|
import { Page } from "../../../types/Page";
|
||||||
import { SecretTitleElement } from "../SecretTitleElement";
|
import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
|
@ -90,7 +90,7 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p class="uk-text-danger" id="errorText" />
|
<p class="uk-text-danger" id="errorText" />
|
||||||
<CodeJarEditor
|
<CodeEditor
|
||||||
language="json"
|
language="json"
|
||||||
tabSize={4}
|
tabSize={4}
|
||||||
code={this.getStringKVData(this.state.kvData)}
|
code={this.getStringKVData(this.state.kvData)}
|
||||||
|
|
Loading…
Reference in a new issue