chore(menu): remove option type demos, fix(menu): support mods without options, feat(menu): override heading autoremove

This commit is contained in:
dragonwocky 2023-02-04 13:34:49 +11:00
parent 809b59ebb1
commit 0fff732fd9
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
7 changed files with 24 additions and 87 deletions

View File

@ -185,7 +185,6 @@ function Banner({ updateAvailable, isDevelopmentBuild }) {
$sponsorship.style.display = agreedToTerms === version ? "" : "none"; $sponsorship.style.display = agreedToTerms === version ? "" : "none";
}); });
// todo: show popup if update available
return html`<section class="notion-enhancer--menu-banner"> return html`<section class="notion-enhancer--menu-banner">
${$welcome}${$sponsorship} ${$welcome}${$sponsorship}
</section>`; </section>`;

View File

@ -22,14 +22,18 @@ const camelToSentenceCase = (string) =>
// ignore platform-specific options // ignore platform-specific options
if (opt.platforms && !opt.platforms.includes(platform)) return options; if (opt.platforms && !opt.platforms.includes(platform)) return options;
// replace consective headings // replace consective headings
const prev = options[options.length - 1]; opt.autoremove ??= true;
if (opt.type === "heading" && prev?.type === opt.type) { const prev = options[options.length - 1],
canReplacePrev = prev?.autoremove && prev?.type === opt.type;
if (opt.type === "heading" && canReplacePrev) {
options[options.length - 1] = opt; options[options.length - 1] = opt;
} else options.push(opt); } else options.push(opt);
return options; return options;
}, []); }, []);
// remove trailing heading // remove trailing heading
return options.at(-1)?.type === "heading" ? options.slice(0, -1) : options; return options.at(-1)?.type === "heading" && options.at(-1)?.autoremove
? options.slice(0, -1)
: options;
}; };
function Option({ _get, _set, ...opt }) { function Option({ _get, _set, ...opt }) {

View File

@ -86,10 +86,12 @@ function Sidebar({ items, categories }) {
for (const { title, mods } of categories) { for (const { title, mods } of categories) {
const $title = html`<${SidebarHeading}>${title}<//>`, const $title = html`<${SidebarHeading}>${title}<//>`,
$mods = mods.map((mod) => [ $mods = mods
mod.id, .filter((mod) => mod.options?.length)
html`<${SidebarButton} id=${mod.id}>${mod.name}<//>`, .map((mod) => [
]); mod.id,
html`<${SidebarButton} id=${mod.id}>${mod.name}<//>`,
]);
$sidebar.append($title, ...$mods.map(([, $btn]) => $btn)); $sidebar.append($title, ...$mods.map(([, $btn]) => $btn));
useState(["rerender"], async () => { useState(["rerender"], async () => {

View File

@ -33,17 +33,17 @@ function Telemetry() {
} }
}); });
// todo: actually collect telemetry
return html`<${Option} return html`<${Option}
type="toggle" type="toggle"
label="Telemetry" label="Telemetry"
description=${html`If telemetry is enabled, usage data will be collected description=${html`If telemetry is enabled, usage data will be collected at
once a week from your device in order to better understand how and where a regular interval from your device in order to better understand how and
the notion-enhancer is used. This data is anonymous and includes only your where the notion-enhancer is used. This data is anonymous and includes
platform (${$.platform}), notion-enhancer version (${$.version}), timezone only your platform (${$.platform}), notion-enhancer version
(${$.timezone}), and enabled mods (${$.enabledMods}). You can opt in or (${$.version}), timezone (${$.timezone}), and enabled mods
out of telemetry at any time. This setting syncs across configuration (${$.enabledMods}). You can opt in or out of telemetry at any time. This
profiles. For more information, read the notion-enhancer's setting syncs across configuration profiles. For more information, read
the notion-enhancer's
<a href=${privacyPolicy} class="ml-[3px]">privacy policy</a>.`} <a href=${privacyPolicy} class="ml-[3px]">privacy policy</a>.`}
...${{ _get, _set }} ...${{ _get, _set }}
/>`; />`;

View File

@ -103,7 +103,7 @@ const render = async () => {
} }
for (let i = 0; i < mods.length; i++) { for (let i = 0; i < mods.length; i++) {
const options = mods[i].options?.filter((opt) => opt.type !== "heading"); const options = mods[i].options?.filter((opt) => opt.type !== "heading");
if (mods[i]._src === "core" || !options.length) continue; if (mods[i]._src === "core" || !options?.length) continue;
const _get = () => isEnabled(mods[i].id), const _get = () => isEnabled(mods[i].id),
_set = async (enabled) => { _set = async (enabled) => {
await setEnabled(mods[i].id, enabled); await setEnabled(mods[i].id, enabled);

View File

@ -26,12 +26,6 @@
"type": "heading", "type": "heading",
"label": "Appearance" "label": "Appearance"
}, },
{
"type": "toggle",
"key": "toggle",
"description": "Sets whether the notion-enhancer icon added to Notion's sidebar should be coloured or monochrome. The latter style will match the theme's icon colour for users who would like the icon to be less noticeable.",
"value": true
},
{ {
"type": "select", "type": "select",
"key": "menuButtonIconStyle", "key": "menuButtonIconStyle",
@ -52,7 +46,8 @@
}, },
{ {
"type": "heading", "type": "heading",
"label": "Advanced" "label": "Advanced",
"autoremove": false
}, },
{ {
"type": "toggle", "type": "toggle",
@ -60,24 +55,6 @@
"description": "Activates built-in debugging tools accessible through the application menu.", "description": "Activates built-in debugging tools accessible through the application menu.",
"platforms": ["darwin", "win32", "linux"], "platforms": ["darwin", "win32", "linux"],
"value": false "value": false
},
{
"type": "color",
"key": "color",
"description": "Activates built-in debugging tools accessible through the application menu.",
"value": "rgb(232, 69, 93)"
},
{
"type": "text",
"key": "text",
"description": "Activates built-in debugging tools accessible through the application menu.",
"value": ""
},
{
"type": "number",
"key": "number",
"description": "Activates built-in debugging tools accessible through the application menu.",
"value": ""
} }
], ],
"clientStyles": ["variables.css"], "clientStyles": ["variables.css"],

View File

@ -12,50 +12,5 @@
"avatar": "https://dragonwocky.me/avatar.jpg" "avatar": "https://dragonwocky.me/avatar.jpg"
} }
], ],
"options": [
{
"type": "heading",
"label": "Hotkeys"
},
{
"type": "hotkey",
"key": "openMenuHotkey",
"description": "Opens the notion-enhancer menu from within Notion.",
"value": "Ctrl+Shift+,"
},
{
"type": "heading",
"label": "Appearance"
},
{
"type": "select",
"key": "menuButtonIconStyle",
"description": "Sets whether the notion-enhancer icon added to Notion's sidebar should be coloured or monochrome. The latter style will match the theme's icon colour for users who would like the icon to be less noticeable.",
"values": ["Colour", "Monochrome"]
},
{
"type": "select",
"key": "loadThemeOverrides",
"description": "Loads the styling required for a theme to customise Notion's interface. Disabling this will increase client performance.",
"values": ["Auto", "Enabled", "Disabled"]
},
{
"type": "file",
"key": "customStyles",
"description": "Adds the styles from an uploaded .css file to Notion. Use this if you would like to customise the current theme or <a href=\"https://notion-enhancer.github.io/advanced/tweaks\">otherwise tweak Notion's appearance</a>.",
"extensions": ["css"]
},
{
"type": "heading",
"label": "Advanced"
},
{
"type": "toggle",
"key": "debugMode",
"description": "Activates built-in debugging tools accessible through the application menu.",
"platforms": ["darwin", "win32", "linux"],
"value": false
}
],
"clientStyles": ["client.css"] "clientStyles": ["client.css"]
} }