Skip to content

Commit

Permalink
chore: notify div on popover correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
  • Loading branch information
aarnphm committed Feb 1, 2025
1 parent aeea555 commit 3cea1a1
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 22 deletions.
4 changes: 2 additions & 2 deletions content/thoughts/Camus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand Down
1 change: 1 addition & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions quartz/components/Evergreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!]),
],
),
),
Expand Down Expand Up @@ -114,7 +114,6 @@ export default ((opts?: EvergreenNotes) => {
return (
<div class="evergreen-content">
<Permanent {...props} />
<AllTags {...props} opts />
<article style={{ marginBottom: 0 }}>
<h3 class="note-title">description</h3>
{content}
Expand All @@ -124,6 +123,7 @@ export default ((opts?: EvergreenNotes) => {
})}
</p>
</article>
<AllTags {...props} opts />
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion quartz/components/pages/TagContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default ((opts?: Partial<TagContentOptions>) => {
}

return (
<div class={classes}>
<div class={classes} data-pagelist>
<article>{content}</article>
<div class="page-listing">
<p>{i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}</p>
Expand Down
2 changes: 2 additions & 0 deletions quartz/components/scripts/palette.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions quartz/components/scripts/popover.inline.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
}
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -496,6 +499,7 @@ async function mouseClickHandler(evt: MouseEvent) {

createSidePanel(asidePanel, ...elts)
}
window.notifyNav(link.dataset.slug as FullSlug)
return
}

Expand Down
1 change: 1 addition & 0 deletions quartz/components/scripts/spa.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ async function navigate(url: URL, isBack: boolean = false) {
}

window.spaNavigate = navigate
window.notifyNav = notifyNav

function createRouter() {
if (typeof window !== "undefined") {
Expand Down
20 changes: 19 additions & 1 deletion quartz/components/scripts/util.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = `<svg xmlns="http://www.w3.org/2000/svg" width=16 height=16 viewbox="0 0 24 24" fill="var(--gray)" stroke="none"><use href="#triple-dots"></svg>`
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")
Expand Down
16 changes: 11 additions & 5 deletions quartz/components/styles/palette.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}

& > * {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions quartz/components/styles/popover.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
&::after {
border-top-width: 1px;
border-left-width: 1px;
transform: translate(12px);
transform: translate(12px, 12px);
}
}

Expand All @@ -90,7 +90,7 @@
&::after {
border-right-width: 1px;
border-top-width: 1px;
transform: translate(2px, 2px);
transform: translate(-18px);
}
}
}
Expand Down

0 comments on commit 3cea1a1

Please sign in to comment.