Stability improvements
This commit is contained in:
parent
c84ea8e09c
commit
ea12cc6629
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
card-mod.js binary
|
File diff suppressed because one or more lines are too long
26
src/main.js
26
src/main.js
@ -2,9 +2,10 @@ import {html, css} from "/card-tools/lit-element.js";
|
||||
import {fireEvent} from "/card-tools/event.js";
|
||||
import {parseTemplate} from "/card-tools/templates.js";
|
||||
|
||||
const HaCard = customElements.get('ha-card');
|
||||
customElements.whenDefined('ha-card').then(() => {
|
||||
const HaCard = customElements.get('ha-card');
|
||||
|
||||
const findConfig = function(node) {
|
||||
const findConfig = function(node) {
|
||||
if(node.config)
|
||||
return node.config;
|
||||
if(node._config)
|
||||
@ -16,9 +17,9 @@ const findConfig = function(node) {
|
||||
if(node.parentNode)
|
||||
return findConfig(node.parentNode);
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
const applyStyle = function(root, style) {
|
||||
const applyStyle = function(root, style) {
|
||||
if(!root || !style) return;
|
||||
|
||||
if(typeof style === "string") {
|
||||
@ -45,16 +46,16 @@ const applyStyle = function(root, style) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HaCard.prototype.updated = function(_) {
|
||||
HaCard.prototype.updated = function(_) {
|
||||
// Apply styles after updates, if specified
|
||||
const config = findConfig(this);
|
||||
if(config && config.style)
|
||||
applyStyle(this, config.style);
|
||||
}
|
||||
}
|
||||
|
||||
HaCard.prototype.firstUpdated = function() {
|
||||
HaCard.prototype.firstUpdated = function() {
|
||||
// Move the header inside the slot instead of in the shadowDOM
|
||||
// makes it easier to style it consistently
|
||||
const header = this.shadowRoot.querySelector(".card-header");
|
||||
@ -65,8 +66,8 @@ HaCard.prototype.firstUpdated = function() {
|
||||
// Listen for changes to hass or the location and update
|
||||
document.querySelector("home-assistant").provideHass(this);
|
||||
window.addEventListener("location-changed", () => this._requestUpdate());
|
||||
}
|
||||
Object.defineProperty(HaCard.prototype, 'hass', {
|
||||
}
|
||||
Object.defineProperty(HaCard.prototype, 'hass', {
|
||||
get() {
|
||||
return this._hass;
|
||||
},
|
||||
@ -77,6 +78,7 @@ Object.defineProperty(HaCard.prototype, 'hass', {
|
||||
this._requestUpdate('hass', oldval);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
fireEvent('ll-rebuild', {});
|
||||
fireEvent('ll-rebuild', {});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user