feat(web): unify reader TOC and bookmarks into one left nav drawer with tabs
This commit is contained in:
@@ -13,11 +13,11 @@ The format loosely follows Keep a Changelog and can be adapted to the team's hab
|
|||||||
- CBZ reader is now chapter-scoped: a chapter's images flow as one continuous strip and scrolling stops at an 本章完 · 下一章 card (only chapter buttons / TOC / slider / bookmarks cross the boundary); a 连读 toggle makes scrolling flow across chapters, and a configurable 0–3-chapter prefetch pre-mounts upcoming chapters for instant switching — the old 连读/整页/适高 mode cycle is gone.
|
- CBZ reader is now chapter-scoped: a chapter's images flow as one continuous strip and scrolling stops at an 本章完 · 下一章 card (only chapter buttons / TOC / slider / bookmarks cross the boundary); a 连读 toggle makes scrolling flow across chapters, and a configurable 0–3-chapter prefetch pre-mounts upcoming chapters for instant switching — the old 连读/整页/适高 mode cycle is gone.
|
||||||
- CBZ 阅读器改为以章为单位:一章图片是一段连续长卷,滚动止于「本章完 · 下一章」卡片(跨章只能靠章节按钮/目录/滑条/书签);「连读」开关让滑动贯穿章节,预读 0–3 章可配置、提前挂载解码实现切章零白屏;移除原 连读/整页/适高 三档循环。
|
- CBZ 阅读器改为以章为单位:一章图片是一段连续长卷,滚动止于「本章完 · 下一章」卡片(跨章只能靠章节按钮/目录/滑条/书签);「连读」开关让滑动贯穿章节,预读 0–3 章可配置、提前挂载解码实现切章零白屏;移除原 连读/整页/适高 三档循环。
|
||||||
|
|
||||||
- Bookmarks in all four readers: a 书签 button in the bar captures the current position (page / chapter+offset / EPUB CFI) with an optional note; the right-side panel lists them — click jumps straight back to that spot, ✎ edits the note in place, ✕ deletes. Bookmarks are per-user and server-side, so they follow you across devices.
|
- Bookmarks in all four readers: a 书签 button in the bar captures the current position (page / chapter+offset / EPUB CFI) with an optional note; the 书签 tab of the left navigation drawer lists them — click jumps straight back to that spot, ✎ edits the note in place, ✕ deletes. Bookmarks are per-user and server-side, so they follow you across devices.
|
||||||
- 四类阅读器新增书签:工具条「书签」按钮把当前位置(页码/章节+章内偏移/EPUB CFI)连同可选备注存下;右侧书签面板点一下即跳回原位,✎ 行内改备注,✕ 删除。书签按用户存在服务端,换设备同账号即见。
|
- 四类阅读器新增书签:工具条「书签」按钮把当前位置(页码/章节+章内偏移/EPUB CFI)连同可选备注存下;左侧导航抽屉的「书签」选项卡内点一下即跳回原位,✎ 行内改备注,✕ 删除。书签按用户存在服务端,换设备同账号即见。
|
||||||
|
|
||||||
- Folder-structured comics gain a 目录 sidebar in the CBZ reader: each archive folder (第N話…) becomes a chapter that jumps to its first page, with 上一章/下一章 buttons, a current-chapter counter, and the active row highlighted and scrolled into view — flat archives show no extra UI.
|
- Folder-structured comics gain a 目录 tab in the CBZ reader's navigation drawer: each archive folder (第N話…) becomes a chapter that jumps to its first page, with 上一章/下一章 buttons, a current-chapter counter, and the active row highlighted and scrolled into view — flat archives show no extra UI.
|
||||||
- 按目录组织的漫画在 CBZ 阅读器新增「目录」侧栏:压缩包内每个文件夹(第N話…)即一章,点击直达该话首页;工具条配上一章/下一章与当前章计数,目录内高亮当前章并自动居中;平铺无目录的包不显示多余控件。
|
- 按目录组织的漫画在 CBZ 阅读器导航抽屉内新增「目录」选项卡:压缩包内每个文件夹(第N話…)即一章,点击直达该话首页;工具条配上一章/下一章与当前章计数,目录内高亮当前章并自动居中;平铺无目录的包不显示多余控件。
|
||||||
|
|
||||||
- Library uploads over 16MB now auto-switch to the resumable chunked protocol (8MB parts): failed parts retry in place up to 3 times and already-sent parts are skipped, so a flaky upload continues instead of starting over; small files keep the original single request.
|
- Library uploads over 16MB now auto-switch to the resumable chunked protocol (8MB parts): failed parts retry in place up to 3 times and already-sent parts are skipped, so a flaky upload continues instead of starting over; small files keep the original single request.
|
||||||
- 书库上传超过 16MB 自动切换为可续传分片协议(每片 8MB):失败的分片原地重试至多 3 次,已传片自动跳过,中断后继续而不是从头再来;小文件仍走原单次上传。
|
- 书库上传超过 16MB 自动切换为可续传分片协议(每片 8MB):失败的分片原地重试至多 3 次,已传片自动跳过,中断后继续而不是从头再来;小文件仍走原单次上传。
|
||||||
@@ -31,6 +31,9 @@ The format loosely follows Keep a Changelog and can be adapted to the team's hab
|
|||||||
|
|
||||||
### Changed / 变更
|
### Changed / 变更
|
||||||
|
|
||||||
|
- Reader navigation tightened into one left-side drawer: 目录 and 书签 are now tabs of a single sidebar shared by all four readers, following the reader theme's colors (books without a TOC — flat archives, EPUB, PDF — show the bookmarks panel alone); the separate right-side bookmark panel and the per-reader TOC popovers are gone.
|
||||||
|
- 阅读器导航收紧为统一左侧抽屉:目录与书签成为四个阅读器共用的同一侧边栏内的两个选项卡,配色跟随阅读器主题(无目录的书——平铺包、EPUB、PDF——仅显示书签面板);原右侧书签面板与各阅读器自绘目录浮层移除。
|
||||||
|
|
||||||
- The web UI was rebuilt on a shadcn/Radix design system: semantic light/dark theme tokens with a system/light/dark switcher (remembered), a persistent app shell (desktop sidebar, tablet icon rail, mobile bottom tabs), a shelf driven by URL-state search/sort/group controls with a flat-first grid and menu-based card actions (confirm dialogs replace native popups), and rebuilt login/admin pages. Readers keep their current chrome and every reading interaction this round; their restyle lands next.
|
- The web UI was rebuilt on a shadcn/Radix design system: semantic light/dark theme tokens with a system/light/dark switcher (remembered), a persistent app shell (desktop sidebar, tablet icon rail, mobile bottom tabs), a shelf driven by URL-state search/sort/group controls with a flat-first grid and menu-based card actions (confirm dialogs replace native popups), and rebuilt login/admin pages. Readers keep their current chrome and every reading interaction this round; their restyle lands next.
|
||||||
- 网页 UI 以 shadcn/Radix 设计系统重做:语义化明暗主题 token + 系统/浅色/深色切换(记忆);常驻应用壳(桌面侧栏、平板图标栏、手机底部标签);书架改为 URL 状态驱动的搜索/排序/分组工具条,默认平铺网格,卡片操作收进菜单(删除改为对话框确认);登录页与 admin 两页同步重做。阅读器保持现状,改版随下一期到达。
|
- 网页 UI 以 shadcn/Radix 设计系统重做:语义化明暗主题 token + 系统/浅色/深色切换(记忆);常驻应用壳(桌面侧栏、平板图标栏、手机底部标签);书架改为 URL 状态驱动的搜索/排序/分组工具条,默认平铺网格,卡片操作收进菜单(删除改为对话框确认);登录页与 admin 两页同步重做。阅读器保持现状,改版随下一期到达。
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useState, type ReactNode } from "react";
|
import { useState } from "react";
|
||||||
import { api } from "../api/client";
|
import { api } from "../api/client";
|
||||||
import type { Book } from "../api/types";
|
import type { Book } from "../api/types";
|
||||||
import { toast } from "./Toaster";
|
import { toast } from "./Toaster";
|
||||||
|
|
||||||
type Locator = Record<string, unknown>;
|
type Locator = Record<string, unknown>;
|
||||||
|
|
||||||
export function useBookmarks(opts: {
|
/** 书签面板内容(供 ReaderNav 的「书签」选项卡承载);跳转后由调用方负责关抽屉. */
|
||||||
|
export function BookmarksTab({
|
||||||
|
book,
|
||||||
|
capture,
|
||||||
|
seek,
|
||||||
|
}: {
|
||||||
book: Book;
|
book: Book;
|
||||||
capture: () => { locator: Locator; percent: number };
|
capture: () => { locator: Locator; percent: number };
|
||||||
seek: (locator: Locator) => void;
|
seek: (locator: Locator) => void;
|
||||||
}): { btn: ReactNode; panel: ReactNode } {
|
}) {
|
||||||
const { book, capture, seek } = opts;
|
|
||||||
const qc = useQueryClient();
|
const qc = useQueryClient();
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const [note, setNote] = useState("");
|
const [note, setNote] = useState("");
|
||||||
const [editId, setEditId] = useState<number | null>(null);
|
const [editId, setEditId] = useState<number | null>(null);
|
||||||
const [editVal, setEditVal] = useState("");
|
const [editVal, setEditVal] = useState("");
|
||||||
@@ -48,107 +51,84 @@ export function useBookmarks(opts: {
|
|||||||
onError: fail,
|
onError: fail,
|
||||||
});
|
});
|
||||||
|
|
||||||
const btn = (
|
return (
|
||||||
<button
|
|
||||||
className="rd-btn"
|
|
||||||
aria-expanded={open}
|
|
||||||
aria-controls="bm-panel"
|
|
||||||
onClick={() => setOpen((v) => !v)}
|
|
||||||
>
|
|
||||||
书签{items.length ? ` ${items.length}` : ""}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
|
|
||||||
const panel = open ? (
|
|
||||||
<>
|
<>
|
||||||
<div className="fixed inset-0 z-30" aria-hidden="true" onClick={() => setOpen(false)} />
|
<div className="mb-2 flex items-center gap-1.5">
|
||||||
<nav
|
<input
|
||||||
id="bm-panel"
|
className="min-w-0 flex-1 rounded-md border border-stone-700 bg-stone-900 px-2 py-1 text-sm text-stone-100 placeholder:text-stone-500"
|
||||||
aria-label="书签"
|
placeholder="备注(可空)"
|
||||||
className="rd-divider absolute inset-y-0 right-0 z-40 flex w-72 flex-col border-l bg-[var(--rd-bg)] p-2 shadow-2xl"
|
maxLength={500}
|
||||||
>
|
value={note}
|
||||||
<div className="mb-2 flex items-center gap-1.5">
|
onChange={(e) => setNote(e.target.value)}
|
||||||
<input
|
onKeyDown={(e) => {
|
||||||
className="min-w-0 flex-1 rounded-md border border-stone-700 bg-stone-900 px-2 py-1 text-sm text-stone-100 placeholder:text-stone-500"
|
if (e.key === "Enter" && !add.isPending) add.mutate();
|
||||||
placeholder="备注(可空)"
|
}}
|
||||||
maxLength={500}
|
/>
|
||||||
value={note}
|
<button className="rd-btn shrink-0" disabled={add.isPending} onClick={() => add.mutate()}>
|
||||||
onChange={(e) => setNote(e.target.value)}
|
加
|
||||||
onKeyDown={(e) => {
|
</button>
|
||||||
if (e.key === "Enter" && !add.isPending) add.mutate();
|
</div>
|
||||||
}}
|
<ul className="space-y-0.5">
|
||||||
/>
|
{q.isPending && <li className="p-2 text-xs text-stone-500">加载中…</li>}
|
||||||
<button className="rd-btn shrink-0" disabled={add.isPending} onClick={() => add.mutate()}>
|
{!q.isPending && items.length === 0 && (
|
||||||
加
|
<li className="p-2 text-xs text-stone-500">还没有书签,读到想记的位置点「加」</li>
|
||||||
</button>
|
)}
|
||||||
</div>
|
{items.map((b) => (
|
||||||
<ul className="min-h-0 flex-1 space-y-0.5 overflow-y-auto">
|
<li key={b.id}>
|
||||||
{q.isPending && <li className="p-2 text-xs text-stone-500">加载中…</li>}
|
{editId === b.id ? (
|
||||||
{!q.isPending && items.length === 0 && (
|
<div className="flex items-center gap-1">
|
||||||
<li className="p-2 text-xs text-stone-500">还没有书签,读到想记的位置点「加」</li>
|
<input
|
||||||
)}
|
className="min-w-0 flex-1 rounded-md border border-stone-700 bg-stone-900 px-2 py-1 text-sm text-stone-100"
|
||||||
{items.map((b) => (
|
maxLength={500}
|
||||||
<li key={b.id}>
|
value={editVal}
|
||||||
{editId === b.id ? (
|
onChange={(e) => setEditVal(e.target.value)}
|
||||||
<div className="flex items-center gap-1">
|
onKeyDown={(e) => {
|
||||||
<input
|
if (e.key === "Enter" && !patch.isPending) patch.mutate({ id: b.id, note: editVal.trim() });
|
||||||
className="min-w-0 flex-1 rounded-md border border-stone-700 bg-stone-900 px-2 py-1 text-sm text-stone-100"
|
}}
|
||||||
maxLength={500}
|
/>
|
||||||
value={editVal}
|
<button
|
||||||
onChange={(e) => setEditVal(e.target.value)}
|
className="rd-btn shrink-0"
|
||||||
onKeyDown={(e) => {
|
disabled={patch.isPending}
|
||||||
if (e.key === "Enter" && !patch.isPending) patch.mutate({ id: b.id, note: editVal.trim() });
|
onClick={() => patch.mutate({ id: b.id, note: editVal.trim() })}
|
||||||
}}
|
>
|
||||||
/>
|
✓
|
||||||
<button
|
</button>
|
||||||
className="rd-btn shrink-0"
|
<button className="rd-btn shrink-0" onClick={() => setEditId(null)}>
|
||||||
disabled={patch.isPending}
|
✕
|
||||||
onClick={() => patch.mutate({ id: b.id, note: editVal.trim() })}
|
</button>
|
||||||
>
|
</div>
|
||||||
✓
|
) : (
|
||||||
</button>
|
<div className="group flex items-center">
|
||||||
<button className="rd-btn shrink-0" onClick={() => setEditId(null)}>
|
<button
|
||||||
✕
|
className="rd-row min-w-0 flex-1 truncate text-left"
|
||||||
</button>
|
title={b.note || undefined}
|
||||||
</div>
|
onClick={() => seek(b.locator)}
|
||||||
) : (
|
>
|
||||||
<div className="group flex items-center">
|
<span className="tabular-nums opacity-70">{Math.round(b.percent * 100)}%</span>{" "}
|
||||||
<button
|
{b.note || <span className="opacity-50">{b.created_at.slice(0, 10)}</span>}
|
||||||
className="rd-row min-w-0 flex-1 truncate text-left"
|
</button>
|
||||||
title={b.note || undefined}
|
<button
|
||||||
onClick={() => {
|
className="rd-btn m-0.5 shrink-0 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100"
|
||||||
seek(b.locator);
|
aria-label="改备注"
|
||||||
setOpen(false);
|
onClick={() => {
|
||||||
}}
|
setEditId(b.id);
|
||||||
>
|
setEditVal(b.note);
|
||||||
<span className="tabular-nums opacity-70">{Math.round(b.percent * 100)}%</span>{" "}
|
}}
|
||||||
{b.note || <span className="opacity-50">{b.created_at.slice(0, 10)}</span>}
|
>
|
||||||
</button>
|
✎
|
||||||
<button
|
</button>
|
||||||
className="rd-btn m-0.5 shrink-0 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100"
|
<button
|
||||||
aria-label="改备注"
|
className="rd-btn m-0.5 shrink-0 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100"
|
||||||
onClick={() => {
|
aria-label="删除书签"
|
||||||
setEditId(b.id);
|
onClick={() => del.mutate(b.id)}
|
||||||
setEditVal(b.note);
|
>
|
||||||
}}
|
✕
|
||||||
>
|
</button>
|
||||||
✎
|
</div>
|
||||||
</button>
|
)}
|
||||||
<button
|
</li>
|
||||||
className="rd-btn m-0.5 shrink-0 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100"
|
))}
|
||||||
aria-label="删除书签"
|
</ul>
|
||||||
onClick={() => del.mutate(b.id)}
|
|
||||||
>
|
|
||||||
✕
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</>
|
</>
|
||||||
) : null;
|
);
|
||||||
|
|
||||||
return { btn, panel };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
|
export type NavTab = "toc" | "bm";
|
||||||
|
|
||||||
|
/** 阅读器左侧导航抽屉:目录/书签选项卡;不传 toc 则退化为纯书签面板. */
|
||||||
|
export function ReaderNav({
|
||||||
|
tab,
|
||||||
|
onTab,
|
||||||
|
onClose,
|
||||||
|
toc,
|
||||||
|
bookmarks,
|
||||||
|
}: {
|
||||||
|
tab: NavTab;
|
||||||
|
onTab?: (t: NavTab) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
toc?: ReactNode;
|
||||||
|
bookmarks: ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="fixed inset-0 z-30" aria-hidden="true" onClick={onClose} />
|
||||||
|
<nav
|
||||||
|
id="reader-nav"
|
||||||
|
aria-label="导航"
|
||||||
|
className="rd-divider absolute inset-y-0 left-0 z-40 flex w-72 flex-col border-r bg-[var(--rd-bg,#171512)] shadow-2xl"
|
||||||
|
style={{ color: "var(--rd-fg,#c6c0b6)" }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
role={toc != null ? "tablist" : undefined}
|
||||||
|
aria-label="导航选项卡"
|
||||||
|
className="rd-divider flex shrink-0 items-center gap-1 border-b p-2"
|
||||||
|
>
|
||||||
|
{toc != null ? (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
role="tab"
|
||||||
|
aria-selected={tab === "toc"}
|
||||||
|
className={"rd-btn" + (tab === "toc" ? " rd-btn-on" : "")}
|
||||||
|
onClick={() => onTab?.("toc")}
|
||||||
|
>
|
||||||
|
目录
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
role="tab"
|
||||||
|
aria-selected={tab === "bm"}
|
||||||
|
className={"rd-btn" + (tab === "bm" ? " rd-btn-on" : "")}
|
||||||
|
onClick={() => onTab?.("bm")}
|
||||||
|
>
|
||||||
|
书签
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className="rd-btn rd-btn-on">书签</span>
|
||||||
|
)}
|
||||||
|
<button className="rd-btn ml-auto" aria-label="关闭导航" onClick={onClose}>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="min-h-0 flex-1 overflow-y-auto p-2">{tab === "toc" ? toc : bookmarks}</div>
|
||||||
|
</nav>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,7 +2,8 @@ import { useQuery } from "@tanstack/react-query";
|
|||||||
import { useEffect, useMemo, useRef, useState, type MouseEvent } from "react";
|
import { useEffect, useMemo, useRef, useState, type MouseEvent } from "react";
|
||||||
import { api, formatPageUrl } from "../api/client";
|
import { api, formatPageUrl } from "../api/client";
|
||||||
import { btn } from "../components/ui";
|
import { btn } from "../components/ui";
|
||||||
import { useBookmarks } from "../components/Bookmarks";
|
import { BookmarksTab } from "../components/Bookmarks";
|
||||||
|
import { ReaderNav, type NavTab } from "../components/reader-nav";
|
||||||
import { fetchObjectUrl } from "../lib/authImage";
|
import { fetchObjectUrl } from "../lib/authImage";
|
||||||
import { useProgressSaver, type ReaderProps } from "../lib/useProgress";
|
import { useProgressSaver, type ReaderProps } from "../lib/useProgress";
|
||||||
import { PageHeights, chapterIndexAt, chapterWin } from "../lib/virt";
|
import { PageHeights, chapterIndexAt, chapterWin } from "../lib/virt";
|
||||||
@@ -79,10 +80,9 @@ export default function CbzReader({ book, initialLocator, initialPercent, chrome
|
|||||||
});
|
});
|
||||||
const count = countQ.data?.count ?? 0;
|
const count = countQ.data?.count ?? 0;
|
||||||
const chapters = countQ.data?.chapters ?? null; // 包内目录结构(第N話/上中下卷);null/单组=扁平整本一章
|
const chapters = countQ.data?.chapters ?? null; // 包内目录结构(第N話/上中下卷);null/单组=扁平整本一章
|
||||||
const [toc, setToc] = useState(false);
|
const [nav, setNav] = useState<null | NavTab>(null);
|
||||||
const activeRow = useRef<HTMLButtonElement>(null);
|
const activeRow = useRef<HTMLButtonElement>(null);
|
||||||
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
||||||
const bm = useBookmarks({ book, capture: saver.capture, seek: (l) => goPage(Number(l.page) || 0) });
|
|
||||||
const boxRef = useRef<HTMLDivElement>(null);
|
const boxRef = useRef<HTMLDivElement>(null);
|
||||||
const [width, setWidth] = useState(480);
|
const [width, setWidth] = useState(480);
|
||||||
const [vh, setVh] = useState(600);
|
const [vh, setVh] = useState(600);
|
||||||
@@ -190,8 +190,8 @@ export default function CbzReader({ book, initialLocator, initialPercent, chrome
|
|||||||
const cur = locked ? Math.min(curRaw, w.end - 1) : curRaw; // 锁章:视口落在章末卡片上时读数不越章(HUD/滑条/进度)
|
const cur = locked ? Math.min(curRaw, w.end - 1) : curRaw; // 锁章:视口落在章末卡片上时读数不越章(HUD/滑条/进度)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (toc) activeRow.current?.scrollIntoView({ block: "center" });
|
if (nav === "toc") activeRow.current?.scrollIntoView({ block: "center" });
|
||||||
}, [toc]);
|
}, [nav]);
|
||||||
|
|
||||||
function scrollToPage(i: number, smooth: boolean) {
|
function scrollToPage(i: number, smooth: boolean) {
|
||||||
const el = boxRef.current;
|
const el = boxRef.current;
|
||||||
@@ -358,10 +358,22 @@ export default function CbzReader({ book, initialLocator, initialPercent, chrome
|
|||||||
预读 {prefetch} 章
|
预读 {prefetch} 章
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{bm.btn}
|
<button
|
||||||
|
className="rd-btn"
|
||||||
|
aria-expanded={nav === "bm"}
|
||||||
|
aria-controls="reader-nav"
|
||||||
|
onClick={() => setNav(nav === "bm" ? null : "bm")}
|
||||||
|
>
|
||||||
|
书签
|
||||||
|
</button>
|
||||||
{chapters && (
|
{chapters && (
|
||||||
<>
|
<>
|
||||||
<button className="rd-btn" aria-expanded={toc} aria-controls="cbz-toc" onClick={() => setToc((v) => !v)}>
|
<button
|
||||||
|
className="rd-btn"
|
||||||
|
aria-expanded={nav === "toc"}
|
||||||
|
aria-controls="reader-nav"
|
||||||
|
onClick={() => setNav(nav === "toc" ? null : "toc")}
|
||||||
|
>
|
||||||
目录
|
目录
|
||||||
</button>
|
</button>
|
||||||
<span className="text-xs tabular-nums opacity-60">
|
<span className="text-xs tabular-nums opacity-60">
|
||||||
@@ -389,34 +401,43 @@ export default function CbzReader({ book, initialLocator, initialPercent, chrome
|
|||||||
<span className="opacity-60">{Math.round(((cur + 1) / Math.max(1, count)) * 100)}%</span>
|
<span className="opacity-60">{Math.round(((cur + 1) / Math.max(1, count)) * 100)}%</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{toc && chapters && (
|
{nav && (
|
||||||
<>
|
<ReaderNav
|
||||||
<div className="fixed inset-0 z-10" aria-hidden="true" onClick={() => setToc(false)} />
|
tab={chapters ? nav : "bm"}
|
||||||
<nav
|
onTab={setNav}
|
||||||
id="cbz-toc"
|
onClose={() => setNav(null)}
|
||||||
aria-label="章节目录"
|
bookmarks={
|
||||||
className="rd-divider absolute inset-y-0 left-0 z-20 w-64 overflow-y-auto border-r bg-[var(--rd-bg)] p-2 shadow-2xl"
|
<BookmarksTab
|
||||||
>
|
book={book}
|
||||||
<ul className="space-y-0.5">
|
capture={saver.capture}
|
||||||
{chapters.map((c, i) => (
|
seek={(l) => {
|
||||||
<li key={i}>
|
goPage(Number(l.page) || 0);
|
||||||
<button
|
setNav(null);
|
||||||
ref={i === ci ? activeRow : undefined}
|
}}
|
||||||
className={"rd-row" + (i === ci ? " rd-btn-on" : "")}
|
/>
|
||||||
onClick={() => {
|
}
|
||||||
goPage(c.start);
|
toc={
|
||||||
setToc(false);
|
chapters && (
|
||||||
}}
|
<ul className="space-y-0.5">
|
||||||
>
|
{chapters.map((c, i) => (
|
||||||
{i + 1}. {c.title}
|
<li key={i}>
|
||||||
</button>
|
<button
|
||||||
</li>
|
ref={i === ci ? activeRow : undefined}
|
||||||
))}
|
className={"rd-row" + (i === ci ? " rd-btn-on" : "")}
|
||||||
</ul>
|
onClick={() => {
|
||||||
</nav>
|
goPage(c.start);
|
||||||
</>
|
setNav(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i + 1}. {c.title}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{bm.panel}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { apiRaw } from "../api/client";
|
import { apiRaw } from "../api/client";
|
||||||
import { useBookmarks } from "../components/Bookmarks";
|
import { BookmarksTab } from "../components/Bookmarks";
|
||||||
|
import { ReaderNav } from "../components/reader-nav";
|
||||||
import { btn } from "../components/ui";
|
import { btn } from "../components/ui";
|
||||||
import { toast } from "../components/Toaster";
|
import { toast } from "../components/Toaster";
|
||||||
import { useProgressSaver, type ReaderProps } from "../lib/useProgress";
|
import { useProgressSaver, type ReaderProps } from "../lib/useProgress";
|
||||||
@@ -32,15 +33,7 @@ export default function EpubReader({ book, initialLocator, initialPercent }: Rea
|
|||||||
const hostRef = useRef<HTMLDivElement>(null);
|
const hostRef = useRef<HTMLDivElement>(null);
|
||||||
const rendRef = useRef<EpubRendition | null>(null);
|
const rendRef = useRef<EpubRendition | null>(null);
|
||||||
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
||||||
const bm = useBookmarks({
|
const [nav, setNav] = useState(false);
|
||||||
book,
|
|
||||||
capture: saver.capture,
|
|
||||||
seek: (l) => {
|
|
||||||
const cfi = String(l.cfi ?? "");
|
|
||||||
if (!cfi) return;
|
|
||||||
Promise.resolve(rendRef.current?.display(cfi)).catch(() => toast("err", "书签定位失败"));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const [err, setErr] = useState("");
|
const [err, setErr] = useState("");
|
||||||
const [nonce, setNonce] = useState(0);
|
const [nonce, setNonce] = useState(0);
|
||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(false);
|
||||||
@@ -113,9 +106,28 @@ export default function EpubReader({ book, initialLocator, initialPercent }: Rea
|
|||||||
<button className={btn} onClick={() => rendRef.current?.next()}>
|
<button className={btn} onClick={() => rendRef.current?.next()}>
|
||||||
下一页
|
下一页
|
||||||
</button>
|
</button>
|
||||||
{bm.btn}
|
<button className="rd-btn" aria-expanded={nav} aria-controls="reader-nav" onClick={() => setNav((v) => !v)}>
|
||||||
|
书签
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{bm.panel}
|
{nav && (
|
||||||
|
<ReaderNav
|
||||||
|
tab="bm"
|
||||||
|
onClose={() => setNav(false)}
|
||||||
|
bookmarks={
|
||||||
|
<BookmarksTab
|
||||||
|
book={book}
|
||||||
|
capture={saver.capture}
|
||||||
|
seek={(l) => {
|
||||||
|
const cfi = String(l.cfi ?? "");
|
||||||
|
setNav(false);
|
||||||
|
if (!cfi) return;
|
||||||
|
Promise.resolve(rendRef.current?.display(cfi)).catch(() => toast("err", "书签定位失败"));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { useEffect, useRef, useState, type KeyboardEvent } from "react";
|
import { useEffect, useRef, useState, type KeyboardEvent } from "react";
|
||||||
import * as pdfjs from "pdfjs-dist";
|
import * as pdfjs from "pdfjs-dist";
|
||||||
import { apiRaw } from "../api/client";
|
import { apiRaw } from "../api/client";
|
||||||
import { useBookmarks } from "../components/Bookmarks";
|
import { BookmarksTab } from "../components/Bookmarks";
|
||||||
|
import { ReaderNav } from "../components/reader-nav";
|
||||||
import { btn } from "../components/ui";
|
import { btn } from "../components/ui";
|
||||||
import { useProgressSaver, type ReaderProps } from "../lib/useProgress";
|
import { useProgressSaver, type ReaderProps } from "../lib/useProgress";
|
||||||
|
|
||||||
@@ -21,14 +22,7 @@ export default function PdfReader({ book, initialLocator, initialPercent }: Read
|
|||||||
const taskRef = useRef<RenderTask | null>(null);
|
const taskRef = useRef<RenderTask | null>(null);
|
||||||
const restored = useRef(false);
|
const restored = useRef(false);
|
||||||
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
||||||
const bm = useBookmarks({
|
const [nav, setNav] = useState(false);
|
||||||
book,
|
|
||||||
capture: saver.capture,
|
|
||||||
seek: (l) => {
|
|
||||||
const p = Number(l.page);
|
|
||||||
if (Number.isInteger(p) && p >= 0 && p < num) setPage(p);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const [num, setNum] = useState(0);
|
const [num, setNum] = useState(0);
|
||||||
const [page, setPage] = useState(0); // 0 基
|
const [page, setPage] = useState(0); // 0 基
|
||||||
const [err, setErr] = useState("");
|
const [err, setErr] = useState("");
|
||||||
@@ -160,9 +154,27 @@ export default function PdfReader({ book, initialLocator, initialPercent }: Read
|
|||||||
<button className={btn} disabled={page >= num - 1} onClick={() => setPage(num - 1)} aria-label="最后一页">
|
<button className={btn} disabled={page >= num - 1} onClick={() => setPage(num - 1)} aria-label="最后一页">
|
||||||
末页
|
末页
|
||||||
</button>
|
</button>
|
||||||
{bm.btn}
|
<button className="rd-btn" aria-expanded={nav} aria-controls="reader-nav" onClick={() => setNav((v) => !v)}>
|
||||||
|
书签
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{bm.panel}
|
{nav && (
|
||||||
|
<ReaderNav
|
||||||
|
tab="bm"
|
||||||
|
onClose={() => setNav(false)}
|
||||||
|
bookmarks={
|
||||||
|
<BookmarksTab
|
||||||
|
book={book}
|
||||||
|
capture={saver.capture}
|
||||||
|
seek={(l) => {
|
||||||
|
const p = Number(l.page);
|
||||||
|
setNav(false);
|
||||||
|
if (Number.isInteger(p) && p >= 0 && p < num) setPage(p);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import DOMPurify from "dompurify";
|
|||||||
import { marked } from "marked";
|
import { marked } from "marked";
|
||||||
import { useEffect, useMemo, useRef, useState, type MouseEvent, type ReactNode } from "react";
|
import { useEffect, useMemo, useRef, useState, type MouseEvent, type ReactNode } from "react";
|
||||||
import { apiRaw } from "../api/client";
|
import { apiRaw } from "../api/client";
|
||||||
import { useBookmarks } from "../components/Bookmarks";
|
import { BookmarksTab } from "../components/Bookmarks";
|
||||||
|
import { ReaderNav, type NavTab } from "../components/reader-nav";
|
||||||
import { btn } from "../components/ui";
|
import { btn } from "../components/ui";
|
||||||
import { chapterText, seekChapter, splitChapters } from "../lib/chapters";
|
import { chapterText, seekChapter, splitChapters } from "../lib/chapters";
|
||||||
import { decodeText } from "../lib/encoding";
|
import { decodeText } from "../lib/encoding";
|
||||||
@@ -134,7 +135,7 @@ export default function TextReader(props: ReaderProps) {
|
|||||||
function MdView({ book, initialLocator, initialPercent, chrome }: ReaderProps) {
|
function MdView({ book, initialLocator, initialPercent, chrome }: ReaderProps) {
|
||||||
const boxRef = useRef<HTMLDivElement>(null);
|
const boxRef = useRef<HTMLDivElement>(null);
|
||||||
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
const saver = useProgressSaver(book.id, { locator: initialLocator, percent: initialPercent });
|
||||||
const bm = useBookmarks({ book, capture: saver.capture, seek: (l) => seek(Number(l.scrollFraction) || 0) });
|
const [nav, setNav] = useState(false);
|
||||||
const restored = useRef(false);
|
const restored = useRef(false);
|
||||||
const pr = useReaderPrefs();
|
const pr = useReaderPrefs();
|
||||||
const [frac, setFrac] = useState(0);
|
const [frac, setFrac] = useState(0);
|
||||||
@@ -183,8 +184,34 @@ function MdView({ book, initialLocator, initialPercent, chrome }: ReaderProps) {
|
|||||||
dangerouslySetInnerHTML={{ __html: html ?? "" }}
|
dangerouslySetInnerHTML={{ __html: html ?? "" }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{chrome.on && <ReaderSheet pr={pr} frac={frac} onSeek={seek}>{bm.btn}</ReaderSheet>}
|
{chrome.on && (
|
||||||
{bm.panel}
|
<ReaderSheet pr={pr} frac={frac} onSeek={seek}>
|
||||||
|
<button
|
||||||
|
className="rd-btn"
|
||||||
|
aria-expanded={nav}
|
||||||
|
aria-controls="reader-nav"
|
||||||
|
onClick={() => setNav((v) => !v)}
|
||||||
|
>
|
||||||
|
书签
|
||||||
|
</button>
|
||||||
|
</ReaderSheet>
|
||||||
|
)}
|
||||||
|
{nav && (
|
||||||
|
<ReaderNav
|
||||||
|
tab="bm"
|
||||||
|
onClose={() => setNav(false)}
|
||||||
|
bookmarks={
|
||||||
|
<BookmarksTab
|
||||||
|
book={book}
|
||||||
|
capture={saver.capture}
|
||||||
|
seek={(l) => {
|
||||||
|
seek(Number(l.scrollFraction) || 0);
|
||||||
|
setNav(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -199,14 +226,9 @@ function TxtView({ book, initialLocator, initialPercent, chrome }: ReaderProps)
|
|||||||
const activeRow = useRef<HTMLButtonElement>(null);
|
const activeRow = useRef<HTMLButtonElement>(null);
|
||||||
const [ci, setCi] = useState(0);
|
const [ci, setCi] = useState(0);
|
||||||
const [frac, setFrac] = useState(0);
|
const [frac, setFrac] = useState(0);
|
||||||
const [toc, setToc] = useState(false);
|
const [nav, setNav] = useState<null | NavTab>(null);
|
||||||
const pr = useReaderPrefs();
|
const pr = useReaderPrefs();
|
||||||
const { text, err, retry } = useFileText(book.file_url ?? "");
|
const { text, err, retry } = useFileText(book.file_url ?? "");
|
||||||
const bm = useBookmarks({
|
|
||||||
book,
|
|
||||||
capture: saver.capture,
|
|
||||||
seek: (l) => goChapter(Number(l.ch) || 0, Number(l.scrollFraction) || 0),
|
|
||||||
});
|
|
||||||
|
|
||||||
const chapters = useMemo(() => (text == null ? null : splitChapters(text)), [text]);
|
const chapters = useMemo(() => (text == null ? null : splitChapters(text)), [text]);
|
||||||
|
|
||||||
@@ -238,8 +260,8 @@ function TxtView({ book, initialLocator, initialPercent, chrome }: ReaderProps)
|
|||||||
}, [ci, chapters]);
|
}, [ci, chapters]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (toc) activeRow.current?.scrollIntoView({ block: "center" });
|
if (nav === "toc") activeRow.current?.scrollIntoView({ block: "center" });
|
||||||
}, [toc]);
|
}, [nav]);
|
||||||
|
|
||||||
function goChapter(i: number, intra = 0) {
|
function goChapter(i: number, intra = 0) {
|
||||||
if (!chapters) return;
|
if (!chapters) return;
|
||||||
@@ -287,14 +309,21 @@ function TxtView({ book, initialLocator, initialPercent, chrome }: ReaderProps)
|
|||||||
</div>
|
</div>
|
||||||
{chrome.on && (
|
{chrome.on && (
|
||||||
<ReaderSheet pr={pr} frac={total} onSeek={seek}>
|
<ReaderSheet pr={pr} frac={total} onSeek={seek}>
|
||||||
{bm.btn}
|
<button
|
||||||
|
className="rd-btn"
|
||||||
|
aria-expanded={nav === "bm"}
|
||||||
|
aria-controls="reader-nav"
|
||||||
|
onClick={() => setNav(nav === "bm" ? null : "bm")}
|
||||||
|
>
|
||||||
|
书签
|
||||||
|
</button>
|
||||||
{chapters.length > 1 && (
|
{chapters.length > 1 && (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
className="rd-btn"
|
className="rd-btn"
|
||||||
aria-expanded={toc}
|
aria-expanded={nav === "toc"}
|
||||||
aria-controls="toc-panel"
|
aria-controls="reader-nav"
|
||||||
onClick={() => setToc((v) => !v)}
|
onClick={() => setNav(nav === "toc" ? null : "toc")}
|
||||||
>
|
>
|
||||||
目录
|
目录
|
||||||
</button>
|
</button>
|
||||||
@@ -311,35 +340,44 @@ function TxtView({ book, initialLocator, initialPercent, chrome }: ReaderProps)
|
|||||||
)}
|
)}
|
||||||
</ReaderSheet>
|
</ReaderSheet>
|
||||||
)}
|
)}
|
||||||
{/* ponytail: 目录一次渲染全部章节,数千章级书若卡顿再上虚拟列表 */}
|
{nav && (
|
||||||
{toc && chapters.length > 1 && (
|
<ReaderNav
|
||||||
<>
|
tab={chapters.length > 1 ? nav : "bm"}
|
||||||
<div className="fixed inset-0 z-10" aria-hidden="true" onClick={() => setToc(false)} />
|
onTab={setNav}
|
||||||
<nav
|
onClose={() => setNav(null)}
|
||||||
id="toc-panel"
|
bookmarks={
|
||||||
aria-label="章节目录"
|
<BookmarksTab
|
||||||
className="rd-divider absolute inset-y-0 left-0 z-20 w-64 overflow-y-auto border-r bg-[var(--rd-bg)] p-2 shadow-2xl"
|
book={book}
|
||||||
>
|
capture={saver.capture}
|
||||||
<ul className="space-y-0.5">
|
seek={(l) => {
|
||||||
{chapters.map((c, i) => (
|
goChapter(Number(l.ch) || 0, Number(l.scrollFraction) || 0);
|
||||||
<li key={i}>
|
setNav(null);
|
||||||
<button
|
}}
|
||||||
ref={i === ci ? activeRow : undefined}
|
/>
|
||||||
className={"rd-row" + (i === ci ? " rd-btn-on" : "")}
|
}
|
||||||
onClick={() => {
|
toc={
|
||||||
goChapter(i);
|
/* ponytail: 目录一次渲染全部章节,数千章级书若卡顿再上虚拟列表 */
|
||||||
setToc(false);
|
chapters.length > 1 && (
|
||||||
}}
|
<ul className="space-y-0.5">
|
||||||
>
|
{chapters.map((c, i) => (
|
||||||
{i + 1}. {c.title}
|
<li key={i}>
|
||||||
</button>
|
<button
|
||||||
</li>
|
ref={i === ci ? activeRow : undefined}
|
||||||
))}
|
className={"rd-row" + (i === ci ? " rd-btn-on" : "")}
|
||||||
</ul>
|
onClick={() => {
|
||||||
</nav>
|
goChapter(i);
|
||||||
</>
|
setNav(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i + 1}. {c.title}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{bm.panel}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user