diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e6edb8..19f8cc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,4 +5,8 @@ Added: Fixed: - Fonts looking blurry - Notification popups are now visible when the (dribbblish) settings are open -- Missing settings for on/off times for `Based on Time` dark mode (#107) \ No newline at end of file +- Missing settings for on/off times for `Based on Time` dark mode (#107) + +Improved: +- Settings that have been changed from default will now show a line next to them. Inspired by the [Visual Studio Code settings UI](https://d33wubrfki0l68.cloudfront.net/d1f1ea4def506997ced23d3d912154794e530e1c/063d2/assets/img/blog/2020-09-17-vscode-settings/settings-ui.png) +- Checkbox / Switch input styles are now more in line with other input styles \ No newline at end of file diff --git a/src/js/ConfigMenu.js b/src/js/ConfigMenu.js index b1f4bc3..d39a377 100644 --- a/src/js/ConfigMenu.js +++ b/src/js/ConfigMenu.js @@ -4,22 +4,22 @@ import MarkdownItAttrs from "markdown-it-attrs"; import svgUndo from "../svg/undo.svg"; -const IGNORED_TYPES = ["button"]; - export default class ConfigMenu { /** * @typedef {Object} DribbblishConfigItem - * @property {"checkbox" | "select" | "button" | "slider" | "number" | "text" | "time" | "color"} type + * @property {"checkbox" | "select" | "button" | "slider" | "number" | "text" | "textarea" | "time" | "color"} type * @property {String|DribbblishConfigArea} [area={name: "Main Settings", order: 0}] * @property {any} [data={}] * @property {Number} [order=0] order < 0 = Higher up | order > 0 = Lower Down - * @property {String} [key] defaults to $AREA_$NAME. e.g: About_Info + * @property {String} [key] defaults to `${area}_${name]`. e.g: About_Info * @property {String} name * @property {String} [description=""] * @property {any} [defaultValue] * @property {Boolean} [hidden=false] + * @property {Boolean} [resetButton=true] * @property {Boolean} [insertOnTop=false] * @property {Boolean} [fireInitialChange=true] + * @property {Boolean} [save=true] * @property {showChildren} [showChildren] * @property {onAppended} [onAppended] * @property {onChange} [onChange] @@ -104,7 +104,7 @@ export default class ConfigMenu { const parent = document.querySelector(`.dribbblish-config-area[name="${options.area.name}"] .dribbblish-config-area-items`); const elem = document.createElement("div"); - elem.style.order = options.order; + if (options.order != 0) elem.style.order = options.order; elem.classList.add("dribbblish-config-item"); elem.setAttribute("key", options.key); elem.setAttribute("type", options.type); @@ -117,7 +117,7 @@ export default class ConfigMenu {

${options.name} - ${IGNORED_TYPES.includes(options.type) ? "" : /* html */ ``} + ${options.resetButton ? /* html */ `` : ""}

@@ -166,8 +166,11 @@ export default class ConfigMenu { data: {}, name: "", description: "", + hidden: false, + resetButton: true, insertOnTop: false, fireInitialChange: true, + save: true, showChildren: () => true, onAppended: () => {}, onChange: () => {}, @@ -185,6 +188,7 @@ export default class ConfigMenu { .join("\n"); options._onChange = options.onChange; options.onChange = (val) => { + $(`.dribbblish-config-item[key="${options.key}"]`).attr("changed", options.save && val != options.defaultValue ? "" : null); options._onChange.call(options, val); const show = options.showChildren.call(options, val); options.children.forEach((child) => this.setHidden(child.key, Array.isArray(show) ? !show.includes(child.key) : !show)); @@ -205,7 +209,7 @@ export default class ConfigMenu { this.addInputHTML({ ...options, input }); $(`#dribbblish-config-input-${options.key}`).on("change", (e) => { - this.set(options.key, e.target.checked); + this.set(options.key, e.target.checked, options.save); options.onChange(this.get(options.key)); }); } else if (options.type == "select") { @@ -223,12 +227,14 @@ export default class ConfigMenu { this.addInputHTML({ ...options, input }); $(`#dribbblish-config-input-${options.key}`).on("change", (e) => { - this.set(options.key, e.target.value); + this.set(options.key, e.target.value, options.save); options.onChange(this.get(options.key)); }); } else if (options.type == "button") { - options.fireInitialChange = false; if (typeof options.data != "string") options.data = options.name; + options.fireInitialChange = false; + options.resetButton = false; + options.save = false; const input = /* html */ `