From 01f1e875aece08631a65cef22b6083da307db848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Vit=C3=A9?= Date: Thu, 31 Oct 2024 22:11:28 +0100 Subject: [PATCH] Fix vertical card editor (#164) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Konrad Vité --- vertical-stack-in-card.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vertical-stack-in-card.js b/vertical-stack-in-card.js index d809197..728741b 100644 --- a/vertical-stack-in-card.js +++ b/vertical-stack-in-card.js @@ -1,5 +1,7 @@ console.log(`%cvertical-stack-in-card\n%cVersion: ${'0.4.4'}`, 'color: #1976d2; font-weight: bold;', ''); +const HELPERS = window.loadCardHelpers ? window.loadCardHelpers() : undefined; + class VerticalStackInCard extends HTMLElement { constructor() { super(); @@ -181,8 +183,16 @@ class VerticalStackInCard extends HTMLElement { return sizes.reduce((a, b) => a + b, 0); } - static getConfigElement() { - return customElements.get('hui-vertical-stack-card').getConfigElement(); + static async getConfigElement() { + // Ensure hui-card-element-editor and hui-card-picker are loaded. + // They happen to be used by the vertical-stack card editor but there must be a better way? + let cls = customElements.get('hui-vertical-stack-card'); + if (!cls) { + (await HELPERS).createCardElement({ type: 'vertical-stack', cards: [] }); + await customElements.whenDefined('hui-vertical-stack-card'); + cls = customElements.get('hui-vertical-stack-card'); + } + return cls.getConfigElement(); } static getStubConfig() {