Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Sep 27, 2024
1 parent 4df8d6b commit d535790
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
20 changes: 18 additions & 2 deletions modules/main/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const parser = usercssMeta.createParser({
mandatoryKeys: ["name"],
parseVar: { // Changes parser for checkbox so that it now returns a boolean. Ref: https://github.com/openstyles/usercss-meta/issues/93
checkbox: parseBool
},
validateVar: { // Changes validator for checkbox so that it now asserts a boolean.
checkbox: validateBool
}
});

Expand All @@ -19,8 +22,21 @@ function parseBool(state) {
state.value = true;
} else {
throw new usercssMeta.ParseError({
code: 'invalidBool',
message: 'value must be 0 or 1',
code: "invalidBool",
message: "value must be 0 or 1",
index: state.valueIndex
});
}
}
/**
* Validates a boolean value.
* @param {object} state The parser state.
*/
function validateBool(state) {
if (!state.value instanceof Boolean) {
throw new usercssMeta.ParseError({
code: "invalidCheckboxDefault",
message: "value must be 0 or 1",
index: state.valueIndex
});
}
Expand Down
13 changes: 7 additions & 6 deletions modules/renderer/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ function setValueToInput(varInput, value) {
break;
}
if (changed) {
log("setValueToInput changes to", value);
varInput.dispatchEvent(new Event("change", { bubbles: true }));
varInput.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { fromCallback: true } }));
}
}
/** Function to add a button to the right side of the setting item.
Expand Down Expand Up @@ -180,7 +179,7 @@ function createLinkedInputs(args) {
number.addEventListener("change", () => {
if (number.reportValidity()) {
range.value = number.value;
range.dispatchEvent(new Event("change", { bubbles: true }));
range.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { fromCallback: false } }));
}
});
return [range, number];
Expand Down Expand Up @@ -354,9 +353,11 @@ function addVar(details, path, name, varObj) {
varItem.textContent = varObj.label;
varItem.title = name;
const varInput = addVarInput(varItem, varObj);
varInput.addEventListener("change", () => {
if (varInput.reportValidity()) {
transitio.configChange(path, { [name]: getValueFromInput(varInput) });
varInput.addEventListener("change", (e) => {
if (!e.detail?.fromCallback && varInput.reportValidity()) {
const msg = { [name]: getValueFromInput(varInput) };
log("configChange", path, msg);
transitio.configChange(path, msg);
}
});
return varInput;
Expand Down

0 comments on commit d535790

Please sign in to comment.