@ggboy123/dsh-paper-reader 1.8.2 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,10 +7,16 @@
7
7
 
8
8
  **English**: [README_EN.md](README_EN.md)
9
9
 
10
- [DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness) 插件:**论文伴读工作台** —— 文献库 + PDF 阅读器 + AI 伴读,回答自带页码、点页码跳回原文。当前版本 **v1.8.2**。
10
+ [DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness) 插件:**论文伴读工作台** —— 文献库 + PDF 阅读器 + AI 伴读,回答自带页码、点页码跳回原文。当前版本 **v1.9.0**。
11
11
 
12
12
  > 💬 **QQ 交流群:1127244508** —— 安装/使用问题、功能建议、bug 反馈都欢迎来聊。
13
13
 
14
+ ## 为什么用论文伴读
15
+
16
+ 1. **论文一多,文件和阅读进度就容易乱。** 按专题、子专题整理论文,每篇论文的 PDF、译文、笔记和学习记录都放在一起;改名、移动、删除都有管理入口,删错了还能从回收站恢复。
17
+ 2. **翻译不该打断阅读。** 不用把段落复制到别的软件,直接在原 PDF 版面上生成中文;支持纯中文、中英对照、左右分屏和划词翻译,公式也能保留。
18
+ 3. **AI 的回答,需要能回到原文核对。** 回答自带页码,点击就跳到对应原文并高亮;可以只问当前论文,也可以把范围扩大到整个专题,减少“答得流畅却找不到出处”。
19
+
14
20
  ![演示:选中即问 → 回答带页码 → 点页码跳回 PDF 并高亮原文](docs/demo.gif)
15
21
 
16
22
  ![默认安装:官方侧栏原样,只多一行开关](https://raw.githubusercontent.com/GGboya/dsh-paper-reader/main/docs/screenshot-default.png)
@@ -28,12 +34,12 @@
28
34
  - 🤖 **可选教练式带读**:专用 preset 制定分步计划;你读原文、作答,AI 点评追问,当前阶段答好才继续,学习进度跨会话累积
29
35
  - 🀄 **一键中文版**:原文 ↔ 纯中文原地切换,译文 PDF 一键导出(纯中文 / 中英对照),翻译引擎零预装自动安装
30
36
  - 📏 **长段落不截断 + 实时进度**:翻译由 `babeldoc-driver.py` 驱动 babeldoc —— 按输入估算输出预算(不再吃 babeldoc 写死的 2048),`finish_reason=length` 自动拆段重译;顶栏进度条实时显示「翻译段落 76%(521/798)」这样的阶段进度,端点拒绝关闭推理时自动降推理强度重试
31
- - 🈯 **划词翻译(公式保留)**(v1.8.2):选中点「译」出纯译文气泡;选区含公式时用 MinerU 识别的 LaTeX 替换文本层乱码、要求模型原样保留
32
- - 🖥️ **中英对照 / 分屏**(v1.8.2):并排对照页或左右分屏同步滚动,随时切换、按文献记忆
33
- - 📝 **笔记**(v1.8.2):划词仍直接弹回「选中即问」气泡(与旧版一致),气泡里新增「笔记」「全局搜索」小按钮;记过的文字下方画蓝色波浪线,鼠标停上去看笔记内容、点一下改或删;笔记窗口与查找窗同一套交互(可拖动、拖边框缩放、位置记忆),批量列表按页排序、点条目跳回原文。笔记存在 `<文献>.notes.json`(跟文献走,换浏览器不丢)
37
+ - 🈯 **划词翻译(公式保留)**(v1.9.0):选中点「译」出纯译文气泡;选区含公式时用 MinerU 识别的 LaTeX 替换文本层乱码、要求模型原样保留
38
+ - 🖥️ **中英对照 / 分屏**(v1.9.0):并排对照页或左右分屏同步滚动,随时切换、按文献记忆
39
+ - 📝 **笔记**(v1.9.0):划词仍直接弹回「选中即问」气泡(与旧版一致),气泡里新增「笔记」「全局搜索」小按钮;记过的文字下方画蓝色波浪线,鼠标停上去看笔记内容、点一下改或删;笔记窗口与查找窗同一套交互(可拖动、拖边框缩放、位置记忆),批量列表按页排序、点条目跳回原文,也可在条目上直接删除(二次确认)。笔记存在 `<文献>.notes.json`(跟文献走,换浏览器不丢)
34
40
  - ⚡ **长文档也流畅**:滚动模式只画视口附近的页、页离开视口即释放画布(其余保留等高占位,滚动条与页码始终准);原文 ↔ 中文切换只摘挂缓存好的页节点,不重新解析不重绘;切语言 / 重开论文不重传 PDF(ETag 304)。前提与已知边界见 [docs/features.md](docs/features.md)
35
- - 🗂️ **文献管理**:专题/论文改名、删除进回收站可恢复
36
- - 🛰️ **OpenCode Go 端点**(v1.8.2):翻译端点供应商预设新增「OpenCode Go」(订阅后复制 API Key 即用,模型名以控制台为准);对 opencode.ai 域的请求自动带稳定 `x-opencode-session` 会话头(同一篇论文的整篇与划词共用同一 ID、跨重启稳定,ID 由本机 0600 secret 派生不含论文名),其它端点不多发任何头
41
+ - 🗂️ **文献管理**:专题/论文在文件名上原地改名,论文可跨专题移动;删除进回收站可恢复
42
+ - 🛰️ **OpenCode Go 端点**(v1.9.0):翻译端点供应商预设新增「OpenCode Go」(订阅后复制 API Key 即用,模型名以控制台为准);对 opencode.ai 域的请求自动带稳定 `x-opencode-session` 会话头(同一篇论文的整篇与划词共用同一 ID、跨重启稳定,ID 由本机 0600 secret 派生不含论文名),其它端点不多发任何头
37
43
  - ➕ **可选增强**(默认关):MinerU 解析——扫描件可读、公式可点引用可检索;嵌入端点——大白话命中术语段落
38
44
 
39
45
  各功能的前提与配置细节见 [docs/features.md](docs/features.md)。
@@ -74,7 +80,7 @@ dsh plugin --profile web add @ggboy123/dsh-paper-reader@latest # 升级也是
74
80
  2. **入库**:+ 新建专题 → ⬆ 上传 PDF
75
81
  3. **读 + 问**:直接提问(回答自带页码),或选中文字弹框提问;点「第 N 页」跳回原文
76
82
  4. **中文版**:顶栏「中」一键生成(首次需在弹出表单里配一次 OpenAI 兼容端点,DeepSeek/GLM/Kimi 的 key 都行)
77
- 5. **管理**:行悬停出 ✎ 改名 / 🗑 删除;对话头部 🕐 历史、+ 新开
83
+ 5. **管理**:行悬停点「⋯」,文件名原地改名(Enter 保存 / Esc 取消),论文可移动到其它专题,也可删除;对话头部 🕐 历史、+ 新开
78
84
 
79
85
  ## 文献管理(安全说明)
80
86
 
package/dist/host.js CHANGED
@@ -3,9 +3,9 @@
3
3
  import { createReadStream, existsSync, lstatSync, readFileSync, realpathSync } from 'node:fs';
4
4
  import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
5
5
  import { randomUUID } from 'node:crypto';
6
- import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path';
6
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
7
7
  import { caseVariantCollisions, existingEntryName, flatArtifactNames, isPaperDir, listPapers, listTopicTree, listTopics, paperDirAncestor, paperPdfPath, paperRefFor, resolveDataDir, resolvePaper, resolveUploadTopic, validateEntryBoundary, validateEntryName, } from "./library.js";
8
- import { ManageError, assertInside, clearTopic, planTopicClear, deletePaper, deleteTopic, isManageError, planPaperDelete, planTopicDelete, realDataDir, renamePaper, renameTopic, resolveTopicDir, validateTopicPath, } from "./library-manage.js";
8
+ import { ManageError, assertInside, clearTopic, planTopicClear, deletePaper, deleteTopic, isManageError, movePaper, planPaperDelete, planTopicDelete, realDataDir, renamePaper, renameTopic, resolveTopicDir, validateTopicPath, } from "./library-manage.js";
9
9
  import { readFormulaIndex, readTextBlockIndex } from "./formulas.js";
10
10
  import { buildScopeContext } from "./scope.js";
11
11
  import { MAX_CHUNKS, MAX_LATEX_CHARS, MAX_TEXT_CHARS, MAX_TOTAL_CHARS, SelectionTranslateError, assembleSource, formulaStatusOf, translateSelection, } from "./translate-selection.js";
@@ -147,7 +147,7 @@ export function registerRoutes(ctx, config) {
147
147
  const hit = sessions.find((s) => s.n === n);
148
148
  return hit?.sessionId ?? `${sessionPrefixFor(ref)}-${n}`;
149
149
  };
150
- /** 专题目录 → dsh 工作区(幂等,进程内缓存)。会话挂到工作区后原生 composer 才可用。 */
150
+ /** 论文目录 → dsh 工作区(幂等,进程内缓存)。会话挂到工作区后原生 composer 才可用。 */
151
151
  const workspaceCache = new Map();
152
152
  /** 删/改/清空一个专题(可能是路径)后,把**整棵子树**的工作区缓存键清掉(方案 §B2.4)。 */
153
153
  const dropWorkspaceCache = (topicPath) => {
@@ -158,8 +158,7 @@ export function registerRoutes(ctx, config) {
158
158
  workspaceCache.delete(k);
159
159
  }
160
160
  };
161
- const ensureTopicWorkspace = async (topic) => {
162
- const dir = join(dataDir, topic);
161
+ const ensureWorkspaceDir = async (dir) => {
163
162
  const cached = workspaceCache.get(dir);
164
163
  if (cached)
165
164
  return cached;
@@ -173,16 +172,19 @@ export function registerRoutes(ctx, config) {
173
172
  return undefined;
174
173
  }
175
174
  };
176
- /** 创建/复用会话:论文伴读 preset 只注册到 dsh;论文入口不默认套用,避免替用户改变 agent。 */
177
- const createPaperSession = async (sessionId, topic) => {
178
- const workspaceId = await ensureTopicWorkspace(topic);
175
+ /** 创建/复用会话:论文伴读 preset 只注册到 dsh;论文入口不默认套用,避免替用户改变 agent。
176
+ * 原生 composer 不经过 /api/ask,当前论文身份只能由工作区表达(issue #21):
177
+ * 新布局挂到 <专题>/<论文>/,同专题多篇不再让模型猜;旧平铺库只能继续挂专题目录。 */
178
+ const createPaperSession = async (sessionId, ref) => {
179
+ const dir = dirname(ref.pdfPath);
180
+ const workspaceId = await ensureWorkspaceDir(dir);
179
181
  if (workspaceId) {
180
182
  try {
181
183
  return await sessionController.create({ sessionId, workspaceId });
182
184
  }
183
185
  catch { /* 工作区挂载失败则回退 cwd */ }
184
186
  }
185
- return sessionController.create({ sessionId, cwd: join(dataDir, topic) });
187
+ return sessionController.create({ sessionId, cwd: dir });
186
188
  };
187
189
  /* ── 破坏性操作(删除/重命名)的共用出口 ──────────────────────────────────
188
190
  契约:docs/reader-ux-requirements.md §2。错误文案一律不含服务端绝对路径;
@@ -744,6 +746,37 @@ export function registerRoutes(ctx, config) {
744
746
  });
745
747
  return;
746
748
  }
749
+ // 移动文献到另一个已存在专题:与改名同一套运行中会话 / 翻译互斥和脱钩回报。
750
+ if ((sub === '/api/library/move-paper' || sub === '/api/library/paper/move') && req.method === 'POST') {
751
+ const body = (await readBody(req));
752
+ if (badEntryBoundary(res, body.name))
753
+ return;
754
+ if (rejectWritePath(body, res))
755
+ return;
756
+ const topicPath = badTopicPath(res, body.topic, true);
757
+ const toTopic = badTopicPath(res, body.toTopic, true);
758
+ if (topicPath === null || toTopic === null)
759
+ return;
760
+ await withInflight(`paper\u0000${topicPath}\u0000${String(body.name ?? '')}`, res, async () => {
761
+ try {
762
+ const plan = planPaperDelete(dataDir, topicPath, body.name);
763
+ const ref = resolveLibraryPaper(plan.topic, plan.name);
764
+ const sessions = await sessionInfo(ref);
765
+ if (!(await requireSessionClear(ref, res)))
766
+ return;
767
+ if (zhStatus(ref).busy) {
768
+ throw new ManageError('translation-busy', 409, '该文献正在生成译文,请等待完成后再移动', {});
769
+ }
770
+ const r = movePaper(dataDir, plan.topic, plan.name, toTopic);
771
+ json(res, 200, { ...r, topic: r.toTopic, name: r.name, detachedSessions: sessions.total });
772
+ }
773
+ catch (err) {
774
+ if (!libFail(res, err))
775
+ throw err;
776
+ }
777
+ });
778
+ return;
779
+ }
747
780
  // 删除专题:仅空专题(非隐藏条目为 0),非递归语义;隐藏条目进回收站而不是销毁。
748
781
  // 规范名 = /api/library/delete-topic;上游 UI 只发 {topic}(没有确认字段),我们的 UI 发
749
782
  // {name, confirmName} 两段式确认。confirmName 语义(本文件):
@@ -1217,7 +1250,7 @@ export function registerRoutes(ctx, config) {
1217
1250
  const all = await scanPaperSessions(ref);
1218
1251
  const n = all.length ? all[all.length - 1].n + 1 : 1;
1219
1252
  const sessionId = `${sessionPrefixFor(ref)}-${n}`;
1220
- await createPaperSession(sessionId, ref.topic);
1253
+ await createPaperSession(sessionId, ref);
1221
1254
  json(res, 200, { ok: true, n, sessionId });
1222
1255
  return;
1223
1256
  }
@@ -1705,7 +1738,7 @@ export function registerRoutes(ctx, config) {
1705
1738
  const n = nParam > 0 ? nParam : sessions.length ? sessions[sessions.length - 1].n : 1;
1706
1739
  const sessionId = await sessionIdFor(ref, n);
1707
1740
  try {
1708
- await createPaperSession(sessionId, ref.topic);
1741
+ await createPaperSession(sessionId, ref);
1709
1742
  }
1710
1743
  catch { /* 已存在则复用;失败由 follow 报错 */ }
1711
1744
  res.writeHead(200, {
@@ -1759,7 +1792,7 @@ export function registerRoutes(ctx, config) {
1759
1792
  n = existing.length ? existing[existing.length - 1].n : 1;
1760
1793
  const sessionId = await sessionIdFor(ref, n);
1761
1794
  try {
1762
- await createPaperSession(sessionId, ref.topic);
1795
+ await createPaperSession(sessionId, ref);
1763
1796
  }
1764
1797
  catch { /* 已存在则复用 */ }
1765
1798
  // ── 范围(方案 §B3.1):缺省/无效一律按「当前论文」;给了非法结构则显式 400 ──
@@ -14,7 +14,7 @@ import { lstatSync, mkdirSync, readdirSync, realpathSync, renameSync, rmSync, rm
14
14
  // 注意口径(评审 F-F):组合层**两套并存**——生产写路径用本模块的 resolveTopicDirChecked
15
15
  // (在其上更严),#4 的 resolveSafeTopic 组合层只被 library.ts 的适配器(上游测试用)调用。
16
16
  // 本模块**消费**它,不再自己重复一套词法/realpath 校验;我们的加严叠在其上(见下)。
17
- import { MAX_TOPIC_DEPTH, MAX_TOPIC_PATH, MAX_TOPIC_SEG, caseVariantCollisions, encodedEscapeError, assertInside as assertInsideShared, existingEntryName, isPaperDir, isPaperPDF, paperDirAncestor, realDataDir as realDataDirShared, validateEntryBoundary as validateBoundaryShared, validateEntryName, } from "./library.js";
17
+ import { MAX_TOPIC_DEPTH, MAX_TOPIC_PATH, MAX_TOPIC_SEG, caseVariantCollisions, encodedEscapeError, assertInside as assertInsideShared, existingEntryName, flatArtifactNames, isPaperDir, isPaperPDF, paperDirAncestor, realDataDir as realDataDirShared, validateEntryBoundary as validateBoundaryShared, validateEntryName, } from "./library.js";
18
18
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
19
19
  import { randomBytes } from 'node:crypto';
20
20
  /** HTTP 状态与机器可读 code 双携带;`extra` 会并入响应体(前端只认 code,不匹配中文)。 */
@@ -1177,6 +1177,105 @@ function renameLegacyPaper(dataDir, topicDir, paperName, newName, renameImpl) {
1177
1177
  }
1178
1178
  return { ok: true, moved: moved.map((m) => basename(m.to)), from: paperName, to: newName };
1179
1179
  }
1180
+ /**
1181
+ * 移动论文到另一个已存在专题。新布局整目录移动;旧平铺布局顺手收纳为论文文件夹。
1182
+ * 目标名不变,因此目标专题下的同名论文目录、平铺 PDF 与大小写变体都必须在动手前拒绝。
1183
+ */
1184
+ export function movePaper(dataDir, topic, name, toTopicRaw, renameImpl = renameSync) {
1185
+ const plan = planPaperDelete(dataDir, topic, name);
1186
+ const toTopic = validateTopicPath(toTopicRaw, true);
1187
+ if (toTopic === plan.topic)
1188
+ throw new ManageError('bad-request', 400, '论文已经在目标专题中');
1189
+ const root = realDataDir(dataDir);
1190
+ const targetTopicDir = resolveExistingTopicDir(dataDir, toTopic);
1191
+ const paperParent = paperDirAncestor(root, toTopic.split('/'));
1192
+ if (paperParent)
1193
+ throw new ManageError('target-exists', 409, `目标专题是论文目录,不能移入:${paperParent}`, { conflicts: [paperParent] });
1194
+ const sourceDir = resolveExistingPaperDir(dataDir, plan.topic, plan.name);
1195
+ const targetDir = join(targetTopicDir, plan.name);
1196
+ let targetExists = false;
1197
+ try {
1198
+ lstatSync(targetDir);
1199
+ targetExists = true;
1200
+ }
1201
+ catch { /* 不存在才可移入 */ }
1202
+ const clashes = [...new Set([
1203
+ ...(targetExists ? [plan.name] : []),
1204
+ ...flatArtifactNames(targetTopicDir, plan.name),
1205
+ ...caseVariantCollisions(targetTopicDir, plan.name),
1206
+ ])];
1207
+ if (clashes.length > 0) {
1208
+ throw new ManageError('target-exists', 409, `目标专题已存在同名文献:${clashes.join('、')}`, { conflicts: clashes });
1209
+ }
1210
+ assertInside(root, targetDir);
1211
+ let targetCreated = false;
1212
+ const fail = (err, rollback = () => ({ rolledBack: [], rollbackFailed: [] })) => {
1213
+ const code = err.code;
1214
+ const { rolledBack, rollbackFailed } = rollback();
1215
+ if (plan.layout === 'legacy' && targetCreated) {
1216
+ try {
1217
+ rmdirSync(targetDir);
1218
+ }
1219
+ catch { /* 非空则保留现场 */ }
1220
+ }
1221
+ const tail = rollbackFailed.length === 0
1222
+ ? '本次移动已全部撤销,文献库未改变'
1223
+ : `但 ${rollbackFailed.length} 个文件未能移回原处,请手动检查:${rollbackFailed.join('、')}`;
1224
+ if (code === 'EBUSY' || code === 'EPERM') {
1225
+ throw new ManageError('file-busy', 409, `文件被占用(可能正在阅读器或其他程序中打开),关闭后重试;${tail}`, {
1226
+ busy: plan.name, moved: [], rolledBack, rollbackFailed, cause: code,
1227
+ });
1228
+ }
1229
+ if (typeof code === 'string' && code && rollbackFailed.length === 0)
1230
+ throw err;
1231
+ throw new ManageError('rename-partial', 500, `移动文献中途失败;${tail}`, {
1232
+ moved: [], rolledBack, rollbackFailed, cause: code ?? 'unknown',
1233
+ });
1234
+ };
1235
+ if (plan.layout === 'folder') {
1236
+ try {
1237
+ renameImpl(sourceDir, targetDir);
1238
+ }
1239
+ catch (err) {
1240
+ fail(err);
1241
+ }
1242
+ }
1243
+ else {
1244
+ try {
1245
+ mkdirSync(targetDir);
1246
+ targetCreated = true;
1247
+ }
1248
+ catch (err) {
1249
+ fail(err);
1250
+ }
1251
+ const moved = [];
1252
+ try {
1253
+ for (const f of plan.files) {
1254
+ const from = join(sourceDir, f.name);
1255
+ const to = join(targetDir, f.name);
1256
+ renameImpl(from, to);
1257
+ moved.push({ from, to });
1258
+ }
1259
+ }
1260
+ catch (err) {
1261
+ fail(err, () => {
1262
+ const rolledBack = [];
1263
+ const rollbackFailed = [];
1264
+ for (const m of [...moved].reverse()) {
1265
+ try {
1266
+ renameImpl(m.to, m.from);
1267
+ rolledBack.push(basename(m.from));
1268
+ }
1269
+ catch {
1270
+ rollbackFailed.push(basename(m.from));
1271
+ }
1272
+ }
1273
+ return { rolledBack, rollbackFailed };
1274
+ });
1275
+ }
1276
+ }
1277
+ return { ok: true, moved: plan.files.map((f) => f.name), from: plan.name, to: plan.name, fromTopic: plan.topic, toTopic, name: plan.name };
1278
+ }
1180
1279
  /**
1181
1280
  * 重命名/移动专题(新布局):`to` 是**相对 dataDir 的路径**(`A/B`)⇒ 天然支持「移动到另一父」。
1182
1281
  * 附带两条新不变量(方案 §B2.5):
package/lib/client.js CHANGED
@@ -191,11 +191,12 @@ window.__ModuleLoader__.load({
191
191
 
192
192
  const NS = 'dsh-paper-reader'
193
193
  const zh = {
194
- library: '文献库',
194
+ library: '文献库', refresh: '刷新',
195
195
  empty: '文献库为空', hint: '新建专题或上传 PDF 开始', newTopic: '新建专题',
196
196
  cancel: '取消', ok: '确定', defaultTopic: '默认专题', uploadBtn: '上传 PDF',
197
197
  newTopicFail: '新建专题失败',
198
198
  rename: '重命名', renameTopic: '重命名专题', renamePaper: '重命名论文',
199
+ renameInlineHint: 'Enter 保存,Esc 取消',
199
200
  renameFail: '重命名失败', delFail: '删除失败',
200
201
  upload: '上传 PDF 到此专题', newChat: '新建对话', session: '会话', pdfTab: '论文 PDF',
201
202
  history: '历史对话',
@@ -290,15 +291,20 @@ window.__ModuleLoader__.load({
290
291
  setThemeStateLight: '浅色(不变深)',
291
292
  // 嵌套子专题(方案 §B2):目录即层级;论文按文件夹整理
292
293
  newSubTopic: '新建子专题', moveTopic: '移动到…', moveTopicTitle: '移动到(目标父专题路径,留空=顶层):',
294
+ movePaper: '移动到…', movePaperTitle: '移动论文', movePaperDestination: '目标专题',
295
+ movePaperHint: 'PDF、译文、笔记和学习记录一起移动;历史伴读会话不会删除,但会与新位置脱钩。',
296
+ moveDone: '已移动到「{topic}」', moveFail: '移动失败',
293
297
  moveTopicHint: '整棵子树跟着移动;历史伴读会话不会删除,但会与树脱钩(确认框会给出数量)',
294
298
  uploadHere: '上传 PDF 到此处',
299
+ topicActions: '专题操作', paperActions: '论文操作',
295
300
  }
296
301
  const en = {
297
- library: 'Library',
302
+ library: 'Library', refresh: 'Refresh',
298
303
  empty: 'Library is empty', hint: 'Create a topic or upload a PDF to start', newTopic: 'New topic',
299
304
  cancel: 'Cancel', ok: 'OK', defaultTopic: 'Default', uploadBtn: 'Upload PDF',
300
305
  newTopicFail: 'Failed to create topic',
301
306
  rename: 'Rename', renameTopic: 'Rename topic', renamePaper: 'Rename paper',
307
+ renameInlineHint: 'Enter to save, Esc to cancel',
302
308
  renameFail: 'Rename failed', delFail: 'Delete failed',
303
309
  upload: 'Upload PDF into this topic', newChat: 'New chat', session: 'Session', pdfTab: 'Paper PDF',
304
310
  history: 'Chat history',
@@ -383,8 +389,12 @@ window.__ModuleLoader__.load({
383
389
  setThemeStateDark: 'dark applied',
384
390
  setThemeStateLight: 'light (unchanged)',
385
391
  newSubTopic: 'New subtopic', moveTopic: 'Move to...', moveTopicTitle: 'Move to (target parent topic path, empty = top level):',
392
+ movePaper: 'Move to...', movePaperTitle: 'Move paper', movePaperDestination: 'Destination topic',
393
+ movePaperHint: 'The PDF, translations, notes, and study progress move together. Past chats are kept but detach from the new location.',
394
+ moveDone: 'Moved to "{topic}"', moveFail: 'Move failed',
386
395
  moveTopicHint: 'The whole subtree moves with it; past chats are kept but detach from the tree (the count is reported).',
387
396
  uploadHere: 'Upload a PDF here',
397
+ topicActions: 'Topic actions', paperActions: 'Paper actions',
388
398
  }
389
399
 
390
400
  let t = (k) => k
@@ -874,26 +884,169 @@ window.__ModuleLoader__.load({
874
884
 
875
885
  /* ---------- 侧栏文献库树(接管 sidebar.workspaces) ---------- */
876
886
  const S = {
877
- root: { padding: '4px 0 12px', fontSize: '13px', color: 'var(--dsw-alias-label-primary, #24292f)' },
878
- head: { display: 'flex', alignItems: 'center', gap: '4px', padding: '8px 10px 6px', fontSize: '12px', fontWeight: 600, color: 'var(--dsw-alias-label-secondary, #656d76)' },
879
- iconBtn: { cursor: 'pointer', border: 'none', background: 'none', color: 'inherit', padding: '0 4px', fontSize: '13px', opacity: .75 },
887
+ root: { padding: '6px 0 14px', fontSize: '13px', color: 'var(--dsw-alias-label-primary, #24292f)' },
888
+ head: { display: 'flex', alignItems: 'center', gap: '3px', minHeight: '38px', padding: '4px 10px 7px 14px', fontSize: '12px', fontWeight: 600, color: 'var(--dsw-alias-label-secondary, #656d76)' },
889
+ headTitle: { display: 'flex', alignItems: 'center', gap: '7px', flex: 1, minWidth: 0 },
890
+ iconBtn: { width: '26px', height: '26px', flex: 'none', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', border: 'none', borderRadius: '6px', background: 'none', color: 'inherit', padding: 0 },
880
891
  // 页内弹窗(Electron 无 window.prompt)与空库入口按钮
881
- btnPrimary: { fontSize: '13px', padding: '5px 14px', borderRadius: '6px', border: 'none', cursor: 'pointer', background: 'var(--dsw-alias-button-primary-fill, #1f6feb)', color: 'var(--dsw-alias-button-primary-foreground, #fff)' },
892
+ // 主按钮固定蓝底白字:部分深色主题把 button-primary-fill/foreground 同时映射成白色(issue #20)。
893
+ btnPrimary: { fontSize: '13px', padding: '5px 14px', borderRadius: '6px', border: 'none', cursor: 'pointer', background: '#1f6feb', color: '#fff' },
882
894
  btnGhost: { fontSize: '13px', padding: '5px 14px', borderRadius: '6px', cursor: 'pointer', background: 'none', border: '1px solid var(--dsw-alias-border-l1, #d0d7de)', color: 'var(--dsw-alias-label-secondary, #656d76)' },
883
- linkBtn: { display: 'inline-flex', alignItems: 'center', gap: '4px', fontSize: '12px', padding: '4px 10px', borderRadius: '6px', cursor: 'pointer', background: 'none', border: '1px solid var(--dsw-alias-border-l1, #d0d7de)', color: 'var(--dsw-alias-label-action-primary, #0969da)' },
884
- topicHead: { display: 'flex', alignItems: 'center', gap: '6px', padding: '5px 8px', margin: '1px 6px 0', borderRadius: '6px', cursor: 'pointer', fontWeight: 600, userSelect: 'none' },
885
- caret: { fontSize: '10px', color: 'var(--dsw-alias-label-secondary, #656d76)', transition: 'transform .12s', display: 'inline-block' },
886
- items: { marginLeft: '14px' },
887
- item: { display: 'flex', alignItems: 'center', gap: '6px', padding: '4px 8px', margin: '0 6px', borderRadius: '6px', cursor: 'pointer', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' },
888
- active: { background: 'var(--dsw-alias-bg-active, rgba(9,105,218,.12))', color: 'var(--dsw-alias-label-action-primary, #0969da)', fontWeight: 600 },
895
+ linkBtn: { display: 'inline-flex', alignItems: 'center', gap: '5px', fontSize: '12px', padding: '5px 10px', borderRadius: '6px', cursor: 'pointer', background: 'none', border: '1px solid var(--dsw-alias-border-l1, #d0d7de)', color: 'var(--dsw-alias-label-action-primary, #0969da)' },
896
+ topicHead: { position: 'relative', display: 'flex', alignItems: 'center', gap: '6px', minHeight: '32px', padding: '4px 5px 4px 7px', margin: '2px 7px 0', borderRadius: '7px', cursor: 'pointer', fontWeight: 550, userSelect: 'none', outline: 'none' },
897
+ caret: { width: '14px', height: '14px', flex: 'none', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', color: 'var(--dsw-alias-label-tertiary, #8c959f)', transition: 'transform .14s ease' },
898
+ items: { position: 'relative', marginLeft: '20px', paddingLeft: '4px', borderLeft: '1px solid var(--dsw-alias-border-l2, #e5e8eb)' },
899
+ item: { position: 'relative', display: 'flex', alignItems: 'center', gap: '7px', minHeight: '31px', padding: '4px 5px 4px 8px', margin: '1px 7px 0 3px', borderRadius: '7px', cursor: 'pointer', whiteSpace: 'nowrap', color: 'var(--dsw-alias-label-secondary, #656d76)', outline: 'none' },
900
+ rowLabel: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
901
+ count: { flex: 'none', minWidth: '18px', padding: '0 5px', borderRadius: '9px', background: 'var(--dsw-alias-bg-inset, rgba(127,127,127,.09))', color: 'var(--dsw-alias-label-tertiary, #8c959f)', fontSize: '10.5px', fontWeight: 500, lineHeight: '18px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
902
+ active: { background: 'var(--dsw-alias-bg-active, rgba(9,105,218,.12))', color: 'var(--dsw-alias-label-primary, #24292f)', fontWeight: 600 },
889
903
  sessionItem: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #656d76)' },
890
- empty: { padding: '10px 12px', fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #656d76)', lineHeight: 1.6 },
904
+ empty: { padding: '12px 14px', fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #656d76)', lineHeight: 1.6 },
891
905
  running: { color: 'var(--dsw-alias-state-success-primary, #1a7f37)', fontSize: '9px' },
892
906
  // 收起态(rail):官方 rail 的控件是 36×36 圆形按钮、左对齐
893
907
  rail: { display: 'flex', flexDirection: 'column', alignItems: 'flex-start' },
894
908
  railBtn: { width: '36px', height: '36px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', border: 'none', background: 'none', borderRadius: '50%', color: 'var(--dsw-alias-label-primary, #24292f)', cursor: 'pointer', fontSize: '17px', padding: '0' },
895
909
  }
896
910
 
911
+ // 同一套细线图标贯穿文献库;不再混用平台相关的彩色 emoji。
912
+ function LibraryIcon({ name, size = 16 }) {
913
+ const paths = {
914
+ chevron: [h('path', { key: 1, d: 'm6 9 6 6 6-6' })],
915
+ folder: [h('path', { key: 1, d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z' })],
916
+ library: [h('path', { key: 1, d: 'M4 19.5A2.5 2.5 0 0 1 6.5 17H20V3H6.5A2.5 2.5 0 0 0 4 5.5Z' }), h('path', { key: 2, d: 'M4 5.5v14A2.5 2.5 0 0 0 6.5 22H20M9 7h7' })],
917
+ paper: [h('path', { key: 1, d: 'M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z' }), h('path', { key: 2, d: 'M14 2v6h6M8 13h8M8 17h5' })],
918
+ upload: [h('path', { key: 1, d: 'M12 16V4m-5 5 5-5 5 5M5 20h14' })],
919
+ plus: [h('path', { key: 1, d: 'M12 5v14M5 12h14' })],
920
+ refresh: [h('path', { key: 1, d: 'M20 6v5h-5M4 18v-5h5' }), h('path', { key: 2, d: 'M18.5 9A7 7 0 0 0 6 6.5L4 11m2 4a7 7 0 0 0 12 2.5l2-4.5' })],
921
+ more: [h('circle', { key: 1, cx: 5, cy: 12, r: 1 }), h('circle', { key: 2, cx: 12, cy: 12, r: 1 }), h('circle', { key: 3, cx: 19, cy: 12, r: 1 })],
922
+ rename: [h('path', { key: 1, d: 'M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z' })],
923
+ move: [h('path', { key: 1, d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z' }), h('path', { key: 2, d: 'M9 13h8m-3-3 3 3-3 3' })],
924
+ subtopic: [h('path', { key: 1, d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z' }), h('path', { key: 2, d: 'M12 10v6m-3-3h6' })],
925
+ trash: [h('path', { key: 1, d: 'M3 6h18M8 6V4h8v2m3 0-1 14H6L5 6m5 5v5m4-5v5' })],
926
+ }
927
+ return h('svg', {
928
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
929
+ strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, focusable: 'false',
930
+ }, paths[name] || paths.paper)
931
+ }
932
+
933
+ /* 行尾只留一个「更多」入口;菜单 portal 到 body,避免被侧栏滚动区裁掉。 */
934
+ function RowMenu({ label, items }) {
935
+ const [open, setOpen] = useState(false)
936
+ const [pos, setPos] = useState(null)
937
+ const anchor = React.useRef(null)
938
+ const menu = React.useRef(null)
939
+ const close = useCallback((focus = false) => {
940
+ setOpen(false)
941
+ if (focus) anchor.current?.focus()
942
+ }, [])
943
+ useEffect(() => {
944
+ if (!open) return
945
+ const rect = anchor.current?.getBoundingClientRect()
946
+ if (!rect) { setOpen(false); return }
947
+ const width = 168
948
+ const estimatedHeight = items.length * 34 + 10
949
+ setPos({
950
+ left: Math.max(8, Math.min(window.innerWidth - width - 8, rect.right - width)),
951
+ top: rect.bottom + estimatedHeight + 8 > window.innerHeight ? Math.max(8, rect.top - estimatedHeight - 4) : rect.bottom + 4,
952
+ })
953
+ const onPointer = (e) => {
954
+ if (!anchor.current?.contains(e.target) && !menu.current?.contains(e.target)) close()
955
+ }
956
+ const onKey = (e) => { if (e.key === 'Escape') { e.preventDefault(); close(true) } }
957
+ const onScroll = () => close()
958
+ document.addEventListener('pointerdown', onPointer)
959
+ document.addEventListener('keydown', onKey)
960
+ window.addEventListener('resize', onScroll)
961
+ window.addEventListener('scroll', onScroll, true)
962
+ return () => {
963
+ document.removeEventListener('pointerdown', onPointer)
964
+ document.removeEventListener('keydown', onKey)
965
+ window.removeEventListener('resize', onScroll)
966
+ window.removeEventListener('scroll', onScroll, true)
967
+ }
968
+ }, [open, close, items.length])
969
+ return h(React.Fragment, null,
970
+ h('button', {
971
+ ref: anchor, type: 'button', className: 'dpr-row-menu-trigger', style: S.iconBtn,
972
+ title: label, 'aria-label': label, 'aria-haspopup': 'menu', 'aria-expanded': open,
973
+ onClick: (e) => { e.stopPropagation(); setOpen((v) => !v) },
974
+ }, h(LibraryIcon, { name: 'more', size: 17 })),
975
+ open && pos && createPortal(h('div', {
976
+ ref: menu, className: 'dpr-row-menu', role: 'menu', 'aria-label': label,
977
+ style: { position: 'fixed', left: pos.left, top: pos.top },
978
+ onClick: (e) => e.stopPropagation(),
979
+ }, items.map((item, index) => h('button', {
980
+ key: item.key, type: 'button', role: 'menuitem', 'data-dpr-act': item.key, autoFocus: index === 0,
981
+ className: item.danger ? 'danger' : '',
982
+ onClick: () => { close(true); item.onSelect() },
983
+ }, h(LibraryIcon, { name: item.icon, size: 15 }), h('span', null, item.label)))), document.body))
984
+ }
985
+
986
+ /* 文件名原地重命名:Enter 保存,Esc / 失焦取消;不经过 Electron 不支持的 prompt。 */
987
+ function InlineRename({ initial, label, onSave, onCancel }) {
988
+ const [value, setValue] = useState(initial)
989
+ const [busy, setBusy] = useState(false)
990
+ const busyRef = React.useRef(false)
991
+ const input = React.useRef(null)
992
+ useEffect(() => { input.current?.focus(); input.current?.select() }, [])
993
+ const submit = async () => {
994
+ const name = value.trim()
995
+ if (!name || name === initial || busyRef.current) { if (!busyRef.current) onCancel(); return }
996
+ busyRef.current = true
997
+ setBusy(true)
998
+ const ok = await onSave(name)
999
+ busyRef.current = false
1000
+ setBusy(false)
1001
+ if (!ok) input.current?.focus()
1002
+ }
1003
+ return h('input', {
1004
+ ref: input, value, type: 'text', disabled: busy, title: t('renameInlineHint'),
1005
+ 'aria-label': label, 'data-dpr-rename': '',
1006
+ style: { flex: 1, minWidth: 0, width: '100%', boxSizing: 'border-box', padding: '2px 5px', border: '1px solid var(--dsw-alias-label-action-primary, #0969da)', borderRadius: '5px', background: 'var(--dsw-alias-bg-layer-1, #fff)', color: 'var(--dsw-alias-label-primary, #24292f)', font: 'inherit', fontSize: '12.5px', lineHeight: '20px', outline: 'none' },
1007
+ onChange: (e) => setValue(e.target.value),
1008
+ onClick: (e) => e.stopPropagation(),
1009
+ onPointerDown: (e) => e.stopPropagation(),
1010
+ onBlur: () => { if (!busyRef.current) onCancel() },
1011
+ onKeyDown: (e) => {
1012
+ e.stopPropagation()
1013
+ if (e.key === 'Enter') { e.preventDefault(); void submit() }
1014
+ else if (e.key === 'Escape') { e.preventDefault(); onCancel() }
1015
+ },
1016
+ })
1017
+ }
1018
+
1019
+ function MovePaperDialog({ topics, currentTopic, onConfirm, onCancel }) {
1020
+ const [destination, setDestination] = useState(currentTopic)
1021
+ const [busy, setBusy] = useState(false)
1022
+ const submit = async () => {
1023
+ setBusy(true)
1024
+ const ok = await onConfirm(destination)
1025
+ setBusy(false)
1026
+ if (ok) onCancel()
1027
+ }
1028
+ return h('div', {
1029
+ style: { position: 'fixed', inset: 0, zIndex: 99999, background: 'rgba(0,0,0,.35)', display: 'flex', alignItems: 'center', justifyContent: 'center', font: 'inherit' },
1030
+ onClick: onCancel,
1031
+ }, h('div', {
1032
+ role: 'dialog', 'aria-label': t('movePaperTitle'),
1033
+ style: { width: '340px', maxWidth: '90vw', padding: '18px', borderRadius: '12px', boxShadow: '0 12px 36px rgba(0,0,0,.28)', background: 'var(--dsw-alias-bg-layer-1, #fff)', color: 'var(--dsw-alias-label-primary, #24292f)' },
1034
+ onClick: (e) => e.stopPropagation(),
1035
+ },
1036
+ h('div', { style: { fontSize: '14px', fontWeight: 600, marginBottom: '14px' } }, t('movePaperTitle')),
1037
+ h('label', { style: { display: 'block', fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #656d76)', marginBottom: '6px' } }, t('movePaperDestination')),
1038
+ h('select', {
1039
+ value: destination, disabled: busy, autoFocus: true,
1040
+ style: { width: '100%', boxSizing: 'border-box', padding: '7px 9px', border: '1px solid var(--dsw-alias-border-l1, #d0d7de)', borderRadius: '7px', background: 'var(--dsw-alias-bg-layer-2, #f6f8fa)', color: 'inherit', font: 'inherit', fontSize: '13px' },
1041
+ onChange: (e) => setDestination(e.target.value),
1042
+ onKeyDown: (e) => { if (e.key === 'Escape') onCancel() },
1043
+ }, topics.map((topic) => h('option', { key: topic, value: topic }, topic))),
1044
+ h('div', { style: { marginTop: '10px', color: 'var(--dsw-alias-label-secondary, #656d76)', fontSize: '11.5px', lineHeight: 1.6 } }, t('movePaperHint')),
1045
+ h('div', { style: { display: 'flex', gap: '8px', justifyContent: 'flex-end', marginTop: '16px' } },
1046
+ h('button', { type: 'button', style: S.btnGhost, disabled: busy, onClick: onCancel }, t('cancel')),
1047
+ h('button', { type: 'button', style: { ...S.btnPrimary, ...(destination === currentTopic || busy ? { opacity: .5, cursor: 'default' } : {}) }, disabled: destination === currentTopic || busy, onClick: () => void submit() }, t('movePaper')))))
1048
+ }
1049
+
897
1050
  /* ---------- 页内文本输入弹窗:Electron 渲染进程不实现 window.prompt
898
1051
  (实测同版本 Electron 调用即抛 "prompt() is not supported",桌面端点「+」
899
1052
  曾因此毫无反应),一律走 createPortal 挂 document.body,避免被侧栏 overflow 裁剪。 ---------- */
@@ -1137,6 +1290,7 @@ window.__ModuleLoader__.load({
1137
1290
  // 子专题:目标父路径('' = 顶层);目录即层级 ⇒ 后端 mkdir recursive + 父目录必须存在
1138
1291
  const [askSub, setAskSub] = useState(null) // { parent }
1139
1292
  const [moving, setMoving] = useState(null) // { topic }
1293
+ const [movingPaper, setMovingPaper] = useState(null) // { topic, name }
1140
1294
  const createSubTopic = useCallback(async (parent, name) => {
1141
1295
  const path = parent ? `${parent}/${name}` : name
1142
1296
  try {
@@ -1168,7 +1322,7 @@ window.__ModuleLoader__.load({
1168
1322
  // 与删除一致:改名失败也可能带回 rollbackFailed(部分产物名字没能回滚)→ 必须给出恢复指引
1169
1323
  const f = clearFailureText(err, t)
1170
1324
  toast(t('renameFail') + ': ' + f.text + (f.recovery ? ' ' + f.recovery : ''), f.recovery ? 15000 : 6000)
1171
- return
1325
+ return false
1172
1326
  }
1173
1327
  // 我们分支的加固实现会回 detachedSessions(会话 id 内嵌旧 topic/name → 改名后不再挂树上,
1174
1328
  // 但会话本体不删除)。上游 UI 不提示这一点,用户会以为会话丢了——保留我们的提示。
@@ -1200,6 +1354,34 @@ window.__ModuleLoader__.load({
1200
1354
  window.dispatchEvent(new CustomEvent('dpr:paper', { detail: { topic: newTopicName, name: newName } }))
1201
1355
  }
1202
1356
  refresh()
1357
+ return true
1358
+ }, [cur, refresh])
1359
+
1360
+ const doMovePaper = useCallback(async (topic, name, toTopic) => {
1361
+ try {
1362
+ const r = await api('/library/move-paper', {
1363
+ method: 'POST', headers: { 'content-type': 'application/json' },
1364
+ body: JSON.stringify({ topic, name, toTopic }),
1365
+ })
1366
+ migrateLsKeys(topic, toTopic, name, name)
1367
+ setSessions((m) => { const c = { ...m }; delete c[`${topic}/${name}`]; return c })
1368
+ setClosed((c) => {
1369
+ const next = { ...c, [toTopic]: false }
1370
+ try { localStorage.setItem('dpr.treeClosed', JSON.stringify(next)) } catch {}
1371
+ return next
1372
+ })
1373
+ if (cur && cur.topic === topic && cur.name === name) {
1374
+ setCur((c) => ({ ...c, topic: toTopic }))
1375
+ window.dispatchEvent(new CustomEvent('dpr:paper', { detail: { topic: toTopic, name } }))
1376
+ }
1377
+ toast(t('moveDone').replace('{topic}', toTopic) + (r.detachedSessions ? ' · ' + t('renameDetached').replace('{n}', String(r.detachedSessions)) : ''), r.detachedSessions ? 6000 : 3000)
1378
+ refresh()
1379
+ return true
1380
+ } catch (err) {
1381
+ const f = clearFailureText(err, t)
1382
+ toast(t('moveFail') + ': ' + f.text + (f.recovery ? ' ' + f.recovery : ''), f.recovery ? 15000 : 6000)
1383
+ return false
1384
+ }
1203
1385
  }, [cur, refresh])
1204
1386
 
1205
1387
  // 删除不走上游的「同一按钮点两次(3s arm)」:改用我们的「服务端删除计划 + 页内确认框」
@@ -1231,6 +1413,15 @@ window.__ModuleLoader__.load({
1231
1413
 
1232
1414
  const topics = lib?.topics ?? []
1233
1415
  const papers = lib?.papers ?? []
1416
+ const destinationTopics = []
1417
+ const collectDestinationTopics = (nodes) => {
1418
+ for (const node of nodes || []) {
1419
+ destinationTopics.push(node.path || node.name)
1420
+ collectDestinationTopics(node.children)
1421
+ }
1422
+ }
1423
+ collectDestinationTopics(lib?.tree)
1424
+ if (destinationTopics.length === 0) destinationTopics.push(...topics)
1234
1425
 
1235
1426
  // 头部「⬆」与空库按钮共用:定位目标专题,没有专题时先自动建「默认专题」
1236
1427
  // (宿主端 mkdir recursive,重名无害)再弹文件选择——空库不再是无入口的死路。
@@ -1412,52 +1603,81 @@ window.__ModuleLoader__.load({
1412
1603
  const childPapers = papersOf(path)
1413
1604
  const children = node.children || []
1414
1605
  const hasKids = children.length > 0 || childPapers.length > 0
1415
- return h('div', { key: path },
1606
+ const paperCount = dprTopicPaperCount(papers, path)
1607
+ const renamingThis = renaming?.kind === 'topic' && renaming.topic === path
1608
+ const toggle = () => {
1609
+ const next = { ...closed, [path]: !collapsed }
1610
+ setClosed(next)
1611
+ try { localStorage.setItem('dpr.treeClosed', JSON.stringify(next)) } catch {}
1612
+ }
1613
+ const onRowKey = (e, action) => {
1614
+ if (e.target !== e.currentTarget) return
1615
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); action() }
1616
+ }
1617
+ return h('div', { key: path, 'data-dpr-node': '' },
1416
1618
  h('div', {
1417
- style: { ...S.topicHead, ...(depth > 0 ? { paddingLeft: 6 + depth * 10 } : {}) }, 'data-dpr-row': '', 'data-dpr-topic': path,
1418
- onClick: () => {
1419
- const next = { ...closed, [path]: !collapsed }
1420
- setClosed(next)
1421
- try { localStorage.setItem('dpr.treeClosed', JSON.stringify(next)) } catch {}
1422
- },
1619
+ style: S.topicHead, className: 'dpr-topic-row', role: 'treeitem', tabIndex: 0,
1620
+ 'aria-expanded': !collapsed, 'data-dpr-row': '', 'data-dpr-topic': path,
1621
+ onClick: toggle, onKeyDown: (e) => onRowKey(e, toggle),
1423
1622
  },
1424
- h('span', { style: { ...S.caret, transform: collapsed ? 'rotate(-90deg)' : 'none' } }, '▾'),
1425
- h('span', { style: { flex: 1, overflow: 'hidden', textOverflow: 'ellipsis' }, title: path }, node.name || path),
1426
- h('button', { style: S.iconBtn, title: t('uploadHere'), onClick: (e) => { e.stopPropagation(); upload(path) } }, '⬆'),
1427
- h('button', { style: S.iconBtn, title: t('newSubTopic'), onClick: (e) => { e.stopPropagation(); setAskSub({ parent: path }) } }, '+'),
1428
- h('button', {
1429
- 'data-dpr-act': 'rename', style: S.iconBtn, title: t('rename'),
1430
- onClick: (e) => { e.stopPropagation(); setRenaming({ kind: 'topic', topic: path }) },
1431
- }, '✎'),
1432
- h('button', {
1433
- 'data-dpr-act': 'move', style: S.iconBtn, title: t('moveTopic'),
1434
- onClick: (e) => { e.stopPropagation(); setMoving({ topic: path }) },
1435
- }, '→'),
1436
- h('button', {
1437
- 'data-dpr-act': 'del', style: S.iconBtn, title: t('delTopic'),
1438
- onClick: (e) => { e.stopPropagation(); openDelete('topic', path, path) },
1439
- }, '🗑'),
1623
+ h('span', { style: { ...S.caret, visibility: hasKids ? 'visible' : 'hidden', transform: collapsed ? 'rotate(-90deg)' : 'none' } }, h(LibraryIcon, { name: 'chevron', size: 14 })),
1624
+ h('span', { className: 'dpr-topic-icon', 'aria-hidden': true }, h(LibraryIcon, { name: 'folder', size: 16 })),
1625
+ renamingThis
1626
+ ? h(InlineRename, {
1627
+ initial: node.name || path.split('/').pop(), label: t('renameTopic'),
1628
+ onSave: async (name) => {
1629
+ const parent = path.includes('/') ? path.slice(0, path.lastIndexOf('/') + 1) : ''
1630
+ const ok = await doRename('topic', path, null, parent + name)
1631
+ if (ok) setRenaming(null)
1632
+ return ok
1633
+ },
1634
+ onCancel: () => setRenaming(null),
1635
+ })
1636
+ : h('span', { style: S.rowLabel, title: path }, node.name || path),
1637
+ !renamingThis && paperCount > 0 ? h('span', { style: S.count, title: `${paperCount} PDF` }, paperCount) : null,
1638
+ !renamingThis && h(RowMenu, {
1639
+ label: t('topicActions'), items: [
1640
+ { key: 'upload', icon: 'upload', label: t('uploadHere'), onSelect: () => upload(path) },
1641
+ { key: 'subtopic', icon: 'subtopic', label: t('newSubTopic'), onSelect: () => setAskSub({ parent: path }) },
1642
+ { key: 'rename', icon: 'rename', label: t('rename'), onSelect: () => setRenaming({ kind: 'topic', topic: path }) },
1643
+ { key: 'move', icon: 'move', label: t('moveTopic'), onSelect: () => setMoving({ topic: path }) },
1644
+ { key: 'del', icon: 'trash', label: t('delTopic'), danger: true, onSelect: () => openDelete('topic', path, path) },
1645
+ ],
1646
+ }),
1440
1647
  ),
1441
- !collapsed && h('div', { style: S.items },
1648
+ !collapsed && h('div', { style: S.items, role: 'group' },
1442
1649
  // 论文节点(叶子):路径 = 父专题路径 + 论文名
1443
1650
  childPapers.map((p) => {
1444
1651
  const isCurrentPaper = cur && cur.topic === p.topic && cur.name === p.name
1652
+ const renamingThisPaper = renaming?.kind === 'paper' && renaming.topic === p.topic && renaming.name === p.name
1445
1653
  return h('div', {
1446
1654
  key: path + '/' + p.name,
1447
- style: { ...S.item, ...(depth > 0 ? { paddingLeft: 6 + depth * 10 } : {}), ...(isCurrentPaper ? S.active : {}) },
1655
+ style: { ...S.item, ...(isCurrentPaper ? S.active : {}) },
1656
+ className: isCurrentPaper ? 'dpr-paper-row dpr-active' : 'dpr-paper-row',
1657
+ role: 'treeitem', tabIndex: 0, 'aria-current': isCurrentPaper ? 'page' : undefined,
1448
1658
  'data-dpr-row': '', 'data-dpr-paper': path + '/' + p.name,
1449
1659
  title: p.pdfPath || p.name,
1450
- onClick: () => enter(p.topic, p.name),
1451
- }, '📄 ',
1452
- h('span', { style: { flex: 1, overflow: 'hidden', textOverflow: 'ellipsis' } }, p.name),
1453
- h('button', {
1454
- 'data-dpr-act': 'rename', style: S.iconBtn, title: t('rename'),
1455
- onClick: (e) => { e.stopPropagation(); setRenaming({ kind: 'paper', topic: p.topic, name: p.name }) },
1456
- }, '✎'),
1457
- h('button', {
1458
- 'data-dpr-act': 'del', style: S.iconBtn, title: t('delPaper'),
1459
- onClick: (e) => { e.stopPropagation(); openDelete('paper', p.topic, p.name) },
1460
- }, '🗑'))
1660
+ onClick: () => enter(p.topic, p.name), onKeyDown: (e) => onRowKey(e, () => enter(p.topic, p.name)),
1661
+ },
1662
+ h('span', { className: 'dpr-paper-icon', 'aria-hidden': true }, h(LibraryIcon, { name: 'paper', size: 15 })),
1663
+ renamingThisPaper
1664
+ ? h(InlineRename, {
1665
+ initial: p.name, label: t('renamePaper'),
1666
+ onSave: async (name) => {
1667
+ const ok = await doRename('paper', p.topic, p.name, name)
1668
+ if (ok) setRenaming(null)
1669
+ return ok
1670
+ },
1671
+ onCancel: () => setRenaming(null),
1672
+ })
1673
+ : h('span', { style: S.rowLabel }, p.name),
1674
+ !renamingThisPaper && h(RowMenu, {
1675
+ label: t('paperActions'), items: [
1676
+ { key: 'rename', icon: 'rename', label: t('rename'), onSelect: () => setRenaming({ kind: 'paper', topic: p.topic, name: p.name }) },
1677
+ { key: 'move', icon: 'move', label: t('movePaper'), onSelect: () => setMovingPaper({ topic: p.topic, name: p.name }) },
1678
+ { key: 'del', icon: 'trash', label: t('delPaper'), danger: true, onSelect: () => openDelete('paper', p.topic, p.name) },
1679
+ ],
1680
+ }))
1461
1681
  }),
1462
1682
  // 子专题(递归)
1463
1683
  children.map((c) => renderNode(c, depth + 1)),
@@ -1471,23 +1691,26 @@ window.__ModuleLoader__.load({
1471
1691
  h('button', {
1472
1692
  type: 'button', style: S.railBtn, 'data-dpr-rail': '', title: t('library'),
1473
1693
  'aria-label': t('library'), onClick: () => expandSidebar && expandSidebar(),
1474
- }, '📚'))
1694
+ }, h(LibraryIcon, { name: 'library', size: 19 })))
1475
1695
  : h(React.Fragment, null,
1476
1696
  h('div', { style: S.head },
1477
- h('span', { style: { flex: 1 } }, t('library')),
1478
- h('button', { style: S.iconBtn, title: t('upload'), onClick: () => uploadSmart() }, '⬆'),
1479
- h('button', { style: S.iconBtn, title: t('newTopic'), onClick: newTopic }, '+'),
1480
- h('button', { style: S.iconBtn, title: 'refresh', onClick: refresh }, '⟳'),
1697
+ h('span', { style: S.headTitle },
1698
+ h('span', null, t('library')),
1699
+ papers.length > 0 ? h('span', { style: S.count }, papers.length) : null),
1700
+ h('button', { type: 'button', style: S.iconBtn, title: t('upload'), 'aria-label': t('upload'), onClick: () => uploadSmart() }, h(LibraryIcon, { name: 'upload', size: 15 })),
1701
+ h('button', { type: 'button', style: S.iconBtn, title: t('newTopic'), 'aria-label': t('newTopic'), onClick: newTopic }, h(LibraryIcon, { name: 'plus', size: 16 })),
1702
+ h('button', { type: 'button', style: S.iconBtn, title: t('refresh'), 'aria-label': t('refresh'), onClick: refresh }, h(LibraryIcon, { name: 'refresh', size: 15 })),
1481
1703
  ),
1482
1704
  lib && topics.length === 0 && h('div', { style: S.empty },
1483
1705
  `${t('empty')}:${t('hint')}`,
1484
- h('div', { style: { display: 'flex', gap: '8px', margin: '8px 0 2px' } },
1485
- h('button', { type: 'button', style: S.linkBtn, onClick: () => uploadSmart() }, '⬆ ', t('uploadBtn')),
1486
- h('button', { type: 'button', style: S.linkBtn, onClick: newTopic }, '+ ', t('newTopic')))),
1706
+ h('div', { style: { display: 'flex', gap: '8px', margin: '10px 0 2px' } },
1707
+ h('button', { type: 'button', style: S.linkBtn, onClick: () => uploadSmart() }, h(LibraryIcon, { name: 'upload', size: 14 }), t('uploadBtn')),
1708
+ h('button', { type: 'button', style: S.linkBtn, onClick: newTopic }, h(LibraryIcon, { name: 'plus', size: 14 }), t('newTopic')))),
1487
1709
  // 递归渲染专题树(方案 §B2.3):专题节点可折叠,论文节点是叶子。
1488
1710
  // 数据来自服务端 /api/library 的 `tree`(完整嵌套树);`papers` 里的 topic 是相对路径,
1489
1711
  // 逐节点用 path 精确匹配(**不用前缀匹配** —— `A` 会误伤兄弟 `A/B`,R10 的教训)。
1490
- (lib?.tree ?? topics.map((t) => ({ name: t, path: t, papers: [], children: [] }))).map((node) => renderNode(node, 0)),
1712
+ h('div', { role: 'tree', 'aria-label': t('library') },
1713
+ (lib?.tree ?? topics.map((topic) => ({ name: topic, path: topic, papers: [], children: [] }))).map((node) => renderNode(node, 0))),
1491
1714
  )
1492
1715
 
1493
1716
  return h('div', {
@@ -1531,18 +1754,12 @@ window.__ModuleLoader__.load({
1531
1754
  onCancel: () => setMoving(null),
1532
1755
  }),
1533
1756
  document.body),
1534
- // 重命名:上游 v1.3.0 的页内输入弹窗(初始值 = 旧名,走 migrateLsKeys 迁移本地记忆)
1535
- renaming && createPortal(
1536
- h(AskText, {
1537
- title: (renaming.kind === 'topic' ? t('renameTopic') : t('renamePaper')) + ':',
1538
- initial: renaming.kind === 'topic' ? renaming.topic : renaming.name,
1539
- confirmText: t('ok'), cancelText: t('cancel'),
1540
- onConfirm: (name) => {
1541
- const r = renaming
1542
- setRenaming(null)
1543
- doRename(r.kind, r.topic, r.name, name)
1544
- },
1545
- onCancel: () => setRenaming(null),
1757
+ // 论文移动:目标专题直接选,避免手输嵌套路径;重命名则在树行内联完成。
1758
+ movingPaper && createPortal(
1759
+ h(MovePaperDialog, {
1760
+ topics: destinationTopics, currentTopic: movingPaper.topic,
1761
+ onConfirm: (toTopic) => doMovePaper(movingPaper.topic, movingPaper.name, toTopic),
1762
+ onCancel: () => setMovingPaper(null),
1546
1763
  }),
1547
1764
  document.body),
1548
1765
  // 删除:确认框必须列出服务端给的清单;专题删除还要输入专题名
@@ -1969,10 +2186,26 @@ window.__ModuleLoader__.load({
1969
2186
  if (!document.getElementById('dpr-surface-css')) {
1970
2187
  const styleEl = document.createElement('style')
1971
2188
  styleEl.id = 'dpr-surface-css'
1972
- styleEl.textContent = '[data-dpr-rail]:hover,[data-dpr-mode]:hover{background:var(--dsw-alias-interactive-bg-hover)!important}'
1973
- // 树行内的 ✎🗑 操作按钮:默认隐身,行悬停才现身(不再有「待确认态常亮」的 armed 状态)
1974
- + '[data-dpr-act]{opacity:0!important;transition:opacity .12s}'
1975
- + '[data-dpr-row]:hover [data-dpr-act]{opacity:1!important}'
2189
+ styleEl.textContent = [
2190
+ '[data-dpr-rail]:hover,[data-dpr-mode]:hover{background:var(--dsw-alias-interactive-bg-hover)!important}',
2191
+ '[data-dsh-plugin="dsh-paper-reader"] svg{display:block;flex:none}',
2192
+ '[data-dpr-row]{transition:background .12s ease,color .12s ease}',
2193
+ '[data-dpr-row]:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.09))!important}',
2194
+ '[data-dpr-row]:focus-visible{box-shadow:inset 0 0 0 2px var(--dsw-alias-label-action-primary,#0969da)}',
2195
+ '[data-dpr-row].dpr-active{background:var(--dsw-alias-bg-active,rgba(9,105,218,.12))!important}',
2196
+ '[data-dpr-row].dpr-active:before{content:"";position:absolute;left:0;top:7px;bottom:7px;width:2px;border-radius:2px;background:var(--dsw-alias-label-action-primary,#0969da)}',
2197
+ '.dpr-topic-icon{color:var(--dsw-alias-label-tertiary,#8c959f)}',
2198
+ '.dpr-paper-icon{color:var(--dsw-alias-label-tertiary,#8c959f)}',
2199
+ '.dpr-active .dpr-paper-icon,[data-dpr-row]:hover .dpr-topic-icon{color:currentColor}',
2200
+ '.dpr-row-menu-trigger{opacity:0!important;transition:opacity .12s,background .12s}',
2201
+ '[data-dpr-row]:hover .dpr-row-menu-trigger,[data-dpr-row]:focus-within .dpr-row-menu-trigger,.dpr-row-menu-trigger[aria-expanded="true"]{opacity:1!important}',
2202
+ '.dpr-row-menu-trigger:hover,.dpr-row-menu-trigger:focus-visible{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))!important;outline:none}',
2203
+ '.dpr-row-menu{z-index:100000;box-sizing:border-box;width:168px;padding:5px;border:1px solid var(--dsw-alias-border-l1,#d0d7de);border-radius:9px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 10px 30px rgba(0,0,0,.18);color:var(--dsw-alias-label-primary,#24292f);font:13px -apple-system,"SF Pro","PingFang SC",sans-serif}',
2204
+ '.dpr-row-menu button{display:flex;align-items:center;gap:9px;width:100%;min-height:32px;padding:6px 8px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer}',
2205
+ '.dpr-row-menu button:hover,.dpr-row-menu button:focus-visible{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.09));outline:none}',
2206
+ '.dpr-row-menu button.danger{color:var(--dsw-alias-state-danger-primary,#cf222e)}',
2207
+ '@media(prefers-reduced-motion:reduce){[data-dpr-row],[data-dpr-row] span,.dpr-row-menu-trigger{transition:none!important}}',
2208
+ ].join('')
1976
2209
  document.head.appendChild(styleEl)
1977
2210
  }
1978
2211
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ggboy123/dsh-paper-reader",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "description": "DeepSeek Harness 插件:论文伴读工作台 — PDF 转录 / 检索 / 原生对话伴读 + 内置阅读器页面。",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/reader/index.html CHANGED
@@ -245,15 +245,24 @@
245
245
  border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 600; flex: none; }
246
246
  #note-head .spacer, #note-actions .spacer { flex: 1; }
247
247
  #note-headcount { font-weight: 400; color: var(--text-2); font-variant-numeric: tabular-nums; }
248
- #note-list { flex: 1; overflow: auto; padding: 4px 8px 10px; }
249
- .note-item { display: block; width: 100%; text-align: left; border: 1px solid var(--border); border-radius: 6px;
250
- background: var(--bg); color: var(--text); padding: 6px 8px; margin: 5px 0; cursor: pointer; font: inherit; font-size: 12px; line-height: 1.5; }
251
- .note-item:hover { border-color: var(--accent); }
252
- .note-item .ni-meta { display: block; color: var(--accent); font-size: 11px; margin-bottom: 2px; }
253
- .note-item .ni-meta .ni-time { float: right; color: var(--text-2); font-weight: 400; }
248
+ #note-list { flex: 1; overflow: auto; padding: 6px 8px 10px; }
249
+ .note-item { position: relative; width: 100%; margin: 6px 0; border: 1px solid var(--border); border-radius: 7px;
250
+ background: var(--bg); color: var(--text); font-size: 12px; line-height: 1.5; }
251
+ .note-item:hover, .note-item:focus-within { border-color: var(--accent); }
252
+ .note-item-main { display: block; width: 100%; padding: 7px 9px; border: 0; border-radius: 7px;
253
+ background: transparent; color: inherit; text-align: left; cursor: pointer; font: inherit; }
254
+ .note-item-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
255
+ .note-item .ni-meta { display: flex; align-items: center; color: var(--accent); font-size: 11px; margin-bottom: 3px; }
256
+ .note-item .ni-meta .ni-time { margin-left: auto; padding-right: 37px; color: var(--text-2); font-weight: 400; font-size: 10.5px; }
257
+ .note-item.delete-armed .ni-meta .ni-time { visibility: hidden; }
254
258
  .note-item .ni-body { display: block; white-space: pre-wrap; word-break: break-word; }
255
- .note-item .ni-quote { display: block; color: var(--text-2); font-size: 11px; margin-top: 3px;
259
+ .note-item .ni-quote { display: block; color: var(--text-2); font-size: 11px; margin-top: 4px;
256
260
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
261
+ .note-item-delete { position: absolute; z-index: 1; top: 5px; right: 6px; min-width: 32px; height: 21px; padding: 0 4px;
262
+ border: 0; border-radius: 4px; background: transparent; color: var(--text-2); cursor: pointer; font: inherit; font-size: 11px; }
263
+ .note-item-delete:hover, .note-item-delete:focus-visible { background: var(--panel); color: #cf222e; outline: 1px solid var(--border); }
264
+ .note-item-delete.armed { background: #cf222e; color: #fff; }
265
+ .note-item-delete:disabled { opacity: .55; cursor: default; }
257
266
  #note-empty { padding: 14px 6px; color: var(--text-2); font-size: 12px; line-height: 1.6; }
258
267
  #note-editor { display: none; flex-direction: column; flex: 1; min-height: 0; padding: 6px 8px 8px; }
259
268
  #note-window.editing #note-list, #note-window.editing #note-empty { display: none; }
@@ -1590,11 +1599,12 @@ window.dprFindDebug = () => {
1590
1599
  盒子层 pointer-events:none,悬停/点击靠坐标命中测试 —— 绝不挡住划词选字。 */
1591
1600
  const NOTE_WIN_KEY = 'dpr.noteWin';
1592
1601
  const NOTE_BODY_MAX = 20000;
1593
- const notes = { list: [], shown: false, editing: null, isNew: true, armed: false, loading: false };
1602
+ const notes = { list: [], shown: false, editing: null, isNew: true, armed: false, listDeleteId: null, loading: false };
1594
1603
  let noteWin = { x: null, y: null, w: 330, h: 360 };
1595
1604
  const noteWinEl = $('note-window');
1596
1605
  const noteTipEl = $('note-tip');
1597
1606
  let noteArmTimer = 0;
1607
+ let noteListDeleteTimer = 0;
1598
1608
  let noteHoverRaf = 0;
1599
1609
  let noteHoverId = null;
1600
1610
 
@@ -1882,6 +1892,7 @@ function noteWinShow(on) {
1882
1892
  if (!on) {
1883
1893
  noteWinEl.classList.remove('on');
1884
1894
  notes.shown = false;
1895
+ noteResetListDelete();
1885
1896
  noteHideTip();
1886
1897
  return;
1887
1898
  }
@@ -1900,6 +1911,7 @@ function renderNoteList() {
1900
1911
  const list = $('note-list');
1901
1912
  const head = $('note-headcount');
1902
1913
  if (!list || !head) return;
1914
+ noteResetListDelete();
1903
1915
  head.textContent = notes.list.length ? `${notes.list.length} 条` : '';
1904
1916
  list.textContent = '';
1905
1917
  if (!notes.list.length) {
@@ -1920,9 +1932,12 @@ function renderNoteList() {
1920
1932
  });
1921
1933
  const frag = document.createDocumentFragment();
1922
1934
  for (const n of sorted) {
1935
+ const item = document.createElement('div');
1936
+ item.className = 'note-item';
1937
+ item.dataset.id = n.id;
1923
1938
  const btn = document.createElement('button');
1924
1939
  btn.type = 'button';
1925
- btn.className = 'note-item';
1940
+ btn.className = 'note-item-main';
1926
1941
  btn.dataset.id = n.id;
1927
1942
  btn.title = n.anchor && n.anchor.page ? `跳到第 ${n.anchor.page} 页` : '这条笔记没有可定位的原文位置';
1928
1943
  const meta = document.createElement('span');
@@ -1944,7 +1959,16 @@ function renderNoteList() {
1944
1959
  q.textContent = '「' + String(n.quote).replace(/\s+/g, ' ') + '」';
1945
1960
  btn.appendChild(q);
1946
1961
  }
1947
- frag.appendChild(btn);
1962
+ const del = document.createElement('button');
1963
+ del.type = 'button';
1964
+ del.className = 'note-item-delete';
1965
+ del.dataset.noteDelete = n.id;
1966
+ del.textContent = '删除';
1967
+ del.title = '删除这条笔记';
1968
+ del.setAttribute('aria-label', `删除笔记:${body.slice(0, 40)}`);
1969
+ item.appendChild(btn);
1970
+ item.appendChild(del);
1971
+ frag.appendChild(item);
1948
1972
  }
1949
1973
  list.appendChild(frag);
1950
1974
  }
@@ -2005,6 +2029,33 @@ async function noteSave() {
2005
2029
  } catch (e) { toast('保存失败:' + e.message, 6000); }
2006
2030
  $('note-save').disabled = false;
2007
2031
  }
2032
+ function noteResetListDelete() {
2033
+ clearTimeout(noteListDeleteTimer);
2034
+ notes.listDeleteId = null;
2035
+ for (const btn of document.querySelectorAll('.note-item-delete')) {
2036
+ btn.disabled = false;
2037
+ btn.classList.remove('armed');
2038
+ btn.textContent = '删除';
2039
+ btn.title = '删除这条笔记';
2040
+ btn.closest('.note-item')?.classList.remove('delete-armed');
2041
+ }
2042
+ }
2043
+ function noteArmListDelete(note, btn) {
2044
+ if (!note || !note.id || !btn) return;
2045
+ if (notes.listDeleteId !== note.id) {
2046
+ noteResetListDelete();
2047
+ notes.listDeleteId = note.id;
2048
+ btn.classList.add('armed');
2049
+ btn.closest('.note-item')?.classList.add('delete-armed');
2050
+ btn.textContent = '确认删除';
2051
+ btn.title = '再点一次确认删除这条笔记';
2052
+ noteListDeleteTimer = setTimeout(noteResetListDelete, 3000);
2053
+ return;
2054
+ }
2055
+ clearTimeout(noteListDeleteTimer);
2056
+ btn.disabled = true;
2057
+ void noteDoDelete(note);
2058
+ }
2008
2059
  function noteArmDelete() {
2009
2060
  const btn = $('note-delete');
2010
2061
  if (!notes.editing || notes.isNew) return;
@@ -2037,6 +2088,7 @@ async function noteDoDelete(note) {
2037
2088
  notesReapply();
2038
2089
  toast('笔记已删除');
2039
2090
  } catch (e) { toast('删除失败:' + e.message, 6000); }
2091
+ finally { noteResetListDelete(); }
2040
2092
  }
2041
2093
  async function noteGoto(note) {
2042
2094
  if (!note) return;
@@ -2089,7 +2141,14 @@ $('note-save').onclick = () => void noteSave();
2089
2141
  $('note-cancel').onclick = () => noteSetEditing(false);
2090
2142
  $('note-delete').onclick = () => noteArmDelete();
2091
2143
  $('note-list').addEventListener('click', (e) => {
2092
- const btn = e.target.closest ? e.target.closest('.note-item') : null;
2144
+ const del = e.target.closest ? e.target.closest('[data-note-delete]') : null;
2145
+ if (del) {
2146
+ e.preventDefault();
2147
+ e.stopPropagation();
2148
+ noteArmListDelete(noteById(del.dataset.noteDelete), del);
2149
+ return;
2150
+ }
2151
+ const btn = e.target.closest ? e.target.closest('.note-item-main') : null;
2093
2152
  if (!btn) return;
2094
2153
  void noteGoto(noteById(btn.dataset.id));
2095
2154
  });