Skip to content

Commit

Permalink
Fix #185
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Mar 15, 2022
1 parent 9748f1c commit a27ed51
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions card-mod.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "card-mod",
"private": true,
"version": "3.1.2",
"version": "3.1.3",
"description": "",
"scripts": {
"build": "rollup -c",
Expand Down
22 changes: 15 additions & 7 deletions src/card-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,18 @@ export class CardMod extends LitElement {
}
}

if (!customElements.get("card-mod")) {
customElements.define("card-mod", CardMod);
console.info(
`%cCARD-MOD ${pjson.version} IS INSTALLED`,
"color: green; font-weight: bold"
);
}
(async () => {
// Wait for scoped customElements registry to be set up
// otherwise the customElements registry card-mod is defined in
// may get overwritten by the polyfill if card-mod is loaded as a module
while (customElements.get("home-assistant") === undefined)
await new Promise((resolve) => window.setTimeout(resolve, 100));

if (!customElements.get("card-mod")) {
customElements.define("card-mod", CardMod);
console.info(
`%cCARD-MOD ${pjson.version} IS INSTALLED`,
"color: green; font-weight: bold"
);
}
})();
12 changes: 9 additions & 3 deletions src/mod-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class ModCard extends LitElement {
}
}

if (!customElements.get("mod-card")) {
customElements.define("mod-card", ModCard);
}
(async () => {
// See explanation in card-mod.ts
while (customElements.get("home-assistant") === undefined)
await new Promise((resolve) => window.setTimeout(resolve, 100));

if (!customElements.get("mod-card")) {
customElements.define("mod-card", ModCard);
}
})();
8 changes: 6 additions & 2 deletions src/patch/ha-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ customElements.whenDefined("ha-svg-icon").then(() => {
if (iconColor) this.style.color = iconColor;
};

(async () => {
const bindCM = async () => {
const cardMods = await findParentCardMod(this);

for (const cm of cardMods) {
cm.addEventListener("card-mod-update", async () => {
await cm.updateComplete;
Expand All @@ -71,6 +70,11 @@ customElements.whenDefined("ha-svg-icon").then(() => {
}

updateIcon();
return cardMods;
};

(async () => {
if ((await bindCM()).size == 0) window.setTimeout(() => bindCM(), 1000);
})();
};
});
4 changes: 4 additions & 0 deletions test/themes/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ test:
border: solid 1px var(--secondary-text-color);
background: url("https://placekitten.com/640/480");
}
card-mod-root: |
paper-tab:nth-of-type(2) {
--card-mod-icon: {{ iif(is_state('light.kitchen_lights', 'on'), "mdi:star", "mdi:star-outline")}};
}
1 change: 1 addition & 0 deletions test/views/1_cards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ x-anchors:
# Applying basic styles to cards
#
title: Cards
icon: mdi:home
cards:
- type: vertical-stack
cards:
Expand Down
1 change: 1 addition & 0 deletions test/views/2_separate_items.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ x-anchors:
# Styling individual items
#
title: Individual items
icon: mdi:home
cards:
- type: vertical-stack
cards:
Expand Down

0 comments on commit a27ed51

Please sign in to comment.