Spaces:
Running
Running
root commited on
Commit ·
c46ffbd
1
Parent(s): 23d257d
稿纸开关侧栏不跳回开头;阅读进度:接着看、目录每章进度、回到原处提示、下一章;协作 AI 审查全景包与牵连检查
Browse files- fanqie/agent.js +34 -3
- fanqie/dist/index.html +2 -2
- public/assets/{index-CuW-4l0q.js → index-DnLQfh19.js} +0 -0
- public/assets/{index-DkBCnEWt.css → index-Ih3zuQhz.css} +0 -0
- public/index.html +2 -2
- ui-src/src/rooms/Book.tsx +38 -4
- ui-src/src/rooms/Editor.tsx +44 -9
- ui-src/src/rooms/Reader.tsx +18 -2
- ui-src/src/rooms/progress.ts +65 -0
- ui-src/src/styles.css +25 -0
fanqie/agent.js
CHANGED
|
@@ -458,12 +458,34 @@ module.exports = function buildAgent(express, projects) {
|
|
| 458 |
const dropRaw = v => JSON.parse(JSON.stringify(v, (k, x) => (k === 'text' || k === 'edits' || k === 'raw' || k === 'source' || k === 'text_locked') ? undefined : x))
|
| 459 |
|
| 460 |
// 把作品资料打包。attach: overview / bible / outline / toc / chapters:1-3 / chapter:<id或章号>
|
|
|
|
| 461 |
// 以及共享资料:rank(热榜总览)/ rank:<分类,如 1_1141> / motif:<卡片uid> / motif_role:<人物,如 哥哥> / material:<素材uid> / refs(本书参考素材)/ rules(番茄平台规定)
|
| 462 |
async function material(pid, attach, maxChars) {
|
| 463 |
const P = pid ? await projects.getProject(pid) : { project: null, chapters: [] }
|
| 464 |
const parts = []
|
| 465 |
const pick = (o, ks) => Object.fromEntries(ks.filter(k => o[k] !== undefined && o[k] !== '' && !(Array.isArray(o[k]) && !o[k].length)).map(k => [k, o[k]]))
|
|
|
|
|
|
|
|
|
|
| 466 |
for (const a of attach) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
if (a === 'overview') parts.push('【作品概览】\n' + JSON.stringify(pick(P.project, ['title', 'genre', 'target_platform', 'target_words', 'pov', 'style', 'premise', 'status']), null, 1))
|
| 468 |
else if (a === 'bible') { const { updated_at, source_material_uids, ...b } = P.bible || {}; parts.push('【作品圣经】\n' + JSON.stringify(b, null, 1)) }
|
| 469 |
else if (a === 'outline') { const { updated_at, ...o } = P.outline || {}; parts.push('【大纲】\n' + JSON.stringify(o, null, 1)) }
|
|
@@ -512,7 +534,13 @@ module.exports = function buildAgent(express, projects) {
|
|
| 512 |
'不要编造平台规则或数据;不要提供照抄现成作品的内容;涉及番茄内容红线的写法一律不建议。',
|
| 513 |
].join('\n')
|
| 514 |
const TASK_SYSTEM = {
|
| 515 |
-
review:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
research: '本次任务:调研。请查证并整理写作 AI 问到的信息(平台规则、题材趋势、时代背景、专业知识等),注明信息来源和时间,区分「��定」和「推测」。',
|
| 517 |
idea: '本次任务:出主意。请给出多个差异明显的方案,每个方案说明亮点、风险和适合的读者,最后给出你的推荐和理由。',
|
| 518 |
draft: '本次任务:起草。请按要求写出草稿,供写作 AI 参考和改写;保持番茄平台的短句、强节奏风格,不出现违规内容。',
|
|
@@ -817,7 +845,10 @@ module.exports = function buildAgent(express, projects) {
|
|
| 817 |
'1. **动笔前**:读作者状态(手册 → 作者状态,即本守则第 1 节)、作品资料、上一章结尾;确认本章目标。',
|
| 818 |
'2. **写作**:一章一章写,每章写完存为新版本(`POST .../chapters/{章节ID}/versions`,`created_by` 填 `AI`),不要覆盖作者的版本。',
|
| 819 |
'3. **自查**:写完一章,读 `/fanqie/api/agent/rules` 里的番茄平台规定,逐条检查本章,把结果写入检查记录(见第 5 节)。作者在章节编辑页的「检查」栏看这些结果,那里没有「运行检查」按钮,检查只由你做。',
|
| 820 |
-
'4. **请协作 AI 把关或帮忙**:概览、圣经、大纲有重大改动,或写完一卷,就请协作 AI 审查;需要查资料、出方案时也可以派给它(见第 6 节)。读完回复再改,并回写处理结果。',
|
|
|
|
|
|
|
|
|
|
| 821 |
'5. **按批注修改**:作者说「按批注修改第 X 章」时,读该章待改批注,逐条改正文、存新版本;在每条批注上写 `reply`(改了什么)并把 `status` 改成 `fixed`(`PATCH .../notes/{批注ID}`)。',
|
| 822 |
'6. **交付说明**:每次工作结束,用三五句话告诉作者做了什么、哪些地方拿不准。', '')
|
| 823 |
L.push('## 5. 检查记录:自查清单与平台规定', '',
|
|
@@ -830,7 +861,7 @@ module.exports = function buildAgent(express, projects) {
|
|
| 830 |
L.push('## 6. 协作 AI(另一个 AI,可以派活)', '',
|
| 831 |
`- 当前设置:${cfg.mode === 'surf' ? `Surf Chat(${SURF_MODELS[cfg.surf_model] || cfg.surf_model})` : cfg.endpoint ? `${cfg.mode} 接口` : '接口未配置'};令牌${cfg.token ? `已保存(末 4 位 ${String(cfg.token).slice(-4)}${cfg.refresh_token && cfg.auto_refresh ? ',会自动续期' : ',约 1 小时过期'})` : '未保存'}。令牌只存在服务器上,你看不到也不需要看到。`,
|
| 832 |
'- 它能做的活:`review` 审查(默认)、`research` 调研、`idea` 出主意、`draft` 起草、`other` 其他。例如:问它概览、圣经、大纲是否合乎逻辑;查某个年代的生活细节;给第 X 章出三种冲突方案。',
|
| 833 |
-
'- 提问:`POST /fanqie/api/agent/reviewer/ask`,字段:`project_id`、`task`、`topic`(如「圣经逻辑」)、`question`、`attach`(可选:作品资料 `overview`、`bible`、`outline`、`toc`、`chapters:1-5`、`chapter:{章节ID或章号}`、`refs`(本书参考素材摘要);共享资料 `rank`(热榜总览)、`rank:{分类,如 1_1141}`、`motif:{母题卡片uid}`、`motif_role:{人物,如 亲兄弟}`、`material:{素材馆uid}`(只给摘要和改写卡)、`rules`(番茄平台规定))、`wait`(最多等几秒,默认 50)、`queue`(默认开:令牌过期时先排队,作者粘贴新令牌或服务器续期成功后自动发出,状态为 `queued`)、`continue`(填上一次的 `ask_id` 或 `"last"`,就在同一个对话里接着问,对方记得上下文)。',
|
| 834 |
'- 回复要几分钟时,接口先返回 `state: "running"`;之后用 `GET /fanqie/api/agent/reviewer/log/{ask_id}?project_id=&wait=120` 取结果(`state` 变成 `done` 或 `error`)。不要重复提问同一件事。',
|
| 835 |
'- 读回复后自己判断采纳哪些——它的意见只是参考,与守则或作者要求冲突时以守则和作者为准。改完用 `PATCH /fanqie/api/agent/reviewer/log/{ask_id}` 回写 `status`(adopted / partial / rejected)和 `response`(怎么处理的)。',
|
| 836 |
'- **你和协作 AI 是同级的**:它的每条意见你都要自己重新想一遍,不能照单全收。两边意见不一致时,**按你的判断执行**,并把分歧逐条记到对应章节的旁栏(作者在章节编辑页的「分歧」栏里看,**绝不写进正文**):`POST /fanqie/api/projects/{project_id}/peer`,body `{"items":[{"chapter_number":11,"ask_id":"…","topic":"一句话主题","reviewer_said":"协作 AI 的意见","my_view":"我的判断和理由","decision":"最后怎么做","verdict":"disagree"}]}`。`verdict` 取 `disagree`(不一致,按我的)/ `partial`(部分采纳)/ `agree`(一致)。不属于某一章的意见不填章节号,算全书层面。查看:`GET /fanqie/api/projects/{project_id}/peer?chapter_id=`;修改或删除:`PATCH` / `DELETE /fanqie/api/projects/{project_id}/peer/{item_id}`。',
|
|
|
|
| 458 |
const dropRaw = v => JSON.parse(JSON.stringify(v, (k, x) => (k === 'text' || k === 'edits' || k === 'raw' || k === 'source' || k === 'text_locked') ? undefined : x))
|
| 459 |
|
| 460 |
// 把作品资料打包。attach: overview / bible / outline / toc / chapters:1-3 / chapter:<id或章号>
|
| 461 |
+
// review:<章号>(审一章的全景包:本章 + 前两章 + 已写好的全部后文 + 概览/圣经/大纲/目录)
|
| 462 |
// 以及共享资料:rank(热榜总览)/ rank:<分类,如 1_1141> / motif:<卡片uid> / motif_role:<人物,如 哥哥> / material:<素材uid> / refs(本书参考素材)/ rules(番茄平台规定)
|
| 463 |
async function material(pid, attach, maxChars) {
|
| 464 |
const P = pid ? await projects.getProject(pid) : { project: null, chapters: [] }
|
| 465 |
const parts = []
|
| 466 |
const pick = (o, ks) => Object.fromEntries(ks.filter(k => o[k] !== undefined && o[k] !== '' && !(Array.isArray(o[k]) && !o[k].length)).map(k => [k, o[k]]))
|
| 467 |
+
const chText = async c => c.current_version_id ? ((await projects.getVersion(pid, c.chapter_id, c.current_version_id)).text || '') : ''
|
| 468 |
+
// review:<章号>:审一章时的「全景包」——本章 + 前情 + 已写好的后文 + 全书设定,让协作 AI 知道后面已经怎么写了
|
| 469 |
+
const expanded = []
|
| 470 |
for (const a of attach) {
|
| 471 |
+
const m = /^review:(\d+)$/.exec(a)
|
| 472 |
+
if (!m) { expanded.push(a); continue }
|
| 473 |
+
const n = Number(m[1])
|
| 474 |
+
const sorted = [...P.chapters].sort((x, y) => x.number - y.number)
|
| 475 |
+
const cur = sorted.find(c => c.number === n)
|
| 476 |
+
if (cur) parts.push(`【本次审查:第${n}章 ${cur.title || ''}】\n${await chText(cur)}`)
|
| 477 |
+
parts.push('【审查须知】\n下面附上作品概览、圣经、全书大纲、章节目录(含每章目标)、本章之前两章的全文、本章之后已经写好的章节全文。提意见前先查后文和大纲:后文已经交代或大纲已经安排的,归为「后文已安排」,不要当成问题。')
|
| 478 |
+
for (const k of ['overview', 'bible', 'outline', 'toc']) expanded.push(k)
|
| 479 |
+
const before = sorted.filter(c => c.number >= n - 2 && c.number < n)
|
| 480 |
+
const after = sorted.filter(c => c.number > n && c.current_version_id)
|
| 481 |
+
expanded.push({ before, after })
|
| 482 |
+
}
|
| 483 |
+
for (const a of expanded) {
|
| 484 |
+
if (typeof a === 'object') {
|
| 485 |
+
for (const c of a.before) parts.push(`【前文 · 第${c.number}章 ${c.title || ''}】\n${await chText(c)}`)
|
| 486 |
+
for (const c of a.after) parts.push(`【后文 · 第${c.number}章 ${c.title || ''}${c.status ? `(${c.status})` : ''}】\n${await chText(c)}`)
|
| 487 |
+
continue
|
| 488 |
+
}
|
| 489 |
if (a === 'overview') parts.push('【作品概览】\n' + JSON.stringify(pick(P.project, ['title', 'genre', 'target_platform', 'target_words', 'pov', 'style', 'premise', 'status']), null, 1))
|
| 490 |
else if (a === 'bible') { const { updated_at, source_material_uids, ...b } = P.bible || {}; parts.push('【作品圣经】\n' + JSON.stringify(b, null, 1)) }
|
| 491 |
else if (a === 'outline') { const { updated_at, ...o } = P.outline || {}; parts.push('【大纲】\n' + JSON.stringify(o, null, 1)) }
|
|
|
|
| 534 |
'不要编造平台规则或数据;不要提供照抄现成作品的内容;涉及番茄内容红线的写法一律不建议。',
|
| 535 |
].join('\n')
|
| 536 |
const TASK_SYSTEM = {
|
| 537 |
+
review: [
|
| 538 |
+
'本次任务:审查。你是严格、坦率的网络小说责任编辑,熟悉番茄小说的内容规范、签约标准和读者口味。',
|
| 539 |
+
'提意见之前,先把附带的大纲、章节目录和后文读完。后文已经交代、大纲已经安排的事,不算问题,单独列为「后文已安排」并注明在第几章;只有资料里确实没有着落的,才算问题。',
|
| 540 |
+
'每条意见标一个等级:【硬伤】逻辑断裂、前后矛盾、人物动机说不通、违反平台规定;【建议】可以更好但现在也成立;【后文已安排】。按 硬伤 → 建议 → 后文已安排 的顺序写。',
|
| 541 |
+
'每条硬伤要引原句、说清为什么不成立、给出可执行的修改方向,并写明「改了会牵连哪几章」。',
|
| 542 |
+
'现在成立的写法不要为了“更好”去推翻;不要重写整段正文,必要时只给一两句示范。没问题就直接说「无硬伤」。',
|
| 543 |
+
].join('\n'),
|
| 544 |
research: '本次任务:调研。请查证并整理写作 AI 问到的信息(平台规则、题材趋势、时代背景、专业知识等),注明信息来源和时间,区分「��定」和「推测」。',
|
| 545 |
idea: '本次任务:出主意。请给出多个差异明显的方案,每个方案说明亮点、风险和适合的读者,最后给出你的推荐和理由。',
|
| 546 |
draft: '本次任务:起草。请按要求写出草稿,供写作 AI 参考和改写;保持番茄平台的短句、强节奏风格,不出现违规内容。',
|
|
|
|
| 845 |
'1. **动笔前**:读作者状态(手册 → 作者状态,即本守则第 1 节)、作品资料、上一章结尾;确认本章目标。',
|
| 846 |
'2. **写作**:一章一章写,每章写完存为新版本(`POST .../chapters/{章节ID}/versions`,`created_by` 填 `AI`),不要覆盖作者的版本。',
|
| 847 |
'3. **自查**:写完一章,读 `/fanqie/api/agent/rules` 里的番茄平台规定,逐条检查本章,把结果写入检查记录(见第 5 节)。作者在章节编辑页的「检查」栏看这些结果,那里没有「运行检查」按钮,检查只由你做。',
|
| 848 |
+
'4. **请协作 AI 把关或帮忙**:概览、圣经、大纲有重大改动,或写完一卷,就请协作 AI 审查;需要查资料、出方案时也可以派给它(见第 6 节)。**审单章一律用 `attach: ["review:章号"]`**,把后文和大纲一起给它,免得它把后文已经安排的事当问题。读完回复再改,并回写处理结果。',
|
| 849 |
+
'4.1 **采纳意见之前先验原文**:先回到原文把那一段前后各读一遍,确认原来的写法**真的**不成立再动手;原来成立的,就记成分歧、不改。不能因为“对方提了”就改。',
|
| 850 |
+
'4.2 **改完做牵连检查(必做)**:① 把改动所在的**整场戏**从头读到尾,核对在场的人、谁先走谁后走、动作先后、时间、道具是否还对得上;② 在全书所有已写章节里搜索这次改动涉及的人名、物件、数字、时间词,看前文铺垫和后文回收是否还成立;③ 牵连到的章节在**同一轮**一起改、一起存版本;④ 在处理记录(`resolution` / `response`)里写明「牵连检查:查了第几章到第几章,改了哪几章」。后面的章改了影响前面,前面也要回头改。',
|
| 851 |
+
'4.3 **自查不能只看改的那一句**:自查时以整场戏和前后章为单位重读,不以“这句话本身通顺”为准。',
|
| 852 |
'5. **按批注修改**:作者说「按批注修改第 X 章」时,读该章待改批注,逐条改正文、存新版本;在每条批注上写 `reply`(改了什么)并把 `status` 改成 `fixed`(`PATCH .../notes/{批注ID}`)。',
|
| 853 |
'6. **交付说明**:每次工作结束,用三五句话告诉作者做了什么、哪些地方拿不准。', '')
|
| 854 |
L.push('## 5. 检查记录:自查清单与平台规定', '',
|
|
|
|
| 861 |
L.push('## 6. 协作 AI(另一个 AI,可以派活)', '',
|
| 862 |
`- 当前设置:${cfg.mode === 'surf' ? `Surf Chat(${SURF_MODELS[cfg.surf_model] || cfg.surf_model})` : cfg.endpoint ? `${cfg.mode} 接口` : '接口未配置'};令牌${cfg.token ? `已保存(末 4 位 ${String(cfg.token).slice(-4)}${cfg.refresh_token && cfg.auto_refresh ? ',会自动续期' : ',约 1 小时过期'})` : '未保存'}。令牌只存在服务器上,你看不到也不需要看到。`,
|
| 863 |
'- 它能做的活:`review` 审查(默认)、`research` 调研、`idea` 出主意、`draft` 起草、`other` 其他。例如:问它概览、圣经、大纲是否合乎逻辑;查某个年代的生活细节;给第 X 章出三种冲突方案。',
|
| 864 |
+
'- 提问:`POST /fanqie/api/agent/reviewer/ask`,字段:`project_id`、`task`、`topic`(如「圣经逻辑」)、`question`、`attach`(可选:作品资料 `overview`、`bible`、`outline`、`toc`、`chapters:1-5`、`chapter:{章节ID或章号}`、`review:{章号}`(**审单章用这个**:本章 + ��两章 + 已写好的全部后文 + 概览/圣经/大纲/目录)、`refs`(本书参考素材摘要);共享资料 `rank`(热榜总览)、`rank:{分类,如 1_1141}`、`motif:{母题卡片uid}`、`motif_role:{人物,如 亲兄弟}`、`material:{素材馆uid}`(只给摘要和改写卡)、`rules`(番茄平台规定))、`wait`(最多等几秒,默认 50)、`queue`(默认开:令牌过期时先排队,作者粘贴新令牌或服务器续期成功后自动发出,状态为 `queued`)、`continue`(填上一次的 `ask_id` 或 `"last"`,就在同一个对话里接着问,对方记得上下文)。',
|
| 865 |
'- 回复要几分钟时,接口先返回 `state: "running"`;之后用 `GET /fanqie/api/agent/reviewer/log/{ask_id}?project_id=&wait=120` 取结果(`state` 变成 `done` 或 `error`)。不要重复提问同一件事。',
|
| 866 |
'- 读回复后自己判断采纳哪些——它的意见只是参考,与守则或作者要求冲突时以守则和作者为准。改完用 `PATCH /fanqie/api/agent/reviewer/log/{ask_id}` 回写 `status`(adopted / partial / rejected)和 `response`(怎么处理的)。',
|
| 867 |
'- **你和协作 AI 是同级的**:它的每条意见你都要自己重新想一遍,不能照单全收。两边意见不一致时,**按你的判断执行**,并把分歧逐条记到对应章节的旁栏(作者在章节编辑页的「分歧」栏里看,**绝不写进正文**):`POST /fanqie/api/projects/{project_id}/peer`,body `{"items":[{"chapter_number":11,"ask_id":"…","topic":"一句话主题","reviewer_said":"协作 AI 的意见","my_view":"我的判断和理由","decision":"最后怎么做","verdict":"disagree"}]}`。`verdict` 取 `disagree`(不一致,按我的)/ `partial`(部分采纳)/ `agree`(一致)。不属于某一章的意见不填章节号,算全书层面。查看:`GET /fanqie/api/projects/{project_id}/peer?chapter_id=`;修改或删除:`PATCH` / `DELETE /fanqie/api/projects/{project_id}/peer/{item_id}`。',
|
fanqie/dist/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
-
<script type="module" crossorigin src="/assets/index-
|
| 12 |
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
|
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
+
<script type="module" crossorigin src="/assets/index-DnLQfh19.js"></script>
|
| 12 |
+
<link rel="stylesheet" crossorigin href="/assets/index-Ih3zuQhz.css">
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
public/assets/{index-CuW-4l0q.js → index-DnLQfh19.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
public/assets/{index-DkBCnEWt.css → index-Ih3zuQhz.css}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
public/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
-
<script type="module" crossorigin src="/assets/index-
|
| 12 |
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
|
|
|
| 8 |
<title>小说写作台</title>
|
| 9 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
|
| 10 |
<script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
|
| 11 |
+
<script type="module" crossorigin src="/assets/index-DnLQfh19.js"></script>
|
| 12 |
+
<link rel="stylesheet" crossorigin href="/assets/index-Ih3zuQhz.css">
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
ui-src/src/rooms/Book.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { ErrorNote, Field, Loading, useConfirm, useToast, AutoText, Empty } from
|
|
| 6 |
import ChapterEditor from './Editor'
|
| 7 |
import { BibleView, OutlineView, RefsView } from './Bible'
|
| 8 |
import Reader from './Reader'
|
|
|
|
| 9 |
|
| 10 |
export type BookCtx = {
|
| 11 |
bundle: ProjectBundle
|
|
@@ -102,6 +103,7 @@ function Binder({ ctx, sub, onAddChapter, onCollapse }: { ctx: BookCtx; sub: str
|
|
| 102 |
const refs = bundle.materials?.items?.length || 0
|
| 103 |
const chars = bundle.bible?.characters?.length || 0
|
| 104 |
const totalWords = bundle.chapters.reduce((n, c) => n + (c.word_count || 0), 0)
|
|
|
|
| 105 |
return (
|
| 106 |
<aside className="binder">
|
| 107 |
<div className="binder-top">
|
|
@@ -112,6 +114,7 @@ function Binder({ ctx, sub, onAddChapter, onCollapse }: { ctx: BookCtx; sub: str
|
|
| 112 |
<div className="binder-book-title">{bundle.project.title}</div>
|
| 113 |
<div className="binder-book-sub">{bundle.project.genre || '未定题材'} · {PROJECT_STATUS[bundle.project.status] || bundle.project.status}</div>
|
| 114 |
</button>
|
|
|
|
| 115 |
|
| 116 |
<div className="binder-section">
|
| 117 |
<div className="binder-label">设定</div>
|
|
@@ -134,14 +137,17 @@ function Binder({ ctx, sub, onAddChapter, onCollapse }: { ctx: BookCtx; sub: str
|
|
| 134 |
{groups.map(([vol, list]) => (
|
| 135 |
<div key={vol || '_'} className="binder-vol">
|
| 136 |
{(groups.length > 1 || vol) && <div className="binder-vol-name">{vol || '未分卷'}</div>}
|
| 137 |
-
{list.map(c =>
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
| 139 |
<span className={cx('ch-dot', `st-${c.current_version_id ? (c.status || 'draft') : 'planned'}`)} />
|
| 140 |
<span className="ch-num">{c.number}</span>
|
| 141 |
<span className="ch-title">{c.title || `第${cnNum(c.number)}章`}</span>
|
| 142 |
{c.word_count ? <span className="ch-wc">{c.word_count >= 1000 ? `${(c.word_count / 1000).toFixed(1)}k` : c.word_count}</span> : null}
|
| 143 |
</button>
|
| 144 |
-
))}
|
| 145 |
</div>
|
| 146 |
))}
|
| 147 |
</div>
|
|
@@ -154,6 +160,33 @@ function Binder({ ctx, sub, onAddChapter, onCollapse }: { ctx: BookCtx; sub: str
|
|
| 154 |
)
|
| 155 |
}
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
function BinderLink({ on, icon, children, onClick, meta }: { on: boolean; icon: React.ReactNode; children: React.ReactNode; onClick: () => void; meta?: string }) {
|
| 158 |
return (
|
| 159 |
<button className={cx('binder-link', on && 'on')} onClick={onClick}>
|
|
@@ -198,7 +231,8 @@ function BookAbout({ ctx, onAddChapter }: { ctx: BookCtx; onAddChapter: () => vo
|
|
| 198 |
<h1 className="page-title serif">{p.title}</h1>
|
| 199 |
{written > 0 && (
|
| 200 |
<div className="about-read">
|
| 201 |
-
<
|
|
|
|
| 202 |
{p.target_words > 0 && total > 0 && <div className="about-goal"><i style={{ width: `${Math.min(100, total / p.target_words * 100)}%` }} /><span>完成 {Math.min(100, Math.round(total / p.target_words * 100))}%</span></div>}
|
| 203 |
</div>
|
| 204 |
)}
|
|
|
|
| 6 |
import ChapterEditor from './Editor'
|
| 7 |
import { BibleView, OutlineView, RefsView } from './Bible'
|
| 8 |
import Reader from './Reader'
|
| 9 |
+
import { useBookProgress, pct, isDone } from './progress'
|
| 10 |
|
| 11 |
export type BookCtx = {
|
| 12 |
bundle: ProjectBundle
|
|
|
|
| 103 |
const refs = bundle.materials?.items?.length || 0
|
| 104 |
const chars = bundle.bible?.characters?.length || 0
|
| 105 |
const totalWords = bundle.chapters.reduce((n, c) => n + (c.word_count || 0), 0)
|
| 106 |
+
const prog = useBookProgress(pid)
|
| 107 |
return (
|
| 108 |
<aside className="binder">
|
| 109 |
<div className="binder-top">
|
|
|
|
| 114 |
<div className="binder-book-title">{bundle.project.title}</div>
|
| 115 |
<div className="binder-book-sub">{bundle.project.genre || '未定题材'} · {PROJECT_STATUS[bundle.project.status] || bundle.project.status}</div>
|
| 116 |
</button>
|
| 117 |
+
<ContinueCard pid={pid} chapters={bundle.chapters} current={sub} />
|
| 118 |
|
| 119 |
<div className="binder-section">
|
| 120 |
<div className="binder-label">设定</div>
|
|
|
|
| 137 |
{groups.map(([vol, list]) => (
|
| 138 |
<div key={vol || '_'} className="binder-vol">
|
| 139 |
{(groups.length > 1 || vol) && <div className="binder-vol-name">{vol || '未分卷'}</div>}
|
| 140 |
+
{list.map(c => {
|
| 141 |
+
const rp = prog.chapters[c.chapter_id]?.max || 0
|
| 142 |
+
return (
|
| 143 |
+
<button key={c.chapter_id} className={cx('binder-ch', sub === c.chapter_id && 'on', rp > 0.01 && 'has-rp', isDone(rp) && 'rp-done')} style={rp > 0.01 ? { ['--rp' as any]: pct(rp) } : undefined}
|
| 144 |
+
title={rp > 0.01 ? (isDone(rp) ? '这一章看完了' : `这一章看到 ${pct(rp)}`) : '这一章还没看'} onClick={() => go(`book/${pid}/${c.chapter_id}`)}>
|
| 145 |
<span className={cx('ch-dot', `st-${c.current_version_id ? (c.status || 'draft') : 'planned'}`)} />
|
| 146 |
<span className="ch-num">{c.number}</span>
|
| 147 |
<span className="ch-title">{c.title || `第${cnNum(c.number)}章`}</span>
|
| 148 |
{c.word_count ? <span className="ch-wc">{c.word_count >= 1000 ? `${(c.word_count / 1000).toFixed(1)}k` : c.word_count}</span> : null}
|
| 149 |
</button>
|
| 150 |
+
)})}
|
| 151 |
</div>
|
| 152 |
))}
|
| 153 |
</div>
|
|
|
|
| 160 |
)
|
| 161 |
}
|
| 162 |
|
| 163 |
+
/* 「接着看」:上次在稿纸或通读里看到哪儿,一点就回去;那章看完了就直接给下一章 */
|
| 164 |
+
function ContinueCard({ pid, chapters, current, big }: { pid: string; chapters: Chapter[]; current: string; big?: boolean }) {
|
| 165 |
+
const prog = useBookProgress(pid)
|
| 166 |
+
const sorted = useMemo(() => [...chapters].filter(c => c.current_version_id).sort((a, b) => a.number - b.number), [chapters])
|
| 167 |
+
const last = prog.last
|
| 168 |
+
const at = last ? sorted.findIndex(c => c.chapter_id === last.cid) : -1
|
| 169 |
+
if (!last || at < 0) {
|
| 170 |
+
if (!big || !sorted.length) return null
|
| 171 |
+
return <button className="continue-card big" onClick={() => go(`book/${pid}/${sorted[0].chapter_id}`)}><span className="cc-k">从头开始看</span><span className="cc-t">第{sorted[0].number}章 {sorted[0].title}</span></button>
|
| 172 |
+
}
|
| 173 |
+
let target = sorted[at], r = last.r, label = '接着看'
|
| 174 |
+
if (isDone(r) && sorted[at + 1]) { target = sorted[at + 1]; r = prog.chapters[target.chapter_id]?.r || 0; label = '上一章看完了,下一章' }
|
| 175 |
+
else if (isDone(r)) label = '最新一章看完了'
|
| 176 |
+
const done = sorted.filter(c => isDone(prog.chapters[c.chapter_id]?.max || 0)).length
|
| 177 |
+
const here = current === target.chapter_id || (current === 'read' && last.mode === 'read')
|
| 178 |
+
if (here && !big) return null
|
| 179 |
+
const href = last.mode === 'read' ? `book/${pid}/read/${target.chapter_id}` : `book/${pid}/${target.chapter_id}`
|
| 180 |
+
return (
|
| 181 |
+
<button className={cx('continue-card', big && 'big')} onClick={() => go(href)} title={last.mode === 'read' ? '回到通读' : '回到正文稿纸'}>
|
| 182 |
+
<span className="cc-k">{label}<em>{fmtAgo(new Date(last.at).toISOString())}</em></span>
|
| 183 |
+
<span className="cc-t">第{target.number}章 {target.title}</span>
|
| 184 |
+
<span className="cc-m">{r > 0.01 && !isDone(r) ? `看到 ${pct(r)}` : isDone(r) ? '已看完' : '从开头看'} · 全书看完 {done}/{sorted.length} 章</span>
|
| 185 |
+
<i className="cc-bar"><b style={{ width: pct(r) }} /></i>
|
| 186 |
+
</button>
|
| 187 |
+
)
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
function BinderLink({ on, icon, children, onClick, meta }: { on: boolean; icon: React.ReactNode; children: React.ReactNode; onClick: () => void; meta?: string }) {
|
| 191 |
return (
|
| 192 |
<button className={cx('binder-link', on && 'on')} onClick={onClick}>
|
|
|
|
| 231 |
<h1 className="page-title serif">{p.title}</h1>
|
| 232 |
{written > 0 && (
|
| 233 |
<div className="about-read">
|
| 234 |
+
<ContinueCard pid={p.project_id} chapters={bundle.chapters} current="about" big />
|
| 235 |
+
<button className="btn" onClick={() => go(`book/${p.project_id}/read`)}><BookOpenText size={16} />通读全书</button>
|
| 236 |
{p.target_words > 0 && total > 0 && <div className="about-goal"><i style={{ width: `${Math.min(100, total / p.target_words * 100)}%` }} /><span>完成 {Math.min(100, Math.round(total / p.target_words * 100))}%</span></div>}
|
| 237 |
</div>
|
| 238 |
)}
|
ui-src/src/rooms/Editor.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
import {
|
| 3 |
Save, Maximize2, Minimize2, PanelRightClose, PanelRightOpen, History, ClipboardCheck, BookmarkPlus, Sparkles, FileCog,
|
| 4 |
-
Type, AlignLeft, RotateCcw, Eye, GitCompare, Copy, Search, Send, X, Check, AlertTriangle, Undo2, Highlighter, Scale,
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { locateNotes, NotesPanel, ReviewText, segmentText, useNotes } from './Review'
|
| 7 |
import { agentApi, Chapter, Material, materialsApi, projectsApi, Version, VersionMeta } from '../api'
|
|
@@ -12,6 +12,7 @@ import { AutoText, Empty, ErrorNote, Field, ListEditor, Loading, Modal, Spinner,
|
|
| 12 |
import type { BookCtx } from './Book'
|
| 13 |
import { toRef } from './Bible'
|
| 14 |
import { feedApi } from './RankInspire'
|
|
|
|
| 15 |
|
| 16 |
type Tab = 'chapter' | 'notes' | 'peer' | 'check' | 'ai' | 'versions' | 'refs'
|
| 17 |
const draftKey = (cid: string) => `xs_draft_${cid}`
|
|
@@ -94,6 +95,9 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 94 |
const [pos, setPos] = useState(0)
|
| 95 |
const restoredFor = useRef('')
|
| 96 |
const posTimer = useRef<any>(null)
|
|
|
|
|
|
|
|
|
|
| 97 |
useEffect(() => {
|
| 98 |
if (!detail || restoredFor.current === cid) return
|
| 99 |
restoredFor.current = cid
|
|
@@ -101,7 +105,9 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 101 |
const apply = (r: number) => requestAnimationFrame(() => requestAnimationFrame(() => {
|
| 102 |
const el = scrollRef.current
|
| 103 |
if (!el || !(r > 0.01)) return
|
|
|
|
| 104 |
el.scrollTop = r * (el.scrollHeight - el.clientHeight)
|
|
|
|
| 105 |
}))
|
| 106 |
if (!isNaN(local)) apply(local)
|
| 107 |
else projectsApi.progress(pid).then(p => { const r = p.chapters?.[cid]?.edit_ratio; if (r != null) apply(r) }, () => {})
|
|
@@ -112,7 +118,9 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 112 |
const max = el.scrollHeight - el.clientHeight
|
| 113 |
const r = max > 0 ? Math.min(1, el.scrollTop / max) : 0
|
| 114 |
setPos(r)
|
|
|
|
| 115 |
try { localStorage.setItem(`xs_epos_${cid}`, r.toFixed(3)) } catch {}
|
|
|
|
| 116 |
clearTimeout(posTimer.current)
|
| 117 |
posTimer.current = setTimeout(() => { projectsApi.saveProgress(pid, { chapter: { chapter_id: cid, edit_ratio: Number(r.toFixed(3)) } }).catch(() => {}) }, 2500)
|
| 118 |
}
|
|
@@ -132,15 +140,33 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 132 |
} catch {}
|
| 133 |
}, [debounced, savedText, detail, cid])
|
| 134 |
|
| 135 |
-
/* 自动增高 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
useEffect(() => {
|
| 137 |
-
const
|
| 138 |
-
if (!
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
const updateChapterInBundle = (c: Chapter) => setBundle(b => ({
|
| 146 |
...b,
|
|
@@ -237,6 +263,7 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 237 |
|
| 238 |
const st = saving ? { k: 'saving', full: '正在保存', short: '保存中' } : dirty ? { k: 'dirty', full: '本机已暂存 · 尚未存为版本', short: '未存版本' } : detail.current_version_id ? { k: 'ok', full: '已与云端版本一致', short: '已同步' } : { k: 'new', full: '新章节,还没有版���', short: '新章节' }
|
| 239 |
const showInspector = inspector && !focus
|
|
|
|
| 240 |
|
| 241 |
return (
|
| 242 |
<div className={cx('editor', showInspector && 'with-inspector')}>
|
|
@@ -262,6 +289,13 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 262 |
</div>
|
| 263 |
</div>
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
{restored && (
|
| 266 |
<div className="banner">
|
| 267 |
<AlertTriangle size={15} />
|
|
@@ -287,6 +321,7 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 287 |
</div>)}
|
| 288 |
{disputes.length > 0 && !focus && <div className="dispute-tip"><mark className="dm">黄色底</mark>是和协作 AI 有分歧的句子,只是标注,复制、发布都不会带上。<button className="link-btn" onClick={pickDispute}>去分歧处理</button></div>}
|
| 289 |
<div className="paper-end">{words > 0 ? `— 本章 ${words.toLocaleString()} 字 —` : ''}</div>
|
|
|
|
| 290 |
</article>
|
| 291 |
</div>
|
| 292 |
|
|
|
|
| 1 |
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
import {
|
| 3 |
Save, Maximize2, Minimize2, PanelRightClose, PanelRightOpen, History, ClipboardCheck, BookmarkPlus, Sparkles, FileCog,
|
| 4 |
+
Type, AlignLeft, RotateCcw, Eye, GitCompare, Copy, Search, Send, X, Check, AlertTriangle, Undo2, Highlighter, Scale, ChevronRight,
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { locateNotes, NotesPanel, ReviewText, segmentText, useNotes } from './Review'
|
| 7 |
import { agentApi, Chapter, Material, materialsApi, projectsApi, Version, VersionMeta } from '../api'
|
|
|
|
| 12 |
import type { BookCtx } from './Book'
|
| 13 |
import { toRef } from './Bible'
|
| 14 |
import { feedApi } from './RankInspire'
|
| 15 |
+
import { noteProgress, pct } from './progress'
|
| 16 |
|
| 17 |
type Tab = 'chapter' | 'notes' | 'peer' | 'check' | 'ai' | 'versions' | 'refs'
|
| 18 |
const draftKey = (cid: string) => `xs_draft_${cid}`
|
|
|
|
| 95 |
const [pos, setPos] = useState(0)
|
| 96 |
const restoredFor = useRef('')
|
| 97 |
const posTimer = useRef<any>(null)
|
| 98 |
+
const [resumed, setResumed] = useState<number | null>(null)
|
| 99 |
+
const lastRatio = useRef(0)
|
| 100 |
+
useEffect(() => { if (resumed == null) return; const t = setTimeout(() => setResumed(null), 7000); return () => clearTimeout(t) }, [resumed])
|
| 101 |
useEffect(() => {
|
| 102 |
if (!detail || restoredFor.current === cid) return
|
| 103 |
restoredFor.current = cid
|
|
|
|
| 105 |
const apply = (r: number) => requestAnimationFrame(() => requestAnimationFrame(() => {
|
| 106 |
const el = scrollRef.current
|
| 107 |
if (!el || !(r > 0.01)) return
|
| 108 |
+
lastRatio.current = r
|
| 109 |
el.scrollTop = r * (el.scrollHeight - el.clientHeight)
|
| 110 |
+
if (r > 0.03 && r < 0.97) setResumed(r)
|
| 111 |
}))
|
| 112 |
if (!isNaN(local)) apply(local)
|
| 113 |
else projectsApi.progress(pid).then(p => { const r = p.chapters?.[cid]?.edit_ratio; if (r != null) apply(r) }, () => {})
|
|
|
|
| 118 |
const max = el.scrollHeight - el.clientHeight
|
| 119 |
const r = max > 0 ? Math.min(1, el.scrollTop / max) : 0
|
| 120 |
setPos(r)
|
| 121 |
+
lastRatio.current = r
|
| 122 |
try { localStorage.setItem(`xs_epos_${cid}`, r.toFixed(3)) } catch {}
|
| 123 |
+
if (restoredFor.current === cid) noteProgress(pid, { cid, r: Number(r.toFixed(3)), mode: 'edit' })
|
| 124 |
clearTimeout(posTimer.current)
|
| 125 |
posTimer.current = setTimeout(() => { projectsApi.saveProgress(pid, { chapter: { chapter_id: cid, edit_ratio: Number(r.toFixed(3)) } }).catch(() => {}) }, 2500)
|
| 126 |
}
|
|
|
|
| 140 |
} catch {}
|
| 141 |
}, [debounced, savedText, detail, cid])
|
| 142 |
|
| 143 |
+
/* 自动增高:撑高稿纸的同时保住看到的位置(开关侧栏、换字号都不跳回开头) */
|
| 144 |
+
const fitTa = (byRatio: boolean) => {
|
| 145 |
+
const el = taRef.current, sc = scrollRef.current
|
| 146 |
+
const top = sc ? sc.scrollTop : 0
|
| 147 |
+
if (el) { el.style.height = 'auto'; el.style.height = `${el.scrollHeight}px` }
|
| 148 |
+
if (sc && restoredFor.current === cid) {
|
| 149 |
+
const max = sc.scrollHeight - sc.clientHeight
|
| 150 |
+
const want = byRatio ? Math.round(lastRatio.current * max) : top
|
| 151 |
+
if (Math.abs(sc.scrollTop - want) > 1) sc.scrollTop = want
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
const fitRef = useRef(fitTa)
|
| 155 |
+
fitRef.current = fitTa
|
| 156 |
+
useEffect(() => { fitRef.current(false) }, [text])
|
| 157 |
+
useEffect(() => { fitRef.current(true) }, [fontSize, pageWidth, detail, reviewMode, focus, inspector])
|
| 158 |
useEffect(() => {
|
| 159 |
+
const sc = scrollRef.current
|
| 160 |
+
if (!sc || typeof ResizeObserver === 'undefined') return
|
| 161 |
+
let w = sc.clientWidth, h = sc.clientHeight
|
| 162 |
+
const ro = new ResizeObserver(() => {
|
| 163 |
+
if (sc.clientWidth === w && sc.clientHeight === h) return
|
| 164 |
+
w = sc.clientWidth; h = sc.clientHeight
|
| 165 |
+
fitRef.current(true)
|
| 166 |
+
})
|
| 167 |
+
ro.observe(sc)
|
| 168 |
+
return () => ro.disconnect()
|
| 169 |
+
}, [detail != null])
|
| 170 |
|
| 171 |
const updateChapterInBundle = (c: Chapter) => setBundle(b => ({
|
| 172 |
...b,
|
|
|
|
| 263 |
|
| 264 |
const st = saving ? { k: 'saving', full: '正在保存', short: '保存中' } : dirty ? { k: 'dirty', full: '本机已暂存 · 尚未存为版本', short: '未存版本' } : detail.current_version_id ? { k: 'ok', full: '已与云端版本一致', short: '已同步' } : { k: 'new', full: '新章节,还没有版���', short: '新章节' }
|
| 265 |
const showInspector = inspector && !focus
|
| 266 |
+
const nextCh = [...bundle.chapters].sort((a, b) => a.number - b.number).find(c => c.number > detail.number && c.current_version_id)
|
| 267 |
|
| 268 |
return (
|
| 269 |
<div className={cx('editor', showInspector && 'with-inspector')}>
|
|
|
|
| 289 |
</div>
|
| 290 |
</div>
|
| 291 |
|
| 292 |
+
{resumed != null && (
|
| 293 |
+
<div className="resume-pill" role="status">
|
| 294 |
+
<span>已回到上次看到的地方 · {pct(resumed)}</span>
|
| 295 |
+
<button onClick={() => { scrollRef.current?.scrollTo({ top: 0, behavior: 'smooth' }); setResumed(null) }}>从开头看</button>
|
| 296 |
+
<button onClick={() => setResumed(null)} aria-label="关闭"><X size={12} /></button>
|
| 297 |
+
</div>
|
| 298 |
+
)}
|
| 299 |
{restored && (
|
| 300 |
<div className="banner">
|
| 301 |
<AlertTriangle size={15} />
|
|
|
|
| 321 |
</div>)}
|
| 322 |
{disputes.length > 0 && !focus && <div className="dispute-tip"><mark className="dm">黄色底</mark>是和协作 AI 有分歧的句子,只是标注,复制、发布都不会带上。<button className="link-btn" onClick={pickDispute}>去分歧处理</button></div>}
|
| 323 |
<div className="paper-end">{words > 0 ? `— 本章 ${words.toLocaleString()} 字 —` : ''}</div>
|
| 324 |
+
{nextCh && !focus && <div className="paper-next"><button className="btn" onClick={() => { noteProgress(pid, { cid, r: 1, mode: 'edit' }); go(`book/${pid}/${nextCh.chapter_id}`) }}>下一章 · 第{cnNum(nextCh.number)}章 {nextCh.title}<ChevronRight size={15} /></button></div>}
|
| 325 |
</article>
|
| 326 |
</div>
|
| 327 |
|
ui-src/src/rooms/Reader.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { Empty, ErrorNote, Spinner, useToast } from '../ui'
|
|
| 6 |
import { locateNotes, NoteForm, NOTE_TYPE, SEVERITY, plainCopy, segmentText, useNotes, type Dispute, type Located } from './Review'
|
| 7 |
import { locateDisputes, usePeer } from './Peer'
|
| 8 |
import type { BookCtx } from './Book'
|
|
|
|
| 9 |
|
| 10 |
// 通读模式:只读连续阅读。隐藏侧边栏;可调字体、字号、行距、背景;可批阅;记住每章读到哪一段(本机 + 云端)。
|
| 11 |
const textCache = new Map<string, string>()
|
|
@@ -104,6 +105,8 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 104 |
const pageRef = useRef<HTMLElement>(null)
|
| 105 |
const saveTimer = useRef<any>(null)
|
| 106 |
const restoring = useRef(false)
|
|
|
|
|
|
|
| 107 |
|
| 108 |
const nb = useNotes(pid, cid)
|
| 109 |
const peer = usePeer(pid, cid)
|
|
@@ -116,7 +119,7 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 116 |
useEffect(() => {
|
| 117 |
let alive = true
|
| 118 |
restoring.current = true
|
| 119 |
-
setText(null); setErr(''); setSel(null); setPop(null)
|
| 120 |
loadText(pid, ch).then(t => { if (alive) setText(t) }).catch(e => alive && setErr(e.message))
|
| 121 |
if (next) loadText(pid, next).catch(() => {})
|
| 122 |
scrollRef.current?.scrollTo({ top: 0 })
|
|
@@ -137,7 +140,12 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 137 |
requestAnimationFrame(() => requestAnimationFrame(() => {
|
| 138 |
const el = pageRef.current?.querySelector(`[data-i="${para}"]`) as HTMLElement | null
|
| 139 |
const box = scrollRef.current
|
| 140 |
-
if (el && box)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
setTimeout(() => { restoring.current = false }, 120)
|
| 142 |
}))
|
| 143 |
}, [text, cid])
|
|
@@ -168,6 +176,7 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 168 |
localStorage.setItem(`xs_rpara_${cid}`, JSON.stringify({ para, ratio: Number(ratio.toFixed(3)) }))
|
| 169 |
} catch {}
|
| 170 |
setChRatio(o => ({ ...o, [cid]: ratio }))
|
|
|
|
| 171 |
clearTimeout(saveTimer.current)
|
| 172 |
saveTimer.current = setTimeout(() => {
|
| 173 |
projectsApi.saveProgress(pid, { reader: { chapter_id: cid, para, ratio: Number(ratio.toFixed(3)) }, chapter: { chapter_id: cid, read_para: para, read_ratio: Number(ratio.toFixed(3)) } }).catch(() => {})
|
|
@@ -318,6 +327,13 @@ function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: C
|
|
| 318 |
</div>
|
| 319 |
)}
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
<div className="reader-scroll" ref={scrollRef} onScroll={onScroll} onClick={() => { tocOpen && setTocOpen(false); setOpen && setSetOpen(false); pop && setPop(null) }}>
|
| 322 |
<article className={cx('reader-page', review && 'reviewing')} ref={pageRef} onMouseUp={onUp} onCopy={plainCopy}>
|
| 323 |
{showVol && <div className="reader-vol">{ch.volume}</div>}
|
|
|
|
| 6 |
import { locateNotes, NoteForm, NOTE_TYPE, SEVERITY, plainCopy, segmentText, useNotes, type Dispute, type Located } from './Review'
|
| 7 |
import { locateDisputes, usePeer } from './Peer'
|
| 8 |
import type { BookCtx } from './Book'
|
| 9 |
+
import { noteProgress } from './progress'
|
| 10 |
|
| 11 |
// 通读模式:只读连续阅读。隐藏侧边栏;可调字体、字号、行距、背景;可批阅;记住每章读到哪一段(本机 + 云端)。
|
| 12 |
const textCache = new Map<string, string>()
|
|
|
|
| 105 |
const pageRef = useRef<HTMLElement>(null)
|
| 106 |
const saveTimer = useRef<any>(null)
|
| 107 |
const restoring = useRef(false)
|
| 108 |
+
const [resumed, setResumed] = useState<number | null>(null)
|
| 109 |
+
useEffect(() => { if (resumed == null) return; const t = setTimeout(() => setResumed(null), 7000); return () => clearTimeout(t) }, [resumed])
|
| 110 |
|
| 111 |
const nb = useNotes(pid, cid)
|
| 112 |
const peer = usePeer(pid, cid)
|
|
|
|
| 119 |
useEffect(() => {
|
| 120 |
let alive = true
|
| 121 |
restoring.current = true
|
| 122 |
+
setText(null); setErr(''); setSel(null); setPop(null); setResumed(null)
|
| 123 |
loadText(pid, ch).then(t => { if (alive) setText(t) }).catch(e => alive && setErr(e.message))
|
| 124 |
if (next) loadText(pid, next).catch(() => {})
|
| 125 |
scrollRef.current?.scrollTo({ top: 0 })
|
|
|
|
| 140 |
requestAnimationFrame(() => requestAnimationFrame(() => {
|
| 141 |
const el = pageRef.current?.querySelector(`[data-i="${para}"]`) as HTMLElement | null
|
| 142 |
const box = scrollRef.current
|
| 143 |
+
if (el && box) {
|
| 144 |
+
box.scrollTop = el.offsetTop - 70
|
| 145 |
+
el.classList.add('reader-mark')
|
| 146 |
+
setTimeout(() => el.classList.remove('reader-mark'), 4000)
|
| 147 |
+
setResumed(para)
|
| 148 |
+
}
|
| 149 |
setTimeout(() => { restoring.current = false }, 120)
|
| 150 |
}))
|
| 151 |
}, [text, cid])
|
|
|
|
| 176 |
localStorage.setItem(`xs_rpara_${cid}`, JSON.stringify({ para, ratio: Number(ratio.toFixed(3)) }))
|
| 177 |
} catch {}
|
| 178 |
setChRatio(o => ({ ...o, [cid]: ratio }))
|
| 179 |
+
noteProgress(pid, { cid, r: Number(ratio.toFixed(3)), mode: 'read', para })
|
| 180 |
clearTimeout(saveTimer.current)
|
| 181 |
saveTimer.current = setTimeout(() => {
|
| 182 |
projectsApi.saveProgress(pid, { reader: { chapter_id: cid, para, ratio: Number(ratio.toFixed(3)) }, chapter: { chapter_id: cid, read_para: para, read_ratio: Number(ratio.toFixed(3)) } }).catch(() => {})
|
|
|
|
| 327 |
</div>
|
| 328 |
)}
|
| 329 |
|
| 330 |
+
{resumed != null && (
|
| 331 |
+
<div className="resume-pill reader-resume" role="status">
|
| 332 |
+
<span>已回到上次读到的地方 · 第{resumed + 1}段</span>
|
| 333 |
+
<button onClick={() => { scrollRef.current?.scrollTo({ top: 0, behavior: 'smooth' }); setResumed(null) }}>从本章开头读</button>
|
| 334 |
+
<button onClick={() => setResumed(null)} aria-label="关闭"><X size={12} /></button>
|
| 335 |
+
</div>
|
| 336 |
+
)}
|
| 337 |
<div className="reader-scroll" ref={scrollRef} onScroll={onScroll} onClick={() => { tocOpen && setTocOpen(false); setOpen && setSetOpen(false); pop && setPop(null) }}>
|
| 338 |
<article className={cx('reader-page', review && 'reviewing')} ref={pageRef} onMouseUp={onUp} onCopy={plainCopy}>
|
| 339 |
{showVol && <div className="reader-vol">{ch.volume}</div>}
|
ui-src/src/rooms/progress.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useState } from 'react'
|
| 2 |
+
import { projectsApi, type ReadProgress } from '../api'
|
| 3 |
+
|
| 4 |
+
// 全书阅读进度:稿纸(正文)和通读两边看到哪儿,合成一份。
|
| 5 |
+
// 本机即时记,云端兜底;目录、作品概览、稿纸、通读都从这里取。
|
| 6 |
+
export type Spot = { cid: string; r: number; at: number; mode: 'edit' | 'read'; para?: number }
|
| 7 |
+
export type ChProg = { r: number; max: number; at: number; mode: 'edit' | 'read'; para?: number }
|
| 8 |
+
export type BookProgress = { chapters: Record<string, ChProg>; last: Spot | null; ready: boolean }
|
| 9 |
+
|
| 10 |
+
const EV = 'xs:progress'
|
| 11 |
+
const key = (pid: string) => `xs_prog_${pid}`
|
| 12 |
+
const readLocal = (pid: string): Record<string, ChProg> => { try { return JSON.parse(localStorage.getItem(key(pid)) || '{}') || {} } catch { return {} } }
|
| 13 |
+
const server = new Map<string, ReadProgress | null>()
|
| 14 |
+
const loading = new Map<string, Promise<void>>()
|
| 15 |
+
const timers = new Map<string, any>()
|
| 16 |
+
|
| 17 |
+
/** 记一笔:某章看到了 r(0~1) */
|
| 18 |
+
export function noteProgress(pid: string, s: Omit<Spot, 'at'>) {
|
| 19 |
+
const m = readLocal(pid)
|
| 20 |
+
const prev = m[s.cid]
|
| 21 |
+
m[s.cid] = { r: s.r, max: Math.max(s.r, prev?.max || 0), at: Date.now(), mode: s.mode, para: s.para }
|
| 22 |
+
try { localStorage.setItem(key(pid), JSON.stringify(m)) } catch {}
|
| 23 |
+
clearTimeout(timers.get(pid))
|
| 24 |
+
timers.set(pid, setTimeout(() => window.dispatchEvent(new CustomEvent(EV, { detail: pid })), 350))
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function merge(pid: string): BookProgress {
|
| 28 |
+
const out: Record<string, ChProg> = {}
|
| 29 |
+
const sv = server.get(pid)
|
| 30 |
+
for (const [cid, c] of Object.entries(sv?.chapters || {})) {
|
| 31 |
+
const at = c.at ? new Date(c.at).getTime() : 0
|
| 32 |
+
const er = c.edit_ratio ?? -1, rr = c.read_ratio ?? -1
|
| 33 |
+
const r = Math.max(er, rr)
|
| 34 |
+
if (r < 0) continue
|
| 35 |
+
out[cid] = { r, max: r, at, mode: rr > er ? 'read' : 'edit', para: c.read_para }
|
| 36 |
+
}
|
| 37 |
+
for (const [cid, c] of Object.entries(readLocal(pid))) {
|
| 38 |
+
const s = out[cid]
|
| 39 |
+
if (!s || c.at >= s.at) out[cid] = { ...c, max: Math.max(c.max || 0, s?.max || 0) }
|
| 40 |
+
else out[cid] = { ...s, max: Math.max(s.max, c.max || 0) }
|
| 41 |
+
}
|
| 42 |
+
let last: Spot | null = null
|
| 43 |
+
for (const [cid, c] of Object.entries(out)) if (!last || c.at > last.at) last = { cid, r: c.r, at: c.at, mode: c.mode, para: c.para }
|
| 44 |
+
return { chapters: out, last, ready: server.has(pid) }
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export function useBookProgress(pid: string): BookProgress {
|
| 48 |
+
const [state, setState] = useState<BookProgress>(() => merge(pid))
|
| 49 |
+
useEffect(() => {
|
| 50 |
+
let alive = true
|
| 51 |
+
const refresh = () => alive && setState(merge(pid))
|
| 52 |
+
refresh()
|
| 53 |
+
if (!server.has(pid) && !loading.has(pid)) {
|
| 54 |
+
loading.set(pid, projectsApi.progress(pid).then(d => { server.set(pid, d) }, () => { server.set(pid, null) }).finally(() => loading.delete(pid)))
|
| 55 |
+
}
|
| 56 |
+
loading.get(pid)?.then(refresh)
|
| 57 |
+
const on = (e: Event) => { if ((e as CustomEvent).detail === pid) refresh() }
|
| 58 |
+
window.addEventListener(EV, on)
|
| 59 |
+
return () => { alive = false; window.removeEventListener(EV, on) }
|
| 60 |
+
}, [pid])
|
| 61 |
+
return state
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export const pct = (r: number) => `${Math.round(Math.min(1, Math.max(0, r)) * 100)}%`
|
| 65 |
+
export const isDone = (r: number) => r >= 0.95
|
ui-src/src/styles.css
CHANGED
|
@@ -1812,3 +1812,28 @@ mark.dispute-demo { background: color-mix(in srgb, #f2c230 34%, transparent); co
|
|
| 1812 |
.peer-card.decided { background: color-mix(in srgb, var(--bg-2) 50%, transparent); }
|
| 1813 |
details.older summary { cursor: pointer; padding: 4px 0; }
|
| 1814 |
details.older[open] { display: flex; flex-direction: column; gap: 8px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1812 |
.peer-card.decided { background: color-mix(in srgb, var(--bg-2) 50%, transparent); }
|
| 1813 |
details.older summary { cursor: pointer; padding: 4px 0; }
|
| 1814 |
details.older[open] { display: flex; flex-direction: column; gap: 8px; }
|
| 1815 |
+
|
| 1816 |
+
/* 阅读进度:接着看 / 目录里每章看到哪儿 / 回到原处提示 */
|
| 1817 |
+
.continue-card { display: flex; flex-direction: column; gap: 2px; margin: 0 10px 8px; padding: 9px 12px 10px; border-radius: var(--r); text-align: left; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); position: relative; overflow: hidden; }
|
| 1818 |
+
.continue-card:hover { border-color: var(--accent); }
|
| 1819 |
+
.continue-card .cc-k { font-size: 11.5px; color: var(--accent); font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
|
| 1820 |
+
.continue-card .cc-k em { font-style: normal; font-weight: 400; color: var(--ink-3); margin-left: auto; }
|
| 1821 |
+
.continue-card .cc-t { font-family: var(--serif); font-size: 14px; color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
| 1822 |
+
.continue-card .cc-m { font-size: 11.5px; color: var(--ink-3); }
|
| 1823 |
+
.continue-card .cc-bar { display: block; height: 3px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 15%, transparent); margin-top: 6px; overflow: hidden; }
|
| 1824 |
+
.continue-card .cc-bar b { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
|
| 1825 |
+
.continue-card.big { margin: 0; min-width: 240px; flex: 1; max-width: 420px; padding: 12px 16px 13px; }
|
| 1826 |
+
.continue-card.big .cc-t { font-size: 16px; }
|
| 1827 |
+
.binder-ch.has-rp { position: relative; }
|
| 1828 |
+
.binder-ch.has-rp::after { content: ''; position: absolute; left: 30px; bottom: 2px; height: 2px; width: calc(100% - 40px); background: linear-gradient(to right, color-mix(in srgb, var(--accent) 45%, transparent) var(--rp), transparent var(--rp)); border-radius: 99px; pointer-events: none; }
|
| 1829 |
+
.binder-ch.rp-done .ch-title { color: var(--ink-3); }
|
| 1830 |
+
.binder-ch.rp-done.on .ch-title { color: var(--accent); }
|
| 1831 |
+
.binder-ch.rp-done .ch-num::after { content: '✓'; margin-left: 2px; font-size: 9px; color: var(--accent); opacity: .8; }
|
| 1832 |
+
.resume-pill { position: sticky; top: 60px; z-index: 6; margin: 0 auto -38px; width: max-content; max-width: calc(100% - 24px); display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 14px; border-radius: 99px; background: var(--ink); color: var(--paper); font-size: 12.5px; box-shadow: var(--shadow-m, 0 6px 20px rgba(0,0,0,.18)); animation: pill-in .25s var(--ease); }
|
| 1833 |
+
.resume-pill button { color: inherit; opacity: .85; padding: 3px 9px; border-radius: 99px; background: rgba(255,255,255,.14); font-size: 12px; }
|
| 1834 |
+
.resume-pill button:hover { opacity: 1; background: rgba(255,255,255,.24); }
|
| 1835 |
+
@keyframes pill-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
|
| 1836 |
+
.paper-next { display: flex; justify-content: center; margin: 18px 0 40px; }
|
| 1837 |
+
.paper-next .btn { gap: 8px; }
|
| 1838 |
+
.reader-mark { box-shadow: inset 3px 0 0 var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); transition: background 2s, box-shadow 2s; }
|
| 1839 |
+
.reader-resume { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); margin: 0; animation: none; }
|