From 3cea1a1cfefb5b8dc9483f2325c93078ea287792 Mon Sep 17 00:00:00 2001 From: Aaron Pham Date: Sat, 1 Feb 2025 12:24:46 -0500 Subject: [PATCH] chore: notify div on popover correctly Signed-off-by: Aaron Pham --- content/thoughts/Camus.md | 4 ++-- globals.d.ts | 1 + quartz/components/Evergreen.tsx | 4 ++-- quartz/components/pages/TagContent.tsx | 2 +- quartz/components/scripts/palette.inline.ts | 2 ++ quartz/components/scripts/popover.inline.ts | 22 ++++++++++++--------- quartz/components/scripts/spa.inline.ts | 1 + quartz/components/scripts/util.ts | 20 ++++++++++++++++++- quartz/components/styles/palette.scss | 16 ++++++++++----- quartz/components/styles/popover.scss | 4 ++-- 10 files changed, 54 insertions(+), 22 deletions(-) diff --git a/content/thoughts/Camus.md b/content/thoughts/Camus.md index 481c569e..266ed3e7 100644 --- a/content/thoughts/Camus.md +++ b/content/thoughts/Camus.md @@ -3,8 +3,8 @@ id: Camus tags: - philosophy date: "2024-02-28" -description: Camus, a scattered thoughts and notes. -modified: "2024-11-27" +description: and absurdism, create value by revolting against the nothingness of life. +modified: 2025-02-01 11:26:15 GMT-05:00 title: Camus --- diff --git a/globals.d.ts b/globals.d.ts index 164a70db..460089e4 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -13,6 +13,7 @@ export declare global { interface Window { spaNavigate(url: URL, isBack: boolean = false) + notifyNav(url: FullSlug) addCleanup(fn: (...args: any[]) => void) stacked: import("./quartz/plugins/types").Notes plausible: { diff --git a/quartz/components/Evergreen.tsx b/quartz/components/Evergreen.tsx index d5a7f716..5067c62d 100644 --- a/quartz/components/Evergreen.tsx +++ b/quartz/components/Evergreen.tsx @@ -66,7 +66,7 @@ const Notes = ((userOpts?: EvergreenNotes) => { href: resolveRelative(fileData.slug!, f.slug!), "data-list": true, class: "perma" }, [ h("div", { class: "title" }, [f.frontmatter?.title]), - h("div", { class: "description" }, [fileData.description!]), + h("div", { class: "description" }, [f.description!]), ], ), ), @@ -114,7 +114,6 @@ export default ((opts?: EvergreenNotes) => { return (
-

description

{content} @@ -124,6 +123,7 @@ export default ((opts?: EvergreenNotes) => { })}

+
) } diff --git a/quartz/components/pages/TagContent.tsx b/quartz/components/pages/TagContent.tsx index c4266d97..1e2e15e4 100644 --- a/quartz/components/pages/TagContent.tsx +++ b/quartz/components/pages/TagContent.tsx @@ -111,7 +111,7 @@ export default ((opts?: Partial) => { } return ( -
+
{content}

{i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}

diff --git a/quartz/components/scripts/palette.inline.ts b/quartz/components/scripts/palette.inline.ts index 8ce9696b..d1c4fa59 100644 --- a/quartz/components/scripts/palette.inline.ts +++ b/quartz/components/scripts/palette.inline.ts @@ -340,7 +340,9 @@ document.addEventListener("nav", async (e) => { if (!asidePanel || !currentHover) return await fetchContent(currentSlug, currentHover.dataset.slug as FullSlug).then((innerDiv) => { + asidePanel.dataset.slug = currentHover!.dataset.slug createSidePanel(asidePanel, ...innerDiv) + window.notifyNav(currentHover!.dataset.slug as FullSlug) hidePalette() }) return diff --git a/quartz/components/scripts/popover.inline.ts b/quartz/components/scripts/popover.inline.ts index b0623d96..c72089ca 100644 --- a/quartz/components/scripts/popover.inline.ts +++ b/quartz/components/scripts/popover.inline.ts @@ -1,5 +1,5 @@ import { arrow, computePosition, flip, inline, Placement, shift } from "@floating-ui/dom" -import { getFullSlug, normalizeRelativeURLs } from "../../util/path" +import { FullSlug, getFullSlug, normalizeRelativeURLs } from "../../util/path" import { getContentType } from "../../util/mime" import xmlFormat from "xml-formatter" import { createSidePanel, fetchCanonical } from "./util" @@ -147,8 +147,6 @@ async function handleDefaultContent( popoverInner.append(...elts) } -const checkFolderTagPage = () => window.document.body.dataset.isFolderTag === "true" - async function setPosition( link: HTMLElement, popoverElement: HTMLElement, @@ -186,11 +184,8 @@ async function setPosition( top: arrowY != null ? `${arrowY}px` : "", }) element.dataset.placement = staticSide - const isFolderTag = checkFolderTagPage() - if (staticSide === "top" && isFolderTag) { - element.style.top = "0px" - } else if (staticSide === "bottom" && isFolderTag) { - element.style.bottom = "0px" + if (staticSide === "right") { + element.style.right = "2px" } } @@ -367,7 +362,14 @@ async function mouseEnterHandler( return handleStackedNotes(container, link, { clientX, clientY }) } - const position = checkFolderTagPage() ? "bottom" : "right" + let position: Placement = "right" + // Check if link is within sidepanel + const isInSidepanel = link.closest(".sidepanel-inner") !== null + if (window.document.body.dataset.isFolderTag === "true") { + position = "left" + } else if (isInSidepanel) { + position = "top" + } if (hasAlreadyBeenFetched(link)) { if (hasPositionChanged(link)) { @@ -465,6 +467,7 @@ async function mouseClickHandler(evt: MouseEvent) { ) if (!asidePanel) return + asidePanel.dataset.slug = link.dataset.slug let response: Response | void if (link.dataset.arxivId) { @@ -496,6 +499,7 @@ async function mouseClickHandler(evt: MouseEvent) { createSidePanel(asidePanel, ...elts) } + window.notifyNav(link.dataset.slug as FullSlug) return } diff --git a/quartz/components/scripts/spa.inline.ts b/quartz/components/scripts/spa.inline.ts index 1ac76db6..ff29d4dc 100644 --- a/quartz/components/scripts/spa.inline.ts +++ b/quartz/components/scripts/spa.inline.ts @@ -734,6 +734,7 @@ async function navigate(url: URL, isBack: boolean = false) { } window.spaNavigate = navigate +window.notifyNav = notifyNav function createRouter() { if (typeof window !== "undefined") { diff --git a/quartz/components/scripts/util.ts b/quartz/components/scripts/util.ts index 8ead57b5..8d4204a4 100644 --- a/quartz/components/scripts/util.ts +++ b/quartz/components/scripts/util.ts @@ -1,4 +1,4 @@ -import { getFullSlug, SimpleSlug } from "../../util/path" +import { FullSlug, getFullSlug, resolveRelative } from "../../util/path" export function registerEscapeHandler(outsideContainer: HTMLElement | null, cb: () => void) { if (!outsideContainer) return @@ -336,6 +336,24 @@ export function createSidePanel(asidePanel: HTMLDivElement, ...inner: HTMLElemen } closeButton.addEventListener("click", onCloseClick) window.addCleanup(() => closeButton.removeEventListener("click", onCloseClick)) + + const redirectButton = document.createElement("button") + redirectButton.classList.add("redirect-button") + redirectButton.ariaLabel = "redirect to page" + redirectButton.title = "redirect to page" + redirectButton.innerHTML = `` + function onRedirectClick() { + window.spaNavigate( + new URL( + resolveRelative(getFullSlug(window), asidePanel.dataset.slug as FullSlug), + window.location.toString(), + ), + ) + } + redirectButton.addEventListener("click", onRedirectClick) + window.addCleanup(() => redirectButton.removeEventListener("click", onRedirectClick)) + + header.appendChild(redirectButton) header.appendChild(closeButton) const sideInner = document.createElement("div") diff --git a/quartz/components/styles/palette.scss b/quartz/components/styles/palette.scss index 00c5b800..0eb28b74 100644 --- a/quartz/components/styles/palette.scss +++ b/quartz/components/styles/palette.scss @@ -80,12 +80,16 @@ ul#helper { overflow: hidden auto; white-space: normal; - &[data-content-type*="pdf"] { + iframe { padding: 0; - max-height: 100%; - iframe { - width: 100%; - } + width: 100%; + height: 100%; + border-width: 0px; + } + + .notes-list, + div[data-pagelist] { + height: 100%; } & > * { @@ -138,6 +142,7 @@ ul#helper { & > .sidepanel-header { position: sticky; bottom: 0; + gap: 0.3em; display: flex; justify-content: flex-end; border-top: 1px solid var(--lightgray); @@ -148,6 +153,7 @@ ul#helper { 0 14px 50px rgba(27, 33, 48, 0.12), 0 10px 30px rgba(27, 33, 48, 0.16); + & > .redirect-button, & > .close-button { display: flex; align-items: center; diff --git a/quartz/components/styles/popover.scss b/quartz/components/styles/popover.scss index 7c7e0450..f410a15a 100644 --- a/quartz/components/styles/popover.scss +++ b/quartz/components/styles/popover.scss @@ -66,7 +66,7 @@ &::after { border-top-width: 1px; border-left-width: 1px; - transform: translate(12px); + transform: translate(12px, 12px); } } @@ -90,7 +90,7 @@ &::after { border-right-width: 1px; border-top-width: 1px; - transform: translate(2px, 2px); + transform: translate(-18px); } } }