Skip to content

Commit

Permalink
v1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Clooos authored Oct 28, 2023
1 parent 534ce87 commit 4d5b6c4
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/bubble-card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var version = 'v1.4.0';
var version = 'v1.4.1';

let editor;
let entityStates = {};
Expand Down Expand Up @@ -114,12 +114,39 @@ class BubbleCard extends HTMLElement {
return hasStateChanged;
}

// const addStyles = function(context, styles, customStyles, state, entityId, stateChangedVar, path = '', element = context.content) {
// const customStylesEval = customStyles ? eval('`' + customStyles + '`') : '';
// let styleAddedKey = styles + 'Added'; // Add 'Added' at the end of the styles value

// // Check if the style has changed
// if (!context[styleAddedKey] || context.previousStyle !== customStylesEval || stateChangedVar) {
// if (!context[styleAddedKey]) {
// // Check if the style element already exists
// context.styleElement = element.querySelector('style'); //context.content
// if (!context.styleElement) {
// // If not, create a new style element
// context.styleElement = document.createElement('style');
// const parentElement = (path ? element.querySelector(path) : element);
// parentElement?.appendChild(context.styleElement);
// }
// context[styleAddedKey] = true;
// }

// // Update the content of the existing style element only if styles have changed
// if (context.styleElement.innerHTML !== customStylesEval + styles) {
// context.styleElement.innerHTML = customStylesEval + styles;
// }

// context.previousStyle = customStylesEval; // Store the current style
// }
// }

const addStyles = function(context, styles, customStyles, state, entityId, stateChangedVar, path = '', element = context.content) {
const customStylesEval = customStyles ? eval('`' + customStyles + '`') : '';
let styleAddedKey = styles + 'Added'; // Add 'Added' at the end of the styles value

// Check if the style has changed
if (!context[styleAddedKey] || context.previousStyle !== customStylesEval || stateChangedVar) {
if (!context[styleAddedKey] || context.previousStyle !== customStylesEval || stateChangedVar || context.previousConfig !== context.config) {
if (!context[styleAddedKey]) {
// Check if the style element already exists
context.styleElement = element.querySelector('style'); //context.content
Expand All @@ -138,6 +165,7 @@ class BubbleCard extends HTMLElement {
}

context.previousStyle = customStylesEval; // Store the current style
context.previousConfig = context.config; // Store the current config
}
}

Expand Down Expand Up @@ -1372,8 +1400,9 @@ class BubbleCard extends HTMLElement {
}
}

if (buttonStateChanged) {
if (buttonStateChanged || this.wasEditing) {
updateStyle(state, this);
this.wasEditing = false;
}

const buttonStyles = `
Expand Down Expand Up @@ -2527,7 +2556,7 @@ class BubbleCardEditor extends LitElement {
});
}

// Working for sliders but add more issues, to be fixed
// Working for sliders (setting to 0) but add more issues, to be fixed
// _valueChanged(ev) {
// if (!this._config || !this.hass) {
// return;
Expand All @@ -2552,9 +2581,11 @@ class BubbleCardEditor extends LitElement {
const target = ev.target;
const detail = ev.detail;
if (target.configValue) {
if (target.value === "" || target.checked === false) {
const { [target.configValue]: _, ...rest } = this._config;
this._config = rest;
if (target.type === 'ha-switch') {
this._config = {
...this._config,
[target.configValue]: target.checked,
}
} else {
this._config = {
...this._config,
Expand Down

0 comments on commit 4d5b6c4

Please sign in to comment.