refactor: implement scroll container context and flex layout

Switch from fixed positioning to a flexbox-based layout for the
main application structure. This introduces a `ScrollContainerCtx` to
provide access to the main scrollable element, allowing child
components like `FileTree` and `RevealManager` to perform accurate
scrolling and positioning relative to the container instead of the
window.

refactor: set JournalPanel height to full
This commit is contained in:
2026-07-08 15:03:31 +08:00
parent b54f7ab1fa
commit 5097aba842
5 changed files with 115 additions and 49 deletions
+13 -2
View File
@@ -1,6 +1,7 @@
import { Component, createMemo, createSignal, Show } from "solid-js";
import { type FileNode, type TocNode } from "../data-loader";
import { useNavigateWithParams } from "./useNavigateWithParams";
import { useScrollContainer } from "../App";
/**
* 检查当前文件路径是否在文件夹内
@@ -98,6 +99,8 @@ export const HeadingNode: Component<{
setIsExpanded(!isExpanded());
}
};
const scrollContainer = useScrollContainer();
const handleClick = (e: MouseEvent) => {
e.preventDefault();
navigate(href);
@@ -105,10 +108,18 @@ export const HeadingNode: Component<{
requestAnimationFrame(() => {
const element = document.getElementById(anchor);
if (element) {
const scroller = scrollContainer();
const navBarHeight = 80;
const elementPosition = element.getBoundingClientRect().top;
const offsetPosition = window.scrollY + elementPosition - navBarHeight;
window.scrollTo({ top: offsetPosition, behavior: "instant" });
const containerTop = scroller?.getBoundingClientRect().top ?? 0;
const relativePosition = elementPosition - containerTop;
const currentScroll = scroller?.scrollTop ?? window.scrollY;
const offsetPosition = currentScroll + relativePosition - navBarHeight;
if (scroller) {
scroller.scrollTo({ top: offsetPosition, behavior: "instant" });
} else {
window.scrollTo({ top: offsetPosition, behavior: "instant" });
}
}
});
};