diff --git a/src/panels/lovelace/editor/card-editor/hui-card-editor.ts b/src/panels/lovelace/editor/card-editor/hui-card-editor.ts
index 8738df3943..90043f69e8 100644
--- a/src/panels/lovelace/editor/card-editor/hui-card-editor.ts
+++ b/src/panels/lovelace/editor/card-editor/hui-card-editor.ts
@@ -23,6 +23,7 @@ import { HaCodeEditor } from "../../../../components/ha-code-editor";
import { fireEvent } from "../../../../common/dom/fire_event";
import { EntityConfig } from "../../entity-rows/types";
import { getCardElementClass } from "../../create-element/create-card-element";
+import { GUIModeChangedEvent } from "../types";
declare global {
interface HASSDomEvents {
@@ -33,6 +34,7 @@ declare global {
config: LovelaceCardConfig;
error?: string;
};
+ "GUImode-changed": GUIModeChangedEvent;
}
}
@@ -85,16 +87,29 @@ export class HuiCardEditor extends LitElement {
}
}
+ public get hasWarning(): boolean {
+ return this._warning !== undefined;
+ }
+
public get hasError(): boolean {
return this._error !== undefined;
}
+ public get GUImode(): boolean {
+ return this._GUImode;
+ }
+
+ public set GUImode(guiMode: boolean) {
+ this._GUImode = guiMode;
+ fireEvent(this as HTMLElement, "GUImode-changed", { guiMode });
+ }
+
private get _yamlEditor(): HaCodeEditor {
return this.shadowRoot!.querySelector("ha-code-editor")! as HaCodeEditor;
}
public toggleMode() {
- this._GUImode = !this._GUImode;
+ this.GUImode = !this.GUImode;
}
public connectedCallback() {
@@ -105,7 +120,7 @@ export class HuiCardEditor extends LitElement {
protected render(): TemplateResult {
return html`
- ${this._GUImode
+ ${this.GUImode
? html`
${this._loading
@@ -145,18 +160,6 @@ export class HuiCardEditor extends LitElement {
`
: ""}
-
-
- ${this.hass!.localize(
- this._GUImode
- ? "ui.panel.lovelace.editor.edit_card.show_code_editor"
- : "ui.panel.lovelace.editor.edit_card.show_visual_editor"
- )}
-
-
`;
}
@@ -165,7 +168,7 @@ export class HuiCardEditor extends LitElement {
super.updated(changedProperties);
if (changedProperties.has("_GUImode")) {
- if (this._GUImode === false) {
+ if (this.GUImode === false) {
// Refresh code editor when switching to yaml mode
this._refreshYamlEditor(true);
}
@@ -245,6 +248,7 @@ export class HuiCardEditor extends LitElement {
this._handleUIConfigChanged(ev as UIConfigChangedEvent)
);
+ this.GUImode = true;
return;
} catch (err) {
if (err.message.startsWith("WARNING:")) {
@@ -252,7 +256,7 @@ export class HuiCardEditor extends LitElement {
} else {
this._error = err;
}
- this._GUImode = false;
+ this.GUImode = false;
} finally {
this._loading = false;
fireEvent(this, "iron-resize");
@@ -277,10 +281,6 @@ export class HuiCardEditor extends LitElement {
.warning {
color: #ffa726;
}
- .buttons {
- text-align: right;
- padding: 8px 0px;
- }
paper-spinner {
display: block;
margin: auto;
diff --git a/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts b/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts
index 9e8ff26856..092482c5fe 100755
--- a/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts
+++ b/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts
@@ -6,6 +6,7 @@ import {
CSSResultArray,
customElement,
property,
+ query,
} from "lit-element";
import deepFreeze from "deep-freeze";
@@ -27,6 +28,7 @@ import { addCard, replaceCard } from "../config-util";
import "../../../../components/dialog/ha-paper-dialog";
import { haStyleDialog } from "../../../../resources/styles";
import { showSaveSuccessToast } from "../../../../util/toast-saved-success";
+import { GUIModeChangedEvent } from "../types";
declare global {
// for fire event
@@ -51,6 +53,9 @@ export class HuiDialogEditCard extends LitElement {
@property() private _saving: boolean = false;
@property() private _error?: string;
+ @query("hui-card-editor") private _cardEditorEl?: HuiCardEditor;
+ @property() private _GUImode?: boolean;
+
public async showDialog(params: EditCardDialogParams): Promise {
this._params = params;
const [view, card] = params.path;
@@ -62,10 +67,6 @@ export class HuiDialogEditCard extends LitElement {
}
}
- private get _cardEditorEl(): HuiCardEditor | null {
- return this.shadowRoot!.querySelector("hui-card-editor");
- }
-
protected render(): TemplateResult {
if (!this._params) {
return html``;
@@ -99,9 +100,9 @@ export class HuiDialogEditCard extends LitElement {
${this._cardConfig === undefined
? html`
`
: html`
@@ -109,15 +110,16 @@ export class HuiDialogEditCard extends LitElement {
${this._error
@@ -133,14 +135,30 @@ export class HuiDialogEditCard extends LitElement {
`}