diff --git a/src/panels/lovelace/components/hui-code-editor.ts b/src/panels/lovelace/components/hui-code-editor.ts
index 9a216931fb..ee0198965c 100644
--- a/src/panels/lovelace/components/hui-code-editor.ts
+++ b/src/panels/lovelace/components/hui-code-editor.ts
@@ -15,7 +15,7 @@ declare global {
}
export class HuiCodeEditor extends HTMLElement {
- public cm;
+ public codemirror;
private _value;
constructor() {
@@ -35,35 +35,34 @@ export class HuiCodeEditor extends HTMLElement {
}
set value(value: string) {
- console.log(value);
- if (this.cm) {
- if (value !== this.cm.getValue()) {
- this.cm.setValue(value);
+ if (this.codemirror) {
+ if (value !== this.codemirror.getValue()) {
+ this.codemirror.setValue(value);
}
}
this._value = value;
}
get value() {
- return this.cm.getValue();
+ return this.codemirror.getValue();
}
public connectedCallback() {
- if (!this.cm) {
- this.cm = CodeMirror(this.shadowRoot, {
+ if (!this.codemirror) {
+ this.codemirror = CodeMirror(this.shadowRoot, {
value: this._value,
lineNumbers: true,
mode: "yaml",
tabSize: 2,
});
- this.cm.on("changes", this._onChange);
+ this.codemirror.on("changes", this._onChange);
} else {
- this.cm.refresh();
+ this.codemirror.refresh();
}
}
private _onChange() {
- fireEvent(_this, "code-changed", { value: _this.cm.getValue() });
+ fireEvent(_this, "code-changed", { value: _this.codemirror.getValue() });
}
}
diff --git a/src/panels/lovelace/editor/card-editor/hui-edit-card.ts b/src/panels/lovelace/editor/card-editor/hui-edit-card.ts
index 4c974e7ecf..669d2e3e3d 100644
--- a/src/panels/lovelace/editor/card-editor/hui-edit-card.ts
+++ b/src/panels/lovelace/editor/card-editor/hui-edit-card.ts
@@ -23,7 +23,7 @@ import { HomeAssistant } from "../../../../types";
import { LovelaceCardConfig } from "../../../../data/lovelace";
import { fireEvent } from "../../../../common/dom/fire_event";
-import "./hui-yaml-editor";
+import "../../components/hui-code-editor";
import "./hui-card-preview";
// This is not a duplicate import, one is for types, one is for element.
// tslint:disable-next-line
@@ -36,9 +36,6 @@ import { addCard, replaceCard } from "../config-util";
declare global {
interface HASSDomEvents {
- "yaml-changed": {
- yaml: string;
- };
"entities-changed": {
entities: EntityConfig[];
};
@@ -118,11 +115,10 @@ export class HuiEditCard extends LitElement {
${this._uiEditor
? this._configElement
: html`
-
+
`}
`;
@@ -238,8 +234,8 @@ export class HuiEditCard extends LitElement {
}
}
- private _handleYamlChanged(ev: YamlChangedEvent): void {
- this._configValue = { format: "yaml", value: ev.detail.yaml };
+ private _handleYamlChanged(ev: CustomEvent): void {
+ this._configValue = { format: "yaml", value: ev.detail.value };
try {
const config = yaml.safeLoad(
this._configValue.value
diff --git a/src/panels/lovelace/editor/card-editor/hui-yaml-editor.ts b/src/panels/lovelace/editor/card-editor/hui-yaml-editor.ts
deleted file mode 100644
index 2b04168c5b..0000000000
--- a/src/panels/lovelace/editor/card-editor/hui-yaml-editor.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import {
- html,
- LitElement,
- PropertyDeclarations,
- TemplateResult,
-} from "lit-element";
-import "@polymer/paper-input/paper-textarea";
-
-import { HomeAssistant } from "../../../../types";
-import { fireEvent } from "../../../../common/dom/fire_event";
-
-import "../../components/hui-code-editor";
-
-export class HuiYAMLEditor extends LitElement {
- protected hass?: HomeAssistant;
- private _yaml?: string;
-
- static get properties(): PropertyDeclarations {
- return { _yaml: {} };
- }
-
- set yaml(yaml: string) {
- if (yaml === undefined) {
- return;
- } else {
- this._yaml = yaml;
- }
- }
-
- protected render(): TemplateResult | void {
- return html`
- ${this.renderStyle()}
-
-
- `;
- }
-
- private renderStyle(): TemplateResult {
- return html`
-
- `;
- }
-
- private _valueChanged(ev: CustomEvent): void {
- fireEvent(this, "yaml-changed", {
- yaml: ev.detail.value,
- });
- }
-}
-
-declare global {
- interface HTMLElementTagNameMap {
- "hui-yaml-editor": HuiYAMLEditor;
- }
-}
-
-customElements.define("hui-yaml-editor", HuiYAMLEditor);