mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 18:56:39 +00:00
Make lovelace optional in card and section (#20970)
This commit is contained in:
parent
0add65feff
commit
9f6afb162a
@ -16,7 +16,7 @@ import type { Lovelace, LovelaceCard, LovelaceLayoutOptions } from "../types";
|
|||||||
export class HuiCard extends ReactiveElement {
|
export class HuiCard extends ReactiveElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public lovelace!: Lovelace;
|
@property({ attribute: false }) public lovelace?: Lovelace;
|
||||||
|
|
||||||
@property({ attribute: false }) public isPanel = false;
|
@property({ attribute: false }) public isPanel = false;
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ export class HuiCard extends ReactiveElement {
|
|||||||
public createElement(config: LovelaceCardConfig) {
|
public createElement(config: LovelaceCardConfig) {
|
||||||
const element = createCardElement(config) as LovelaceCard;
|
const element = createCardElement(config) as LovelaceCard;
|
||||||
element.hass = this.hass;
|
element.hass = this.hass;
|
||||||
element.editMode = this.lovelace.editMode;
|
element.editMode = this.lovelace?.editMode;
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ export class HuiCard extends ReactiveElement {
|
|||||||
this._element.hass = this.hass;
|
this._element.hass = this.hass;
|
||||||
}
|
}
|
||||||
if (changedProperties.has("lovelace")) {
|
if (changedProperties.has("lovelace")) {
|
||||||
this._element.editMode = this.lovelace.editMode;
|
this._element.editMode = this.lovelace?.editMode;
|
||||||
}
|
}
|
||||||
if (changedProperties.has("hass") || changedProperties.has("lovelace")) {
|
if (changedProperties.has("hass") || changedProperties.has("lovelace")) {
|
||||||
this._updateElement();
|
this._updateElement();
|
||||||
@ -131,7 +131,7 @@ export class HuiCard extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
const visible =
|
const visible =
|
||||||
forceVisible ||
|
forceVisible ||
|
||||||
this.lovelace.editMode ||
|
this.lovelace?.editMode ||
|
||||||
!this._config?.visibility ||
|
!this._config?.visibility ||
|
||||||
checkConditionsMet(this._config.visibility, this.hass);
|
checkConditionsMet(this._config.visibility, this.hass);
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ declare global {
|
|||||||
export class HuiSection extends ReactiveElement {
|
export class HuiSection extends ReactiveElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public lovelace!: Lovelace;
|
|
||||||
|
|
||||||
@property({ attribute: false }) public config!: LovelaceSectionRawConfig;
|
@property({ attribute: false }) public config!: LovelaceSectionRawConfig;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public lovelace?: Lovelace;
|
||||||
|
|
||||||
@property({ type: Number }) public index!: number;
|
@property({ type: Number }) public index!: number;
|
||||||
|
|
||||||
@property({ type: Number }) public viewIndex!: number;
|
@property({ type: Number }) public viewIndex!: number;
|
||||||
@ -222,7 +222,7 @@ export class HuiSection extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
const visible =
|
const visible =
|
||||||
forceVisible ||
|
forceVisible ||
|
||||||
this.lovelace.editMode ||
|
this.lovelace?.editMode ||
|
||||||
!this.config.visibility ||
|
!this.config.visibility ||
|
||||||
checkConditionsMet(this.config.visibility, this.hass);
|
checkConditionsMet(this.config.visibility, this.hass);
|
||||||
|
|
||||||
@ -246,6 +246,7 @@ export class HuiSection extends ReactiveElement {
|
|||||||
this._layoutElementType = config.type;
|
this._layoutElementType = config.type;
|
||||||
this._layoutElement.addEventListener("ll-create-card", (ev) => {
|
this._layoutElement.addEventListener("ll-create-card", (ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
if (!this.lovelace) return;
|
||||||
showCreateCardDialog(this, {
|
showCreateCardDialog(this, {
|
||||||
lovelaceConfig: this.lovelace.config,
|
lovelaceConfig: this.lovelace.config,
|
||||||
saveConfig: this.lovelace.saveConfig,
|
saveConfig: this.lovelace.saveConfig,
|
||||||
@ -255,6 +256,7 @@ export class HuiSection extends ReactiveElement {
|
|||||||
});
|
});
|
||||||
this._layoutElement.addEventListener("ll-edit-card", (ev) => {
|
this._layoutElement.addEventListener("ll-edit-card", (ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
if (!this.lovelace) return;
|
||||||
const { cardIndex } = parseLovelaceCardPath(ev.detail.path);
|
const { cardIndex } = parseLovelaceCardPath(ev.detail.path);
|
||||||
showEditCardDialog(this, {
|
showEditCardDialog(this, {
|
||||||
lovelaceConfig: this.lovelace.config,
|
lovelaceConfig: this.lovelace.config,
|
||||||
@ -265,6 +267,7 @@ export class HuiSection extends ReactiveElement {
|
|||||||
});
|
});
|
||||||
this._layoutElement.addEventListener("ll-delete-card", (ev) => {
|
this._layoutElement.addEventListener("ll-delete-card", (ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
if (!this.lovelace) return;
|
||||||
if (ev.detail.confirm) {
|
if (ev.detail.confirm) {
|
||||||
confDeleteCard(this, this.hass!, this.lovelace!, ev.detail.path);
|
confDeleteCard(this, this.hass!, this.lovelace!, ev.detail.path);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user