diff --git a/custom_components/lotus_view_studio/const.py b/custom_components/lotus_view_studio/const.py index fee8758..404d438 100644 --- a/custom_components/lotus_view_studio/const.py +++ b/custom_components/lotus_view_studio/const.py @@ -2,7 +2,7 @@ DOMAIN = "lotus_view_studio" LEGACY_DOMAIN = "lotus_visual" -VERSION = "0.13.0b3" +VERSION = "0.13.0b4" URL_BASE = "/lotus_view_studio_static" BRAND_URL = "/lotus_view_studio_brand" LEGACY_URL_BASE = "/lotus_visual_static" @@ -10,4 +10,4 @@ PANEL_PATH = "lotus-view-studio" PANEL_TITLE = "Lotus View Studio" PANEL_ICON = "lotus:lotus" -MODULE_URL = f"{URL_BASE}/lotus-visual.js?v={VERSION}" \ No newline at end of file +MODULE_URL = f"{URL_BASE}/lotus-visual.js?v={VERSION}" diff --git a/custom_components/lotus_view_studio/frontend/lotus-card-picker-bridge.js b/custom_components/lotus_view_studio/frontend/lotus-card-picker-bridge.js index 71baf9c..70b2d0f 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-card-picker-bridge.js +++ b/custom_components/lotus_view_studio/frontend/lotus-card-picker-bridge.js @@ -8,8 +8,8 @@ * and already-mounted pickers are rebuilt once. */ -import { registerLotusCards } from "./lotus-card-registry.js?v=0.13.0b3"; -import { lotusDebug, lotusSetHass } from "./lotus-i18n.js?v=0.13.0b3"; +import { registerLotusCards } from "./lotus-card-registry.js?v=0.13.0b4"; +import { lotusDebug, lotusSetHass } from "./lotus-i18n.js?v=0.13.0b4"; const PATCHED = Symbol.for("lotusVisual.cardPickerPatched.v1"); diff --git a/custom_components/lotus_view_studio/frontend/lotus-card-registry.js b/custom_components/lotus_view_studio/frontend/lotus-card-registry.js index 5be88d2..13825db 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-card-registry.js +++ b/custom_components/lotus_view_studio/frontend/lotus-card-registry.js @@ -1,7 +1,7 @@ /* * Lotus View Studio custom-card registry. */ -import { lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { lotusT } from "./lotus-i18n.js?v=0.13.0b4"; export const LOTUS_STACK_CARD_ENTRY = Object.freeze({ type: "lotus-visual-stack", diff --git a/custom_components/lotus_view_studio/frontend/lotus-core.js b/custom_components/lotus_view_studio/frontend/lotus-core.js index 5552982..f86ca14 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-core.js +++ b/custom_components/lotus_view_studio/frontend/lotus-core.js @@ -1,6 +1,6 @@ -import { lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { lotusT } from "./lotus-i18n.js?v=0.13.0b4"; -export const LOTUS_VISUAL_VERSION = "0.13.0b3"; +export const LOTUS_VISUAL_VERSION = "0.13.0b4"; export const LOTUS_LAYOUT_KEY = "lotus"; export const LOTUS_LEGACY_LAYOUT_KEYS = Object.freeze(["lotus_visual_layout"]); @@ -161,4 +161,4 @@ export const lotusThemeCss = ` } .lotus-icon-button:disabled { opacity: .35; cursor: default; } .lotus-icon-button ha-icon { --mdc-icon-size: 22px; } -`; \ No newline at end of file +`; diff --git a/custom_components/lotus_view_studio/frontend/lotus-digicode-card.js b/custom_components/lotus_view_studio/frontend/lotus-digicode-card.js index 21a09a2..e6bb0b6 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-digicode-card.js +++ b/custom_components/lotus_view_studio/frontend/lotus-digicode-card.js @@ -1,5 +1,5 @@ /* - * Lotus Digicode 1.3.7 + * Lotus Digicode 1.3.8 * Configurable keypad / PIN validation card for Lotus View Studio. * * Three PIN security levels are supported: @@ -8,10 +8,10 @@ * 3) application-layer RSA-OAEP transport + server-side salted PIN hash. */ -import { deepClone, clamp } from "./lotus-core.js?v=0.13.0b3"; -import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { deepClone, clamp } from "./lotus-core.js?v=0.13.0b4"; +import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b4"; -const LOTUS_DIGICODE_VERSION = "1.3.7"; +const LOTUS_DIGICODE_VERSION = "1.3.8"; const LOTUS_DIGICODE_TYPE = "custom:lotus-digicode-card"; const DIGICODE_SECURITY_MODES = Object.freeze({ FRONTEND: "frontend_entity", @@ -1314,6 +1314,7 @@ class LotusDigicodeCardEditor extends HTMLElement { this._previewResizeObserver = new ResizeObserver(() => this._layoutPreviewShell()); this._activeResize = null; this._pendingServerPin = ""; + this._serverActionDirty = false; this._serverSecurityStatus = { loaded: false, configured: false, length: 0, mode: null, pin_id: "", error: "" }; this._serverStatusToken = 0; this._lastSaveValiditySignature = ""; @@ -1868,6 +1869,7 @@ class LotusDigicodeCardEditor extends HTMLElement { } const result = await this._hass.callWS(message); this._pendingServerPin = ""; + this._serverActionDirty = false; const input = this.shadowRoot?.querySelector(".lotus-pin-field input"); if (input) input.value = ""; this._serverSecurityStatus = { @@ -1908,6 +1910,28 @@ class LotusDigicodeCardEditor extends HTMLElement { } } + _renderSecurityAction(parent) { + const block = document.createElement("div"); + block.className = "security-action"; + const heading = document.createElement("h4"); + heading.textContent = lotusT("Action après validation du PIN"); + const help = document.createElement("p"); + help.className = "helper"; + help.textContent = this._usesServerSecurity() + ? lotusT("Choisissez l’action avant d’enregistrer le PIN. Le PIN et cette action sont enregistrés ensemble côté serveur.") + : lotusT("Cette action est exécutée automatiquement lorsque le code saisi est correct."); + block.append(heading, help); + this._renderAction(block); + + if (this._usesServerSecurity() && this._serverActionDirty) { + const warning = document.createElement("p"); + warning.className = "security-note warning action-sync-warning"; + warning.textContent = lotusT("Action modifiée : réenregistrez le PIN et l’action sur le serveur pour appliquer cette modification."); + block.appendChild(warning); + } + parent.appendChild(block); + } + _renderSecuritySource(parent) { this._nativeSelectField(parent, "security.mode", "Niveau de sécurité du PIN", this._securityMode(), [ [DIGICODE_SECURITY_MODES.FRONTEND, "Niveau 1 — Entité Home Assistant (compatibilité)"], @@ -1931,6 +1955,7 @@ class LotusDigicodeCardEditor extends HTMLElement { "Ce mode ne permet pas un PIN commençant par 0 et la valeur reste lisible par le frontend Home Assistant.", ], "warning"); this._codeEntity(parent); + this._renderSecurityAction(parent); return; } @@ -1966,6 +1991,7 @@ class LotusDigicodeCardEditor extends HTMLElement { parent.appendChild(note); } + this._renderSecurityAction(parent); this._passwordField(parent, "PIN à enregistrer côté serveur"); const button = document.createElement("button"); button.type = "button"; @@ -2075,6 +2101,11 @@ class LotusDigicodeCardEditor extends HTMLElement { status.dataset.kind = "error"; return; } + if (this._serverActionDirty) { + status.textContent = lotusT("Action modifiée : saisissez de nouveau le PIN puis enregistrez le PIN et l’action sur le serveur."); + status.dataset.kind = "warning"; + return; + } status.textContent = lotusT(`PIN serveur configuré : ${this._serverSecurityStatus.length} chiffre${this._serverSecurityStatus.length > 1 ? "s" : ""}. Le PIN lui-même n’est jamais renvoyé à l’éditeur. L’aperçu teste ce PIN réel sans exécuter l’action.`); status.dataset.kind = "ok"; } @@ -2089,7 +2120,10 @@ class LotusDigicodeCardEditor extends HTMLElement { form.computeLabel = () => lotusT("Action exécutée lorsque le code est correct"); form.addEventListener("value-changed", (event) => { const value = event.detail?.value?.action; - this._commit((config) => { config.action = value && typeof value === "object" ? clone(value) : { action: "none" }; }); + const nextAction = value && typeof value === "object" ? clone(value) : { action: "none" }; + if (JSON.stringify(nextAction) === JSON.stringify(this._config.action)) return; + if (this._usesServerSecurity()) this._serverActionDirty = true; + this._commit((config) => { config.action = nextAction; }); }); parent.appendChild(form); } else { @@ -2259,7 +2293,7 @@ class LotusDigicodeCardEditor extends HTMLElement { if (!frame || !shell || this._activeResize) return; const rect = frame.getBoundingClientRect(); if (rect.width <= 20 || rect.height <= 20) return; - const pad = 42; + const pad = 78; // Reserve space for the contextual Edit/Test toolbar. const availW = Math.max(60, rect.width - pad * 2); const availH = Math.max(90, rect.height - pad * 2); const ratio = this._config.design.width / Math.max(1, this._config.design.height); @@ -2498,13 +2532,6 @@ class LotusDigicodeCardEditor extends HTMLElement { this._number(success, "success.delay", "Délai avant réinitialisation (ms)", this._config.success.delay, 0, 5000, 50, (value) => this._commit((c) => { c.success.delay = Number(value); }), "box"); pane.appendChild(success); - const actionDescription = this._usesServerSecurity() - ? "Pour les actions de service/toggle, l’action est exécutée côté serveur après validation du PIN. Après toute modification de cette action, réenregistrez le PIN dans la section Code et sécurité afin de mettre à jour l’action autorisée côté serveur." - : "L’action est exécutée automatiquement dès que le dernier chiffre rend le code correct."; - const action = this._section("Action Home Assistant", actionDescription); - this._renderAction(action); - pane.appendChild(action); - const previewTitle = document.createElement("div"); previewTitle.className = "preview-title"; previewTitle.textContent = `Lotus Digicode · ${LOTUS_DIGICODE_VERSION}`; diff --git a/custom_components/lotus_view_studio/frontend/lotus-digicode-editor-ux-b4.js b/custom_components/lotus_view_studio/frontend/lotus-digicode-editor-ux-b4.js new file mode 100644 index 0000000..65c5b74 --- /dev/null +++ b/custom_components/lotus_view_studio/frontend/lotus-digicode-editor-ux-b4.js @@ -0,0 +1,319 @@ +/* + * Lotus Digicode contextual editor — internal 0.13.0b4 test candidate. + * + * - Contextual configuration driven by preview selection. + * - Explicit Edit/Test toggle. Test mode validates the real PIN with + * preview=true and therefore never executes the protected Home Assistant action. + * - Keeps security/PIN/action configuration together in the main card editor. + */ + +import { lotusT } from "./lotus-i18n.js?v=0.13.0b4"; + +const editorClass = customElements.get("lotus-digicode-card-editor"); + +const SECTION_TARGETS = Object.freeze({ + "Nom": "security", + "Code et sécurité": "security", + "Format responsive": "frame", + "Interaction": "interaction", + "Contour du digicode": "frame", + "Matrice des touches": "keys", + "Ordre et placement des touches": "keys", + "Touches": "keys", + "Contenu des touches": "keys", + "Cadran de saisie": "display", + "Correction de saisie": "controls", + "Retour en cas d’erreur": "feedback", + "Retour en cas de code correct": "feedback", +}); + +if (editorClass && !editorClass.prototype.__lotusDigicodeContextEditorB4) { + editorClass.prototype.__lotusDigicodeContextEditorB4 = true; + + const originalSection = editorClass.prototype._section; + editorClass.prototype._section = function contextualSection(title, description = "") { + const section = originalSection.call(this, title, description); + section.dataset.lotusSectionSource = title; + section.dataset.lotusSectionTarget = SECTION_TARGETS[title] || "security"; + return section; + }; + + editorClass.prototype._lotusDigicodePreview = function digicodePreview() { + return this.shadowRoot?.querySelector("lotus-digicode-card.digicode-preview") + || this.shadowRoot?.querySelector("lotus-digicode-card"); + }; + + editorClass.prototype._lotusDigicodeRuntimeRoot = function digicodeRuntimeRoot() { + return this._lotusDigicodePreview()?.shadowRoot || null; + }; + + editorClass.prototype._lotusDigicodeTargetFromEvent = function targetFromEvent(event) { + const path = typeof event.composedPath === "function" ? event.composedPath() : []; + const element = path.find((node) => node instanceof Element && ( + node.classList?.contains("key") + || node.classList?.contains("code-display") + || node.classList?.contains("keys-area") + || node.classList?.contains("digicode-shell") + )); + if (!element) return "frame"; + if (element.classList.contains("key")) { + return element.classList.contains("backspace") || element.classList.contains("clear") + ? "controls" + : "keys"; + } + if (element.classList.contains("code-display")) return "display"; + if (element.classList.contains("keys-area")) return "keys"; + return "frame"; + }; + + editorClass.prototype._lotusDigicodeApplyContext = function applyContext() { + const pane = this.shadowRoot?.querySelector(".config-pane"); + if (!pane) return; + const target = this._lotusDigicodeSelection || "security"; + pane.querySelectorAll(".editor-section").forEach((section) => { + section.hidden = section.dataset.lotusSectionTarget !== target; + }); + pane.scrollTop = 0; + }; + + editorClass.prototype._lotusDigicodeMarkSelection = function markSelection() { + const root = this._lotusDigicodeRuntimeRoot(); + if (!root) return; + root.querySelectorAll(".lotus-digicode-edit-selected") + .forEach((node) => node.classList.remove("lotus-digicode-edit-selected")); + if (this._lotusDigicodeTestMode) return; + + const target = this._lotusDigicodeSelection || "security"; + let nodes = []; + if (target === "frame") nodes = [root.querySelector(".digicode-shell")]; + else if (target === "display" || target === "feedback") nodes = [root.querySelector(".code-display")]; + else if (target === "keys") nodes = Array.from(root.querySelectorAll(".key.digit")); + else if (target === "controls") nodes = Array.from(root.querySelectorAll(".key.backspace,.key.clear")); + nodes.filter(Boolean).forEach((node) => node.classList.add("lotus-digicode-edit-selected")); + }; + + editorClass.prototype._lotusDigicodeSyncToolbar = function syncToolbar() { + const toolbar = this.shadowRoot?.querySelector(".lotus-digicode-toolbar"); + if (!toolbar) return; + toolbar.querySelectorAll("button[data-target]").forEach((button) => { + const active = !this._lotusDigicodeTestMode + && button.dataset.target === (this._lotusDigicodeSelection || "security"); + button.disabled = Boolean(this._lotusDigicodeTestMode); + button.classList.toggle("active", active); + button.setAttribute("aria-pressed", active ? "true" : "false"); + }); + const toggle = toolbar.querySelector("button[data-test-toggle]"); + if (toggle) { + const testing = Boolean(this._lotusDigicodeTestMode); + toggle.classList.toggle("test-active", testing); + toggle.title = lotusT(testing ? "Revenir au mode édition" : "Tester le digicode"); + toggle.setAttribute("aria-label", toggle.title); + toggle.querySelector("ha-icon")?.setAttribute("icon", testing ? "mdi:pencil" : "mdi:play-circle-outline"); + } + }; + + editorClass.prototype._lotusDigicodeSelect = function select(target) { + if (this._lotusDigicodeTestMode) return; + this._lotusDigicodeSelection = target || "security"; + this._lotusDigicodeApplyContext(); + this._lotusDigicodeMarkSelection(); + this._lotusDigicodeSyncToolbar(); + }; + + editorClass.prototype._lotusDigicodeSetTestMode = function setTestMode(value) { + this._lotusDigicodeTestMode = Boolean(value); + const preview = this._lotusDigicodePreview(); + // Critical safety invariant: the editor always runs the card in preview mode. + // A correct server PIN can be tested, but digicode_security.py refuses to + // execute the configured action when preview=true. + if (preview) preview.preview = true; + this.shadowRoot?.querySelector(".preview-frame") + ?.classList.toggle("lotus-digicode-test-mode", this._lotusDigicodeTestMode); + this.shadowRoot?.querySelector(".preview-pane") + ?.classList.toggle("lotus-digicode-testing", this._lotusDigicodeTestMode); + this.shadowRoot?.querySelector(".lotus-digicode-test-badge") + ?.toggleAttribute("hidden", !this._lotusDigicodeTestMode); + this._lotusDigicodeMarkSelection(); + this._lotusDigicodeSyncToolbar(); + }; + + editorClass.prototype._lotusDigicodeEnsureRuntimeStyle = function ensureRuntimeStyle() { + const root = this._lotusDigicodeRuntimeRoot(); + if (!root || root.querySelector('style[data-lotus-digicode-context="1"]')) return; + const style = document.createElement("style"); + style.dataset.lotusDigicodeContext = "1"; + style.textContent = ` + .code-display { pointer-events:auto !important; } + .lotus-digicode-edit-selected { + outline:2px solid var(--primary-color,#03a9f4) !important; + outline-offset:3px !important; + } + .key.lotus-digicode-edit-selected { outline-offset:1px !important; } + `; + root.appendChild(style); + }; + + editorClass.prototype._lotusDigicodeInstallUi = function installUi() { + const previewPane = this.shadowRoot?.querySelector(".preview-pane"); + const frame = this.shadowRoot?.querySelector(".preview-frame"); + const preview = this._lotusDigicodePreview(); + const root = preview?.shadowRoot; + if (!previewPane || !frame || !preview || !root) return; + + this._lotusDigicodeEnsureRuntimeStyle(); + + if (!previewPane.querySelector(".lotus-digicode-toolbar")) { + const toolbar = document.createElement("div"); + toolbar.className = "lotus-digicode-toolbar"; + toolbar.setAttribute("role", "toolbar"); + toolbar.setAttribute("aria-label", lotusT("Configuration du digicode")); + const items = [ + ["security", "mdi:shield-key-outline", "PIN, sécurité et action"], + ["frame", "mdi:crop-square", "Format et contour du digicode"], + ["display", "mdi:form-textbox-password", "Cadran de saisie"], + ["keys", "mdi:dialpad", "Touches numériques"], + ["controls", "mdi:backspace-outline", "Touches de correction"], + ["feedback", "mdi:check-circle-outline", "Retours correct / erreur"], + ["interaction", "mdi:gesture-tap", "Interaction"], + ]; + for (const [target, iconName, label] of items) { + const button = document.createElement("button"); + button.type = "button"; + button.dataset.target = target; + button.title = lotusT(label); + button.setAttribute("aria-label", button.title); + button.setAttribute("aria-pressed", "false"); + const icon = document.createElement("ha-icon"); + icon.setAttribute("icon", iconName); + button.appendChild(icon); + button.addEventListener("pointerdown", (event) => { + event.preventDefault(); + event.stopPropagation(); + }); + button.addEventListener("click", (event) => { + event.preventDefault(); + event.stopPropagation(); + this._lotusDigicodeSelect(target); + }); + toolbar.appendChild(button); + } + + const separator = document.createElement("span"); + separator.className = "lotus-toolbar-separator"; + toolbar.appendChild(separator); + + const testButton = document.createElement("button"); + testButton.type = "button"; + testButton.dataset.testToggle = "1"; + testButton.className = "test-toggle"; + const testIcon = document.createElement("ha-icon"); + testIcon.setAttribute("icon", "mdi:play-circle-outline"); + testButton.appendChild(testIcon); + testButton.addEventListener("click", (event) => { + event.preventDefault(); + event.stopPropagation(); + this._lotusDigicodeSetTestMode(!this._lotusDigicodeTestMode); + }); + toolbar.appendChild(testButton); + previewPane.appendChild(toolbar); + + const badge = document.createElement("div"); + badge.className = "lotus-digicode-test-badge"; + badge.textContent = lotusT("MODE TEST — validation réelle du PIN, aucune action Home Assistant exécutée"); + badge.hidden = true; + previewPane.appendChild(badge); + } + + if (!root.querySelector('[data-lotus-digicode-selector-listener="1"]')) { + const sentinel = document.createElement("span"); + sentinel.hidden = true; + sentinel.dataset.lotusDigicodeSelectorListener = "1"; + root.appendChild(sentinel); + root.addEventListener("pointerdown", (event) => { + if (this._lotusDigicodeTestMode || this._activeResize) return; + const target = this._lotusDigicodeTargetFromEvent(event); + event.preventDefault(); + event.stopImmediatePropagation(); + this._lotusDigicodeSelect(target); + }, true); + } + + if (!frame.dataset.lotusDigicodeBackgroundSelector) { + frame.dataset.lotusDigicodeBackgroundSelector = "1"; + frame.addEventListener("pointerdown", (event) => { + if (this._lotusDigicodeTestMode || this._activeResize) return; + if (event.target === frame) this._lotusDigicodeSelect("security"); + }); + } + + this._lotusDigicodeApplyContext(); + this._lotusDigicodeSetTestMode(Boolean(this._lotusDigicodeTestMode)); + this._lotusDigicodeSelect(this._lotusDigicodeSelection || "security"); + }; + + const originalRender = editorClass.prototype._render; + editorClass.prototype._render = function contextualRender(...args) { + const selection = this._lotusDigicodeSelection || "security"; + const testMode = Boolean(this._lotusDigicodeTestMode); + const result = originalRender.apply(this, args); + this._lotusDigicodeSelection = selection; + this._lotusDigicodeTestMode = testMode; + + const style = document.createElement("style"); + style.dataset.lotusDigicodeContextUi = "1"; + style.textContent = ` + .editor-section[hidden], .lotus-digicode-test-badge[hidden] { display:none !important; } + .preview-title { top:58px !important; } + .lotus-digicode-toolbar { + position:absolute; top:8px; left:50%; transform:translateX(-50%); z-index:50; + display:flex; align-items:center; gap:4px; max-width:calc(100% - 20px); padding:5px; + box-sizing:border-box; overflow-x:auto; + border:1px solid var(--divider-color,rgba(127,127,127,.25)); border-radius:12px; + background:var(--card-background-color,#fff); box-shadow:0 2px 8px rgba(0,0,0,.12); + } + .lotus-digicode-toolbar button { + appearance:none; flex:0 0 auto; display:grid; place-items:center; width:34px; height:34px; padding:0; + border:1px solid transparent; border-radius:9px; color:var(--secondary-text-color,#727272); + background:transparent; cursor:pointer; + } + .lotus-digicode-toolbar button:hover:not(:disabled) { + color:var(--primary-text-color,#212121); + background:color-mix(in srgb,var(--primary-color,#03a9f4) 10%,transparent); + } + .lotus-digicode-toolbar button.active { + color:var(--text-primary-color,#fff); background:var(--primary-color,#03a9f4); + } + .lotus-digicode-toolbar button:disabled:not([data-test-toggle]) { opacity:.32; cursor:default; } + .lotus-digicode-toolbar button.test-active { + color:var(--text-primary-color,#fff); background:var(--success-color,#43a047); + } + .lotus-digicode-toolbar ha-icon { --mdc-icon-size:20px; } + .lotus-toolbar-separator { flex:0 0 1px; width:1px; height:24px; margin:0 2px; background:var(--divider-color,rgba(127,127,127,.25)); } + .preview-pane.lotus-digicode-testing .preview-title { display:none !important; } + .lotus-digicode-test-badge { + position:absolute; left:50%; top:58px; transform:translateX(-50%); z-index:49; + max-width:calc(100% - 24px); padding:4px 8px; box-sizing:border-box; + border-radius:8px; background:var(--success-color,#43a047); color:white; + font-size:10px; font-weight:700; text-align:center; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; + } + .preview-frame.lotus-digicode-test-mode { cursor:default; } + .preview-frame.lotus-digicode-test-mode .resize-handle, + .preview-frame.lotus-digicode-test-mode .size-badge { display:none !important; } + .security-action { + margin:14px 0; padding:12px; border:1px solid var(--divider-color,rgba(127,127,127,.22)); + border-radius:10px; background:color-mix(in srgb,var(--secondary-background-color,#f5f5f5) 72%,transparent); + } + .security-action h4 { margin:0 0 6px; font-size:14px; } + .security-action .helper { margin:0 0 8px; } + .security-note[data-kind="warning"], .action-sync-warning { color:var(--warning-color,#f57c00); } + @media (max-width:980px) { + .preview-title { top:auto !important; } + .lotus-digicode-toolbar { position:absolute; } + } + `; + this.shadowRoot?.appendChild(style); + + requestAnimationFrame(() => this._lotusDigicodeInstallUi()); + return result; + }; +} diff --git a/custom_components/lotus_view_studio/frontend/lotus-direct-create-bridge.js b/custom_components/lotus_view_studio/frontend/lotus-direct-create-bridge.js index d830d4e..833e121 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-direct-create-bridge.js +++ b/custom_components/lotus_view_studio/frontend/lotus-direct-create-bridge.js @@ -1,5 +1,5 @@ /* - * Lotus View Studio direct-create bridge — v0.13.0b3 + * Lotus View Studio direct-create bridge — v0.13.0b4 * * Goal * ---- @@ -203,7 +203,7 @@ function installCaptureBridge() { .catch(() => {}); window.LotusVisual = Object.assign(window.LotusVisual || {}, { - directCreateBridge: "0.13.0b3", + directCreateBridge: "0.13.0b4", directCreateMode: "capture-import-before-dialog", }); } diff --git a/custom_components/lotus_view_studio/frontend/lotus-edit-dialog-bridge.js b/custom_components/lotus_view_studio/frontend/lotus-edit-dialog-bridge.js index 7c2070e..1a43375 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-edit-dialog-bridge.js +++ b/custom_components/lotus_view_studio/frontend/lotus-edit-dialog-bridge.js @@ -1,5 +1,5 @@ /* - * Lotus View Studio edit-dialog bridge — v0.13.0b3 + * Lotus View Studio edit-dialog bridge — v0.13.0b4 * * Home Assistant's native hui-dialog-edit-card owns two columns on desktop: * - .element-editor (ha-scrollbar) @@ -25,7 +25,7 @@ * frontend. Non-Lotus cards are not changed. */ -import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b4"; const PATCHED = Symbol.for("lotusVisual.editDialogBridge.v0837"); const CAPTURE_INSTALLED = Symbol.for("lotusVisual.editDialogCapture.v0837"); @@ -934,7 +934,7 @@ function installBridge() { .catch(() => {}); window.LotusVisual = Object.assign(window.LotusVisual || {}, { - editDialogBridge: "0.13.0b3", + editDialogBridge: "0.13.0b4", editDialogMode: "visual-preview-yaml-code-only", }); } diff --git a/custom_components/lotus_view_studio/frontend/lotus-i18n-europe.js b/custom_components/lotus_view_studio/frontend/lotus-i18n-europe.js index a15b4ef..05cad3a 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-i18n-europe.js +++ b/custom_components/lotus_view_studio/frontend/lotus-i18n-europe.js @@ -1,5 +1,5 @@ -/* European language pack for Lotus View Studio 0.13.0b3. */ -export const LOTUS_EUROPE_VERSION = "0.13.0b3"; +/* European language pack for Lotus View Studio 0.13.0b4. */ +export const LOTUS_EUROPE_VERSION = "0.13.0b4"; export const LOTUS_EUROPE_LANGUAGES = Object.freeze([ { value: "nl", nativeName: "Nederlands", englishName: "Dutch" }, { value: "pl", nativeName: "Polski", englishName: "Polish" }, diff --git a/custom_components/lotus_view_studio/frontend/lotus-i18n-extra.js b/custom_components/lotus_view_studio/frontend/lotus-i18n-extra.js index e1b2c4a..8913243 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-i18n-extra.js +++ b/custom_components/lotus_view_studio/frontend/lotus-i18n-extra.js @@ -4,7 +4,7 @@ * here so every advertised language remains usable. */ -export const LOTUS_I18N_EXTRA_VERSION = "0.13.0b3"; +export const LOTUS_I18N_EXTRA_VERSION = "0.13.0b4"; export const LOTUS_EXTRA_LANGUAGES = Object.freeze([ { value: "it", nativeName: "Italiano", englishName: "Italian" }, diff --git a/custom_components/lotus_view_studio/frontend/lotus-i18n.js b/custom_components/lotus_view_studio/frontend/lotus-i18n.js index cb7a800..96f097f 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-i18n.js +++ b/custom_components/lotus_view_studio/frontend/lotus-i18n.js @@ -4,13 +4,13 @@ import { LOTUS_EXTRA_REPLACEMENTS, LOTUS_EXTRA_SELECTOR_LABELS, LOTUS_RTL_LANGUAGES, -} from "./lotus-i18n-extra.js?v=0.13.0b3"; +} from "./lotus-i18n-extra.js?v=0.13.0b4"; import { LOTUS_EUROPE_LANGUAGES, LOTUS_EUROPE_EXACT, LOTUS_EUROPE_REPLACEMENTS, LOTUS_EUROPE_SELECTOR_LABELS, -} from "./lotus-i18n-europe.js?v=0.13.0b3"; +} from "./lotus-i18n-europe.js?v=0.13.0b4"; /* * Lotus View Studio internationalization core. @@ -18,7 +18,7 @@ import { * a per-user manual override persisted by the Lotus View Studio backend. */ -export const LOTUS_I18N_VERSION = "0.13.0b3"; +export const LOTUS_I18N_VERSION = "0.13.0b4"; export const LOTUS_LANGUAGES = Object.freeze([ { value: "auto", nativeName: "Automatique — Home Assistant", englishName: "Automatic — Home Assistant" }, @@ -734,6 +734,22 @@ const EXACT_EN = { "verticale": "vertical", "horizontale": "horizontal", + "Action après validation du PIN": "Action after PIN validation", + "Choisissez l’action avant d’enregistrer le PIN. Le PIN et cette action sont enregistrés ensemble côté serveur.": "Choose the action before saving the PIN. The PIN and this action are stored together on the server.", + "Cette action est exécutée automatiquement lorsque le code saisi est correct.": "This action is executed automatically when the entered code is correct.", + "Action modifiée : réenregistrez le PIN et l’action sur le serveur pour appliquer cette modification.": "Action changed: save the PIN and action on the server again to apply this change.", + "Action modifiée : saisissez de nouveau le PIN puis enregistrez le PIN et l’action sur le serveur.": "Action changed: enter the PIN again, then save the PIN and action on the server.", + "PIN, sécurité et action": "PIN, security and action", + "Format et contour du digicode": "Keypad size and frame", + "Touches numériques": "Numeric keys", + "Touches de correction": "Correction keys", + "Retours correct / erreur": "Success / error feedback", + "Configuration du digicode": "Keypad configuration", + "Revenir au mode édition": "Return to edit mode", + "Tester le digicode": "Test the keypad", + "MODE TEST — validation réelle du PIN, aucune action Home Assistant exécutée": "TEST MODE — real PIN validation, no Home Assistant action is executed", + "Tester le slider": "Test the slider", + "MODE TEST — simulation, aucune action Home Assistant exécutée": "TEST MODE — simulation, no Home Assistant action is executed", }; const EXACT_DE = { @@ -1420,6 +1436,22 @@ const EXACT_DE = { "verticale": "vertikal", "horizontale": "horizontal", + "Action après validation du PIN": "Aktion nach PIN-Prüfung", + "Choisissez l’action avant d’enregistrer le PIN. Le PIN et cette action sont enregistrés ensemble côté serveur.": "Wählen Sie die Aktion aus, bevor Sie die PIN speichern. PIN und Aktion werden gemeinsam auf dem Server gespeichert.", + "Cette action est exécutée automatiquement lorsque le code saisi est correct.": "Diese Aktion wird automatisch ausgeführt, wenn der eingegebene Code korrekt ist.", + "Action modifiée : réenregistrez le PIN et l’action sur le serveur pour appliquer cette modification.": "Aktion geändert: Speichern Sie PIN und Aktion erneut auf dem Server, um die Änderung anzuwenden.", + "Action modifiée : saisissez de nouveau le PIN puis enregistrez le PIN et l’action sur le serveur.": "Aktion geändert: Geben Sie die PIN erneut ein und speichern Sie anschließend PIN und Aktion auf dem Server.", + "PIN, sécurité et action": "PIN, Sicherheit und Aktion", + "Format et contour du digicode": "Größe und Rahmen des Tastenfelds", + "Touches numériques": "Zifferntasten", + "Touches de correction": "Korrekturtasten", + "Retours correct / erreur": "Rückmeldung Erfolg / Fehler", + "Configuration du digicode": "Tastenfeld-Konfiguration", + "Revenir au mode édition": "Zurück zum Bearbeitungsmodus", + "Tester le digicode": "Tastenfeld testen", + "MODE TEST — validation réelle du PIN, aucune action Home Assistant exécutée": "TESTMODUS — echte PIN-Prüfung, keine Home-Assistant-Aktion wird ausgeführt", + "Tester le slider": "Slider testen", + "MODE TEST — simulation, aucune action Home Assistant exécutée": "TESTMODUS — Simulation, keine Home-Assistant-Aktion wird ausgeführt", }; diff --git a/custom_components/lotus_view_studio/frontend/lotus-icon-size-bridge.js b/custom_components/lotus_view_studio/frontend/lotus-icon-size-bridge.js index 15393e0..e0a4eec 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-icon-size-bridge.js +++ b/custom_components/lotus_view_studio/frontend/lotus-icon-size-bridge.js @@ -1,5 +1,5 @@ /* - * Lotus View Studio native picture-elements responsive bridge — v0.13.0b3 + * Lotus View Studio native picture-elements responsive bridge — v0.13.0b4 * * Lotus Stack is deliberately saved as a native Home Assistant picture-elements * card. Native state-icon/state-label elements do not know the logical Lotus @@ -197,6 +197,6 @@ if (labelClass) installLabelBridge(labelClass); else customElements.whenDefined("hui-state-label-element").then(() => installLabelBridge(customElements.get("hui-state-label-element"))); window.LotusVisual = Object.assign(window.LotusVisual || {}, { - iconSizeBridge: "0.13.0b3", - stackResponsiveBridge: "0.13.0b3", + iconSizeBridge: "0.13.0b4", + stackResponsiveBridge: "0.13.0b4", }); diff --git a/custom_components/lotus_view_studio/frontend/lotus-iconset.js b/custom_components/lotus_view_studio/frontend/lotus-iconset.js index ec1fb2b..be3a51e 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-iconset.js +++ b/custom_components/lotus_view_studio/frontend/lotus-iconset.js @@ -3,7 +3,7 @@ * mark without requiring an external custom-icons integration. */ -const LOTUS_ICONSET_VERSION = "0.13.0b3"; +const LOTUS_ICONSET_VERSION = "0.13.0b4"; // 24x24 monochrome sidebar icon: a simplified Lotus inside a window frame. // It follows currentColor so Home Assistant controls selected/unselected colors. diff --git a/custom_components/lotus_view_studio/frontend/lotus-image-fit-bridge.js b/custom_components/lotus_view_studio/frontend/lotus-image-fit-bridge.js index 8cddff8..2d18062 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-image-fit-bridge.js +++ b/custom_components/lotus_view_studio/frontend/lotus-image-fit-bridge.js @@ -1,5 +1,5 @@ /* - * Lotus View Studio native picture-elements image-fit bridge — v0.13.0b3 + * Lotus View Studio native picture-elements image-fit bridge — v0.13.0b4 * * Home Assistant's hui-image component supports fitMode (cover/contain/fill), * but hui-image-element currently does not forward such a property to it. @@ -61,5 +61,5 @@ if (existing) { } window.LotusVisual = Object.assign(window.LotusVisual || {}, { - imageFitBridge: "0.13.0b3", + imageFitBridge: "0.13.0b4", }); diff --git a/custom_components/lotus_view_studio/frontend/lotus-slide-card.js b/custom_components/lotus_view_studio/frontend/lotus-slide-card.js index 04410dc..d67b48e 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-slide-card.js +++ b/custom_components/lotus_view_studio/frontend/lotus-slide-card.js @@ -6,8 +6,8 @@ * executed once the handle reaches the validation threshold and is released. */ -import { deepClone, clamp } from "./lotus-core.js?v=0.13.0b3"; -import { lotusLocalizeSelector, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { deepClone, clamp } from "./lotus-core.js?v=0.13.0b4"; +import { lotusLocalizeSelector, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b4"; const LOTUS_SLIDE_VERSION = "1.3.0"; const LOTUS_SLIDE_TYPE = "custom:lotus-slide-card"; diff --git a/custom_components/lotus_view_studio/frontend/lotus-slide-editor-b1.js b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-b1.js index 641f2a2..9e0495a 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-slide-editor-b1.js +++ b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-b1.js @@ -1,5 +1,5 @@ /* - * Lotus Slide editor UX patch for Lotus View Studio 0.13.0b3. + * Lotus Slide editor UX patch for Lotus View Studio 0.13.0b1. * * Goals: * - allow each side/end position to explicitly have no icon or image; @@ -9,7 +9,7 @@ * This module is loaded after lotus-slide-card.js and only patches the editor. */ -import { lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { lotusT } from "./lotus-i18n.js?v=0.13.0b0"; const MAX_SIDE_VISUAL_VALUES = 20; const DEFERRED_SIZE_KEYS = new Set([ diff --git a/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-b1.js b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-b1.js index 8237672..8818f35 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-b1.js +++ b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-b1.js @@ -1,5 +1,5 @@ /* - * Lotus Slide direct preview editor — 0.13.0b3. + * Lotus Slide direct preview editor — 0.13.0b1. * * The live preview is also a context selector: clicking an element reveals only * the relevant configuration section. Selected visual elements can be resized diff --git a/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-fix-b1.js b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-fix-b1.js index 5ce7eea..42657c5 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-fix-b1.js +++ b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-direct-fix-b1.js @@ -1,6 +1,6 @@ -/* Refinements for the 0.13.0b3 direct Lotus Slide preview editor. */ +/* Refinements for the 0.13.0b1 direct Lotus Slide preview editor. */ -import { lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { lotusT } from "./lotus-i18n.js?v=0.13.0b1"; const editorClass = customElements.get("lotus-slide-card-editor"); diff --git a/custom_components/lotus_view_studio/frontend/lotus-slide-editor-ux-b4.js b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-ux-b4.js new file mode 100644 index 0000000..d26af20 --- /dev/null +++ b/custom_components/lotus_view_studio/frontend/lotus-slide-editor-ux-b4.js @@ -0,0 +1,834 @@ +/* + * Lotus Slide UX enhancements — local 0.13.0b4 test candidate. + * + * This module deliberately patches only Lotus Slide/Card editor behaviour so + * the candidate can be tested locally before any GitHub publication. + */ + +import { lotusT } from "./lotus-i18n.js?v=0.13.0b4"; + +const MAX_SIDE_VISUAL_VALUES = 20; +const CHEVRON_PREFIX = "mdi:chevron-double-"; +const DEFERRED_SIZE_KEYS = new Set([ + "width", + "height", + "thickness", + "size", + "border_width", + "radius", + "bevel", + "font_size", +]); + +const clone = (value) => { + if (typeof structuredClone === "function") return structuredClone(value); + return JSON.parse(JSON.stringify(value)); +}; + +const clampValue = (value, min, max) => Math.min(max, Math.max(min, Number(value) || 0)); +const isChevron = (value) => String(value || "").startsWith(CHEVRON_PREFIX); +const isDeferredSizePath = (path) => DEFERRED_SIZE_KEYS.has(String(path ?? "").split(".").pop()); + +const oppositeDirection = (direction) => ({ up: "down", down: "up", left: "right", right: "left" }[direction] || direction); +const directionalThumbIcon = (config, side) => { + let towardEnd; + if (config?.orientation === "vertical") towardEnd = config?.reverse ? "down" : "up"; + else towardEnd = config?.reverse ? "left" : "right"; + const direction = side === "end" ? oppositeDirection(towardEnd) : towardEnd; + return `${CHEVRON_PREFIX}${direction}`; +}; + +const sideHasPotentialVisual = (conf) => { + if (!conf) return false; + if (conf.visual_type === "image") { + if (String(conf.image ?? "").trim()) return true; + if (String(conf.binary_image_1 ?? "").trim()) return true; + if (String(conf.binary_image_2 ?? "").trim()) return true; + return Array.isArray(conf.values) && conf.values.some((entry) => String(entry?.image ?? "").trim()); + } + if (String(conf.icon ?? "").trim()) return true; + if (String(conf.binary_icon_1 ?? "").trim()) return true; + if (String(conf.binary_icon_2 ?? "").trim()) return true; + return Array.isArray(conf.values) && conf.values.some((entry) => String(entry?.icon ?? "").trim()); +}; + +const clearSideVisual = (side) => { + if (!side) return; + side.visual_type = "icon"; + side.icon = ""; + side.image = ""; + side.state_entity = ""; + side.state_mode = "static"; + side.binary_icon_1 = ""; + side.binary_icon_2 = ""; + side.binary_image_1 = ""; + side.binary_image_2 = ""; + side.value_count = 0; + side.values = []; + if (side.background && typeof side.background === "object") side.background.enabled = false; +}; + +const thumbStateFromRaw = (rawConfig, normalizedConfig = undefined) => { + const rawThumb = rawConfig?.icons?.thumb && typeof rawConfig.icons.thumb === "object" + ? rawConfig.icons.thumb + : {}; + const normalizedThumb = normalizedConfig?.icons?.thumb || {}; + const fallbackStart = directionalThumbIcon(normalizedConfig || rawConfig || {}, "start"); + const fallbackEnd = directionalThumbIcon(normalizedConfig || rawConfig || {}, "end"); + const legacy = String(rawThumb.icon ?? normalizedThumb.icon ?? "").trim(); + const hasPair = Object.prototype.hasOwnProperty.call(rawThumb, "icon_start") + || Object.prototype.hasOwnProperty.call(rawThumb, "icon_end"); + const explicitAuto = Object.prototype.hasOwnProperty.call(rawThumb, "auto_direction") + ? rawThumb.auto_direction === true + : null; + // Legacy 0.13.0b0 confirm sliders stored auto_direction:false even though + // their stock thumb was a directional chevron. Treat that untouched stock + // icon as the new automatic default. A real custom icon still disables it. + const automatic = hasPair + ? explicitAuto === true + : (explicitAuto === true || !legacy || isChevron(legacy)); + return { + automatic, + start: String(rawThumb.icon_start ?? legacy ?? fallbackStart).trim() || fallbackStart, + end: String(rawThumb.icon_end ?? fallbackEnd).trim() || fallbackEnd, + }; +}; + +/* -------------------------------------------------------------------------- */ +/* Runtime card: two thumb icons + hard button/body size constraint. */ +/* -------------------------------------------------------------------------- */ + +const cardClass = customElements.get("lotus-slide-card"); +if (cardClass && !cardClass.prototype.__lotusSlideLocalB1RuntimePatched) { + cardClass.prototype.__lotusSlideLocalB1RuntimePatched = true; + + const originalSetConfig = cardClass.prototype.setConfig; + cardClass.prototype.setConfig = function patchedSetConfig(config) { + const raw = config ? clone(config) : config; + const stateBefore = thumbStateFromRaw(raw || {}); + originalSetConfig.call(this, raw); + this._lotusThumbIcons = thumbStateFromRaw(raw || {}, this._config); + if (stateBefore.automatic === false) this._lotusThumbIcons.automatic = false; + + // The thumb must never protrude beyond the outside cross-dimension of the + // slider body. This also sanitizes hand-written YAML. + if (this._config?.thumb && this._config?.track) { + this._config.thumb.size = Math.min(Number(this._config.thumb.size) || 0, Number(this._config.track.thickness) || 0); + } + if (this._config?.icons?.thumb) { + this._config.icons.thumb.icon_start = this._lotusThumbIcons.start; + this._config.icons.thumb.icon_end = this._lotusThumbIcons.end; + this._config.icons.thumb.auto_direction = this._lotusThumbIcons.automatic; + this._config.icons.thumb.icon = this._lotusThumbIcons.start; + } + this._render(); + }; + + cardClass.prototype._thumbDirectionalIcon = function patchedThumbIcon() { + const state = this._lotusThumbIcons || thumbStateFromRaw(this._config, this._config); + let side = "start"; + if (this._config.mode === "two_state") { + const origin = this._dragging + ? (this._dragOrigin >= 0.5 ? 1 : 0) + : (this._progress >= 0.5 ? 1 : 0); + side = origin === 1 ? "end" : "start"; + } else { + side = this._progress * 100 >= this._config.threshold ? "end" : "start"; + } + if (state.automatic) return directionalThumbIcon(this._config, side); + return side === "end" ? state.end : state.start; + }; +} + +/* -------------------------------------------------------------------------- */ +/* Editor. */ +/* -------------------------------------------------------------------------- */ + +const editorClass = customElements.get("lotus-slide-card-editor"); +if (editorClass && !editorClass.prototype.__lotusSlideLocalB1EditorPatched) { + editorClass.prototype.__lotusSlideLocalB1EditorPatched = true; + + const originalSetConfig = editorClass.prototype.setConfig; + editorClass.prototype.setConfig = function patchedEditorSetConfig(config) { + this._lotusThumbIcons = thumbStateFromRaw(config || {}); + originalSetConfig.call(this, config); + this._lotusThumbIcons = thumbStateFromRaw(config || {}, this._config); + if (this._config?.thumb && this._config?.track) { + this._config.thumb.size = Math.min(Number(this._config.thumb.size) || 0, Number(this._config.track.thickness) || 0); + } + // Re-render once so the first visible editor already contains the local + // enhancements and the clamped geometry. + this._render(); + }; + + editorClass.prototype._emit = function patchedEmit() { + const config = clone(this._config); + config.icons ??= {}; + config.icons.thumb ??= {}; + const state = this._lotusThumbIcons || thumbStateFromRaw(config, config); + config.icons.thumb.icon = state.start; + config.icons.thumb.icon_start = state.start; + config.icons.thumb.icon_end = state.end; + config.icons.thumb.auto_direction = state.automatic; + this.dispatchEvent(new CustomEvent("config-changed", { + bubbles: true, + composed: true, + detail: { config }, + })); + }; + + const originalCommit = editorClass.prototype._commit; + editorClass.prototype._commit = function patchedCommit(mutator, options = {}) { + return originalCommit.call(this, (next) => { + mutator(next); + if (next?.thumb && next?.track) { + const trackThickness = clampValue(next.track.thickness, 18, 100); + next.track.thickness = trackThickness; + next.thumb.size = clampValue(next.thumb.size, 8, trackThickness); + } + }, options); + }; + + /* Deferred size/dimension inputs: commit only on Enter or blur. */ + const originalNumber = editorClass.prototype._number; + editorClass.prototype._number = function patchedNumber(parent, path, label, value, min, max, step, onChange, mode = "slider") { + if (path === "thumb.size") { + min = 8; + max = Math.max(8, Number(this._config?.track?.thickness) || 8); + } + if (!isDeferredSizePath(path)) { + return originalNumber.call(this, parent, path, label, value, min, max, step, onChange, mode); + } + + const wrap = document.createElement("label"); + wrap.className = "fallback-field lotus-deferred-number-field"; + wrap.dataset.fieldPath = path; + const span = document.createElement("span"); + span.textContent = lotusT(label); + const input = document.createElement("input"); + input.type = "number"; + input.inputMode = "decimal"; + input.value = value ?? ""; + if (Number.isFinite(Number(min))) input.min = String(min); + if (Number.isFinite(Number(max))) input.max = String(max); + if (Number.isFinite(Number(step)) && Number(step) > 0) input.step = String(step); + + const initial = Number(value); + const restore = () => { input.value = Number.isFinite(initial) ? String(initial) : String(value ?? ""); }; + const commit = () => { + const raw = String(input.value ?? "").trim().replace(",", "."); + if (!raw) { restore(); return; } + let next = Number(raw); + if (!Number.isFinite(next)) { restore(); return; } + const low = Number(min); + const high = Number(max); + if (Number.isFinite(low)) next = Math.max(low, next); + if (Number.isFinite(high)) next = Math.min(high, next); + const inc = Number(step); + if (Number.isFinite(inc) && inc > 0) { + const base = Number.isFinite(low) ? low : 0; + next = base + Math.round((next - base) / inc) * inc; + if (Number.isFinite(low)) next = Math.max(low, next); + if (Number.isFinite(high)) next = Math.min(high, next); + } + input.value = String(next); + if (!Number.isFinite(initial) || Math.abs(next - initial) > 1e-9) onChange(next); + }; + input.addEventListener("keydown", (event) => { + if (event.key === "Enter") { + event.preventDefault(); + input.blur(); + } else if (event.key === "Escape") { + event.preventDefault(); + restore(); + input.blur(); + } + }); + input.addEventListener("blur", commit); + wrap.append(span, input); + parent.appendChild(wrap); + return wrap; + }; + + /* Side visuals: explicit None / Icon / Image. */ + editorClass.prototype._renderSideVisualGroup = function patchedSideVisualGroup(parent, kind, title) { + const conf = this._config.icons[kind]; + this._lotusSideVisualDraft ??= Object.create(null); + const drafted = this._lotusSideVisualDraft[kind]; + const selected = sideHasPotentialVisual(conf) + ? conf.visual_type + : (["none", "icon", "image"].includes(drafted) ? drafted : "none"); + + const group = document.createElement("div"); + group.className = "subgroup"; + group.dataset.lotusVisualTarget = kind; + const h4 = document.createElement("h4"); + h4.textContent = lotusT(title); + group.appendChild(h4); + + this._select(group, `icons.${kind}.visual_type`, "Type visuel de l’extrémité", selected, + [["none", "Aucun"], ["icon", "Icône"], ["image", "Image"]], (value) => { + const nextType = ["icon", "image"].includes(value) ? value : "none"; + this._lotusSideVisualDraft[kind] = nextType; + if (nextType === "none") { + this._commit((c) => clearSideVisual(c.icons[kind])); + } else { + this._commit((c) => { c.icons[kind].visual_type = nextType; }); + } + }); + + if (selected === "none") { + parent.appendChild(group); + return; + } + + this._entityField(group, `icons.${kind}.state_entity`, "Entité source de l’état visuel (facultatif)", conf.state_entity, + (value) => this._commit((c) => { c.icons[kind].state_entity = value; })); + this._select(group, `icons.${kind}.state_mode`, "Mode de variation selon l’état", conf.state_mode, + [["static", "Visuel fixe"], ["binary", "Deux états → visuel"], ["integer", "Valeur entière → visuel"]], + (value) => this._commit((c) => { c.icons[kind].state_mode = ["binary", "integer"].includes(value) ? value : "static"; })); + + if (selected === "image") { + this._imagePicker(group, `icons.${kind}.image`, conf.state_mode === "static" ? "Image" : "Image de secours", conf.image, + (value) => this._commit((c) => { c.icons[kind].visual_type = "image"; c.icons[kind].image = value; })); + this._select(group, `icons.${kind}.image_fit`, "Ajustement de l’image", conf.image_fit, + [["contain", "Contenir"], ["cover", "Couvrir"], ["fill", "Étirer"]], + (value) => this._commit((c) => { c.icons[kind].image_fit = value; })); + } else { + this._icon(group, `icons.${kind}.icon`, conf.state_mode === "static" ? "Icône" : "Icône de secours", conf.icon, + (value) => this._commit((c) => { c.icons[kind].visual_type = "icon"; c.icons[kind].icon = value; })); + } + this._number(group, `icons.${kind}.size`, "Taille du visuel (%)", conf.size, 12, 100, 1, + (value) => this._commit((c) => { c.icons[kind].size = Number(value); })); + + if (conf.state_mode === "binary") { + for (const index of [1, 2]) { + const map = document.createElement("div"); + map.className = "state-map-row"; + this._text(map, `icons.${kind}.binary_state_${index}`, `Condition ${index}`, conf[`binary_state_${index}`], + (value) => this._commit((c) => { c.icons[kind][`binary_state_${index}`] = value; })); + if (selected === "image") { + this._imagePicker(map, `icons.${kind}.binary_image_${index}`, `Image ${index}`, conf[`binary_image_${index}`], + (value) => this._commit((c) => { c.icons[kind].visual_type = "image"; c.icons[kind][`binary_image_${index}`] = value; })); + } else { + this._icon(map, `icons.${kind}.binary_icon_${index}`, `Icône ${index}`, conf[`binary_icon_${index}`], + (value) => this._commit((c) => { c.icons[kind].visual_type = "icon"; c.icons[kind][`binary_icon_${index}`] = value; })); + this._color(map, `icons.${kind}.binary_color_${index}`, `Couleur ${index}`, conf[`binary_color_${index}`], + (value) => this._commit((c) => { c.icons[kind][`binary_color_${index}`] = value; }), true); + } + group.appendChild(map); + } + const helper = document.createElement("p"); + helper.className = "helper"; + helper.textContent = lotusT("OFF/0/false et ON/1/true sont reconnus comme états binaires équivalents. Les comparaisons numériques restent possibles."); + group.appendChild(helper); + } else if (conf.state_mode === "integer") { + this._number(group, `icons.${kind}.value_count`, "Nombre de valeurs", conf.value_count, 0, MAX_SIDE_VISUAL_VALUES, 1, + (value) => this._commit((c) => { + const side = c.icons[kind]; + const count = Math.max(0, Math.min(MAX_SIDE_VISUAL_VALUES, Math.floor(Number(value) || 0))); + const previous = Array.isArray(side.values) ? side.values : []; + side.value_count = count; + side.values = Array.from({ length: count }, (_, idx) => ({ + value: Number.isInteger(Number(previous[idx]?.value)) ? Number(previous[idx].value) : idx, + icon: String(previous[idx]?.icon ?? ""), + color: String(previous[idx]?.color ?? "state"), + image: String(previous[idx]?.image ?? ""), + })); + }), "box"); + for (let index = 0; index < conf.value_count; index += 1) { + const mapping = conf.values[index] ?? { value: index, icon: "", color: "state", image: "" }; + const map = document.createElement("div"); + map.className = "state-map-row"; + this._number(map, `icons.${kind}.values.${index}.value`, `Valeur ${index + 1}`, mapping.value, -999999, 999999, 1, + (value) => this._commit((c) => { c.icons[kind].values[index].value = Number(value); }), "box"); + if (selected === "image") { + this._imagePicker(map, `icons.${kind}.values.${index}.image`, `Image ${index + 1}`, mapping.image, + (value) => this._commit((c) => { c.icons[kind].visual_type = "image"; c.icons[kind].values[index].image = value; })); + } else { + this._icon(map, `icons.${kind}.values.${index}.icon`, `Icône ${index + 1}`, mapping.icon, + (value) => this._commit((c) => { c.icons[kind].visual_type = "icon"; c.icons[kind].values[index].icon = value; })); + this._color(map, `icons.${kind}.values.${index}.color`, `Couleur ${index + 1}`, mapping.color, + (value) => this._commit((c) => { c.icons[kind].values[index].color = value; }), true); + } + group.appendChild(map); + } + } + + this._boolean(group, `icons.${kind}.background.enabled`, "Afficher un fond derrière le visuel", conf.background.enabled, + (value) => this._commit((c) => { c.icons[kind].background.enabled = value; })); + if (conf.background.enabled) { + this._color(group, `icons.${kind}.background.color`, "Couleur du fond du visuel", conf.background.color, + (value) => this._commit((c) => { c.icons[kind].background.color = value; })); + this._number(group, `icons.${kind}.background.opacity`, "Opacité du fond (%)", conf.background.opacity, 0, 100, 1, + (value) => this._commit((c) => { c.icons[kind].background.opacity = Number(value); })); + this._number(group, `icons.${kind}.background.size`, "Taille du fond (%)", conf.background.size, 20, 100, 1, + (value) => this._commit((c) => { c.icons[kind].background.size = Number(value); })); + this._number(group, `icons.${kind}.background.radius`, "Arrondi du fond (%)", conf.background.radius, 0, 50, 1, + (value) => this._commit((c) => { c.icons[kind].background.radius = Number(value); })); + } + + if (selected === "icon" && conf.state_mode === "static") { + this._boolean(group, `icons.${kind}.dynamic`, "Couleur liée à la position du curseur", conf.dynamic, + (value) => this._commit((c) => { c.icons[kind].dynamic = value; })); + this._color(group, `icons.${kind}.color_start`, "Couleur au départ", conf.color_start, + (value) => this._commit((c) => { c.icons[kind].color_start = value; })); + if (conf.dynamic) { + this._color(group, `icons.${kind}.color_end`, "Couleur à l’arrivée", conf.color_end, + (value) => this._commit((c) => { c.icons[kind].color_end = value; })); + } + } + parent.appendChild(group); + }; + + /* Thumb editor: two configurable icons in both slider modes. */ + const originalRenderIconGroup = editorClass.prototype._renderIconGroup; + editorClass.prototype._renderIconGroup = function patchedIconGroup(parent, kind, title) { + if (kind !== "thumb") return originalRenderIconGroup.call(this, parent, kind, title); + + const conf = this._config.icons.thumb; + const state = this._lotusThumbIcons || thumbStateFromRaw(this._config, this._config); + this._lotusThumbIcons = state; + const group = document.createElement("div"); + group.className = "subgroup"; + group.dataset.lotusVisualTarget = "thumb"; + const h4 = document.createElement("h4"); + h4.textContent = lotusT(title); + group.appendChild(h4); + + this._boolean(group, "icons.thumb.auto_direction", "Adapter automatiquement les flèches à l’orientation", state.automatic, (value) => { + state.automatic = Boolean(value); + this._emit(); + this._render(); + }); + + const startShown = state.automatic ? directionalThumbIcon(this._config, "start") : state.start; + const endShown = state.automatic ? directionalThumbIcon(this._config, "end") : state.end; + this._icon(group, "icons.thumb.icon_start", "Icône du bouton côté départ", startShown, (value) => { + state.start = String(value || "") || directionalThumbIcon(this._config, "start"); + state.automatic = false; + this._emit(); + this._render(); + }); + this._icon(group, "icons.thumb.icon_end", "Icône du bouton côté arrivée", endShown, (value) => { + state.end = String(value || "") || directionalThumbIcon(this._config, "end"); + state.automatic = false; + this._emit(); + this._render(); + }); + + this._number(group, "icons.thumb.size", "Taille de l’icône (%)", conf.size, 12, 100, 1, + (value) => this._commit((c) => { c.icons.thumb.size = Number(value); })); + this._boolean(group, "icons.thumb.dynamic", "Couleur liée à la position du curseur", conf.dynamic, + (value) => this._commit((c) => { c.icons.thumb.dynamic = value; })); + this._color(group, "icons.thumb.color_start", "Couleur au départ", conf.color_start, + (value) => this._commit((c) => { c.icons.thumb.color_start = value; })); + if (conf.dynamic) { + this._color(group, "icons.thumb.color_end", "Couleur à l’arrivée", conf.color_end, + (value) => this._commit((c) => { c.icons.thumb.color_end = value; })); + } + parent.appendChild(group); + }; + + /* Section tagging allows contextual navigation without relying on translated text. */ + const SECTION_TARGETS = Object.freeze({ + "Nom": "general", + "Comportement": "general", + "Interaction": "interaction", + "Format responsive": "general", + "Corps / glissière du slider": "track", + "Bouton du slider": "thumb", + "Icônes et images d’extrémité": "visuals", + "Texte": "text", + "Action Home Assistant": "general", + "Actions des deux positions": "general", + }); + const originalSection = editorClass.prototype._section; + editorClass.prototype._section = function patchedSection(title, description = "") { + const section = originalSection.call(this, title, description); + section.dataset.lotusSectionSource = title; + section.dataset.lotusSectionTarget = SECTION_TARGETS[title] || "general"; + return section; + }; + + editorClass.prototype._lotusApplyContext = function applyContext() { + const pane = this.shadowRoot?.querySelector(".config-pane"); + if (!pane) return; + const selected = this._lotusSelection || "general"; + pane.querySelectorAll(".editor-section").forEach((section) => { + const target = section.dataset.lotusSectionTarget || "general"; + let visible = target === selected; + if (["start", "end"].includes(selected)) visible = target === "visuals"; + if (selected === "thumb" && target === "visuals") visible = true; + section.hidden = !visible; + if (target === "visuals") { + section.querySelectorAll(".subgroup").forEach((group) => { + const kind = group.dataset.lotusVisualTarget; + if (!kind) return; + group.hidden = selected === "thumb" ? kind !== "thumb" : (["start", "end"].includes(selected) ? kind !== selected : false); + }); + } + }); + pane.scrollTop = 0; + }; + + editorClass.prototype._lotusPreviewTargetFromEvent = function targetFromEvent(event) { + const path = typeof event.composedPath === "function" ? event.composedPath() : []; + const el = path.find((node) => node instanceof Element && ( + node.classList?.contains("slide-thumb") + || node.classList?.contains("slide-label") + || node.classList?.contains("slide-icon-zone") + || node.classList?.contains("slide-track") + )); + if (!el) return "general"; + if (el.classList.contains("slide-thumb")) return "thumb"; + if (el.classList.contains("slide-label")) return "text"; + if (el.classList.contains("slide-icon-zone")) return el.dataset.iconKind === "end" ? "end" : "start"; + if (el.classList.contains("slide-track")) return "track"; + return "general"; + }; + + editorClass.prototype._lotusPreviewElement = function previewElement(target = this._lotusSelection) { + const preview = this.shadowRoot?.querySelector("lotus-slide-card.slide-preview"); + const root = preview?.shadowRoot; + if (!preview || !root) return null; + if (target === "general") return preview; + if (target === "track") return root.querySelector(".slide-track"); + if (target === "thumb") return root.querySelector(".slide-thumb"); + if (target === "text") return root.querySelector(".slide-label"); + if (["start", "end"].includes(target)) { + const zone = root.querySelector(`.slide-icon-zone[data-icon-kind="${target}"]`); + return zone?.querySelector(".slide-side-icon,.slide-side-image") || zone; + } + return null; + }; + + editorClass.prototype._lotusMarkSelection = function markSelection() { + const root = this.shadowRoot?.querySelector("lotus-slide-card.slide-preview")?.shadowRoot; + if (!root) return; + root.querySelectorAll(".lotus-edit-selected").forEach((el) => el.classList.remove("lotus-edit-selected")); + if (this._lotusTestMode) return; + const target = this._lotusPreviewElement(); + target?.classList?.add("lotus-edit-selected"); + }; + + editorClass.prototype._lotusPositionResizeOverlay = function positionResizeOverlay() { + const overlay = this.shadowRoot?.querySelector(".lotus-resize-overlay"); + const frame = this.shadowRoot?.querySelector(".preview-frame"); + const target = this._lotusPreviewElement(); + if (!overlay || !frame || !target || this._lotusTestMode || this._lotusSelection === "interaction") { + if (overlay) overlay.hidden = true; + return; + } + if (["start", "end"].includes(this._lotusSelection) && !sideHasPotentialVisual(this._config.icons[this._lotusSelection])) { + overlay.hidden = true; + return; + } + const tr = target.getBoundingClientRect(); + const fr = frame.getBoundingClientRect(); + if (!(tr.width > 0 && tr.height > 0)) { overlay.hidden = true; return; } + overlay.hidden = false; + overlay.style.left = `${tr.left - fr.left}px`; + overlay.style.top = `${tr.top - fr.top}px`; + overlay.style.width = `${tr.width}px`; + overlay.style.height = `${tr.height}px`; + }; + + editorClass.prototype._lotusSelect = function select(target) { + if (this._lotusTestMode) return; + this._lotusSelection = target || "general"; + this._lotusApplyContext(); + this._lotusMarkSelection(); + this._lotusSyncToolbar(); + requestAnimationFrame(() => this._lotusPositionResizeOverlay()); + }; + + editorClass.prototype._lotusResizeDraft = function resizeDraft(session, event) { + const dx = event.clientX - session.x; + const dy = event.clientY - session.y; + const draft = clone(session.config); + const target = session.target; + if (target === "general") { + const rw = Math.max(0.1, (session.rect.width + dx) / Math.max(1, session.rect.width)); + const rh = Math.max(0.1, (session.rect.height + dy) / Math.max(1, session.rect.height)); + draft.design.width = clampValue(session.config.design.width * rw, 5, 200); + draft.design.height = clampValue(session.config.design.height * rh, 5, 200); + } else if (target === "track") { + const delta = this._config.orientation === "vertical" ? dx : dy; + const cross = this._config.orientation === "vertical" ? session.rect.width : session.rect.height; + draft.track.thickness = clampValue(session.config.track.thickness * Math.max(0.1, (cross + delta) / Math.max(1, cross)), 18, 100); + draft.thumb.size = Math.min(draft.thumb.size, draft.track.thickness); + } else if (target === "thumb") { + const ratio = Math.max(0.1, Math.max( + (session.rect.width + dx) / Math.max(1, session.rect.width), + (session.rect.height + dy) / Math.max(1, session.rect.height), + )); + draft.thumb.size = clampValue(session.config.thumb.size * ratio, 8, draft.track.thickness); + } else if (["start", "end"].includes(target)) { + const ratio = Math.max(0.1, Math.max( + (session.rect.width + dx) / Math.max(1, session.rect.width), + (session.rect.height + dy) / Math.max(1, session.rect.height), + )); + draft.icons[target].size = clampValue(session.config.icons[target].size * ratio, 12, 100); + } else if (target === "text") { + const ratio = Math.max(0.1, (session.rect.height + dy) / Math.max(1, session.rect.height)); + draft.text.font_size = clampValue(session.config.text.font_size * ratio, 8, 36); + } + return draft; + }; + + editorClass.prototype._lotusApplyResizePreview = function applyResizePreview(draft) { + const preview = this.shadowRoot?.querySelector("lotus-slide-card.slide-preview"); + if (!preview) return; + preview.setConfig(draft); + preview.hass = this._hass; + preview.preview = true; + if (this._lotusSelection === "general") preview.style.aspectRatio = `${draft.design.width}/${draft.design.height}`; + this._lotusMarkSelection(); + requestAnimationFrame(() => this._lotusPositionResizeOverlay()); + }; + + editorClass.prototype._lotusCommitResize = function commitResize(target, draft) { + this._commit((config) => { + if (target === "general") { + config.design.width = Math.round(draft.design.width * 100) / 100; + config.design.height = Math.round(draft.design.height * 100) / 100; + } else if (target === "track") { + config.track.thickness = Math.round(draft.track.thickness * 100) / 100; + config.thumb.size = Math.min(config.thumb.size, config.track.thickness); + } else if (target === "thumb") { + config.thumb.size = Math.min(Math.round(draft.thumb.size * 100) / 100, config.track.thickness); + } else if (["start", "end"].includes(target)) { + config.icons[target].size = Math.round(draft.icons[target].size * 100) / 100; + } else if (target === "text") { + config.text.font_size = Math.round(draft.text.font_size * 100) / 100; + } + }); + }; + + editorClass.prototype._lotusStartResize = function startResize(event) { + if (this._lotusTestMode) return; + const targetEl = this._lotusPreviewElement(); + if (!targetEl) return; + event.preventDefault(); + event.stopPropagation(); + const session = { + target: this._lotusSelection || "general", + x: event.clientX, + y: event.clientY, + rect: targetEl.getBoundingClientRect(), + config: clone(this._config), + draft: null, + }; + this._lotusResizeSession = session; + const move = (e) => { + e.preventDefault(); + session.draft = this._lotusResizeDraft(session, e); + this._lotusApplyResizePreview(session.draft); + }; + const end = (e) => { + e.preventDefault(); + window.removeEventListener("pointermove", move, true); + window.removeEventListener("pointerup", end, true); + window.removeEventListener("pointercancel", end, true); + this._lotusResizeSession = null; + if (session.draft) this._lotusCommitResize(session.target, session.draft); + else this._lotusPositionResizeOverlay(); + }; + window.addEventListener("pointermove", move, true); + window.addEventListener("pointerup", end, true); + window.addEventListener("pointercancel", end, true); + }; + + editorClass.prototype._lotusSideMeta = function sideMeta(kind) { + const vertical = this._config.orientation === "vertical"; + const reverse = this._config.reverse === true; + if (vertical) { + if (kind === "start") return { icon: reverse ? "mdi:chevron-up" : "mdi:chevron-down", label: reverse ? "Extrémité haute / départ" : "Extrémité basse / départ" }; + return { icon: reverse ? "mdi:chevron-down" : "mdi:chevron-up", label: reverse ? "Extrémité basse / arrivée" : "Extrémité haute / arrivée" }; + } + if (kind === "start") return { icon: reverse ? "mdi:chevron-right" : "mdi:chevron-left", label: reverse ? "Extrémité droite / départ" : "Extrémité gauche / départ" }; + return { icon: reverse ? "mdi:chevron-left" : "mdi:chevron-right", label: reverse ? "Extrémité gauche / arrivée" : "Extrémité droite / arrivée" }; + }; + + editorClass.prototype._lotusSyncToolbar = function syncToolbar() { + const toolbar = this.shadowRoot?.querySelector(".lotus-slide-toolbar"); + if (!toolbar) return; + toolbar.querySelectorAll("button[data-target]").forEach((button) => { + const active = !this._lotusTestMode && button.dataset.target === (this._lotusSelection || "general"); + button.classList.toggle("active", active); + button.disabled = this._lotusTestMode; + button.setAttribute("aria-pressed", active ? "true" : "false"); + }); + const test = toolbar.querySelector("button[data-test-toggle]"); + if (test) { + test.classList.toggle("test-active", Boolean(this._lotusTestMode)); + test.title = lotusT(this._lotusTestMode ? "Revenir au mode édition" : "Tester le slider"); + test.setAttribute("aria-label", test.title); + const icon = test.querySelector("ha-icon"); + icon?.setAttribute("icon", this._lotusTestMode ? "mdi:pencil" : "mdi:play-circle-outline"); + } + }; + + editorClass.prototype._lotusSetTestMode = function setTestMode(value) { + this._lotusTestMode = Boolean(value); + const preview = this.shadowRoot?.querySelector("lotus-slide-card.slide-preview"); + if (preview) preview.preview = true; // Simulation only: never call HA services from the editor. + this.shadowRoot?.querySelector(".preview-frame")?.classList.toggle("lotus-test-mode", this._lotusTestMode); + this.shadowRoot?.querySelector(".lotus-test-badge")?.toggleAttribute("hidden", !this._lotusTestMode); + this._lotusMarkSelection(); + this._lotusSyncToolbar(); + this._lotusPositionResizeOverlay(); + }; + + editorClass.prototype._lotusInstallEditorUi = function installEditorUi() { + const previewPane = this.shadowRoot?.querySelector(".preview-pane"); + const frame = this.shadowRoot?.querySelector(".preview-frame"); + const preview = this.shadowRoot?.querySelector("lotus-slide-card.slide-preview"); + const root = preview?.shadowRoot; + if (!previewPane || !frame || !preview || !root) return; + + // Runtime style inside the preview shadow root. + const runtimeStyle = document.createElement("style"); + runtimeStyle.dataset.lotusEditorUx = "1"; + runtimeStyle.textContent = ` + .slide-icon-zone,.slide-label { pointer-events:auto !important; } + .lotus-edit-selected { outline:2px solid var(--primary-color,#03a9f4) !important; outline-offset:3px !important; } + `; + root.appendChild(runtimeStyle); + + // Context toolbar. + const start = this._lotusSideMeta("start"); + const end = this._lotusSideMeta("end"); + const toolbar = document.createElement("div"); + toolbar.className = "lotus-slide-toolbar"; + toolbar.setAttribute("role", "toolbar"); + toolbar.setAttribute("aria-label", lotusT("Configuration du slider")); + const items = [ + ["general", "mdi:tune-variant", "Général"], + ["track", "mdi:minus-thick", "Corps / glissière du slider"], + ["start", start.icon, start.label], + ["thumb", "mdi:circle-double", "Bouton du slider"], + ["end", end.icon, end.label], + ["text", "mdi:format-text", "Texte"], + ["interaction", "mdi:gesture-tap", "Interaction"], + ]; + for (const [target, iconName, label] of items) { + const button = document.createElement("button"); + button.type = "button"; + button.dataset.target = target; + button.title = lotusT(label); + button.setAttribute("aria-label", lotusT(label)); + const icon = document.createElement("ha-icon"); + icon.setAttribute("icon", iconName); + button.appendChild(icon); + button.addEventListener("click", (e) => { e.preventDefault(); e.stopPropagation(); this._lotusSelect(target); }); + toolbar.appendChild(button); + } + const separator = document.createElement("span"); + separator.className = "lotus-toolbar-separator"; + toolbar.appendChild(separator); + const testButton = document.createElement("button"); + testButton.type = "button"; + testButton.dataset.testToggle = "1"; + testButton.className = "test-toggle"; + const testIcon = document.createElement("ha-icon"); + testIcon.setAttribute("icon", "mdi:play-circle-outline"); + testButton.appendChild(testIcon); + testButton.addEventListener("click", (e) => { + e.preventDefault(); + e.stopPropagation(); + this._lotusSetTestMode(!this._lotusTestMode); + }); + toolbar.appendChild(testButton); + previewPane.appendChild(toolbar); + + const badge = document.createElement("div"); + badge.className = "lotus-test-badge"; + badge.textContent = lotusT("MODE TEST — simulation, aucune action Home Assistant exécutée"); + badge.hidden = true; + previewPane.appendChild(badge); + + const overlay = document.createElement("div"); + overlay.className = "lotus-resize-overlay"; + overlay.innerHTML = '
'; + frame.appendChild(overlay); + overlay.querySelector(".lotus-resize-handle")?.addEventListener("pointerdown", (e) => this._lotusStartResize(e)); + + // In edit mode, clicking the mini editor selects a context. In test mode, + // the event is intentionally left untouched so Lotus Slide behaves normally. + root.addEventListener("pointerdown", (event) => { + if (this._lotusTestMode || this._lotusResizeSession) return; + const target = this._lotusPreviewTargetFromEvent(event); + event.preventDefault(); + event.stopImmediatePropagation(); + this._lotusSelect(target); + }, true); + frame.addEventListener("pointerdown", (event) => { + if (this._lotusTestMode || this._lotusResizeSession) return; + if (event.target === frame) this._lotusSelect("general"); + }); + + this._lotusApplyContext(); + this._lotusSetTestMode(Boolean(this._lotusTestMode)); + this._lotusSelect(this._lotusSelection || "general"); + }; + + const originalRender = editorClass.prototype._render; + editorClass.prototype._render = function patchedRender(...args) { + const selected = this._lotusSelection || "general"; + const testMode = Boolean(this._lotusTestMode); + const result = originalRender.apply(this, args); + this._lotusSelection = selected; + this._lotusTestMode = testMode; + + // The thumb size field must expose only values that fit in the current body. + const thumbInput = this.shadowRoot?.querySelector('[data-field-path="thumb.size"] input'); + if (thumbInput) thumbInput.max = String(this._config.track.thickness); + + const style = document.createElement("style"); + style.dataset.lotusSlideLocalUx = "1"; + style.textContent = ` + .editor-section[hidden], .subgroup[hidden], .lotus-test-badge[hidden], .lotus-resize-overlay[hidden] { display:none !important; } + .preview-title { top:58px !important; } + .preview-frame { padding-top:82px !important; } + .lotus-slide-toolbar { + position:absolute; top:8px; left:50%; transform:translateX(-50%); z-index:50; + display:flex; align-items:center; gap:4px; max-width:calc(100% - 20px); padding:5px; + border:1px solid var(--divider-color,rgba(127,127,127,.25)); border-radius:12px; + background:var(--card-background-color,#fff); box-shadow:0 2px 8px rgba(0,0,0,.12); overflow-x:auto; + } + .lotus-slide-toolbar button { + appearance:none; flex:0 0 auto; display:grid; place-items:center; width:34px; height:34px; padding:0; + border:1px solid transparent; border-radius:9px; color:var(--secondary-text-color,#727272); background:transparent; cursor:pointer; + } + .lotus-slide-toolbar button:hover:not(:disabled) { background:color-mix(in srgb,var(--primary-color,#03a9f4) 10%,transparent); color:var(--primary-text-color,#212121); } + .lotus-slide-toolbar button.active { color:var(--text-primary-color,#fff); background:var(--primary-color,#03a9f4); } + .lotus-slide-toolbar button:disabled { opacity:.35; cursor:default; } + .lotus-slide-toolbar button.test-toggle.test-active { color:var(--text-primary-color,#fff); background:var(--success-color,#43a047); } + .lotus-slide-toolbar ha-icon { --mdc-icon-size:20px; } + .lotus-toolbar-separator { width:1px; height:24px; margin:0 2px; background:var(--divider-color,rgba(127,127,127,.35)); flex:0 0 auto; } + .lotus-test-badge { + position:absolute; top:56px; left:50%; transform:translateX(-50%); z-index:45; white-space:nowrap; + padding:4px 9px; border-radius:999px; font-size:10px; font-weight:700; + color:var(--text-primary-color,#fff); background:var(--success-color,#43a047); pointer-events:none; + } + .lotus-resize-overlay { position:absolute; z-index:30; box-sizing:border-box; border:1px dashed var(--primary-color,#03a9f4); pointer-events:none; } + .lotus-resize-handle { + position:absolute; right:-7px; bottom:-7px; width:14px; height:14px; box-sizing:border-box; + border:2px solid var(--card-background-color,#fff); border-radius:50%; background:var(--primary-color,#03a9f4); + box-shadow:0 1px 4px rgba(0,0,0,.3); cursor:nwse-resize; pointer-events:auto; touch-action:none; + } + .preview-frame.lotus-test-mode { outline:2px solid color-mix(in srgb,var(--success-color,#43a047) 55%,transparent); outline-offset:-2px; } + @media (max-width:980px) { + .lotus-slide-toolbar { position:relative; top:auto; left:auto; transform:none; margin:0 auto 8px; width:max-content; max-width:100%; } + .preview-title { position:static !important; margin:0 0 8px !important; } + .preview-frame { padding-top:24px !important; } + .lotus-test-badge { position:relative; top:auto; left:auto; transform:none; width:max-content; max-width:100%; margin:0 auto 8px; } + } + `; + this.shadowRoot?.appendChild(style); + requestAnimationFrame(() => this._lotusInstallEditorUi()); + return result; + }; +} diff --git a/custom_components/lotus_view_studio/frontend/lotus-tabs-editor.js b/custom_components/lotus_view_studio/frontend/lotus-tabs-editor.js index 0f08e31..5e7847d 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-tabs-editor.js +++ b/custom_components/lotus_view_studio/frontend/lotus-tabs-editor.js @@ -5,13 +5,13 @@ import { lotusSlugify, lotusThemeCss, lotusTabEdgeBorderPath, -} from "./lotus-core.js?v=0.13.0b3"; +} from "./lotus-core.js?v=0.13.0b4"; import { lotusDebug, lotusLocalizeSelector, lotusSetHass, lotusT, -} from "./lotus-i18n.js?v=0.13.0b3"; +} from "./lotus-i18n.js?v=0.13.0b4"; const LOTUS_VIEW_META_KEY = "lotus_visual"; const LOTUS_TABS_KEY = "tabs"; diff --git a/custom_components/lotus_view_studio/frontend/lotus-view-editor-bridge.js b/custom_components/lotus_view_studio/frontend/lotus-view-editor-bridge.js index feac235..33d395b 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-view-editor-bridge.js +++ b/custom_components/lotus_view_studio/frontend/lotus-view-editor-bridge.js @@ -1,4 +1,4 @@ -import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b4"; const LOTUS_VIEW_TYPE = "custom:lotus-visual-layout"; const LOTUS_VIEW_LABEL = "Lotus View Studio"; diff --git a/custom_components/lotus_view_studio/frontend/lotus-visual-layout.js b/custom_components/lotus_view_studio/frontend/lotus-visual-layout.js index b485424..7be9f09 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-visual-layout.js +++ b/custom_components/lotus_view_studio/frontend/lotus-visual-layout.js @@ -9,10 +9,10 @@ import { makeIconButton, fireEvent, lotusTabEdgeBorderPath, -} from "./lotus-core.js?v=0.13.0b3"; -import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b3"; -import { registerLotusStackCard, registerLotusSlideCard, registerLotusDigicodeCard } from "./lotus-card-registry.js?v=0.13.0b3"; -import { openLotusTabsEditor } from "./lotus-tabs-editor.js?v=0.13.0b3"; +} from "./lotus-core.js?v=0.13.0b4"; +import { lotusDebug, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b4"; +import { registerLotusStackCard, registerLotusSlideCard, registerLotusDigicodeCard } from "./lotus-card-registry.js?v=0.13.0b4"; +import { openLotusTabsEditor } from "./lotus-tabs-editor.js?v=0.13.0b4"; const DEFAULT_LAYOUT = Object.freeze({ x: 2, y: 2, width: 30, height: 18, locked: false, z: 1 }); @@ -238,6 +238,31 @@ const slideConfigFromCard = (config) => { return null; }; +const makeFreshDigicodePinId = () => { + const suffix = globalThis.crypto?.randomUUID + ? globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, 12) + : Math.random().toString(36).slice(2, 14); + return `digicode_${suffix}`; +}; + +// A duplicated or pasted server-secured Digicode must never reuse the source +// server identity. The PIN itself is not in Lovelace, but pin_id points to the +// server-side PIN + protected action. Reusing it would make two visual cards +// share one security record. +const withFreshDigicodeServerIdentity = (cardConfig) => { + const copy = deepClone(cardConfig); + const digicode = digicodeConfigFromCard(copy); + const mode = String(digicode?.security?.mode ?? ""); + if (digicode && (mode === "server_plain" || mode === "server_encrypted")) { + digicode.security = { + ...(digicode.security && typeof digicode.security === "object" ? digicode.security : {}), + pin_id: makeFreshDigicodePinId(), + revision: 0, + }; + } + return copy; +}; + const modalBlockerEnabled = (config) => Boolean( digicodeConfigFromCard(config)?.interaction?.modal_blocker === true || slideConfigFromCard(config)?.interaction?.modal_blocker === true @@ -5358,7 +5383,7 @@ class LotusVisualLayout extends HTMLElement { }; if (!targetTabId) delete copyLayout.tab; - const cleanCopy = this._withCleanLotusLayout(deepClone(clipboard.card), copyLayout, insertedIndex); + const cleanCopy = this._withCleanLotusLayout(withFreshDigicodeServerIdentity(clipboard.card), copyLayout, insertedIndex); view.cards.push(cleanCopy); // The cards setter can be called by Home Assistant while saveConfig is @@ -5408,7 +5433,7 @@ class LotusVisualLayout extends HTMLElement { const original = view?.cards?.[this._selectedIndex]; if (!view || !original) return; - const copy = deepClone(original); + const copy = withFreshDigicodeServerIdentity(original); const sourceLayout = this._readStoredLayout(this._selectedIndex); const width = sourceLayout.width; const height = sourceLayout.height; diff --git a/custom_components/lotus_view_studio/frontend/lotus-visual-manager.js b/custom_components/lotus_view_studio/frontend/lotus-visual-manager.js index 5a7ab8c..3cd0eab 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-visual-manager.js +++ b/custom_components/lotus_view_studio/frontend/lotus-visual-manager.js @@ -4,7 +4,7 @@ import { lotusSlugify, lotusThemeCss, makeIconButton, -} from "./lotus-core.js?v=0.13.0b3"; +} from "./lotus-core.js?v=0.13.0b4"; import { LOTUS_LANGUAGES, lotusGetAutomaticLanguage, @@ -13,7 +13,7 @@ import { lotusSetHass, lotusSetLanguagePreference, lotusT, -} from "./lotus-i18n.js?v=0.13.0b3"; +} from "./lotus-i18n.js?v=0.13.0b4"; const LOTUS_BRAND_ICON_URL = `/lotus_view_studio_brand/icon.png?v=${LOTUS_VISUAL_VERSION}`; const DEFAULT_VIEW_ICON = "mdi:view-dashboard-outline"; diff --git a/custom_components/lotus_view_studio/frontend/lotus-visual-stack.js b/custom_components/lotus_view_studio/frontend/lotus-visual-stack.js index 8b87546..8625777 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-visual-stack.js +++ b/custom_components/lotus_view_studio/frontend/lotus-visual-stack.js @@ -1,5 +1,5 @@ -import { registerLotusStackCard } from "./lotus-card-registry.js?v=0.13.0b3"; -import { lotusDebug, lotusLocalizeSelector, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b3"; +import { registerLotusStackCard } from "./lotus-card-registry.js?v=0.13.0b4"; +import { lotusDebug, lotusLocalizeSelector, lotusSetHass, lotusT } from "./lotus-i18n.js?v=0.13.0b4"; /* diff --git a/custom_components/lotus_view_studio/frontend/lotus-visual.js b/custom_components/lotus_view_studio/frontend/lotus-visual.js index 3565391..bb87970 100644 --- a/custom_components/lotus_view_studio/frontend/lotus-visual.js +++ b/custom_components/lotus_view_studio/frontend/lotus-visual.js @@ -1,7 +1,7 @@ // Bootstrap version is intentionally local: the first import must itself be // cache-busted. A static import of lotus-core.js could otherwise survive an // integration upgrade in the browser ESM module map. -const LOTUS_VISUAL_BOOTSTRAP_VERSION = "0.13.0b3"; +const LOTUS_VISUAL_BOOTSTRAP_VERSION = "0.13.0b4"; await import(`./lotus-iconset.js?v=${LOTUS_VISUAL_BOOTSTRAP_VERSION}`); const { LOTUS_VISUAL_VERSION } = await import(`./lotus-core.js?v=${LOTUS_VISUAL_BOOTSTRAP_VERSION}`); @@ -22,12 +22,9 @@ await import(`./lotus-icon-size-bridge.js?v=${LOTUS_VISUAL_VERSION}`); // registrations are repaired even when a legacy element was loaded first. await import(`./lotus-visual-stack.js?v=${LOTUS_VISUAL_VERSION}`); await import(`./lotus-slide-card.js?v=${LOTUS_VISUAL_VERSION}`); -// 0.13.0b3 keeps the stable 1.3.0 runtime and the editor UX refinements -// introduced during the 0.13.0 beta cycle. -await import(`./lotus-slide-editor-b1.js?v=${LOTUS_VISUAL_VERSION}`); -await import(`./lotus-slide-editor-direct-b1.js?v=${LOTUS_VISUAL_VERSION}`); -await import(`./lotus-slide-editor-direct-fix-b1.js?v=${LOTUS_VISUAL_VERSION}`); +await import(`./lotus-slide-editor-ux-b4.js?v=${LOTUS_VISUAL_VERSION}`); await import(`./lotus-digicode-card.js?v=${LOTUS_VISUAL_VERSION}`); +await import(`./lotus-digicode-editor-ux-b4.js?v=${LOTUS_VISUAL_VERSION}`); if (!customElements.get("lotus-layers-card")) { await import(`./lotus-layers.js?v=${LOTUS_VISUAL_VERSION}`); } @@ -48,4 +45,4 @@ const lotusViewStudioApi = { }; window.LotusViewStudio = Object.assign(window.LotusViewStudio || {}, lotusViewStudioApi); // Backward-compatible global namespace for existing scripts and dashboards. -window.LotusVisual = Object.assign(window.LotusVisual || {}, lotusViewStudioApi); \ No newline at end of file +window.LotusVisual = Object.assign(window.LotusVisual || {}, lotusViewStudioApi); diff --git a/custom_components/lotus_view_studio/manifest.json b/custom_components/lotus_view_studio/manifest.json index fc4ffda..3c99b5c 100644 --- a/custom_components/lotus_view_studio/manifest.json +++ b/custom_components/lotus_view_studio/manifest.json @@ -18,5 +18,5 @@ "issue_tracker": "https://github.com/NALINFORGE/LotusViewStudio/issues", "requirements": [], "single_config_entry": true, - "version": "0.13.0b3" + "version": "0.13.0b4" }