/** * notion-enhancer * (c) 2023 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ "use strict"; import { Description } from "./Description.mjs"; function SidebarHeading({}, ...children) { const { html } = globalThis.__enhancerApi; return html`

${children}

`; } function SidebarButton({ id, icon, ...props }, ...children) { const { html, extendProps, setState, useState } = globalThis.__enhancerApi, $btn = html`<${props["href"] ? "a" : "button"} class="flex items-center select-none text-[14px] min-h-[27px] px-[12px] my-px last:mb-[12px] w-full transition hover:bg-[color:var(--theme--bg-hover)] disabled:hidden rounded-[3px]" ...${props} > ${icon ? html`` : ""} ${children} `; if (!props["href"]) { extendProps($btn, { onclick: () => setState({ transition: "fade", view: id }), }); useState(["view"], ([view = "welcome"]) => { const active = view.toLowerCase() === id.toLowerCase(); $btn.style.background = active ? "var(--theme--bg-hover)" : ""; $btn.style.fontWeight = active ? "600" : ""; }); } return $btn; } function Sidebar({ items, categories }) { const { html, useState } = globalThis.__enhancerApi, { version, initDatabase, isEnabled } = globalThis.__enhancerApi, $agreeToUnlock = html`To unlock the notion-enhancer's full functionality, agree to the privacy policy and terms & conditions on the welcome page. `, $sidebar = html``; useState(["rerender"], async () => { const agreedToTerms = await initDatabase().get("agreedToTerms"); $agreeToUnlock.style.display = agreedToTerms === version ? "none" : ""; [...$sidebar.children].forEach(($btn) => { if (!$btn.disableUntilAgreedToTerms) return; $btn.disabled = agreedToTerms !== version; }); }); for (const { title, mods } of categories) { const $title = html`<${SidebarHeading}>${title}`, $mods = mods .filter((mod) => mod.options?.length) .map((mod) => [ mod.id, html`<${SidebarButton} id=${mod.id}>${mod.name}`, ]); $sidebar.append($title, ...$mods.map(([, $btn]) => $btn)); useState(["rerender"], async () => { let sectionVisible = false; for (const [id, $btn] of $mods) { $btn.disabled = !(await isEnabled(id)); sectionVisible ||= !$btn.disabled; } $title.style.display = sectionVisible ? "" : "none"; }); } return $sidebar; } export { Sidebar };