fix: prevent double updateUI, move imports to top, label for attributes
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { initEingabe } from './eingabe.js';
|
||||
|
||||
// Globaler State — aktive Farbe als { h, s, l } (HSL, 0-360, 0-100, 0-100)
|
||||
// state.color is read-only from outside — always use setColor() to update,
|
||||
// so that the colorChanged event is dispatched to all listening modules.
|
||||
@@ -22,8 +24,6 @@ document.querySelectorAll('.tab-btn').forEach(btn => {
|
||||
});
|
||||
});
|
||||
|
||||
import { initEingabe } from './eingabe.js';
|
||||
|
||||
function addFavorit(hsl) { console.log('addFavorit', hsl); }
|
||||
function addColorToSchema(hsl) { console.log('addColorToSchema', hsl); }
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hexToRgb, rgbToHex, hexToHsl, hslToHex, hslToRgb, rgbToHsl } from './converter.js';
|
||||
import { hexToHsl, hslToHex, hslToRgb, rgbToHsl } from './converter.js';
|
||||
import { state } from './app.js';
|
||||
|
||||
function hslToDisplay({ h, s, l }) { return h + ', ' + s + '%, ' + l + '%'; }
|
||||
@@ -39,7 +39,6 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(val)) {
|
||||
const hsl = hexToHsl(val);
|
||||
state.setColor(hsl);
|
||||
updateUI(hsl);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -48,7 +47,6 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
|
||||
if (rgb) {
|
||||
const hsl = rgbToHsl(rgb);
|
||||
state.setColor(hsl);
|
||||
updateUI(hsl);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -56,11 +54,16 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
|
||||
const hsl = parseHsl(hslInput.value);
|
||||
if (hsl) {
|
||||
state.setColor(hsl);
|
||||
updateUI(hsl);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('colorChanged', () => updateUI(state.color));
|
||||
document.addEventListener('colorChanged', () => {
|
||||
if (document.activeElement !== hexInput &&
|
||||
document.activeElement !== rgbInput &&
|
||||
document.activeElement !== hslInput) {
|
||||
updateUI(state.color);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('eingabe-fav-btn').addEventListener('click', () => {
|
||||
onSaveFavorit(state.color);
|
||||
|
||||
Reference in New Issue
Block a user