diff --git a/package-lock.json b/package-lock.json index 3719d73..a860e7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "decluttering-card", - "version": "0.6.3", + "version": "1.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "decluttering-card", - "version": "0.6.3", + "version": "1.0.3", "license": "MIT", "dependencies": { "custom-card-helpers": "^1.5.0", diff --git a/package.json b/package.json index 7909687..43349cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "decluttering-card", - "version": "1.0.0", + "version": "1.0.3", "description": "Decluttering Card for Lovelace", "main": "dist/decluttering-card.js", "scripts": { diff --git a/src/decluttering-card.ts b/src/decluttering-card.ts index e66a792..b68d67f 100644 --- a/src/decluttering-card.ts +++ b/src/decluttering-card.ts @@ -149,10 +149,6 @@ abstract class DeclutteringElement extends LitElement { :host(.child-card-hidden) { display: none; } - :host([edit-mode='true']) { - display: block !important; - border: 1px solid var(--primary-color); - } `; } @@ -391,8 +387,8 @@ class DeclutteringCardEditor extends LitElement implements LovelaceCardEditor { @customElement('decluttering-template') // eslint-disable-next-line @typescript-eslint/no-unused-vars class DeclutteringTemplate extends DeclutteringElement { - @property({ attribute: 'edit-mode', reflect: true }) editMode; - @state() private _previewMode = false; + @property({ type: Boolean, reflect: true }) preview = false; + @state() private _template?: string; static getConfigElement(): HTMLElement { @@ -417,6 +413,10 @@ class DeclutteringTemplate extends DeclutteringElement { margin: 8px; color: var(--primary-color); } + :host([preview]) { + display: block !important; + border: 1px solid var(--primary-color); + } `; } @@ -428,28 +428,27 @@ class DeclutteringTemplate extends DeclutteringElement { this._setTemplateConfig(config, undefined); } - async connectedCallback(): Promise { - super.connectedCallback(); - - this._previewMode = this.parentElement?.localName === 'hui-card-preview'; - if (!this.editMode && !this._previewMode) { - this.setAttribute('hidden', ''); - } else { - this.removeAttribute('hidden'); + protected render(): TemplateResult | void { + this.setVisibility(!this.preview); + if (this.preview) { + return html` +
${this._template}
+ ${super.render()} + `; } + return html``; } - protected render(): TemplateResult | void { - if (this._template) { - if (this._previewMode) return super.render(); - if (this.editMode) { - return html` -
${this._template}
- ${super.render()} - `; - } + private setVisibility(hidden: boolean): void { + if (this.hasAttribute('hidden') !== hidden) { + this.toggleAttribute('hidden', hidden); + this.dispatchEvent( + new Event('card-visibility-changed', { + bubbles: true, + composed: true, + }), + ); } - return html``; } } diff --git a/src/types.ts b/src/types.ts index e76c9b9..b01bd82 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,7 +34,6 @@ export interface LovelaceElementConfig { export interface LovelaceRow extends HTMLElement { hass?: HomeAssistant; - editMode?: boolean; setConfig(config: LovelaceRowConfig); }