Fix type errors and prettier

This commit is contained in:
arg3t 2025-07-31 14:53:50 +02:00
parent 43cfbaae22
commit 689b54a945
7 changed files with 18 additions and 22 deletions

View File

@ -169,7 +169,7 @@ document.addEventListener("render", (e) => {
// runs when content is rendered or re-rendered // runs when content is rendered or re-rendered
// e.detail.htmlElement contains the DOM element that was updated // e.detail.htmlElement contains the DOM element that was updated
const container = e.detail.htmlElement const container = e.detail.htmlElement
// attach event listeners to elements within this container // attach event listeners to elements within this container
const toggleSwitch = container.querySelector("#switch") as HTMLInputElement const toggleSwitch = container.querySelector("#switch") as HTMLInputElement
if (toggleSwitch) { if (toggleSwitch) {

View File

@ -15,16 +15,17 @@ document.addEventListener("nav", (e: CustomEventMap["nav"]) => {
// Access the current page URL // Access the current page URL
const currentUrl = e.detail.url const currentUrl = e.detail.url
console.log(`User navigated to: ${currentUrl}`) console.log(`User navigated to: ${currentUrl}`)
// Good for: // Good for:
// - Analytics tracking // - Analytics tracking
// - URL-dependent state updates // - URL-dependent state updates
// - Setting up page-level event handlers // - Setting up page-level event handlers
// - Theme/mode initialization // - Theme/mode initialization
}) })
``` ```
**When it fires:** **When it fires:**
- On initial page load - On initial page load
- On client-side navigation (if SPA routing is enabled) - On client-side navigation (if SPA routing is enabled)
- Does NOT fire on content re-renders - Does NOT fire on content re-renders
@ -37,11 +38,11 @@ The `render` event is fired when content needs to be processed or updated. This
document.addEventListener("render", (e: CustomEventMap["render"]) => { document.addEventListener("render", (e: CustomEventMap["render"]) => {
// Access the container that was updated // Access the container that was updated
const container = e.detail.htmlElement const container = e.detail.htmlElement
// Process elements within this container // Process elements within this container
const codeBlocks = container.querySelectorAll("pre code") const codeBlocks = container.querySelectorAll("pre code")
codeBlocks.forEach(addSyntaxHighlighting) codeBlocks.forEach(addSyntaxHighlighting)
// Good for: // Good for:
// - Setting up event listeners on new content // - Setting up event listeners on new content
// - Processing dynamic content (syntax highlighting, math rendering, etc.) // - Processing dynamic content (syntax highlighting, math rendering, etc.)
@ -50,6 +51,7 @@ document.addEventListener("render", (e: CustomEventMap["render"]) => {
``` ```
**When it fires:** **When it fires:**
- On initial page load (with `document.body` as the container) - On initial page load (with `document.body` as the container)
- When popover content is loaded - When popover content is loaded
- When search results are displayed - When search results are displayed
@ -106,10 +108,12 @@ Always clean up event handlers to prevent memory leaks:
```ts ```ts
addRenderListener((container) => { addRenderListener((container) => {
const buttons = container.querySelectorAll(".my-button") const buttons = container.querySelectorAll(".my-button")
const handleClick = (e) => { /* ... */ } const handleClick = (e) => {
/* ... */
buttons.forEach(button => { }
buttons.forEach((button) => {
button.addEventListener("click", handleClick) button.addEventListener("click", handleClick)
// Clean up when navigating away // Clean up when navigating away
window.addCleanup(() => { window.addCleanup(() => {
@ -168,4 +172,4 @@ addRenderListener((container) => {
}) })
``` ```
This provides cleaner separation of concerns and better performance. This provides cleaner separation of concerns and better performance.

View File

@ -291,12 +291,6 @@ document.addEventListener("prenav", async () => {
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
const currentSlug = e.detail.url const currentSlug = e.detail.url
const rerender = e.detail.rerender
// If this is secondary nav call, do not populate explorer again
if (rerender) {
return
}
await setupExplorer(currentSlug) await setupExplorer(currentSlug)

View File

@ -577,9 +577,6 @@ function cleanupGlobalGraphs() {
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
const slug = e.detail.url const slug = e.detail.url
// if we are rerendering, we can ignore this event
if (e.detail.rerender) return
addToVisited(simplifySlug(slug)) addToVisited(simplifySlug(slug))
async function renderLocalGraph() { async function renderLocalGraph() {

View File

@ -1,5 +1,5 @@
import { computePosition, flip, inline, shift } from "@floating-ui/dom" import { computePosition, flip, inline, shift } from "@floating-ui/dom"
import { FullSlug, normalizeRelativeURLs } from "../../util/path" import { normalizeRelativeURLs } from "../../util/path"
import { fetchCanonical, dispatchRenderEvent, addRenderListener } from "./util" import { fetchCanonical, dispatchRenderEvent, addRenderListener } from "./util"
const p = new DOMParser() const p = new DOMParser()

View File

@ -38,7 +38,7 @@ const getOpts = ({ target }: Event): { url: URL; scroll?: boolean } | undefined
function notifyNav(url: FullSlug) { function notifyNav(url: FullSlug) {
const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } }) const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } })
document.dispatchEvent(event) document.dispatchEvent(event)
// Also trigger render event for the whole document body // Also trigger render event for the whole document body
dispatchRenderEvent(document.body) dispatchRenderEvent(document.body)
} }

View File

@ -137,7 +137,8 @@
} }
// Hide the decrypt form when encrypted content appears in popover and search // Hide the decrypt form when encrypted content appears in popover and search
.search-space, .popover { .search-space,
.popover {
.encrypted-content .encryption-notice .decrypt-form { .encrypted-content .encryption-notice .decrypt-form {
display: none; display: none;
} }