Update cookcli-card.js

This commit is contained in:
TheThomaas 2026-09-16 15:43:07 +02:00
parent 56429986b9
commit c34a53b621

79
dist/cookcli-card.js vendored
View file

@ -33,10 +33,6 @@
*/ */
class CookCliCard extends HTMLElement { class CookCliCard extends HTMLElement {
static getConfigElement() {
return document.createElement("cookcli-card-editor");
}
static getStubConfig() { static getStubConfig() {
return { title: "Recettes" }; return { title: "Recettes" };
} }
@ -183,23 +179,18 @@ class CookCliCard extends HTMLElement {
} }
} }
class CookCliCardEditor extends LitElement { class CookCliCardEditor extends HTMLElement {
setConfig(config) { setConfig(config) {
this._config = config || {}; this._config = config || {};
} }
configChanged(newConfig) { set hass(hass) {
const event = new Event("config-changed", { this._hass = hass;
bubbles: true,
composed: true,
});
event.detail = { config: newConfig };
this.dispatchEvent(event);
} }
static getConfigForm() { // Définit le schéma du formulaire (une entrée par champ configurable)
return { get _schema() {
schema: [ return [
{ {
name: "title", name: "title",
selector: { text: {} }, selector: { text: {} },
@ -214,36 +205,56 @@ class CookCliCardEditor extends LitElement {
selector: { text: {} }, selector: { text: {} },
helper: "Optionnel — ID d'entrée si plusieurs serveurs CookCLI", helper: "Optionnel — ID d'entrée si plusieurs serveurs CookCLI",
}, },
], ];
computeLabel: (schema) => { }
// Fournit les libellés des champs
_computeLabel(schema) {
const labels = { const labels = {
title: "Titre", title: "Titre",
dashboard_path: "Chemin du dashboard", dashboard_path: "Chemin du dashboard",
entry_id: "Entry ID", entry_id: "Entry ID",
}; };
return labels[schema.name] || schema.name; return labels[schema.name] || schema.name;
},
computeHelper: (schema) => {
switch (schema.name) {
case "entity":
return "This text describes the function of the entity selector";
case "unit":
return "The unit of measurement for this card";
}
return undefined;
},
assertConfig: (config) => {
if (config.other_option) {
throw new Error("'other_option' is unexpected.");
}
},
};
} }
// Gère les changements dans le formulaire
_valueChanged(ev) {
if (!this._config || !this._hass) {
return;
}
const newConfig = { ...this._config, ...ev.detail.value };
this._config = newConfig;
const event = new CustomEvent("config-changed", {
detail: { config: newConfig },
bubbles: true,
composed: true,
});
this.dispatchEvent(event);
}
render() {
if (!this._hass) return;
this.innerHTML = `
<ha-form
.hass=${this._hass}
.data=${this._config}
.schema=${this._schema}
.computeLabel=${this._computeLabel.bind(this)}
@value-changed=${this._valueChanged.bind(this)}
></ha-form>
`;
}
connectedCallback() {
this.render();
}
} }
customElements.define("cookcli-card", CookCliCard); customElements.define("cookcli-card", CookCliCard);
customElements.define("cookcli-card-editor", CookCliCardEditor);
window.customCards = window.customCards || []; window.customCards = window.customCards || [];
window.customCards.push({ window.customCards.push({