Spaces:
Running
Running
root commited on
Commit ·
23d257d
1
Parent(s): a9b62b5
工作台体验:分歧由作者拍板、正文分歧标注、检查页展示 AI 检查结果、通读阅读器(字体/背景/批阅/进度)、作者状态移入手册、热榜改为按需抓取、兄弟姐妹合并角色、文本框可下拉
Browse files- fanqie/agent.js +57 -10
- fanqie/dist/index.html +2 -2
- fanqie/motif2.js +28 -11
- fanqie/mount.js +4 -1
- fanqie/projects.js +60 -1
- fanqie/rank.js +11 -3
- public/assets/index-CJFM5oGG.css +0 -0
- public/assets/{index-DDqDQBro.js → index-CuW-4l0q.js} +0 -0
- public/assets/index-DkBCnEWt.css +0 -0
- public/index.html +2 -2
- ui-src/src/App.tsx +1 -1
- ui-src/src/api.ts +10 -0
- ui-src/src/rooms/Agent.tsx +15 -15
- ui-src/src/rooms/Book.tsx +2 -2
- ui-src/src/rooms/Editor.tsx +78 -95
- ui-src/src/rooms/Guide.tsx +14 -3
- ui-src/src/rooms/Library.tsx +2 -2
- ui-src/src/rooms/Motif2.tsx +2 -2
- ui-src/src/rooms/Peer.tsx +99 -25
- ui-src/src/rooms/Rank.tsx +7 -7
- ui-src/src/rooms/RankInspire.tsx +2 -2
- ui-src/src/rooms/Reader.tsx +273 -40
- ui-src/src/rooms/Review.tsx +37 -16
- ui-src/src/rooms/Shelf.tsx +1 -1
- ui-src/src/styles.css +83 -12
- ui-src/src/ui.tsx +21 -8
fanqie/agent.js
CHANGED
|
@@ -444,9 +444,23 @@ module.exports = function buildAgent(express, projects) {
|
|
| 444 |
} finally { clearTimeout(timer) }
|
| 445 |
}
|
| 446 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
// 把作品资料打包。attach: overview / bible / outline / toc / chapters:1-3 / chapter:<id或章号>
|
|
|
|
| 448 |
async function material(pid, attach, maxChars) {
|
| 449 |
-
const P = await projects.getProject(pid)
|
| 450 |
const parts = []
|
| 451 |
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]]))
|
| 452 |
for (const a of attach) {
|
|
@@ -464,6 +478,29 @@ module.exports = function buildAgent(express, projects) {
|
|
| 464 |
parts.push(`【第${c.number}章 ${c.title || ''}】\n${v.text || ''}`)
|
| 465 |
}
|
| 466 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
}
|
| 468 |
let text = parts.join('\n\n')
|
| 469 |
if (text.length > maxChars) text = text.slice(0, maxChars) + `\n\n(资料超过 ${maxChars} 字,后面已截断)`
|
|
@@ -622,7 +659,7 @@ module.exports = function buildAgent(express, projects) {
|
|
| 622 |
const attach = (Array.isArray(b.attach) ? b.attach : []).map(String).slice(0, 20)
|
| 623 |
const prof = await getProfile()
|
| 624 |
let mat = { text: '' }
|
| 625 |
-
if (
|
| 626 |
// 接着上一次对话聊(Surf 会话保留上下文)
|
| 627 |
let cont = null, sid = null
|
| 628 |
if (cfg.mode === 'surf') {
|
|
@@ -637,7 +674,7 @@ module.exports = function buildAgent(express, projects) {
|
|
| 637 |
} else sid = crypto.randomUUID()
|
| 638 |
}
|
| 639 |
const userSys = task === 'review' && cfg.system ? cfg.system : TASK_SYSTEM[task]
|
| 640 |
-
const system = [BASE_SYSTEM, userSys, `作者当前状态:${LABEL.account[prof.account]};${LABEL.first_book[prof.first_book]};${LABEL.contract[prof.contract]}。${prof.note || ''}`].filter(Boolean).join('\n\n')
|
| 641 |
const prompt = [mat.project ? `作品:《${mat.project.title}》` : '', `${TASKS[task]}任务 · ${String(b.topic || '').slice(0, 80) || '提问'}\n\n${question}`, mat.text ? `\n以下是作品资料:\n\n${mat.text}` : ''].filter(Boolean).join('\n')
|
| 642 |
const message = cont ? prompt : `【协作说明】\n${system}\n\n【任务】\n${prompt}`
|
| 643 |
const rec = {
|
|
@@ -741,7 +778,8 @@ module.exports = function buildAgent(express, projects) {
|
|
| 741 |
const B = origin || ''
|
| 742 |
L.push('# AI 工作守则', '',
|
| 743 |
'> 这份守则写给直接操作本工作台的 AI 助手,作者也会读。所有条目都是硬性要求,与作者临时指令冲突时,先停下来问作者。', '')
|
| 744 |
-
L.push('## 1. 作者现在的状态', '',
|
|
|
|
| 745 |
`- 账号:${LABEL.account[prof.account]}(${prof.level || '等级未填'})`,
|
| 746 |
`- 第一本书:${LABEL.first_book[prof.first_book]}`,
|
| 747 |
`- 签约:${LABEL.contract[prof.contract]}`,
|
|
@@ -770,12 +808,15 @@ module.exports = function buildAgent(express, projects) {
|
|
| 770 |
'| 母题库 v2 · 分类 | `GET /fanqie/api/motif2/meta` | 人物原型、母题、情绪、年代等分类和数量 |',
|
| 771 |
'| 母题库 v2 · 检索 | `GET /fanqie/api/motif2/cards?q=关键词&role=人物&m=母题&emo=情绪`、`/fanqie/api/motif2/role?r=爷爷`、`/fanqie/api/motif2/card?uid=` | 按人物、关系、事件找卡片 |',
|
| 772 |
'| 母题库 v2 · 组稿 | `POST /fanqie/api/motif2/compose`,字段 `idea`、`cast:[{role}]`、`mot:[]`、`emo:[]` | 自动串成提纲 |',
|
| 773 |
-
'| 番茄热榜 | `GET /fanqie/feed/rank.md`(带访问密码) | 读趋势、写解读和总纲 |',
|
|
|
|
|
|
|
| 774 |
L.push('**用素材的规矩:** 素材只借结构、情绪和细节的“类型”,写进小说时人名、地名、职业、具体情节都必须换成自己的;不整段搬用卡片里的句子;一章最多借 1–2 条素材。', '')
|
| 775 |
L.push('## 4. 工作流程', '',
|
| 776 |
-
'
|
|
|
|
| 777 |
'2. **写作**:一章一章写,每章写完存为新版本(`POST .../chapters/{章节ID}/versions`,`created_by` 填 `AI`),不要覆盖作者的版本。',
|
| 778 |
-
'3. **自查**:写完一章,读 `/fanqie/api/agent/rules` 里的番茄平台规定,逐条检查本章,把结果写入检查记录(见第 5 节)。',
|
| 779 |
'4. **请协作 AI 把关或帮忙**:概览、圣经、大纲有重大改动,或写完一卷,就请协作 AI 审查;需要查资料、出方案时也可以派给它(见第 6 节)。读完回复再改,并回写处理结果。',
|
| 780 |
'5. **按批注修改**:作者说「按批注修改第 X 章」时,读该章待改批注,逐条改正文、存新版本;在每条批注上写 `reply`(改了什么)并把 `status` 改成 `fixed`(`PATCH .../notes/{批注ID}`)。',
|
| 781 |
'6. **交付说明**:每次工作结束,用三五句话告诉作者做了什么、哪些地方拿不准。', '')
|
|
@@ -783,17 +824,23 @@ module.exports = function buildAgent(express, projects) {
|
|
| 783 |
'- 规则来源:`GET /fanqie/api/agent/rules` → `checklist`(发布前自查,三组)和 `platform`(番茄内容红线 + 低质规则)。',
|
| 784 |
'- 检查由你(AI)逐条阅读正文后判断,**不能用关键词���配代替阅读**。',
|
| 785 |
'- 写入:`POST /fanqie/api/agent/audits`,字段:`project_id`、`kind`(`checklist` 自查清单 / `platform` 平台规定 / `logic` 逻辑)、`scope`(`book` / `chapter`)、`chapter_id`、`version_id`、`by`、`summary`、`items[]`(`id`、`title`、`result`=pass/warn/fail/na、`note`、`quote` 引用原文、`fix` 修改建议)。',
|
|
|
|
|
|
|
| 786 |
'- 作者在工作台「检查」和「手册 → 自查清单」里看到这些结果。', '')
|
| 787 |
L.push('## 6. 协作 AI(另一个 AI,可以派活)', '',
|
| 788 |
`- 当前设置:${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 小时过期'})` : '未保存'}。令牌只存在服务器上,你看不到也不需要看到。`,
|
| 789 |
'- 它能做的活:`review` 审查(默认)、`research` 调研、`idea` 出主意、`draft` 起草、`other` 其他。例如:问它概览、圣经、大纲是否合乎逻辑;查某个年代的生活细节;给第 X 章出三种冲突方案。',
|
| 790 |
-
'- 提问:`POST /fanqie/api/agent/reviewer/ask`,字段:`project_id`、`task`、`topic`(如「圣经逻辑」)、`question`、`attach`(可选:`overview`、`bible`、`outline`、`toc`、`chapters:1-5`、`chapter:{章节ID或章号}`)、`wait`(最多等几秒,默认 50)、`queue`(默认开:令牌过期时先排队,作者粘贴新令牌或服务器续期成功后自动发出,状态为 `queued`)、`continue`(填上一次的 `ask_id` 或 `"last"`,就在同一个对话里接着问,对方记得上下文)。',
|
| 791 |
'- 回复要几分钟时,接口先返回 `state: "running"`;之后用 `GET /fanqie/api/agent/reviewer/log/{ask_id}?project_id=&wait=120` 取结果(`state` 变成 `done` 或 `error`)。不要重复提问同一件事。',
|
| 792 |
'- 读回复后自己判断采纳哪些——它的意见只是参考,与守则或作者要求冲突时以守则和作者为准。改完用 `PATCH /fanqie/api/agent/reviewer/log/{ask_id}` 回写 `status`(adopted / partial / rejected)和 `response`(怎么处理的)。',
|
| 793 |
'- **你和协作 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}`。',
|
| 794 |
-
'- 不把「素材采集」的任何内容发给它(你本来也读不到);只发作品资料和你自己写的问题。',
|
| 795 |
'- 令牌由服务器自己用续期令牌滚动续期,作者只需在「AI 协作 → 协作 AI」粘贴一次。返回令牌过期(401/403)、续期失败或积分用完:停下来告诉作者,请作者重新粘贴一次,不要自己找令牌、也不要读令牌。', '')
|
| 796 |
-
L.push('## 7.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
L.push('---', '每次请求都要带访问密码请求头 `x-app-password`。本守则地址:`/fanqie/api/agent/guide.md`。')
|
| 798 |
return L.filter(x => x !== null && x !== undefined).join('\n')
|
| 799 |
}
|
|
|
|
| 444 |
} finally { clearTimeout(timer) }
|
| 445 |
}
|
| 446 |
|
| 447 |
+
// 站内只读接口(不带采集室钥匙,素材原文会被服务器剔除):给协作 AI 打包热榜、母题库、素材馆
|
| 448 |
+
async function selfGet(pathq) {
|
| 449 |
+
const port = process.env.PORT || 7860
|
| 450 |
+
const r = await fetch(`http://127.0.0.1:${port}${pathq}`, { headers: { 'x-app-password': encodeURIComponent(process.env.APP_PASSWORD || '') } })
|
| 451 |
+
const t = await r.text()
|
| 452 |
+
if (!r.ok) throw bad(`读取 ${pathq.split('?')[0]} 失败:${t.slice(0, 120)}`, 502)
|
| 453 |
+
return JSON.parse(t)
|
| 454 |
+
}
|
| 455 |
+
// 素材只给摘要和改写卡,不给任何原文字段
|
| 456 |
+
const SAFE_MAT = ['uid', 'sum', 'card', 'g', 'k', 'q', 'motifs', 'm', 'tags']
|
| 457 |
+
const safeMat = it => Object.fromEntries(SAFE_MAT.filter(k => it && it[k] !== undefined).map(k => [k, it[k]]))
|
| 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) {
|
|
|
|
| 478 |
parts.push(`【第${c.number}章 ${c.title || ''}】\n${v.text || ''}`)
|
| 479 |
}
|
| 480 |
}
|
| 481 |
+
else if (a === 'rank' || a.startsWith('rank:')) {
|
| 482 |
+
const f = await require('./rank.js').feed({ scope: a.slice(5) || 'all', brief: true, format: 'md' })
|
| 483 |
+
parts.push(`【番茄热榜 ${f.date || ''}(只看趋势,书名人物情节不得照搬)】\n${f.text}`)
|
| 484 |
+
}
|
| 485 |
+
else if (a.startsWith('motif:')) {
|
| 486 |
+
const r = await selfGet(`/fanqie/api/motif2/card?uid=${encodeURIComponent(a.slice(6))}`)
|
| 487 |
+
parts.push(`【母题库卡片 ${a.slice(6)}(只借结构和情绪类型)】\n${JSON.stringify(dropRaw(r.card), null, 1)}`)
|
| 488 |
+
}
|
| 489 |
+
else if (a.startsWith('motif_role:')) {
|
| 490 |
+
const r = await selfGet(`/fanqie/api/motif2/role?r=${encodeURIComponent(a.slice(11))}`)
|
| 491 |
+
const slim = dropRaw({ role: r.role, total: r.total_all, motifs: (r.motifs || []).slice(0, 20), emo: r.emo, st: r.st, tone: r.tone, acts: (r.acts || []).slice(0, 60), people: r.people })
|
| 492 |
+
parts.push(`【母题库 · 人物「${a.slice(11)}」】\n${JSON.stringify(slim, null, 1)}`)
|
| 493 |
+
}
|
| 494 |
+
else if (a.startsWith('material:')) {
|
| 495 |
+
const r = await selfGet(`/fanqie/api/materials/item?uid=${encodeURIComponent(a.slice(9))}`)
|
| 496 |
+
parts.push(`【素材馆条目(摘要和改写卡)】\n${JSON.stringify(safeMat(r), null, 1)}`)
|
| 497 |
+
}
|
| 498 |
+
else if (a === 'refs' && P.materials) {
|
| 499 |
+
parts.push('【本书参考素材(摘要)】\n' + JSON.stringify((P.materials.items || []).map(safeMat), null, 1))
|
| 500 |
+
}
|
| 501 |
+
else if (a === 'rules') {
|
| 502 |
+
parts.push('【番茄平台规定(内容红线 + 低质与 AI)】\n' + platformRules().map(r => `- [${r.id}] ${r.title}:${r.detail}`).join('\n'))
|
| 503 |
+
}
|
| 504 |
}
|
| 505 |
let text = parts.join('\n\n')
|
| 506 |
if (text.length > maxChars) text = text.slice(0, maxChars) + `\n\n(资料超过 ${maxChars} 字,后面已截断)`
|
|
|
|
| 659 |
const attach = (Array.isArray(b.attach) ? b.attach : []).map(String).slice(0, 20)
|
| 660 |
const prof = await getProfile()
|
| 661 |
let mat = { text: '' }
|
| 662 |
+
if (attach.length && (pid || attach.every(a => /^(rank|motif|motif_role|material|rules)\b/.test(a)))) mat = await material(pid, attach, cfg.max_chars || 120000)
|
| 663 |
// 接着上一次对话聊(Surf 会话保留上下文)
|
| 664 |
let cont = null, sid = null
|
| 665 |
if (cfg.mode === 'surf') {
|
|
|
|
| 674 |
} else sid = crypto.randomUUID()
|
| 675 |
}
|
| 676 |
const userSys = task === 'review' && cfg.system ? cfg.system : TASK_SYSTEM[task]
|
| 677 |
+
const system = [BASE_SYSTEM, userSys, `作者当前状态(你和写作 AI 都必须按此判断):${LABEL.account[prof.account]};${LABEL.first_book[prof.first_book]};${LABEL.contract[prof.contract]}。${prof.note || ''}\n${implications(prof).map(x => '- ' + x).join('\n')}`].filter(Boolean).join('\n\n')
|
| 678 |
const prompt = [mat.project ? `作品:《${mat.project.title}》` : '', `${TASKS[task]}任务 · ${String(b.topic || '').slice(0, 80) || '提问'}\n\n${question}`, mat.text ? `\n以下是作品资料:\n\n${mat.text}` : ''].filter(Boolean).join('\n')
|
| 679 |
const message = cont ? prompt : `【协作说明】\n${system}\n\n【任务】\n${prompt}`
|
| 680 |
const rec = {
|
|
|
|
| 778 |
const B = origin || ''
|
| 779 |
L.push('# AI 工作守则', '',
|
| 780 |
'> 这份守则写给直接操作本工作台的 AI 助手,作者也会读。所有条目都是硬性要求,与作者临时指令冲突时,先停下来问作者。', '')
|
| 781 |
+
L.push('## 1. 作者现在的状态(总规则,你和协作 AI 都必须遵守)', '',
|
| 782 |
+
'> 作者在「手册 → 作者状态」里填写。写新章、改旧章之前先读这一节;发给协作 AI 的每个问题也会自动带上这一节。', '',
|
| 783 |
`- 账号:${LABEL.account[prof.account]}(${prof.level || '等级未填'})`,
|
| 784 |
`- 第一本书:${LABEL.first_book[prof.first_book]}`,
|
| 785 |
`- 签约:${LABEL.contract[prof.contract]}`,
|
|
|
|
| 808 |
'| 母题库 v2 · 分类 | `GET /fanqie/api/motif2/meta` | 人物原型、母题、情绪、年代等分类和数量 |',
|
| 809 |
'| 母题库 v2 · 检索 | `GET /fanqie/api/motif2/cards?q=关键词&role=人物&m=母题&emo=情绪`、`/fanqie/api/motif2/role?r=爷爷`、`/fanqie/api/motif2/card?uid=` | 按人物、关系、事件找卡片 |',
|
| 810 |
'| 母题库 v2 · 组稿 | `POST /fanqie/api/motif2/compose`,字段 `idea`、`cast:[{role}]`、`mot:[]`、`emo:[]` | 自动串成提纲 |',
|
| 811 |
+
'| 番茄热榜 | `GET /fanqie/feed/rank.md`(带访问密码)、`GET /fanqie/api/rank/feed?scope=all&brief=1` | 读趋势、写解读和总纲 |',
|
| 812 |
+
'| 分歧待办 | `GET /fanqie/api/projects/{作品ID}/peer?todo=1` | 作者已表态、你还没处理的分歧(写新章前必须先处理) |',
|
| 813 |
+
'| 阅读进度 | `GET /fanqie/api/projects/{作品ID}/progress` | 作者读到哪一章哪一段(只读,不要改) |', '')
|
| 814 |
L.push('**用素材的规矩:** 素材只借结构、情绪和细节的“类型”,写进小说时人名、地名、职业、具体情节都必须换成自己的;不整段搬用卡片里的句子;一章最多借 1–2 条素材。', '')
|
| 815 |
L.push('## 4. 工作流程', '',
|
| 816 |
+
'0. **先处理作者对分歧的裁决**:`GET /fanqie/api/projects/{作品ID}/peer?todo=1`。每条 `author_decision`:`adopt` = 按协作 AI 的意见改;`keep` = 维持现在的写法(不用改正文);`own` = 按 `author_note` 里作者自己的想法改。改完存新版本,再 `PATCH /fanqie/api/projects/{作品ID}/peer/{item_id}`,body `{"resolved":true,"resolution":"怎么处理的"}`,这条就不再显示。作者没表态的(`author_decision` 为空)不用管。这一步做完才能往下写新章。',
|
| 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. **交付说明**:每次工作结束,用三五句话告诉作者做了什么、哪些地方拿不准。', '')
|
|
|
|
| 824 |
'- 规则来源:`GET /fanqie/api/agent/rules` → `checklist`(发布前自查,三组)和 `platform`(番茄内容红线 + 低质规则)。',
|
| 825 |
'- 检查由你(AI)逐条阅读正文后判断,**不能用关键词���配代替阅读**。',
|
| 826 |
'- 写入:`POST /fanqie/api/agent/audits`,字段:`project_id`、`kind`(`checklist` 自查清单 / `platform` 平台规定 / `logic` 逻辑)、`scope`(`book` / `chapter`)、`chapter_id`、`version_id`、`by`、`summary`、`items[]`(`id`、`title`、`result`=pass/warn/fail/na、`note`、`quote` 引用原文、`fix` 修改建议)。',
|
| 827 |
+
'- 单章检查必须填 `scope: "chapter"`、`chapter_id`、`chapter_number`、`version_id`(检查的是哪一版),作者才能在该章「检查」栏看到;`by` 填 `写作 AI`。',
|
| 828 |
+
'- 协作 AI 的审查回复会按话题「第N章 · …」自动归到该章「检查」栏,所以单章审查的 `topic` 一律以「第N章」开头。',
|
| 829 |
'- 作者在工作台「检查」和「手册 → 自查清单」里看到这些结果。', '')
|
| 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}`。',
|
| 837 |
+
'- 不把「素材采集」的任何内容发给它(你本来也读不到);只发作品资料、热榜、母题库、素材馆的摘要和改写卡,以及你自己写的问题。服务器打包时会再剔除一次原文字段。',
|
| 838 |
'- 令牌由服务器自己用续期令牌滚动续期,作者只需在「AI 协作 → 协作 AI」粘贴一次。返回令牌过期(401/403)、续期失败或积分用完:停下来告诉作者,请作者重新粘贴一次,不要自己找令牌、也不要读令牌。', '')
|
| 839 |
+
L.push('## 7. 番茄热榜怎么更新', '',
|
| 840 |
+
'- 热榜**不会自动更新**。只有作者在对话里说「抓取今天的番茄热榜」时才做,一天最多一次。',
|
| 841 |
+
'- 步骤:① `GET /fanqie/api/rank/status` 确认没有任务在跑;② `POST /fanqie/api/rank/scrape`(当天已抓过会返回 409,作者坚持要重抓时加 `?force=1`);③ 每隔一两分钟看 `status`,`running` 变成 false 后 `POST /fanqie/api/rank/enrich` 补书籍详情和标签;④ 读 `GET /fanqie/api/rank/feed?scope=all&brief=1`,写「AI 解读」存到 `PUT /fanqie/api/rank/ai/{日期}`。',
|
| 842 |
+
'- 抓取代码在服务器 `fanqie/rank.js`(分类榜 → 防爬字体解码 → 统计),不用另外想办法。', '')
|
| 843 |
+
L.push('## 8. 作品列表', '', ...((list.projects || []).map(p => `- 《${p.title}》 ID:\`${p.project_id}\``)), '')
|
| 844 |
L.push('---', '每次请求都要带访问密码请求头 `x-app-password`。本守则地址:`/fanqie/api/agent/guide.md`。')
|
| 845 |
return L.filter(x => x !== null && x !== undefined).join('\n')
|
| 846 |
}
|
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-CuW-4l0q.js"></script>
|
| 12 |
+
<link rel="stylesheet" crossorigin href="/assets/index-DkBCnEWt.css">
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
fanqie/motif2.js
CHANGED
|
@@ -61,7 +61,24 @@ function docOf(c) {
|
|
| 61 |
parts.push(...(c.lines || []), ...(c.det || []), ...(c.facts || []), ...(c.needs || []), ...(c.open || []), ...(c.roles || []))
|
| 62 |
return parts.filter(Boolean).join('|')
|
| 63 |
}
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
async function refresh(force = false) {
|
| 66 |
if (S.loading) return S.loading
|
| 67 |
if (!force && S.tax && Date.now() - S.loadedAt < 10 * 60 * 1000) return
|
|
@@ -116,7 +133,7 @@ function filterCards(q) {
|
|
| 116 |
const ws = terms(q.w)
|
| 117 |
return S.cards.filter(c =>
|
| 118 |
(!role || c._roles.includes(role)) &&
|
| 119 |
-
(!st || (c.ppl || []).some(p => p.role
|
| 120 |
(!ms.length || ms.every(m => (c.mot || []).includes(m) || (c.ev || []).some(e => e.m === m))) &&
|
| 121 |
(!emo.length || emo.some(e => (c.emo || []).includes(e))) &&
|
| 122 |
(!place.length || place.some(p => (c.place || []).includes(p))) &&
|
|
@@ -133,7 +150,7 @@ const wrap = fn => async (req, res) => { try { await ready(); res.json(await fn(
|
|
| 133 |
router.get('/meta', wrap(() => {
|
| 134 |
const P = S.progress || {}
|
| 135 |
return {
|
| 136 |
-
taxonomy: S.tax,
|
| 137 |
progress: { done_batches: P.done_batches || 0, total_batches: P.total_batches || 0, done_items: P.done_items || 0, total_items: P.total_items || 0, counts: P.counts || {}, updated_at: P.updated_at, next_batch: P.next_batch },
|
| 138 |
cards: S.cards.length,
|
| 139 |
full: S.cards.filter(c => c.lv === 'full').length,
|
|
@@ -168,13 +185,13 @@ router.get('/role', wrap(req => {
|
|
| 168 |
const acts = []
|
| 169 |
for (const c of list) {
|
| 170 |
if (c.lv !== 'full') continue
|
| 171 |
-
const ids = new Set((c.ppl || []).filter(p => p.role
|
| 172 |
-
const person = (c.ppl || []).find(p => p.role
|
| 173 |
for (const t of c.ties || []) if (ids.has(t.p)) for (const a of t.acts || []) acts.push({ a, uid: c.uid, rel: t.rel, tone: t.tone, st: person?.st, pov: c.pov?.role, q: c.q, mot: c.mot?.[0] })
|
| 174 |
}
|
| 175 |
acts.sort((a, b) => (b.q || 0) - (a.q || 0))
|
| 176 |
const people = []
|
| 177 |
-
for (const c of list) for (const p of c.ppl || []) if (p.role
|
| 178 |
const lines = []
|
| 179 |
for (const c of list) for (const l of c.lines || []) lines.push({ l, uid: c.uid, emo: c.emo?.[0], fit: c.fit })
|
| 180 |
const size = Math.min(50, Math.max(1, Number(req.query.size) || 12))
|
|
@@ -183,8 +200,8 @@ router.get('/role', wrap(req => {
|
|
| 183 |
role, total_all: all.length, total: list.length,
|
| 184 |
motifs: countBy(all, c => [...new Set([...(c.mot || []), ...(c.ev || []).map(e => e.m)])]).map(x => ({ ...x, t: motifName(x.k), grp: motifGroup(x.k) })),
|
| 185 |
emo: countBy(all, c => c.emo),
|
| 186 |
-
st: countBy(all, c => (c.ppl || []).filter(p => p.role
|
| 187 |
-
tone: countBy(all, c => (c.ties || []).filter(t => (c.ppl || []).some(p => p.id === t.p && p.role
|
| 188 |
acts: acts.slice(0, 80), people: people.slice(0, 30), lines: lines.slice(0, 30),
|
| 189 |
page, size, items: list.slice((page - 1) * size, page * size).map(lite),
|
| 190 |
}
|
|
@@ -247,7 +264,7 @@ function scoreCard(c, setup, ws) {
|
|
| 247 |
let s = (c.q || 0) * 1.3
|
| 248 |
for (const r of castRoles) if (c._roles.includes(r)) {
|
| 249 |
s += 6
|
| 250 |
-
const ids = new Set((c.ppl || []).filter(p => p.role
|
| 251 |
if ((c.ties || []).some(t => ids.has(t.p) && (t.acts || []).length)) s += 3
|
| 252 |
}
|
| 253 |
const mm = new Set([...(c.mot || []), ...(c.ev || []).map(e => e.m)])
|
|
@@ -317,7 +334,7 @@ router.post('/compose', wrap(req => {
|
|
| 317 |
picks.main = take('main', mainList.length ? mainList : full)
|
| 318 |
picks.people = {}
|
| 319 |
for (const r of castRoles) {
|
| 320 |
-
const list = full.filter(x => (x.c.ppl || []).some(p => p.role
|
| 321 |
picks.people[r] = take('role:' + r, list, 2)
|
| 322 |
}
|
| 323 |
picks.twist = take('twist', full.filter(x => x.c.twist))
|
|
@@ -331,7 +348,7 @@ router.post('/compose', wrap(req => {
|
|
| 331 |
for (const r of castRoles) {
|
| 332 |
const items = []
|
| 333 |
for (const c of allPicked) {
|
| 334 |
-
const ids = new Set((c.ppl || []).filter(p => p.role
|
| 335 |
for (const t of c.ties || []) if (ids.has(t.p)) for (const a of t.acts || []) items.push({ a, uid: c.uid, tone: t.tone })
|
| 336 |
}
|
| 337 |
roleActs[r] = items.slice(0, 8)
|
|
|
|
| 61 |
parts.push(...(c.lines || []), ...(c.det || []), ...(c.facts || []), ...(c.needs || []), ...(c.open || []), ...(c.roles || []))
|
| 62 |
return parts.filter(Boolean).join('|')
|
| 63 |
}
|
| 64 |
+
// 同性手足长幼可互换:查「亲兄弟」同时看哥哥和弟弟,查「亲姐妹」同时看姐姐和妹妹(逻辑上长幼只影响称呼和家里的话语权,素材结构可以通用)
|
| 65 |
+
const MERGED_ROLES = { 亲兄弟: ['哥哥', '弟弟'], 亲姐妹: ['姐姐', '妹妹'] }
|
| 66 |
+
const roleIs = (r, role) => r === role || (MERGED_ROLES[role] || []).includes(r)
|
| 67 |
+
function rolesOf(c) {
|
| 68 |
+
const base = c.lv === 'full' ? [...new Set((c.ppl || []).map(p => p.role))] : (c.roles || [])
|
| 69 |
+
const extra = Object.entries(MERGED_ROLES).filter(([, l]) => l.some(r => base.includes(r))).map(([k]) => k)
|
| 70 |
+
return extra.length ? [...base, ...extra] : base
|
| 71 |
+
}
|
| 72 |
+
function taxWithMerged(tax) {
|
| 73 |
+
if (!tax || !tax.roles) return tax
|
| 74 |
+
const roles = {}
|
| 75 |
+
for (const [g, l] of Object.entries(tax.roles)) {
|
| 76 |
+
const list = [...l]
|
| 77 |
+
for (const [k, members] of Object.entries(MERGED_ROLES)) if (list.includes(members[0]) && !list.includes(k)) list.splice(list.indexOf(members[0]), 0, k)
|
| 78 |
+
roles[g] = list
|
| 79 |
+
}
|
| 80 |
+
return { ...tax, roles }
|
| 81 |
+
}
|
| 82 |
async function refresh(force = false) {
|
| 83 |
if (S.loading) return S.loading
|
| 84 |
if (!force && S.tax && Date.now() - S.loadedAt < 10 * 60 * 1000) return
|
|
|
|
| 133 |
const ws = terms(q.w)
|
| 134 |
return S.cards.filter(c =>
|
| 135 |
(!role || c._roles.includes(role)) &&
|
| 136 |
+
(!st || (c.ppl || []).some(p => roleIs(p.role, role) && p.st === st)) &&
|
| 137 |
(!ms.length || ms.every(m => (c.mot || []).includes(m) || (c.ev || []).some(e => e.m === m))) &&
|
| 138 |
(!emo.length || emo.some(e => (c.emo || []).includes(e))) &&
|
| 139 |
(!place.length || place.some(p => (c.place || []).includes(p))) &&
|
|
|
|
| 150 |
router.get('/meta', wrap(() => {
|
| 151 |
const P = S.progress || {}
|
| 152 |
return {
|
| 153 |
+
taxonomy: taxWithMerged(S.tax), merged_roles: MERGED_ROLES,
|
| 154 |
progress: { done_batches: P.done_batches || 0, total_batches: P.total_batches || 0, done_items: P.done_items || 0, total_items: P.total_items || 0, counts: P.counts || {}, updated_at: P.updated_at, next_batch: P.next_batch },
|
| 155 |
cards: S.cards.length,
|
| 156 |
full: S.cards.filter(c => c.lv === 'full').length,
|
|
|
|
| 185 |
const acts = []
|
| 186 |
for (const c of list) {
|
| 187 |
if (c.lv !== 'full') continue
|
| 188 |
+
const ids = new Set((c.ppl || []).filter(p => roleIs(p.role, role)).map(p => p.id))
|
| 189 |
+
const person = (c.ppl || []).find(p => roleIs(p.role, role))
|
| 190 |
for (const t of c.ties || []) if (ids.has(t.p)) for (const a of t.acts || []) acts.push({ a, uid: c.uid, rel: t.rel, tone: t.tone, st: person?.st, pov: c.pov?.role, q: c.q, mot: c.mot?.[0] })
|
| 191 |
}
|
| 192 |
acts.sort((a, b) => (b.q || 0) - (a.q || 0))
|
| 193 |
const people = []
|
| 194 |
+
for (const c of list) for (const p of c.ppl || []) if (roleIs(p.role, role) && (p.trait || p.want)) people.push({ trait: p.trait, want: p.want, st: p.st, uid: c.uid })
|
| 195 |
const lines = []
|
| 196 |
for (const c of list) for (const l of c.lines || []) lines.push({ l, uid: c.uid, emo: c.emo?.[0], fit: c.fit })
|
| 197 |
const size = Math.min(50, Math.max(1, Number(req.query.size) || 12))
|
|
|
|
| 200 |
role, total_all: all.length, total: list.length,
|
| 201 |
motifs: countBy(all, c => [...new Set([...(c.mot || []), ...(c.ev || []).map(e => e.m)])]).map(x => ({ ...x, t: motifName(x.k), grp: motifGroup(x.k) })),
|
| 202 |
emo: countBy(all, c => c.emo),
|
| 203 |
+
st: countBy(all, c => (c.ppl || []).filter(p => roleIs(p.role, role)).map(p => p.st)),
|
| 204 |
+
tone: countBy(all, c => (c.ties || []).filter(t => (c.ppl || []).some(p => p.id === t.p && roleIs(p.role, role))).map(t => t.tone)),
|
| 205 |
acts: acts.slice(0, 80), people: people.slice(0, 30), lines: lines.slice(0, 30),
|
| 206 |
page, size, items: list.slice((page - 1) * size, page * size).map(lite),
|
| 207 |
}
|
|
|
|
| 264 |
let s = (c.q || 0) * 1.3
|
| 265 |
for (const r of castRoles) if (c._roles.includes(r)) {
|
| 266 |
s += 6
|
| 267 |
+
const ids = new Set((c.ppl || []).filter(p => roleIs(p.role, r)).map(p => p.id))
|
| 268 |
if ((c.ties || []).some(t => ids.has(t.p) && (t.acts || []).length)) s += 3
|
| 269 |
}
|
| 270 |
const mm = new Set([...(c.mot || []), ...(c.ev || []).map(e => e.m)])
|
|
|
|
| 334 |
picks.main = take('main', mainList.length ? mainList : full)
|
| 335 |
picks.people = {}
|
| 336 |
for (const r of castRoles) {
|
| 337 |
+
const list = full.filter(x => (x.c.ppl || []).some(p => roleIs(p.role, r)) && (x.c.ties || []).some(t => (x.c.ppl || []).some(p => p.id === t.p && roleIs(p.role, r))))
|
| 338 |
picks.people[r] = take('role:' + r, list, 2)
|
| 339 |
}
|
| 340 |
picks.twist = take('twist', full.filter(x => x.c.twist))
|
|
|
|
| 348 |
for (const r of castRoles) {
|
| 349 |
const items = []
|
| 350 |
for (const c of allPicked) {
|
| 351 |
+
const ids = new Set((c.ppl || []).filter(p => roleIs(p.role, r)).map(p => p.id))
|
| 352 |
for (const t of c.ties || []) if (ids.has(t.p)) for (const a of t.acts || []) items.push({ a, uid: c.uid, tone: t.tone })
|
| 353 |
}
|
| 354 |
roleActs[r] = items.slice(0, 8)
|
fanqie/mount.js
CHANGED
|
@@ -59,7 +59,10 @@ module.exports = function mountFanqie(app, passwordOk, express) {
|
|
| 59 |
app.put('/fanqie/api/projects/:projectId/checks/:versionId', projectRoute(req => projects.saveCheck(req.params.projectId, req.params.versionId, req.body || {})))
|
| 60 |
app.get('/fanqie/api/projects/:projectId/context', projectRoute(req => projects.getContext(req.params.projectId, req.query.chapter_id)))
|
| 61 |
// 协作 AI 意见裁决(逐章旁栏,不进正文)
|
| 62 |
-
app.get('/fanqie/api/projects/:projectId/peer', projectRoute(req => projects.listPeer(req.params.projectId, req.query.chapter_id ? String(req.query.chapter_id) : '')))
|
|
|
|
|
|
|
|
|
|
| 63 |
app.post('/fanqie/api/projects/:projectId/peer', projectRoute(req => projects.addPeer(req.params.projectId, req.body || {}), 201))
|
| 64 |
app.patch('/fanqie/api/projects/:projectId/peer/:itemId', projectRoute(req => projects.updatePeer(req.params.projectId, req.params.itemId, req.body || {})))
|
| 65 |
app.delete('/fanqie/api/projects/:projectId/peer/:itemId', projectRoute(req => projects.deletePeer(req.params.projectId, req.params.itemId)))
|
|
|
|
| 59 |
app.put('/fanqie/api/projects/:projectId/checks/:versionId', projectRoute(req => projects.saveCheck(req.params.projectId, req.params.versionId, req.body || {})))
|
| 60 |
app.get('/fanqie/api/projects/:projectId/context', projectRoute(req => projects.getContext(req.params.projectId, req.query.chapter_id)))
|
| 61 |
// 协作 AI 意见裁决(逐章旁栏,不进正文)
|
| 62 |
+
app.get('/fanqie/api/projects/:projectId/peer', projectRoute(req => projects.listPeer(req.params.projectId, req.query.chapter_id ? String(req.query.chapter_id) : '', { todo: req.query.todo === '1' })))
|
| 63 |
+
app.put('/fanqie/api/projects/:projectId/peer/:itemId/author', projectRoute(req => projects.decidePeer(req.params.projectId, req.params.itemId, req.body || {})))
|
| 64 |
+
app.get('/fanqie/api/projects/:projectId/progress', projectRoute(req => projects.getProgress(req.params.projectId)))
|
| 65 |
+
app.put('/fanqie/api/projects/:projectId/progress', projectRoute(req => projects.saveProgress(req.params.projectId, req.body || {})))
|
| 66 |
app.post('/fanqie/api/projects/:projectId/peer', projectRoute(req => projects.addPeer(req.params.projectId, req.body || {}), 201))
|
| 67 |
app.patch('/fanqie/api/projects/:projectId/peer/:itemId', projectRoute(req => projects.updatePeer(req.params.projectId, req.params.itemId, req.body || {})))
|
| 68 |
app.delete('/fanqie/api/projects/:projectId/peer/:itemId', projectRoute(req => projects.deletePeer(req.params.projectId, req.params.itemId)))
|
fanqie/projects.js
CHANGED
|
@@ -635,18 +635,33 @@ function cleanPeer(b, prev, chapters) {
|
|
| 635 |
my_view: b.my_view !== undefined ? s(b.my_view, 3000) : (prev ? prev.my_view : ''),
|
| 636 |
decision: b.decision !== undefined ? s(b.decision, 2000) : (prev ? prev.decision : ''),
|
| 637 |
verdict,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
created_by: prev ? prev.created_by : (s(b.created_by, 40) || 'writer_ai'),
|
| 639 |
created_at: prev ? prev.created_at : now(),
|
| 640 |
updated_at: now()
|
| 641 |
}
|
|
|
|
|
|
|
| 642 |
if (!out.reviewer_said) throw new HttpError(400, '缺少 reviewer_said(协作 AI 的意见)')
|
| 643 |
if (!out.my_view) throw new HttpError(400, '缺少 my_view(我的判断)')
|
| 644 |
return out
|
| 645 |
}
|
| 646 |
-
|
|
|
|
| 647 |
await getProjectOrThrow(projectId)
|
| 648 |
const d = await readJson(peerKey(projectId), { items: [] })
|
| 649 |
let items = d.items || []
|
|
|
|
|
|
|
| 650 |
if (chapterId === 'book') items = items.filter(x => !x.chapter_id)
|
| 651 |
else if (chapterId) items = items.filter(x => x.chapter_id === chapterId || !x.chapter_id)
|
| 652 |
const by = { agree: 0, partial: 0, disagree: 0 }
|
|
@@ -677,6 +692,22 @@ async function updatePeer(projectId, itemId, body) {
|
|
| 677 |
return d.items[i]
|
| 678 |
})
|
| 679 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
async function deletePeer(projectId, itemId) {
|
| 681 |
return withLock(`peer:${projectId}`, async () => {
|
| 682 |
const d = await readJson(peerKey(projectId), { items: [] })
|
|
@@ -688,7 +719,35 @@ async function deletePeer(projectId, itemId) {
|
|
| 688 |
})
|
| 689 |
}
|
| 690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
module.exports = {
|
|
|
|
| 692 |
listProjects, createProject, getProject, updateProject, deleteProject, saveBible, saveOutline, saveMaterials,
|
| 693 |
listChapters, createChapter, getChapter: getChapterOrThrow, updateChapter,
|
| 694 |
listVersions, getVersion, saveVersion, rollback, saveCheck, getCheck, basicCheck, getContext,
|
|
|
|
| 635 |
my_view: b.my_view !== undefined ? s(b.my_view, 3000) : (prev ? prev.my_view : ''),
|
| 636 |
decision: b.decision !== undefined ? s(b.decision, 2000) : (prev ? prev.decision : ''),
|
| 637 |
verdict,
|
| 638 |
+
// 正文里对应的那段话(只用于在编辑页、通读页加底色标注,复制和发布的正文里不会带上)
|
| 639 |
+
quote: b.quote !== undefined ? s(b.quote, 600) : (prev ? prev.quote || '' : ''),
|
| 640 |
+
// 作者裁决:adopt 采纳协作 AI 的意见 / keep 维持现在的写法 / own 按作者自己的想法;空 = 作者还没处理(写作 AI 不用管)
|
| 641 |
+
author_decision: prev ? prev.author_decision || '' : '',
|
| 642 |
+
author_note: prev ? prev.author_note || '' : '',
|
| 643 |
+
author_at: prev ? prev.author_at || null : null,
|
| 644 |
+
// 写作 AI 按作者裁决处理完:resolved=true,界面上不再显示
|
| 645 |
+
resolved: b.resolved !== undefined ? !!b.resolved : (prev ? !!prev.resolved : false),
|
| 646 |
+
resolution: b.resolution !== undefined ? s(b.resolution, 2000) : (prev ? prev.resolution || '' : ''),
|
| 647 |
+
resolved_at: prev ? prev.resolved_at || null : null,
|
| 648 |
created_by: prev ? prev.created_by : (s(b.created_by, 40) || 'writer_ai'),
|
| 649 |
created_at: prev ? prev.created_at : now(),
|
| 650 |
updated_at: now()
|
| 651 |
}
|
| 652 |
+
if (out.resolved && !(prev && prev.resolved)) out.resolved_at = now()
|
| 653 |
+
if (!out.resolved) out.resolved_at = null
|
| 654 |
if (!out.reviewer_said) throw new HttpError(400, '缺少 reviewer_said(协作 AI 的意见)')
|
| 655 |
if (!out.my_view) throw new HttpError(400, '缺少 my_view(我的判断)')
|
| 656 |
return out
|
| 657 |
}
|
| 658 |
+
const AUTHOR_DECISIONS = ['adopt', 'keep', 'own']
|
| 659 |
+
async function listPeer(projectId, chapterId, opts = {}) {
|
| 660 |
await getProjectOrThrow(projectId)
|
| 661 |
const d = await readJson(peerKey(projectId), { items: [] })
|
| 662 |
let items = d.items || []
|
| 663 |
+
// todo=1:作者已经表态、写作 AI 还没处理的(写新章之前必须先处理完)
|
| 664 |
+
if (opts.todo) items = items.filter(x => x.author_decision && !x.resolved)
|
| 665 |
if (chapterId === 'book') items = items.filter(x => !x.chapter_id)
|
| 666 |
else if (chapterId) items = items.filter(x => x.chapter_id === chapterId || !x.chapter_id)
|
| 667 |
const by = { agree: 0, partial: 0, disagree: 0 }
|
|
|
|
| 692 |
return d.items[i]
|
| 693 |
})
|
| 694 |
}
|
| 695 |
+
// 作者裁决(只由作者在工作台上点):decision 为空表示撤回
|
| 696 |
+
async function decidePeer(projectId, itemId, body) {
|
| 697 |
+
return withLock(`peer:${projectId}`, async () => {
|
| 698 |
+
const d = await readJson(peerKey(projectId), { items: [] })
|
| 699 |
+
const i = (d.items || []).findIndex(x => x.item_id === itemId)
|
| 700 |
+
if (i < 0) throw new HttpError(404, '没有这条记录')
|
| 701 |
+
const dec = String(body.decision || '')
|
| 702 |
+
if (dec && !AUTHOR_DECISIONS.includes(dec)) throw new HttpError(400, 'decision 只能是 adopt / keep / own')
|
| 703 |
+
const note = String(body.note ?? '').trim().slice(0, 3000)
|
| 704 |
+
if (dec === 'own' && !note) throw new HttpError(400, '选「按我的想法」时请写下你的想法')
|
| 705 |
+
const x = d.items[i]
|
| 706 |
+
d.items[i] = { ...x, author_decision: dec, author_note: dec ? note : '', author_at: dec ? now() : null, resolved: false, resolution: '', resolved_at: null, updated_at: now() }
|
| 707 |
+
await writeJson(peerKey(projectId), { items: d.items, updated_at: now() })
|
| 708 |
+
return d.items[i]
|
| 709 |
+
})
|
| 710 |
+
}
|
| 711 |
async function deletePeer(projectId, itemId) {
|
| 712 |
return withLock(`peer:${projectId}`, async () => {
|
| 713 |
const d = await readJson(peerKey(projectId), { items: [] })
|
|
|
|
| 719 |
})
|
| 720 |
}
|
| 721 |
|
| 722 |
+
/* 阅读进度(通读页 + 每章稿纸),存 R2,换设备也能接着读 */
|
| 723 |
+
function progressKey(projectId) { return projectKey(projectId, 'progress.json') }
|
| 724 |
+
async function getProgress(projectId) {
|
| 725 |
+
await getProjectOrThrow(projectId)
|
| 726 |
+
return readJson(progressKey(projectId), { reader: null, chapters: {} })
|
| 727 |
+
}
|
| 728 |
+
async function saveProgress(projectId, body) {
|
| 729 |
+
await getProjectOrThrow(projectId)
|
| 730 |
+
return withLock(`progress:${projectId}`, async () => {
|
| 731 |
+
const d = await readJson(progressKey(projectId), { reader: null, chapters: {} })
|
| 732 |
+
const num = (v, max) => Math.max(0, Math.min(max, Number(v) || 0))
|
| 733 |
+
if (body.reader && body.reader.chapter_id) d.reader = { chapter_id: cleanId(body.reader.chapter_id, 'chapter_id'), para: Math.floor(num(body.reader.para, 100000)), ratio: num(body.reader.ratio, 1), at: now() }
|
| 734 |
+
if (body.chapter && body.chapter.chapter_id) {
|
| 735 |
+
const cid = cleanId(body.chapter.chapter_id, 'chapter_id')
|
| 736 |
+
const prev = (d.chapters || {})[cid] || {}
|
| 737 |
+
const next = { ...prev, at: now() }
|
| 738 |
+
if (body.chapter.read_para !== undefined) next.read_para = Math.floor(num(body.chapter.read_para, 100000))
|
| 739 |
+
if (body.chapter.read_ratio !== undefined) next.read_ratio = num(body.chapter.read_ratio, 1)
|
| 740 |
+
if (body.chapter.edit_ratio !== undefined) next.edit_ratio = num(body.chapter.edit_ratio, 1)
|
| 741 |
+
d.chapters = { ...(d.chapters || {}), [cid]: next }
|
| 742 |
+
}
|
| 743 |
+
d.updated_at = now()
|
| 744 |
+
await writeJson(progressKey(projectId), d)
|
| 745 |
+
return d
|
| 746 |
+
})
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
module.exports = {
|
| 750 |
+
getProgress, saveProgress, decidePeer,
|
| 751 |
listProjects, createProject, getProject, updateProject, deleteProject, saveBible, saveOutline, saveMaterials,
|
| 752 |
listChapters, createChapter, getChapter: getChapterOrThrow, updateChapter,
|
| 753 |
listVersions, getVersion, saveVersion, rollback, saveCheck, getCheck, basicCheck, getContext,
|
fanqie/rank.js
CHANGED
|
@@ -529,7 +529,14 @@ module.exports = function buildRank(express) {
|
|
| 529 |
const bad = m => { const e = new Error(m); e.status = 400; return e }
|
| 530 |
|
| 531 |
router.get('/status', wrap(() => ({ ...JOB, log: JOB.log.slice(-20), llm: Boolean(process.env.LLM_API_KEY && process.env.LLM_BASE_URL && process.env.LLM_MODEL) })))
|
| 532 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
router.post('/enrich', wrap(async () => { await enrich(); return { ...JOB } }))
|
| 534 |
router.get('/analysis', wrap(req => analysisFor(String(req.query.date || ''))))
|
| 535 |
router.get('/list', wrap(async req => {
|
|
@@ -616,8 +623,9 @@ module.exports = function buildRank(express) {
|
|
| 616 |
return { project_id: id }
|
| 617 |
}))
|
| 618 |
|
| 619 |
-
//
|
| 620 |
-
|
|
|
|
| 621 |
try {
|
| 622 |
if (JOB.running || cnHour() < 8) return
|
| 623 |
const idx = await getJ(P + 'index.json', { snapshots: [] })
|
|
|
|
| 529 |
const bad = m => { const e = new Error(m); e.status = 400; return e }
|
| 530 |
|
| 531 |
router.get('/status', wrap(() => ({ ...JOB, log: JOB.log.slice(-20), llm: Boolean(process.env.LLM_API_KEY && process.env.LLM_BASE_URL && process.env.LLM_MODEL) })))
|
| 532 |
+
// 抓取只在作者吩咐后由写作 AI 调用;同一天(北京时间)已抓过就拒绝,除非带 force=1
|
| 533 |
+
router.post('/scrape', wrap(async req => {
|
| 534 |
+
if (!JOB.running && !(req.query.force === '1' || req.body?.force)) {
|
| 535 |
+
const idx = await getJ(P + 'index.json', { snapshots: [] })
|
| 536 |
+
if (idx?.latest === cnDate()) { const e = new Error(`今天(${cnDate()})已经抓过了,一天最多一次`); e.status = 409; throw e }
|
| 537 |
+
}
|
| 538 |
+
await scrape(); return { ...JOB }
|
| 539 |
+
}))
|
| 540 |
router.post('/enrich', wrap(async () => { await enrich(); return { ...JOB } }))
|
| 541 |
router.get('/analysis', wrap(req => analysisFor(String(req.query.date || ''))))
|
| 542 |
router.get('/list', wrap(async req => {
|
|
|
|
| 623 |
return { project_id: id }
|
| 624 |
}))
|
| 625 |
|
| 626 |
+
// 不再自动定时抓取:榜单只在作者吩咐时由写作 AI 手动抓(POST /scrape,然后 POST /enrich 补详情)。
|
| 627 |
+
// 如需恢复每天自动抓,设置环境变量 RANK_AUTO=1。
|
| 628 |
+
if (process.env.RANK_AUTO === '1') setInterval(async () => {
|
| 629 |
try {
|
| 630 |
if (JOB.running || cnHour() < 8) return
|
| 631 |
const idx = await getJ(P + 'index.json', { snapshots: [] })
|
public/assets/index-CJFM5oGG.css
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
public/assets/{index-DDqDQBro.js → index-CuW-4l0q.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
public/assets/index-DkBCnEWt.css
ADDED
|
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-CuW-4l0q.js"></script>
|
| 12 |
+
<link rel="stylesheet" crossorigin href="/assets/index-DkBCnEWt.css">
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<div id="root"></div>
|
ui-src/src/App.tsx
CHANGED
|
@@ -101,7 +101,7 @@ function Shell({ onLock }: { onLock: () => void }) {
|
|
| 101 |
else content = <Shelf />
|
| 102 |
|
| 103 |
return (
|
| 104 |
-
<div className=
|
| 105 |
<nav className="rail" aria-label="主导航">
|
| 106 |
<button className="rail-brand" onClick={() => go('shelf')} title="小说写作台"><Feather size={18} /></button>
|
| 107 |
<div className="rail-items">
|
|
|
|
| 101 |
else content = <Shelf />
|
| 102 |
|
| 103 |
return (
|
| 104 |
+
<div className={cx('shell', head === 'book' && parts[2] === 'read' && 'reading')}>
|
| 105 |
<nav className="rail" aria-label="主导航">
|
| 106 |
<button className="rail-brand" onClick={() => go('shelf')} title="小说写作台"><Feather size={18} /></button>
|
| 107 |
<div className="rail-items">
|
ui-src/src/api.ts
CHANGED
|
@@ -198,6 +198,9 @@ export const projectsApi = {
|
|
| 198 |
createRequest: (id: string, body: { type: string; instruction: string; chapter_id?: string | null }) => post<any>(`${P}/${id}/requests`, body),
|
| 199 |
notes: (id: string, cid: string) => get<{ notes: Note[]; reviews: Review[] }>(`${P}/${id}/chapters/${cid}/notes`),
|
| 200 |
peer: (id: string, cid?: string) => get<{ items: PeerItem[]; counts: Record<string, number> }>(`${P}/${id}/peer${qs({ chapter_id: cid })}`),
|
|
|
|
|
|
|
|
|
|
| 201 |
createNote: (id: string, cid: string, body: Partial<Note>) => post<Note>(`${P}/${id}/chapters/${cid}/notes`, body),
|
| 202 |
updateNote: (id: string, cid: string, nid: string, body: Partial<Note>) => patch<Note>(`${P}/${id}/chapters/${cid}/notes/${nid}`, body),
|
| 203 |
deleteNote: (id: string, cid: string, nid: string) => del(`${P}/${id}/chapters/${cid}/notes/${nid}`),
|
|
@@ -251,6 +254,13 @@ export interface ReviewerCfg {
|
|
| 251 |
export interface PeerItem {
|
| 252 |
item_id: string; chapter_id: string | null; chapter_number: number | null; ask_id: string; topic: string
|
| 253 |
reviewer_said: string; my_view: string; decision: string; verdict: 'agree' | 'partial' | 'disagree'; created_by: string; created_at: string; updated_at: string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
}
|
| 255 |
export interface ReviewerAsk {
|
| 256 |
ask_id: string; project_id: string | null; topic: string; question: string; attach: string[]; asked_by: string; reviewer: string
|
|
|
|
| 198 |
createRequest: (id: string, body: { type: string; instruction: string; chapter_id?: string | null }) => post<any>(`${P}/${id}/requests`, body),
|
| 199 |
notes: (id: string, cid: string) => get<{ notes: Note[]; reviews: Review[] }>(`${P}/${id}/chapters/${cid}/notes`),
|
| 200 |
peer: (id: string, cid?: string) => get<{ items: PeerItem[]; counts: Record<string, number> }>(`${P}/${id}/peer${qs({ chapter_id: cid })}`),
|
| 201 |
+
decidePeer: (id: string, itemId: string, body: { decision: '' | 'adopt' | 'keep' | 'own'; note?: string }) => put<PeerItem>(`${P}/${id}/peer/${itemId}/author`, body),
|
| 202 |
+
progress: (id: string) => get<ReadProgress>(`${P}/${id}/progress`),
|
| 203 |
+
saveProgress: (id: string, body: { reader?: { chapter_id: string; para: number; ratio?: number }; chapter?: { chapter_id: string; read_para?: number; read_ratio?: number; edit_ratio?: number } }) => put<ReadProgress>(`${P}/${id}/progress`, body),
|
| 204 |
createNote: (id: string, cid: string, body: Partial<Note>) => post<Note>(`${P}/${id}/chapters/${cid}/notes`, body),
|
| 205 |
updateNote: (id: string, cid: string, nid: string, body: Partial<Note>) => patch<Note>(`${P}/${id}/chapters/${cid}/notes/${nid}`, body),
|
| 206 |
deleteNote: (id: string, cid: string, nid: string) => del(`${P}/${id}/chapters/${cid}/notes/${nid}`),
|
|
|
|
| 254 |
export interface PeerItem {
|
| 255 |
item_id: string; chapter_id: string | null; chapter_number: number | null; ask_id: string; topic: string
|
| 256 |
reviewer_said: string; my_view: string; decision: string; verdict: 'agree' | 'partial' | 'disagree'; created_by: string; created_at: string; updated_at: string
|
| 257 |
+
quote?: string; author_decision?: '' | 'adopt' | 'keep' | 'own'; author_note?: string; author_at?: string | null
|
| 258 |
+
resolved?: boolean; resolution?: string; resolved_at?: string | null
|
| 259 |
+
}
|
| 260 |
+
export interface ReadProgress {
|
| 261 |
+
reader: { chapter_id: string; para: number; ratio?: number; at: string } | null
|
| 262 |
+
chapters: Record<string, { read_para?: number; read_ratio?: number; edit_ratio?: number; at?: string }>
|
| 263 |
+
updated_at?: string
|
| 264 |
}
|
| 265 |
export interface ReviewerAsk {
|
| 266 |
ask_id: string; project_id: string | null; topic: string; question: string; attach: string[]; asked_by: string; reviewer: string
|
ui-src/src/rooms/Agent.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { agentApi, getPassword, projectsApi, type AgentProfile, type Audit, type ReviewerAsk, type ReviewerCfg, type ReviewerCheck } from '../api'
|
| 7 |
import { copyText, cx, fmtAgo, fmtDate, go, useAsync } from '../lib'
|
| 8 |
-
import { Empty, ErrorNote, Field, Loading, Segmented, Spinner, Tabs, Tag, useConfirm, useToast } from '../ui'
|
| 9 |
import { Md } from '../md'
|
| 10 |
|
| 11 |
/* ================= 共用小部件(书房、手册也在用) ================= */
|
|
@@ -81,27 +81,27 @@ export function ProjectPicker({ value, onChange }: { value: string; onChange: (v
|
|
| 81 |
}
|
| 82 |
|
| 83 |
/* ================= AI 协作室 ================= */
|
| 84 |
-
type T = 'guide' | '
|
| 85 |
export default function AgentRoom({ tab }: { tab: string }) {
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
return (
|
| 88 |
<div className="room agent">
|
| 89 |
<header className="room-head">
|
| 90 |
<div>
|
| 91 |
<div className="eyebrow"><Bot size={14} />AI 协作</div>
|
| 92 |
-
<h1 className="room-title serif">写作 AI 的守则
|
| 93 |
-
<p className="muted small-note">写作
|
| 94 |
</div>
|
| 95 |
</header>
|
| 96 |
<Tabs<T> value={t} onChange={v => go(`agent/${v}`)} className="room-tabs" items={[
|
| 97 |
{ id: 'guide', label: <><ScrollText size={14} />AI 守则</> },
|
| 98 |
-
{ id: 'profile', label: <><UserRound size={14} />作者状态</> },
|
| 99 |
{ id: 'reviewer', label: <><Sparkles size={14} />协作 AI</> },
|
| 100 |
{ id: 'audits', label: <><ClipboardCheck size={14} />检查记录</> },
|
| 101 |
]} />
|
| 102 |
<div className="room-body">
|
| 103 |
{t === 'guide' && <GuideTab />}
|
| 104 |
-
{t === 'profile' && <ProfileTab />}
|
| 105 |
{t === 'reviewer' && <ReviewerTab />}
|
| 106 |
{t === 'audits' && <AuditsTab />}
|
| 107 |
</div>
|
|
@@ -135,7 +135,7 @@ function GuideTab() {
|
|
| 135 |
const ACCOUNT = [{ id: 'new', label: '刚注册' }, { id: 'active', label: '已发过书' }, { id: 'veteran', label: '老作者' }] as const
|
| 136 |
const FIRST = [{ id: 'none', label: '还没开始' }, { id: 'writing', label: '正在写,未完成' }, { id: 'done', label: '已完本' }] as const
|
| 137 |
const CONTRACT = [{ id: 'none', label: '未签约' }, { id: 'applying', label: '申请中' }, { id: 'signed', label: '已签约' }] as const
|
| 138 |
-
function
|
| 139 |
const toast = useToast()
|
| 140 |
const p = useAsync(() => agentApi.profile(), [])
|
| 141 |
const [f, setF] = useState<AgentProfile | null>(null)
|
|
@@ -155,12 +155,12 @@ function ProfileTab() {
|
|
| 155 |
<h2 className="sheet-title serif">我现在的状态</h2>
|
| 156 |
<div className="stack">
|
| 157 |
<Field label="番茄账号"><Segmented value={f.account} onChange={v => set('account', v)} items={ACCOUNT as any} /></Field>
|
| 158 |
-
<Field label="作者等级" hint="作家后台显示的等级,例如 Lv0"><
|
| 159 |
<Field label="第一本书"><Segmented value={f.first_book} onChange={v => set('first_book', v)} items={FIRST as any} /></Field>
|
| 160 |
<Field label="签约情况"><Segmented value={f.contract} onChange={v => set('contract', v)} items={CONTRACT as any} /></Field>
|
| 161 |
<Field label="已在平台发布的章节数"><input className="input auto" type="number" min={0} value={f.published_chapters} onChange={e => set('published_chapters', Number(e.target.value))} /></Field>
|
| 162 |
-
<Field label="当前目标"><
|
| 163 |
-
<Field label="想对 AI 说的话" hint="原话会写进守则,AI 每次动笔前都会读到"><
|
| 164 |
</div>
|
| 165 |
<div className="row end" style={{ marginTop: 14 }}>
|
| 166 |
<button className="btn primary" disabled={busy || !dirty} onClick={save}>{busy ? <Spinner size={14} /> : <Save size={14} />}{dirty ? '保存' : '已保存'}</button>
|
|
@@ -314,13 +314,13 @@ function ReviewerTab() {
|
|
| 314 |
<Field label="接口地址" hint={f.mode === 'openai' ? '例如 https://…/v1/chat/completions' : f.mode === 'anthropic' ? '例如 https://api.anthropic.com/v1/messages' : '收到 POST 请求的完整地址'}><input className="input" value={f.endpoint} onChange={e => set('endpoint', e.target.value)} /></Field>
|
| 315 |
<Field label="模型"><input className="input" value={f.model} onChange={e => set('model', e.target.value)} /></Field>
|
| 316 |
{f.mode === 'custom' && <>
|
| 317 |
-
<Field label="请求头模板(JSON)" hint="可用 {{token}}"><
|
| 318 |
-
<Field label="请求体模板(JSON)" hint="可用 {{prompt}} {{system}} {{full}} {{model}} {{token}}"><
|
| 319 |
<Field label="回复所在字段" hint="例如 data.reply 或 choices.0.message.content"><input className="input" value={f.reply_path} onChange={e => set('reply_path', e.target.value)} /></Field>
|
| 320 |
</>}
|
| 321 |
<label className="vault-check"><input type="checkbox" checked={f.sse} onChange={e => set('sse', e.target.checked)} />接口以流式(event-stream)返回</label>
|
| 322 |
</>}
|
| 323 |
-
<Field label="审查时的要求(可选)" hint="留空则用默认:严格的番茄责任编辑,只审查不代写。调研、出主意、起草有各自的默认要求"><
|
| 324 |
</div>
|
| 325 |
<div className="row end gap wrap" style={{ marginTop: 14 }}>
|
| 326 |
{surf && <button className="btn ghost" disabled={!!busy || !f.token_set} onClick={check} title="查账号、积分和令牌剩余时间,不花积分">{busy === 'check' ? <Spinner size={14} /> : <PlugZap size={14} />}检查连接</button>}
|
|
@@ -403,7 +403,7 @@ function AskItem({ x, reload }: { x: ReviewerAsk; reload: () => void }) {
|
|
| 403 |
</div>
|
| 404 |
)
|
| 405 |
}
|
| 406 |
-
const ATT: Record<string, string> = { overview: '概览', bible: '圣经', outline: '大纲', toc: '目录', chapters: '章节', chapter: '章节' }
|
| 407 |
|
| 408 |
function AuditsTab() {
|
| 409 |
const confirm = useConfirm()
|
|
|
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { agentApi, getPassword, projectsApi, type AgentProfile, type Audit, type ReviewerAsk, type ReviewerCfg, type ReviewerCheck } from '../api'
|
| 7 |
import { copyText, cx, fmtAgo, fmtDate, go, useAsync } from '../lib'
|
| 8 |
+
import { AutoText, Empty, ErrorNote, Field, Loading, Segmented, Spinner, Tabs, Tag, useConfirm, useToast } from '../ui'
|
| 9 |
import { Md } from '../md'
|
| 10 |
|
| 11 |
/* ================= 共用小部件(书房、手册也在用) ================= */
|
|
|
|
| 81 |
}
|
| 82 |
|
| 83 |
/* ================= AI 协作室 ================= */
|
| 84 |
+
type T = 'guide' | 'reviewer' | 'audits'
|
| 85 |
export default function AgentRoom({ tab }: { tab: string }) {
|
| 86 |
+
// 作者状态已移到「手册 → 作者状态」
|
| 87 |
+
useEffect(() => { if (tab === 'profile') go('guide/author') }, [tab])
|
| 88 |
+
const t = (['guide', 'reviewer', 'audits'].includes(tab) ? tab : 'guide') as T
|
| 89 |
return (
|
| 90 |
<div className="room agent">
|
| 91 |
<header className="room-head">
|
| 92 |
<div>
|
| 93 |
<div className="eyebrow"><Bot size={14} />AI 协作</div>
|
| 94 |
+
<h1 className="room-title serif">写作 AI 的守则与协作</h1>
|
| 95 |
+
<p className="muted small-note">你是作者,我(写作 AI)按你的吩咐写:先读这里的守则和手册里的「作者状态」,再动笔;写完自查,需要时请「协作 AI」审查、调研、出主意。你读结果、写批注、在分歧里拍板,告诉我下一步。</p>
|
| 96 |
</div>
|
| 97 |
</header>
|
| 98 |
<Tabs<T> value={t} onChange={v => go(`agent/${v}`)} className="room-tabs" items={[
|
| 99 |
{ id: 'guide', label: <><ScrollText size={14} />AI 守则</> },
|
|
|
|
| 100 |
{ id: 'reviewer', label: <><Sparkles size={14} />协作 AI</> },
|
| 101 |
{ id: 'audits', label: <><ClipboardCheck size={14} />检查记录</> },
|
| 102 |
]} />
|
| 103 |
<div className="room-body">
|
| 104 |
{t === 'guide' && <GuideTab />}
|
|
|
|
| 105 |
{t === 'reviewer' && <ReviewerTab />}
|
| 106 |
{t === 'audits' && <AuditsTab />}
|
| 107 |
</div>
|
|
|
|
| 135 |
const ACCOUNT = [{ id: 'new', label: '刚注册' }, { id: 'active', label: '已发过书' }, { id: 'veteran', label: '老作者' }] as const
|
| 136 |
const FIRST = [{ id: 'none', label: '还没开始' }, { id: 'writing', label: '正在写,未完成' }, { id: 'done', label: '已完本' }] as const
|
| 137 |
const CONTRACT = [{ id: 'none', label: '未签约' }, { id: 'applying', label: '申请中' }, { id: 'signed', label: '已签约' }] as const
|
| 138 |
+
export function AuthorProfile() {
|
| 139 |
const toast = useToast()
|
| 140 |
const p = useAsync(() => agentApi.profile(), [])
|
| 141 |
const [f, setF] = useState<AgentProfile | null>(null)
|
|
|
|
| 155 |
<h2 className="sheet-title serif">我现在的状态</h2>
|
| 156 |
<div className="stack">
|
| 157 |
<Field label="番茄账号"><Segmented value={f.account} onChange={v => set('account', v)} items={ACCOUNT as any} /></Field>
|
| 158 |
+
<Field label="作者等级" hint="作家后台显示的等级,例如 Lv0"><AutoText className="one" minRows={1} value={f.level} onChange={v => set('level', v)} /></Field>
|
| 159 |
<Field label="第一本书"><Segmented value={f.first_book} onChange={v => set('first_book', v)} items={FIRST as any} /></Field>
|
| 160 |
<Field label="签约情况"><Segmented value={f.contract} onChange={v => set('contract', v)} items={CONTRACT as any} /></Field>
|
| 161 |
<Field label="已在平台发布的章节数"><input className="input auto" type="number" min={0} value={f.published_chapters} onChange={e => set('published_chapters', Number(e.target.value))} /></Field>
|
| 162 |
+
<Field label="当前目标"><AutoText className="one" minRows={1} value={f.goal} onChange={v => set('goal', v)} /></Field>
|
| 163 |
+
<Field label="想对 AI 说的话" hint="原话会写进守则,AI 每次动笔前都会读到"><AutoText minRows={3} value={f.note} onChange={v => set('note', v)} /></Field>
|
| 164 |
</div>
|
| 165 |
<div className="row end" style={{ marginTop: 14 }}>
|
| 166 |
<button className="btn primary" disabled={busy || !dirty} onClick={save}>{busy ? <Spinner size={14} /> : <Save size={14} />}{dirty ? '保存' : '已保存'}</button>
|
|
|
|
| 314 |
<Field label="接口地址" hint={f.mode === 'openai' ? '例如 https://…/v1/chat/completions' : f.mode === 'anthropic' ? '例如 https://api.anthropic.com/v1/messages' : '收到 POST 请求的完整地址'}><input className="input" value={f.endpoint} onChange={e => set('endpoint', e.target.value)} /></Field>
|
| 315 |
<Field label="模型"><input className="input" value={f.model} onChange={e => set('model', e.target.value)} /></Field>
|
| 316 |
{f.mode === 'custom' && <>
|
| 317 |
+
<Field label="请求头模板(JSON)" hint="可用 {{token}}"><AutoText className="mono" minRows={3} value={f.headers_tpl} onChange={v => set('headers_tpl', v)} placeholder={'{"Authorization": "Bearer {{token}}"}'} /></Field>
|
| 318 |
+
<Field label="请求体模板(JSON)" hint="可用 {{prompt}} {{system}} {{full}} {{model}} {{token}}"><AutoText className="mono" minRows={4} value={f.body_tpl} onChange={v => set('body_tpl', v)} placeholder={'{"message": "{{full}}"}'} /></Field>
|
| 319 |
<Field label="回复所在字段" hint="例如 data.reply 或 choices.0.message.content"><input className="input" value={f.reply_path} onChange={e => set('reply_path', e.target.value)} /></Field>
|
| 320 |
</>}
|
| 321 |
<label className="vault-check"><input type="checkbox" checked={f.sse} onChange={e => set('sse', e.target.checked)} />接口以流式(event-stream)返回</label>
|
| 322 |
</>}
|
| 323 |
+
<Field label="审查时的要求(可选)" hint="留空则用默认:严格的番茄责任编辑,只审查不代写。调研、出主意、起草有各自的默认要求"><AutoText className="" minRows={3} value={f.system} onChange={v => set('system', v)} /></Field>
|
| 324 |
</div>
|
| 325 |
<div className="row end gap wrap" style={{ marginTop: 14 }}>
|
| 326 |
{surf && <button className="btn ghost" disabled={!!busy || !f.token_set} onClick={check} title="查账号、积分和令牌剩余时间,不花积分">{busy === 'check' ? <Spinner size={14} /> : <PlugZap size={14} />}检查连接</button>}
|
|
|
|
| 403 |
</div>
|
| 404 |
)
|
| 405 |
}
|
| 406 |
+
const ATT: Record<string, string> = { overview: '概览', bible: '圣经', outline: '大纲', toc: '目录', chapters: '章节', chapter: '章节', rank: '热榜', motif: '母题', motif_role: '母题角色', material: '素材', refs: '参考素材', rules: '平台规定' }
|
| 407 |
|
| 408 |
function AuditsTab() {
|
| 409 |
const confirm = useConfirm()
|
ui-src/src/rooms/Book.tsx
CHANGED
|
@@ -118,8 +118,8 @@ function Binder({ ctx, sub, onAddChapter, onCollapse }: { ctx: BookCtx; sub: str
|
|
| 118 |
<BinderLink on={sub === 'about'} icon={<Info size={15} />} onClick={() => go(`book/${pid}/about`)}>作品概览</BinderLink>
|
| 119 |
<BinderLink on={sub === 'bible'} icon={<Users size={15} />} onClick={() => go(`book/${pid}/bible`)} meta={chars ? `${chars} 人` : ''}>作品圣经</BinderLink>
|
| 120 |
<BinderLink on={sub === 'outline'} icon={<ListTree size={15} />} onClick={() => go(`book/${pid}/outline`)}>大纲</BinderLink>
|
| 121 |
-
<BinderLink on={sub === 'read'} icon={<BookOpenText size={15} />} onClick={() => go(`book/${pid}/read`)} meta={totalWords ? `${fmtNum(totalWords)} 字` : ''}>通读全书</BinderLink>
|
| 122 |
<BinderLink on={sub === 'refs'} icon={<Bookmark size={15} />} onClick={() => go(`book/${pid}/refs`)} meta={`${refs}/3`}>参考素材</BinderLink>
|
|
|
|
| 123 |
</div>
|
| 124 |
|
| 125 |
<div className="binder-section grow">
|
|
@@ -223,7 +223,7 @@ function BookAbout({ ctx, onAddChapter }: { ctx: BookCtx; onAddChapter: () => vo
|
|
| 223 |
<Field label="发布平台"><input className="input" value={f.target_platform} onChange={e => set('target_platform', e.target.value)} /></Field>
|
| 224 |
<Field label="目标字数"><input className="input" type="number" value={f.target_words} onChange={e => set('target_words', Number(e.target.value) || 0)} /></Field>
|
| 225 |
<Field label="叙事视角"><input className="input" value={f.pov} onChange={e => set('pov', e.target.value)} /></Field>
|
| 226 |
-
<Field label="文风"><
|
| 227 |
<Field label="一句话梗概" className="span2"><AutoText value={f.premise} onChange={v => set('premise', v)} minRows={3} placeholder="用一句话说清:谁,遇到了什么事,想要什么。" /></Field>
|
| 228 |
</div>
|
| 229 |
<div className="sheet-actions">
|
|
|
|
| 118 |
<BinderLink on={sub === 'about'} icon={<Info size={15} />} onClick={() => go(`book/${pid}/about`)}>作品概览</BinderLink>
|
| 119 |
<BinderLink on={sub === 'bible'} icon={<Users size={15} />} onClick={() => go(`book/${pid}/bible`)} meta={chars ? `${chars} 人` : ''}>作品圣经</BinderLink>
|
| 120 |
<BinderLink on={sub === 'outline'} icon={<ListTree size={15} />} onClick={() => go(`book/${pid}/outline`)}>大纲</BinderLink>
|
|
|
|
| 121 |
<BinderLink on={sub === 'refs'} icon={<Bookmark size={15} />} onClick={() => go(`book/${pid}/refs`)} meta={`${refs}/3`}>参考素材</BinderLink>
|
| 122 |
+
<BinderLink on={sub === 'read'} icon={<BookOpenText size={15} />} onClick={() => go(`book/${pid}/read`)} meta={totalWords ? `${fmtNum(totalWords)} 字` : ''}>通读全书</BinderLink>
|
| 123 |
</div>
|
| 124 |
|
| 125 |
<div className="binder-section grow">
|
|
|
|
| 223 |
<Field label="发布平台"><input className="input" value={f.target_platform} onChange={e => set('target_platform', e.target.value)} /></Field>
|
| 224 |
<Field label="目标字数"><input className="input" type="number" value={f.target_words} onChange={e => set('target_words', Number(e.target.value) || 0)} /></Field>
|
| 225 |
<Field label="叙事视角"><input className="input" value={f.pov} onChange={e => set('pov', e.target.value)} /></Field>
|
| 226 |
+
<Field label="文风"><AutoText className="one" minRows={1} value={f.style} onChange={v => set('style', v)} /></Field>
|
| 227 |
<Field label="一句话梗概" className="span2"><AutoText value={f.premise} onChange={v => set('premise', v)} minRows={3} placeholder="用一句话说清:谁,遇到了什么事,想要什么。" /></Field>
|
| 228 |
</div>
|
| 229 |
<div className="sheet-actions">
|
ui-src/src/rooms/Editor.tsx
CHANGED
|
@@ -3,17 +3,17 @@ 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, useNotes } from './Review'
|
| 7 |
import { agentApi, Chapter, Material, materialsApi, projectsApi, Version, VersionMeta } from '../api'
|
| 8 |
import { AskLog, AuditCard, SayToAi } from './Agent'
|
| 9 |
-
import { PeerPanel, peerCount, usePeer } from './Peer'
|
| 10 |
import { cnNum, copyText, countWords, cx, diffParagraphs, fmtAgo, fmtDate, go, CHAPTER_STATUS, GENRE, KIND, VERSION_KIND, useLocal, useDebounced, useAsync } from '../lib'
|
| 11 |
import { AutoText, Empty, ErrorNote, Field, ListEditor, Loading, Modal, Spinner, Tabs, useConfirm, useToast, Segmented, Tag } from '../ui'
|
| 12 |
import type { BookCtx } from './Book'
|
| 13 |
import { toRef } from './Bible'
|
| 14 |
import { feedApi } from './RankInspire'
|
| 15 |
|
| 16 |
-
type Tab = 'chapter' | 'notes' | 'peer' | '
|
| 17 |
const draftKey = (cid: string) => `xs_draft_${cid}`
|
| 18 |
type Draft = { text: string; base: string | null; at: string }
|
| 19 |
const readDraft = (cid: string): Draft | null => { try { return JSON.parse(localStorage.getItem(draftKey(cid)) || 'null') } catch { return null } }
|
|
@@ -54,6 +54,9 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 54 |
const [activeNote, setActiveNote] = useState('')
|
| 55 |
const located = useMemo(() => locateNotes(text, nb.notes || []), [text, nb.notes])
|
| 56 |
const openNotes = located.filter(n => n.status === 'open').length
|
|
|
|
|
|
|
|
|
|
| 57 |
const pickNote = (id: string) => { setActiveNote(''); setTimeout(() => setActiveNote(id), 0); setInspector(true); setTab('notes') }
|
| 58 |
const createNote = async (f: any) => {
|
| 59 |
try {
|
|
@@ -86,6 +89,35 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 86 |
}, [pid, cid])
|
| 87 |
useEffect(() => { load() }, [load])
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
const dirty = detail != null && text !== savedText
|
| 90 |
const words = useMemo(() => countWords(text), [text])
|
| 91 |
const session = startWords.current == null ? 0 : words - startWords.current
|
|
@@ -208,14 +240,15 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 208 |
|
| 209 |
return (
|
| 210 |
<div className={cx('editor', showInspector && 'with-inspector')}>
|
| 211 |
-
<div className="manuscript-scroll">
|
| 212 |
<div className="editor-bar">
|
|
|
|
| 213 |
<div className="eb-left">
|
| 214 |
<span className="eb-crumb">{bundle.project.title}<i>/</i>{detail.volume ? <>{detail.volume}<i>/</i></> : null}第{cnNum(detail.number)}章</span>
|
| 215 |
<span className={cx('eb-state', 'st-' + st.k)} title={st.full} role="status">{st.k === 'saving' ? <Spinner size={12} /> : <i className="eb-dot" />}<span className="eb-full">{st.full}</span><span className="eb-short">{st.short}</span></span>
|
| 216 |
</div>
|
| 217 |
<div className="eb-right">
|
| 218 |
-
<span className="eb-count" title={`本章 ${words.toLocaleString()} 字(去掉空白)${session ? `,本次 ${session > 0 ? '+' : ''}${session}` : ''}`}><b>{words.toLocaleString()}</b> 字{session !== 0 && <em className={session > 0 ? 'up' : 'down'}>{session > 0 ? '+' : ''}{session}</em>}</span>
|
| 219 |
<button className={cx('btn small', reviewMode ? 'primary' : 'ghost', 'review-toggle')} onClick={() => setReviewMode(!reviewMode)} title="批阅模式:选中句子加批注">
|
| 220 |
<Highlighter size={14} /><span className="eb-lbl">{reviewMode ? '退出批阅' : '批阅'}</span>{openNotes > 0 && <em className="badge">{openNotes}</em>}
|
| 221 |
</button>
|
|
@@ -245,10 +278,14 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 245 |
{detail.goal && !focus && <div className="paper-goal"><span>本章目标</span>{detail.goal}</div>}
|
| 246 |
{reviewMode ? <>
|
| 247 |
<div className="review-tip"><Highlighter size={14} />批阅中:正文只读,选中任意句子即可批注;点黄色标记查看批注。<button className="link-btn" onClick={() => setReviewMode(false)}>回到编辑</button></div>
|
| 248 |
-
<ReviewText text={text} notes={located} active={activeNote} onPick={pickNote} onCreate={createNote} />
|
| 249 |
</> : (
|
| 250 |
-
<
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
<div className="paper-end">{words > 0 ? `— 本章 ${words.toLocaleString()} 字 —` : ''}</div>
|
| 253 |
</article>
|
| 254 |
</div>
|
|
@@ -260,16 +297,16 @@ export default function ChapterEditor({ ctx, chapter }: { ctx: BookCtx; chapter:
|
|
| 260 |
{ id: 'chapter', label: <><FileCog size={14} />本章</> },
|
| 261 |
{ id: 'notes', label: <><Highlighter size={14} />批注</>, count: openNotes || undefined },
|
| 262 |
{ id: 'peer', label: <><Scale size={14} />分歧</>, count: peerCount(peer.data) || undefined },
|
| 263 |
-
{ id: 'versions', label: <><History size={14} />版本</>, count: versions.length || undefined },
|
| 264 |
{ id: 'check', label: <><ClipboardCheck size={14} />检查</> },
|
|
|
|
|
|
|
| 265 |
{ id: 'refs', label: <><BookmarkPlus size={14} />素材</> },
|
| 266 |
-
{ id: 'ai', label: <><Sparkles size={14} />AI 协作</> },
|
| 267 |
]} />
|
| 268 |
<div className="inspector-body">
|
| 269 |
{tab === 'chapter' && <ChapterMeta ctx={ctx} detail={detail} onSaved={c => { setDetail(d => d ? { ...d, ...c } : d); updateChapterInBundle(c); setTitle(c.title) }} />}
|
| 270 |
{tab === 'notes' && <NotesPanel bundle={bundle} detail={detail} text={text} notes={nb.notes} setNotes={nb.setNotes} reviews={nb.reviews} setReviews={nb.setReviews}
|
| 271 |
active={activeNote} setActive={id => { setActiveNote(''); setTimeout(() => setActiveNote(id), 0) }} reviewMode={reviewMode} setReviewMode={setReviewMode} />}
|
| 272 |
-
{tab === 'peer' && <PeerPanel data={peer} />}
|
| 273 |
{tab === 'versions' && <VersionsPanel pid={pid} cid={cid} versions={versions} current={detail.current_version_id} editorText={text} onLoad={loadIntoEditor} />}
|
| 274 |
{tab === 'check' && <CheckPanel num={detail.number} pid={pid} cid={cid} currentVersion={detail.current_version_id} text={text} dirty={dirty} />}
|
| 275 |
{tab === 'refs' && <RefsPanel ctx={ctx} />}
|
|
@@ -413,7 +450,7 @@ function VersionsPanel({ pid, cid, versions, current, editorText, onLoad }: {
|
|
| 413 |
<div className="panel-stack">
|
| 414 |
<div className="muted small-note">勾选两个版本可以互相对比。</div>
|
| 415 |
{pick.length === 2 && <button className="btn small ghost block" onClick={compareTwo} disabled={busy === 'pair'}><GitCompare size={14} />对比所选的两个版本</button>}
|
| 416 |
-
<ol className="timeline">
|
| 417 |
{versions.map((m, i) => (
|
| 418 |
<li key={m.version_id} className={cx(m.version_id === current && 'current')}>
|
| 419 |
<label className="tl-check"><input type="checkbox" checked={pick.includes(m.version_id)} onChange={e => setPick(p => e.target.checked ? [...p.slice(-1), m.version_id] : p.filter(x => x !== m.version_id))} /></label>
|
|
@@ -475,23 +512,8 @@ function DiffView({ a, b }: { a: { label: string; text: string }; b: { label: st
|
|
| 475 |
)
|
| 476 |
}
|
| 477 |
|
| 478 |
-
/* ---------- 检查 ---------- */
|
| 479 |
-
function CheckPanel({ num, pid, cid, currentVersion, text
|
| 480 |
-
const toast = useToast()
|
| 481 |
-
const [result, setResult] = useState<any>(null)
|
| 482 |
-
const [busy, setBusy] = useState(false)
|
| 483 |
-
const [stored, setStored] = useState<any>(undefined)
|
| 484 |
-
useEffect(() => {
|
| 485 |
-
let alive = true
|
| 486 |
-
setStored(undefined)
|
| 487 |
-
if (currentVersion) projectsApi.getCheck(pid, currentVersion).then(r => alive && setStored(r), () => alive && setStored(null))
|
| 488 |
-
else setStored(null)
|
| 489 |
-
return () => { alive = false }
|
| 490 |
-
}, [pid, currentVersion])
|
| 491 |
-
const run = async () => {
|
| 492 |
-
setBusy(true)
|
| 493 |
-
try { const r = await projectsApi.check(pid, cid); setResult(r); setStored(r) } catch (e: any) { toast(e.message, 'err') } finally { setBusy(false) }
|
| 494 |
-
}
|
| 495 |
const stats = useMemo(() => {
|
| 496 |
const paras = text.split(/\n+/).map(s => s.trim()).filter(Boolean)
|
| 497 |
const plain = text.replace(/\s/g, '')
|
|
@@ -501,8 +523,14 @@ function CheckPanel({ num, pid, cid, currentVersion, text, dirty }: { num: numbe
|
|
| 501 |
const firstPara = paras[0] || ''
|
| 502 |
return { words: [...plain].length, paras: paras.length, avg: paras.length ? Math.round([...plain].length / paras.length) : 0, dialog: plain.length ? Math.round(quoted / plain.length * 100) : 0, longest, longParas, opening: countWords(firstPara) }
|
| 503 |
}, [text])
|
| 504 |
-
const
|
| 505 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
return (
|
| 507 |
<div className="panel-stack">
|
| 508 |
<div className="mini-stats">
|
|
@@ -518,67 +546,27 @@ function CheckPanel({ num, pid, cid, currentVersion, text, dirty }: { num: numbe
|
|
| 518 |
{stats.words > 0 && stats.dialog < 8 && <li>对话很少,可以考虑用对白推动情节。</li>}
|
| 519 |
{stats.words === 0 && <li>稿纸还是空的。</li>}
|
| 520 |
</ul>
|
|
|
|
|
|
|
| 521 |
|
| 522 |
<div className="divider" />
|
| 523 |
<div className="row between">
|
| 524 |
-
<b className="panel-h">
|
| 525 |
-
<button className="btn
|
| 526 |
</div>
|
| 527 |
-
<div className="muted small-note">
|
| 528 |
-
{
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
</div>
|
| 536 |
-
{Array.isArray(shown.issues) && shown.issues.length > 0 && (
|
| 537 |
-
<ul className="issues">
|
| 538 |
-
{shown.issues.map((it: any, i: number) => <li key={i} className={it.level}>{it.message || it.msg || JSON.stringify(it)}</li>)}
|
| 539 |
-
</ul>
|
| 540 |
-
)}
|
| 541 |
-
{shown.dimensions && (
|
| 542 |
-
<div className="dims">
|
| 543 |
-
{Object.entries(shown.dimensions).map(([k, v]) => (
|
| 544 |
-
<div key={k}><span>{DIM[k] || k}</span><em>{v === 'pending_ai' ? '待 AI 检查' : typeof v === 'string' ? v : (v as any)?.status || JSON.stringify(v)}</em></div>
|
| 545 |
-
))}
|
| 546 |
-
</div>
|
| 547 |
-
)}
|
| 548 |
-
{shown.note && <div className="muted small-note">{shown.note}</div>}
|
| 549 |
-
</div>
|
| 550 |
-
)}
|
| 551 |
-
{stored === null && !result && currentVersion && <div className="muted small-note">当前版本还没有检查记录。</div>}
|
| 552 |
|
| 553 |
<div className="divider" />
|
| 554 |
-
<
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
}
|
| 558 |
-
|
| 559 |
-
/* 番茄平台规定:由 AI 逐条阅读本章后判断,结果存在检查记录里 */
|
| 560 |
-
function PlatformAudit({ num, pid, cid, currentVersion }: { num: number; pid: string; cid: string; currentVersion: string | null }) {
|
| 561 |
-
const d = useAsync(() => agentApi.audits({ project_id: pid, chapter_id: cid, n: 20 }), [pid, cid])
|
| 562 |
-
const items = d.data?.items || []
|
| 563 |
-
const plat = items.find(a => a.kind === 'platform')
|
| 564 |
-
const others = items.filter(a => a !== plat).slice(0, 3)
|
| 565 |
-
const stale = plat && currentVersion && plat.version_id && plat.version_id !== currentVersion
|
| 566 |
-
return (
|
| 567 |
-
<div className="panel-stack">
|
| 568 |
-
<div className="row between">
|
| 569 |
-
<b className="panel-h">番茄平台规定</b>
|
| 570 |
-
<button className="link-btn" onClick={() => go('guide/red')}>看规定原文</button>
|
| 571 |
-
</div>
|
| 572 |
-
<div className="muted small-note">内容红线、低质与 AI 规则,由写作 AI 逐条读完本章后判断(不是关键词匹配),每条都附原文和修改建议。</div>
|
| 573 |
-
{d.error ? <ErrorNote error={d.error} onRetry={d.reload} /> : !d.data ? <Spinner size={13} label="读取检查记录…" /> : plat ? <>
|
| 574 |
-
{stale && <div className="note-warn">这份结果检查的是旧版本,本章已经改过,建议让 AI 重新检查。</div>}
|
| 575 |
-
<AuditCard a={plat} open />
|
| 576 |
-
</> : <div className="muted small-note">本章还没有平台规定检查记录。</div>}
|
| 577 |
-
<SayToAi text={`请按「番茄平台规定」逐条检查第${num}章,结果写进检查记录。`} />
|
| 578 |
-
{others.length > 0 && <>
|
| 579 |
-
<b className="panel-h">本章其他检查</b>
|
| 580 |
-
{others.map(a => <AuditCard key={a.audit_id} a={a} />)}
|
| 581 |
-
</>}
|
| 582 |
</div>
|
| 583 |
)
|
| 584 |
}
|
|
@@ -642,24 +630,19 @@ function RefsPanel({ ctx }: { ctx: BookCtx }) {
|
|
| 642 |
)
|
| 643 |
}
|
| 644 |
|
| 645 |
-
/* ---------- AI 协作:写作由 AI
|
| 646 |
function AiPanel({ ctx, detail }: { ctx: BookCtx; detail: Chapter; text: string }) {
|
| 647 |
const { bundle } = ctx
|
| 648 |
const pid = bundle.project.project_id
|
| 649 |
const n = detail.number
|
| 650 |
-
const prof = useAsync(() => agentApi.profile().catch(() => null), [])
|
| 651 |
const log = useAsync(() => agentApi.log(pid, 5), [pid])
|
| 652 |
-
const p = prof.data
|
| 653 |
return (
|
| 654 |
<div className="panel-stack">
|
| 655 |
-
<div className="
|
| 656 |
-
<div className="row between"><b className="panel-h">作者状态</b><button className="link-btn" onClick={() => go('agent/profile')}>修改</button></div>
|
| 657 |
-
{p ? <div className="gap-s">{p.labels && Object.values(p.labels).map(x => <Tag key={x}>{x}</Tag>)}{p.level && <Tag>{p.level}</Tag>}</div> : <Spinner size={13} />}
|
| 658 |
-
<div className="muted small-note">AI 每次动笔前都会读「AI 守则」,按你的状态调整写法。<button className="link-btn" onClick={() => go('agent/guide')}>看守则</button></div>
|
| 659 |
-
</div>
|
| 660 |
<b className="panel-h">直接对 AI 说</b>
|
| 661 |
-
<SayToAi hint="写这一章" text={`请阅读 AI 守则和《${bundle.project.title}》的设定,写第${n}章,存为新版本。`} />
|
| 662 |
<SayToAi hint="按批注改" text={`请按批注修改第${n}章:逐条处理待改批注,存新版本,并在批注上回复改了什么。`} />
|
|
|
|
| 663 |
<SayToAi hint="请协作 AI 把关" text={`请把第${n}章发给协作 AI 审查,问它逻辑和人设有没有问题,读完回复再决定怎么改。`} />
|
| 664 |
<div className="divider" />
|
| 665 |
<RequestsBox pid={pid} cid={detail.chapter_id} />
|
|
|
|
| 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'
|
| 8 |
import { AskLog, AuditCard, SayToAi } from './Agent'
|
| 9 |
+
import { PeerPanel, locateDisputes, peerCount, usePeer } from './Peer'
|
| 10 |
import { cnNum, copyText, countWords, cx, diffParagraphs, fmtAgo, fmtDate, go, CHAPTER_STATUS, GENRE, KIND, VERSION_KIND, useLocal, useDebounced, useAsync } from '../lib'
|
| 11 |
import { AutoText, Empty, ErrorNote, Field, ListEditor, Loading, Modal, Spinner, Tabs, useConfirm, useToast, Segmented, Tag } from '../ui'
|
| 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}`
|
| 18 |
type Draft = { text: string; base: string | null; at: string }
|
| 19 |
const readDraft = (cid: string): Draft | null => { try { return JSON.parse(localStorage.getItem(draftKey(cid)) || 'null') } catch { return null } }
|
|
|
|
| 54 |
const [activeNote, setActiveNote] = useState('')
|
| 55 |
const located = useMemo(() => locateNotes(text, nb.notes || []), [text, nb.notes])
|
| 56 |
const openNotes = located.filter(n => n.status === 'open').length
|
| 57 |
+
const disputes = useMemo(() => locateDisputes(text, peer.data?.items, cid), [text, peer.data, cid])
|
| 58 |
+
const mirror = useMemo(() => disputes.length ? segmentText(text, [], disputes) : null, [text, disputes])
|
| 59 |
+
const pickDispute = () => { setInspector(true); setTab('peer') }
|
| 60 |
const pickNote = (id: string) => { setActiveNote(''); setTimeout(() => setActiveNote(id), 0); setInspector(true); setTab('notes') }
|
| 61 |
const createNote = async (f: any) => {
|
| 62 |
try {
|
|
|
|
| 89 |
}, [pid, cid])
|
| 90 |
useEffect(() => { load() }, [load])
|
| 91 |
|
| 92 |
+
/* 每章稿纸看到哪儿:本机 + 云端各存一份,下次打开回到原处 */
|
| 93 |
+
const scrollRef = useRef<HTMLDivElement>(null)
|
| 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
|
| 100 |
+
const local = Number(localStorage.getItem(`xs_epos_${cid}`) || 'NaN')
|
| 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) }, () => {})
|
| 108 |
+
}, [detail, cid, pid])
|
| 109 |
+
const onScroll = () => {
|
| 110 |
+
const el = scrollRef.current
|
| 111 |
+
if (!el) return
|
| 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 |
+
}
|
| 119 |
+
useEffect(() => () => clearTimeout(posTimer.current), [cid])
|
| 120 |
+
|
| 121 |
const dirty = detail != null && text !== savedText
|
| 122 |
const words = useMemo(() => countWords(text), [text])
|
| 123 |
const session = startWords.current == null ? 0 : words - startWords.current
|
|
|
|
| 240 |
|
| 241 |
return (
|
| 242 |
<div className={cx('editor', showInspector && 'with-inspector')}>
|
| 243 |
+
<div className="manuscript-scroll" ref={scrollRef} onScroll={onScroll}>
|
| 244 |
<div className="editor-bar">
|
| 245 |
+
<div className="eb-progress" title={`本章看到 ${Math.round(pos * 100)}%`}><i style={{ width: `${Math.round(pos * 100)}%` }} /></div>
|
| 246 |
<div className="eb-left">
|
| 247 |
<span className="eb-crumb">{bundle.project.title}<i>/</i>{detail.volume ? <>{detail.volume}<i>/</i></> : null}第{cnNum(detail.number)}章</span>
|
| 248 |
<span className={cx('eb-state', 'st-' + st.k)} title={st.full} role="status">{st.k === 'saving' ? <Spinner size={12} /> : <i className="eb-dot" />}<span className="eb-full">{st.full}</span><span className="eb-short">{st.short}</span></span>
|
| 249 |
</div>
|
| 250 |
<div className="eb-right">
|
| 251 |
+
<span className="eb-count" title={`本章 ${words.toLocaleString()} 字(去掉空白)${session ? `,本次 ${session > 0 ? '+' : ''}${session}` : ''};看到 ${Math.round(pos * 100)}%`}><b>{words.toLocaleString()}</b> 字{session !== 0 && <em className={session > 0 ? 'up' : 'down'}>{session > 0 ? '+' : ''}{session}</em>}</span>
|
| 252 |
<button className={cx('btn small', reviewMode ? 'primary' : 'ghost', 'review-toggle')} onClick={() => setReviewMode(!reviewMode)} title="批阅模式:选中句子加批注">
|
| 253 |
<Highlighter size={14} /><span className="eb-lbl">{reviewMode ? '退出批阅' : '批阅'}</span>{openNotes > 0 && <em className="badge">{openNotes}</em>}
|
| 254 |
</button>
|
|
|
|
| 278 |
{detail.goal && !focus && <div className="paper-goal"><span>本章目标</span>{detail.goal}</div>}
|
| 279 |
{reviewMode ? <>
|
| 280 |
<div className="review-tip"><Highlighter size={14} />批阅中:正文只读,选中任意句子即可批注;点黄色标记查看批注。<button className="link-btn" onClick={() => setReviewMode(false)}>回到编辑</button></div>
|
| 281 |
+
<ReviewText text={text} notes={located} active={activeNote} onPick={pickNote} onCreate={createNote} disputes={disputes} onDispute={pickDispute} />
|
| 282 |
</> : (
|
| 283 |
+
<div className="paper-text-wrap">
|
| 284 |
+
{mirror && <div className="paper-mirror" aria-hidden="true">{mirror.map((m, i) => m.d ? <mark key={i} className="dm">{m.t}</mark> : <React.Fragment key={i}>{m.t}</React.Fragment>)}{'\n'}</div>}
|
| 285 |
+
<textarea ref={taRef} className="paper-text" value={text} onChange={e => setText(e.target.value)} spellCheck={false}
|
| 286 |
+
placeholder={'从这里开始写。\n\n稿纸会自动暂存在本机;写到满意时,按 Ctrl+S 或点「存为版本」保存到云端。'} />
|
| 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>
|
|
|
|
| 297 |
{ id: 'chapter', label: <><FileCog size={14} />本章</> },
|
| 298 |
{ id: 'notes', label: <><Highlighter size={14} />批注</>, count: openNotes || undefined },
|
| 299 |
{ id: 'peer', label: <><Scale size={14} />分歧</>, count: peerCount(peer.data) || undefined },
|
|
|
|
| 300 |
{ id: 'check', label: <><ClipboardCheck size={14} />检查</> },
|
| 301 |
+
{ id: 'ai', label: <><Sparkles size={14} />AI 和协作 AI</> },
|
| 302 |
+
{ id: 'versions', label: <><History size={14} />版本</>, count: versions.length || undefined },
|
| 303 |
{ id: 'refs', label: <><BookmarkPlus size={14} />素材</> },
|
|
|
|
| 304 |
]} />
|
| 305 |
<div className="inspector-body">
|
| 306 |
{tab === 'chapter' && <ChapterMeta ctx={ctx} detail={detail} onSaved={c => { setDetail(d => d ? { ...d, ...c } : d); updateChapterInBundle(c); setTitle(c.title) }} />}
|
| 307 |
{tab === 'notes' && <NotesPanel bundle={bundle} detail={detail} text={text} notes={nb.notes} setNotes={nb.setNotes} reviews={nb.reviews} setReviews={nb.setReviews}
|
| 308 |
active={activeNote} setActive={id => { setActiveNote(''); setTimeout(() => setActiveNote(id), 0) }} reviewMode={reviewMode} setReviewMode={setReviewMode} />}
|
| 309 |
+
{tab === 'peer' && <PeerPanel data={peer} pid={pid} />}
|
| 310 |
{tab === 'versions' && <VersionsPanel pid={pid} cid={cid} versions={versions} current={detail.current_version_id} editorText={text} onLoad={loadIntoEditor} />}
|
| 311 |
{tab === 'check' && <CheckPanel num={detail.number} pid={pid} cid={cid} currentVersion={detail.current_version_id} text={text} dirty={dirty} />}
|
| 312 |
{tab === 'refs' && <RefsPanel ctx={ctx} />}
|
|
|
|
| 450 |
<div className="panel-stack">
|
| 451 |
<div className="muted small-note">勾选两个版本可以互相对比。</div>
|
| 452 |
{pick.length === 2 && <button className="btn small ghost block" onClick={compareTwo} disabled={busy === 'pair'}><GitCompare size={14} />对比所选的两个版本</button>}
|
| 453 |
+
<ol className="timeline vt">
|
| 454 |
{versions.map((m, i) => (
|
| 455 |
<li key={m.version_id} className={cx(m.version_id === current && 'current')}>
|
| 456 |
<label className="tl-check"><input type="checkbox" checked={pick.includes(m.version_id)} onChange={e => setPick(p => e.target.checked ? [...p.slice(-1), m.version_id] : p.filter(x => x !== m.version_id))} /></label>
|
|
|
|
| 512 |
)
|
| 513 |
}
|
| 514 |
|
| 515 |
+
/* ---------- 检查:只展示写作 AI 和协作 AI 已经做过的检查,没有「运行」按钮 ---------- */
|
| 516 |
+
function CheckPanel({ num, pid, cid, currentVersion, text }: { num: number; pid: string; cid: string; currentVersion: string | null; text: string; dirty: boolean }) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
const stats = useMemo(() => {
|
| 518 |
const paras = text.split(/\n+/).map(s => s.trim()).filter(Boolean)
|
| 519 |
const plain = text.replace(/\s/g, '')
|
|
|
|
| 523 |
const firstPara = paras[0] || ''
|
| 524 |
return { words: [...plain].length, paras: paras.length, avg: paras.length ? Math.round([...plain].length / paras.length) : 0, dialog: plain.length ? Math.round(quoted / plain.length * 100) : 0, longest, longParas, opening: countWords(firstPara) }
|
| 525 |
}, [text])
|
| 526 |
+
const audits = useAsync(() => agentApi.audits({ project_id: pid, chapter_id: cid, n: 20 }), [pid, cid])
|
| 527 |
+
const log = useAsync(() => agentApi.log(pid, 200), [pid])
|
| 528 |
+
const items = audits.data?.items || []
|
| 529 |
+
const latest = (k: string) => items.find(a => a.kind === k)
|
| 530 |
+
const mine = [latest('platform'), latest('logic'), latest('checklist')].filter(Boolean) as typeof items
|
| 531 |
+
const older = items.filter(a => !mine.includes(a)).slice(0, 4)
|
| 532 |
+
const re = new RegExp(`^第${num}章(?![0-9〇一二三四五六七八九十])`)
|
| 533 |
+
const peerAsks = (log.data?.items || []).filter(x => re.test(x.topic || '') || (x.attach || []).includes(`chapter:${num}`) && /审查|检查|把关/.test(x.topic || ''))
|
| 534 |
return (
|
| 535 |
<div className="panel-stack">
|
| 536 |
<div className="mini-stats">
|
|
|
|
| 546 |
{stats.words > 0 && stats.dialog < 8 && <li>对话很少,可以考虑用对白推动情节。</li>}
|
| 547 |
{stats.words === 0 && <li>稿纸还是空的。</li>}
|
| 548 |
</ul>
|
| 549 |
+
<SayToAi hint="请写作 AI 检查" text={`请按「番茄平台规定」和逻辑、人设逐条检查第${num}章,结果写进检查记录。`} />
|
| 550 |
+
<SayToAi hint="请协作 AI 检查" text={`请把第${num}章发给协作 AI 审查,问它逻辑和人设有没有问题,读完回复再决定怎么改。`} />
|
| 551 |
|
| 552 |
<div className="divider" />
|
| 553 |
<div className="row between">
|
| 554 |
+
<b className="panel-h">写作 AI 的检查</b>
|
| 555 |
+
<button className="link-btn" onClick={() => go('guide/red')}>看规定原文</button>
|
| 556 |
</div>
|
| 557 |
+
<div className="muted small-note">我每写完、改完一章,会逐条读完再判断(不是关键词匹配),每条附原文和修改建议。</div>
|
| 558 |
+
{audits.error ? <ErrorNote error={audits.error} onRetry={audits.reload} /> : !audits.data ? <Spinner size={13} label="读取检查记录…" />
|
| 559 |
+
: mine.length ? mine.map(a => <div key={a.audit_id} className="stack" style={{ gap: 6 }}>
|
| 560 |
+
{currentVersion && a.version_id && a.version_id !== currentVersion && <div className="note-warn">这份结果检查的是旧版本,本章之后改过。</div>}
|
| 561 |
+
<AuditCard a={a} open={a === mine[0]} />
|
| 562 |
+
</div>)
|
| 563 |
+
: <div className="muted small-note">本章还没有检查记录。</div>}
|
| 564 |
+
{older.length > 0 && <details className="older"><summary className="muted small-note">更早的检查 {older.length} 条</summary>{older.map(a => <AuditCard key={a.audit_id} a={a} />)}</details>}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
|
| 566 |
<div className="divider" />
|
| 567 |
+
<div className="row between"><b className="panel-h">协作 AI 的检查</b><button className="link-btn" onClick={() => go('agent/reviewer')}>全部记录</button></div>
|
| 568 |
+
{log.error ? <ErrorNote error={log.error} onRetry={log.reload} /> : !log.data ? <Spinner size={13} label="读取中…" />
|
| 569 |
+
: <AskLog items={peerAsks} reload={log.reload} empty={`协作 AI 还没审查过第${num}章。`} />}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
</div>
|
| 571 |
)
|
| 572 |
}
|
|
|
|
| 630 |
)
|
| 631 |
}
|
| 632 |
|
| 633 |
+
/* ---------- AI 和协作 AI:写作由 AI 按作者的吩咐在工作台上完成,这里只放给它的话、留言和协作记录 ---------- */
|
| 634 |
function AiPanel({ ctx, detail }: { ctx: BookCtx; detail: Chapter; text: string }) {
|
| 635 |
const { bundle } = ctx
|
| 636 |
const pid = bundle.project.project_id
|
| 637 |
const n = detail.number
|
|
|
|
| 638 |
const log = useAsync(() => agentApi.log(pid, 5), [pid])
|
|
|
|
| 639 |
return (
|
| 640 |
<div className="panel-stack">
|
| 641 |
+
<div className="muted small-note">我和协作 AI 动笔、审查之前都会先读手册里的<button className="link-btn" onClick={() => go('guide/author')}>作者状态</button>和<button className="link-btn" onClick={() => go('agent/guide')}>AI 守则</button>。</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 642 |
<b className="panel-h">直接对 AI 说</b>
|
| 643 |
+
<SayToAi hint="写这一章" text={`请先处理我对分歧的决定,再阅读 AI 守则和《${bundle.project.title}》的设定,写第${n}章,存为新版本。`} />
|
| 644 |
<SayToAi hint="按批注改" text={`请按批注修改第${n}章:逐条处理待改批注,存新版本,并在批注上回复改了什么。`} />
|
| 645 |
+
<SayToAi hint="按我对分歧的决定改" text={`请按我在「分歧」里的决定修改第${n}章,改完把这些分歧标为已处理。`} />
|
| 646 |
<SayToAi hint="请协作 AI 把关" text={`请把第${n}章发给协作 AI 审查,问它逻辑和人设有没有问题,读完回复再决定怎么改。`} />
|
| 647 |
<div className="divider" />
|
| 648 |
<RequestsBox pid={pid} cid={detail.chapter_id} />
|
ui-src/src/rooms/Guide.tsx
CHANGED
|
@@ -1,17 +1,18 @@
|
|
| 1 |
import React, { useEffect, useMemo, useState } from 'react'
|
| 2 |
import {
|
| 3 |
BookMarked, Map, Workflow, Bot, ShieldAlert, ListChecks, PenLine, Link2, Search, Check, AlertTriangle,
|
| 4 |
-
ExternalLink, ChevronRight, Gauge, GitCompareArrows, Copy, Download, Quote, Ban, Info, CircleCheck,
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { guide, sources, srcMap, rules, ruleMap, ai, aiByRule, aiMarkdown, aiPromptBlock, LEVEL, type Rule, type AiRule } from '../handbook'
|
| 7 |
import { copyText, cx, fmtAgo, go, useAsync, useLocal } from '../lib'
|
| 8 |
import { agentApi, type AuditItem } from '../api'
|
| 9 |
-
import { AuditCard, ProjectPicker, ResultBadge, SayToAi } from './Agent'
|
| 10 |
import { Md } from '../md'
|
| 11 |
import { Empty, ErrorNote, Tag, useToast } from '../ui'
|
| 12 |
|
| 13 |
const SECTIONS = [
|
| 14 |
{ id: 'start', t: '总览', i: Map, n: '' },
|
|
|
|
| 15 |
{ id: 'sign', t: '签约与收益', i: Workflow, n: '' },
|
| 16 |
{ id: 'red', t: '内容红线', i: ShieldAlert, n: '' },
|
| 17 |
{ id: 'quality', t: '低质与 AI', i: Gauge, n: '' },
|
|
@@ -55,6 +56,7 @@ export default function Guide({ section, focus }: { section: string; focus?: str
|
|
| 55 |
</aside>
|
| 56 |
<article className="guide-body page" key={s}>
|
| 57 |
{s === 'start' && <Start />}
|
|
|
|
| 58 |
{s === 'sign' && <Sign />}
|
| 59 |
{s === 'red' && <Red />}
|
| 60 |
{s === 'quality' && <RuleSection sec="quality" eyebrow="低质与 AI" title={guide.secs.quality.title} sub={guide.secs.quality.sub} />}
|
|
@@ -68,6 +70,15 @@ export default function Guide({ section, focus }: { section: string; focus?: str
|
|
| 68 |
)
|
| 69 |
}
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
function Head({ eyebrow, title, sub, children }: { eyebrow: string; title: string; sub?: string; children?: React.ReactNode }) {
|
| 72 |
return <header className="doc-head"><div className="eyebrow">{eyebrow}</div><h1 className="page-title serif">{title}</h1>{sub && <p className="page-sub">{sub}</p>}{children}</header>
|
| 73 |
}
|
|
@@ -152,7 +163,7 @@ function Start() {
|
|
| 152 |
))}
|
| 153 |
</section>
|
| 154 |
<h2 className="h2 serif">规则变化时间线</h2>
|
| 155 |
-
<ol className="timeline">
|
| 156 |
{guide.changelog.map((c: any, i: number) => (
|
| 157 |
<li key={i}><span className="tl-date">{c.date}</span><div><b>{c.t}</b><p>{c.d} <Src ids={c.src} /></p></div></li>
|
| 158 |
))}
|
|
|
|
| 1 |
import React, { useEffect, useMemo, useState } from 'react'
|
| 2 |
import {
|
| 3 |
BookMarked, Map, Workflow, Bot, ShieldAlert, ListChecks, PenLine, Link2, Search, Check, AlertTriangle,
|
| 4 |
+
ExternalLink, ChevronRight, Gauge, GitCompareArrows, Copy, Download, Quote, Ban, Info, CircleCheck, UserRound,
|
| 5 |
} from 'lucide-react'
|
| 6 |
import { guide, sources, srcMap, rules, ruleMap, ai, aiByRule, aiMarkdown, aiPromptBlock, LEVEL, type Rule, type AiRule } from '../handbook'
|
| 7 |
import { copyText, cx, fmtAgo, go, useAsync, useLocal } from '../lib'
|
| 8 |
import { agentApi, type AuditItem } from '../api'
|
| 9 |
+
import { AuditCard, AuthorProfile, ProjectPicker, ResultBadge, SayToAi } from './Agent'
|
| 10 |
import { Md } from '../md'
|
| 11 |
import { Empty, ErrorNote, Tag, useToast } from '../ui'
|
| 12 |
|
| 13 |
const SECTIONS = [
|
| 14 |
{ id: 'start', t: '总览', i: Map, n: '' },
|
| 15 |
+
{ id: 'author', t: '作者状态', i: UserRound, n: '必读' },
|
| 16 |
{ id: 'sign', t: '签约与收益', i: Workflow, n: '' },
|
| 17 |
{ id: 'red', t: '内容红线', i: ShieldAlert, n: '' },
|
| 18 |
{ id: 'quality', t: '低质与 AI', i: Gauge, n: '' },
|
|
|
|
| 56 |
</aside>
|
| 57 |
<article className="guide-body page" key={s}>
|
| 58 |
{s === 'start' && <Start />}
|
| 59 |
+
{s === 'author' && <Author />}
|
| 60 |
{s === 'sign' && <Sign />}
|
| 61 |
{s === 'red' && <Red />}
|
| 62 |
{s === 'quality' && <RuleSection sec="quality" eyebrow="低质与 AI" title={guide.secs.quality.title} sub={guide.secs.quality.sub} />}
|
|
|
|
| 70 |
)
|
| 71 |
}
|
| 72 |
|
| 73 |
+
/* ---------- 作者状态:全局规则,写作 AI 和协作 AI 都要按它判断 ---------- */
|
| 74 |
+
function Author() {
|
| 75 |
+
return <>
|
| 76 |
+
<Head eyebrow="作者状态 · 全局规则" title="你现在处在哪个阶段"
|
| 77 |
+
sub="这是全书通用的规则:我(写作 AI)动笔前、协作 AI 审查前,都会先读这里,按你的账号、等级、签约情况和目标来判断该怎么写、怎么提意见。改了马上生效。" />
|
| 78 |
+
<AuthorProfile />
|
| 79 |
+
</>
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
function Head({ eyebrow, title, sub, children }: { eyebrow: string; title: string; sub?: string; children?: React.ReactNode }) {
|
| 83 |
return <header className="doc-head"><div className="eyebrow">{eyebrow}</div><h1 className="page-title serif">{title}</h1>{sub && <p className="page-sub">{sub}</p>}{children}</header>
|
| 84 |
}
|
|
|
|
| 163 |
))}
|
| 164 |
</section>
|
| 165 |
<h2 className="h2 serif">规则变化时间线</h2>
|
| 166 |
+
<ol className="timeline gt">
|
| 167 |
{guide.changelog.map((c: any, i: number) => (
|
| 168 |
<li key={i}><span className="tl-date">{c.date}</span><div><b>{c.t}</b><p>{c.d} <Src ids={c.src} /></p></div></li>
|
| 169 |
))}
|
ui-src/src/rooms/Library.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
| 6 |
} from 'lucide-react'
|
| 7 |
import { Material, materialsApi, projectsApi, Project } from '../api'
|
| 8 |
import { copyText, cx, fmtDate, fmtNum, go, GENRE, KIND, DECISION, ROLE, useAsync, useBasket, useDebounced, writeBasket, readBasket } from '../lib'
|
| 9 |
-
import { Drawer, Empty, ErrorNote, Loading, Modal, Pager, Segmented, Spinner, Stars, Tabs, Tag, useToast } from '../ui'
|
| 10 |
import { toRef } from './Bible'
|
| 11 |
|
| 12 |
type LTab = 'materials' | 'motifs' | 'compose'
|
|
@@ -436,7 +436,7 @@ function ComposeTab({ onOpen }: { onOpen: (uid: string) => void }) {
|
|
| 436 |
<div className="compose">
|
| 437 |
<section className="compose-input sheet">
|
| 438 |
<h2 className="sheet-title serif">写一句你的故事想法</h2>
|
| 439 |
-
<
|
| 440 |
onKeyDown={e => { if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) run(0) }} />
|
| 441 |
<div className="fgroup-label">选母题(可选,最多 4 个)</div>
|
| 442 |
<div className="motif-chips">
|
|
|
|
| 6 |
} from 'lucide-react'
|
| 7 |
import { Material, materialsApi, projectsApi, Project } from '../api'
|
| 8 |
import { copyText, cx, fmtDate, fmtNum, go, GENRE, KIND, DECISION, ROLE, useAsync, useBasket, useDebounced, writeBasket, readBasket } from '../lib'
|
| 9 |
+
import { AutoText, Drawer, Empty, ErrorNote, Loading, Modal, Pager, Segmented, Spinner, Stars, Tabs, Tag, useToast } from '../ui'
|
| 10 |
import { toRef } from './Bible'
|
| 11 |
|
| 12 |
type LTab = 'materials' | 'motifs' | 'compose'
|
|
|
|
| 436 |
<div className="compose">
|
| 437 |
<section className="compose-input sheet">
|
| 438 |
<h2 className="sheet-title serif">写一句你的故事想法</h2>
|
| 439 |
+
<AutoText className="idea serif-input" minRows={2} value={idea} onChange={v => setIdea(v)} placeholder="例如:被全家当提款机的女儿,在父亲葬礼上发现自己是抱养的"
|
| 440 |
onKeyDown={e => { if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) run(0) }} />
|
| 441 |
<div className="fgroup-label">选母题(可选,最多 4 个)</div>
|
| 442 |
<div className="motif-chips">
|
ui-src/src/rooms/Motif2.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { Users, Search, Sparkles, Copy, RefreshCw, Pin, X, ShieldCheck, AlertTri
|
|
| 3 |
import { get, post, qs } from '../api'
|
| 4 |
import { copyText, cx, fmtNum, go, useAsync, useDebounced } from '../lib'
|
| 5 |
import { TextLocked } from './Library'
|
| 6 |
-
import { Drawer, Empty, ErrorNote, Loading, Pager, Stars, Tabs, Tag, useToast } from '../ui'
|
| 7 |
import { basketAdd } from './Library'
|
| 8 |
|
| 9 |
const A = '/fanqie/api/motif2'
|
|
@@ -306,7 +306,7 @@ function ComposeTab({ meta, onOpen }: { meta: any; onOpen: (u: string) => void }
|
|
| 306 |
<div className="compose m2-compose">
|
| 307 |
<section className="sheet compose-input">
|
| 308 |
<h2 className="sheet-title serif">1. 你的主角和故事</h2>
|
| 309 |
-
<
|
| 310 |
<div className="m2-selects">
|
| 311 |
<label className="m2-sel"><span>主角性别</span><select className="input mini" value={hero.sex} onChange={e => setHero({ ...hero, sex: e.target.value })}><option value="">不限</option><option>男</option><option>女</option></select></label>
|
| 312 |
<label className="m2-sel"><span>故事年代</span><select className="input mini" value={hero.era} onChange={e => setHero({ ...hero, era: e.target.value })}><option value="">不限</option>{(tx.era || []).filter((x: string) => x !== '不明').map((x: string) => <option key={x}>{x}</option>)}</select></label>
|
|
|
|
| 3 |
import { get, post, qs } from '../api'
|
| 4 |
import { copyText, cx, fmtNum, go, useAsync, useDebounced } from '../lib'
|
| 5 |
import { TextLocked } from './Library'
|
| 6 |
+
import { AutoText, Drawer, Empty, ErrorNote, Loading, Pager, Stars, Tabs, Tag, useToast } from '../ui'
|
| 7 |
import { basketAdd } from './Library'
|
| 8 |
|
| 9 |
const A = '/fanqie/api/motif2'
|
|
|
|
| 306 |
<div className="compose m2-compose">
|
| 307 |
<section className="sheet compose-input">
|
| 308 |
<h2 className="sheet-title serif">1. 你的主角和故事</h2>
|
| 309 |
+
<AutoText className="serif-input" minRows={2} value={idea} onChange={v => setIdea(v)} placeholder="一句话设定或关键词(可选),例如:被爷爷带大的穷小子,爷爷临终前留下一个旧木箱" />
|
| 310 |
<div className="m2-selects">
|
| 311 |
<label className="m2-sel"><span>主角性别</span><select className="input mini" value={hero.sex} onChange={e => setHero({ ...hero, sex: e.target.value })}><option value="">不限</option><option>男</option><option>女</option></select></label>
|
| 312 |
<label className="m2-sel"><span>故事年代</span><select className="input mini" value={hero.era} onChange={e => setHero({ ...hero, era: e.target.value })}><option value="">不限</option>{(tx.era || []).filter((x: string) => x !== '不明').map((x: string) => <option key={x}>{x}</option>)}</select></label>
|
ui-src/src/rooms/Peer.tsx
CHANGED
|
@@ -1,71 +1,145 @@
|
|
| 1 |
import React, { useState } from 'react'
|
| 2 |
-
import { Scale, ChevronDown, ChevronRight } from 'lucide-react'
|
| 3 |
import { projectsApi, type PeerItem } from '../api'
|
| 4 |
import { fmtDate, useAsync } from '../lib'
|
| 5 |
-
import {
|
|
|
|
| 6 |
|
| 7 |
const VERDICT: Record<PeerItem['verdict'], { label: string; tone: string }> = {
|
| 8 |
-
disagree: { label: '不一致
|
| 9 |
partial: { label: '部分采纳', tone: 'warn' },
|
| 10 |
agree: { label: '一致 · 已采纳', tone: 'ok' },
|
| 11 |
}
|
|
|
|
| 12 |
|
| 13 |
export function usePeer(pid: string, cid: string) {
|
| 14 |
return useAsync(() => projectsApi.peer(pid, cid), [pid, cid])
|
| 15 |
}
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
const v = VERDICT[x.verdict] || VERDICT.disagree
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
return (
|
| 20 |
-
<div className={`peer-card v-${x.verdict}`}>
|
| 21 |
<div className="peer-head">
|
| 22 |
<Tag tone={v.tone}>{v.label}</Tag>
|
| 23 |
{x.topic && <b className="peer-topic">{x.topic}</b>}
|
|
|
|
|
|
|
|
|
|
| 24 |
</div>
|
|
|
|
| 25 |
<div className="peer-row"><span className="peer-who">协作 AI 说</span><p>{x.reviewer_said}</p></div>
|
| 26 |
-
<div className="peer-row mine"><span className="peer-who">
|
| 27 |
-
{x.decision && <div className="peer-row final"><span className="peer-who">
|
| 28 |
-
<div className="peer-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
</div>
|
| 30 |
)
|
| 31 |
}
|
| 32 |
|
| 33 |
-
function Group({ title, items, open: open0 }: { title: string; items: PeerItem[]; open?: boolean }) {
|
| 34 |
const [open, setOpen] = useState(!!open0)
|
| 35 |
if (!items.length) return null
|
| 36 |
return (
|
| 37 |
<div className="peer-group">
|
| 38 |
<button className="peer-gtitle" onClick={() => setOpen(o => !o)}>{open ? <ChevronDown size={14} /> : <ChevronRight size={14} />}{title}<em>{items.length}</em></button>
|
| 39 |
-
{open && <div className="stack">{items.map(x => <PeerCard key={x.item_id} x={x} />)}</div>}
|
| 40 |
</div>
|
| 41 |
)
|
| 42 |
}
|
| 43 |
|
| 44 |
-
export function PeerPanel({ data }: { data: ReturnType<typeof usePeer> }) {
|
| 45 |
if (data.error) return <ErrorNote error={data.error} onRetry={data.reload} />
|
| 46 |
if (!data.data) return <Spinner size={13} label="读取中…" />
|
| 47 |
const all = data.data.items || []
|
|
|
|
| 48 |
const mine = all.filter(x => x.chapter_id)
|
| 49 |
-
const book = all.filter(x => !x.chapter_id)
|
| 50 |
-
const
|
|
|
|
|
|
|
|
|
|
| 51 |
return (
|
| 52 |
<div className="peer-panel stack">
|
| 53 |
-
<p className="muted small-note"><Scale size={13} />
|
| 54 |
-
{!
|
| 55 |
-
{
|
| 56 |
<div className="peer-sum">
|
| 57 |
<span>本章</span>
|
| 58 |
-
{
|
| 59 |
-
{
|
| 60 |
-
{by(mine, 'agree').length > 0 && <Tag tone="ok">一致 {by(mine, 'agree').length}</Tag>}
|
| 61 |
</div>
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
</>
|
| 66 |
-
|
| 67 |
</div>
|
| 68 |
)
|
| 69 |
}
|
| 70 |
|
| 71 |
-
export const peerCount = (d?: { items: PeerItem[] } | null) => (d?.items || []).filter(x => x.chapter_id && x.verdict !== 'agree').length
|
|
|
|
| 1 |
import React, { useState } from 'react'
|
| 2 |
+
import { Scale, ChevronDown, ChevronRight, Check, Undo2, PenLine, Hourglass } from 'lucide-react'
|
| 3 |
import { projectsApi, type PeerItem } from '../api'
|
| 4 |
import { fmtDate, useAsync } from '../lib'
|
| 5 |
+
import type { Dispute } from './Review'
|
| 6 |
+
import { AutoText, Empty, ErrorNote, Spinner, Tag, useToast } from '../ui'
|
| 7 |
|
| 8 |
const VERDICT: Record<PeerItem['verdict'], { label: string; tone: string }> = {
|
| 9 |
+
disagree: { label: '不一致', tone: 'err' },
|
| 10 |
partial: { label: '部分采纳', tone: 'warn' },
|
| 11 |
agree: { label: '一致 · 已采纳', tone: 'ok' },
|
| 12 |
}
|
| 13 |
+
const DECISION: Record<string, string> = { adopt: '采纳协作 AI 的意见', keep: '维持写作 AI 的做法', own: '按我的想法' }
|
| 14 |
|
| 15 |
export function usePeer(pid: string, cid: string) {
|
| 16 |
return useAsync(() => projectsApi.peer(pid, cid), [pid, cid])
|
| 17 |
}
|
| 18 |
|
| 19 |
+
/** 还没处理完、需要在正文里标出来的分歧 */
|
| 20 |
+
export const openDisputes = (items?: PeerItem[] | null) => (items || []).filter(x => x.chapter_id && x.verdict !== 'agree' && !x.resolved)
|
| 21 |
+
/** 在正文里找到分歧引用的那句话 */
|
| 22 |
+
export function locateDisputes(text: string, items?: PeerItem[] | null, cid?: string): Dispute[] {
|
| 23 |
+
const out: Dispute[] = []
|
| 24 |
+
for (const x of openDisputes(items)) {
|
| 25 |
+
if (cid && x.chapter_id !== cid) continue
|
| 26 |
+
const q = (x.quote || '').trim()
|
| 27 |
+
if (!q || q.length < 2) continue
|
| 28 |
+
const at = text.indexOf(q)
|
| 29 |
+
if (at >= 0) out.push({ at, to: at + q.length, id: x.item_id, tip: (x.topic ? x.topic + ':' : '') + (x.author_decision ? '(你已决定)' : '(待你决定)') })
|
| 30 |
+
}
|
| 31 |
+
return out
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function PeerCard({ x, pid, onChange }: { x: PeerItem; pid: string; onChange: (n: PeerItem) => void }) {
|
| 35 |
+
const toast = useToast()
|
| 36 |
const v = VERDICT[x.verdict] || VERDICT.disagree
|
| 37 |
+
const [own, setOwn] = useState(false)
|
| 38 |
+
const [note, setNote] = useState(x.author_note || '')
|
| 39 |
+
const [busy, setBusy] = useState(false)
|
| 40 |
+
const decided = !!x.author_decision
|
| 41 |
+
const canDecide = x.verdict !== 'agree' && !x.resolved
|
| 42 |
+
|
| 43 |
+
const decide = async (decision: '' | 'adopt' | 'keep' | 'own', n = '') => {
|
| 44 |
+
setBusy(true)
|
| 45 |
+
try {
|
| 46 |
+
const r = await projectsApi.decidePeer(pid, x.item_id, { decision, note: n })
|
| 47 |
+
onChange(r); setOwn(false)
|
| 48 |
+
toast(decision ? '已记下你的决定,我下次写之前会先按它改' : '已撤回', 'ok')
|
| 49 |
+
} catch (e: any) { toast(e.message || '保存失败', 'err') } finally { setBusy(false) }
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
return (
|
| 53 |
+
<div className={`peer-card v-${x.verdict}${decided ? ' decided' : ''}`}>
|
| 54 |
<div className="peer-head">
|
| 55 |
<Tag tone={v.tone}>{v.label}</Tag>
|
| 56 |
{x.topic && <b className="peer-topic">{x.topic}</b>}
|
| 57 |
+
{canDecide && (decided
|
| 58 |
+
? <span className="peer-state wait"><Hourglass size={12} />已决定,等我处理</span>
|
| 59 |
+
: <span className="peer-state todo">待你决定</span>)}
|
| 60 |
</div>
|
| 61 |
+
{x.quote && <div className="peer-quote">「{x.quote}」</div>}
|
| 62 |
<div className="peer-row"><span className="peer-who">协作 AI 说</span><p>{x.reviewer_said}</p></div>
|
| 63 |
+
<div className="peer-row mine"><span className="peer-who">写作 AI 认为</span><p>{x.my_view}</p></div>
|
| 64 |
+
{x.decision && <div className="peer-row final"><span className="peer-who">目前的做法</span><p>{x.decision}</p></div>}
|
| 65 |
+
{x.resolved && x.resolution && <div className="peer-row final"><span className="peer-who">已处理</span><p>{x.resolution}</p></div>}
|
| 66 |
+
|
| 67 |
+
{canDecide && decided && (
|
| 68 |
+
<div className="peer-author">
|
| 69 |
+
<div className="peer-row author"><span className="peer-who">你的决定</span>
|
| 70 |
+
<p><b>{DECISION[x.author_decision!] || x.author_decision}</b>{x.author_note ? `:${x.author_note}` : ''}</p>
|
| 71 |
+
</div>
|
| 72 |
+
<div className="peer-actions">
|
| 73 |
+
<span className="muted">{fmtDate(x.author_at)}</span>
|
| 74 |
+
<button className="btn small ghost" disabled={busy} onClick={() => decide('')}><Undo2 size={13} />撤回</button>
|
| 75 |
+
</div>
|
| 76 |
+
</div>
|
| 77 |
+
)}
|
| 78 |
+
|
| 79 |
+
{canDecide && !decided && (
|
| 80 |
+
<div className="peer-author">
|
| 81 |
+
{!own ? (
|
| 82 |
+
<div className="peer-actions">
|
| 83 |
+
<span className="muted">你来定:</span>
|
| 84 |
+
<button className="btn small" disabled={busy} onClick={() => decide('adopt')}><Check size={13} />采纳协作 AI</button>
|
| 85 |
+
<button className="btn small" disabled={busy} onClick={() => decide('keep')}>维持现状</button>
|
| 86 |
+
<button className="btn small ghost" disabled={busy} onClick={() => setOwn(true)}><PenLine size={13} />按我的想法</button>
|
| 87 |
+
</div>
|
| 88 |
+
) : (
|
| 89 |
+
<div className="stack" style={{ gap: 6 }}>
|
| 90 |
+
<AutoText value={note} onChange={setNote} minRows={2} placeholder="写下你希望怎么改,我下次写之前会照做" autoFocus />
|
| 91 |
+
<div className="peer-actions">
|
| 92 |
+
<button className="btn small primary" disabled={busy || !note.trim()} onClick={() => decide('own', note.trim())}>确定</button>
|
| 93 |
+
<button className="btn small ghost" disabled={busy} onClick={() => setOwn(false)}>取消</button>
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
)}
|
| 97 |
+
</div>
|
| 98 |
+
)}
|
| 99 |
+
<div className="peer-foot muted">{fmtDate(x.resolved_at || x.updated_at || x.created_at)}</div>
|
| 100 |
</div>
|
| 101 |
)
|
| 102 |
}
|
| 103 |
|
| 104 |
+
function Group({ title, items, open: open0, pid, onChange }: { title: string; items: PeerItem[]; open?: boolean; pid: string; onChange: (n: PeerItem) => void }) {
|
| 105 |
const [open, setOpen] = useState(!!open0)
|
| 106 |
if (!items.length) return null
|
| 107 |
return (
|
| 108 |
<div className="peer-group">
|
| 109 |
<button className="peer-gtitle" onClick={() => setOpen(o => !o)}>{open ? <ChevronDown size={14} /> : <ChevronRight size={14} />}{title}<em>{items.length}</em></button>
|
| 110 |
+
{open && <div className="stack">{items.map(x => <PeerCard key={x.item_id} x={x} pid={pid} onChange={onChange} />)}</div>}
|
| 111 |
</div>
|
| 112 |
)
|
| 113 |
}
|
| 114 |
|
| 115 |
+
export function PeerPanel({ data, pid }: { data: ReturnType<typeof usePeer>; pid: string }) {
|
| 116 |
if (data.error) return <ErrorNote error={data.error} onRetry={data.reload} />
|
| 117 |
if (!data.data) return <Spinner size={13} label="读取中…" />
|
| 118 |
const all = data.data.items || []
|
| 119 |
+
const onChange = (n: PeerItem) => data.setData(d => d ? { ...d, items: d.items.map(x => x.item_id === n.item_id ? n : x) } : d)
|
| 120 |
const mine = all.filter(x => x.chapter_id)
|
| 121 |
+
const book = all.filter(x => !x.chapter_id && x.verdict !== 'agree' && !x.resolved)
|
| 122 |
+
const open = mine.filter(x => x.verdict !== 'agree' && !x.resolved)
|
| 123 |
+
const todo = open.filter(x => !x.author_decision)
|
| 124 |
+
const waiting = open.filter(x => x.author_decision)
|
| 125 |
+
const done = mine.filter(x => x.verdict === 'agree' || x.resolved)
|
| 126 |
return (
|
| 127 |
<div className="peer-panel stack">
|
| 128 |
+
<p className="muted small-note"><Scale size={13} /> 协作 AI 的意见我都会先自己想一遍;我们意见不一致时,<b>由你来定</b>:采纳协作 AI、维持现状,或者写下你的想法。你没表态的,我先按自己的判断走;你表态了,我下次写新章之前会先按你的决定改好,改完这条就不再显示。正文里用<mark className="dispute-demo">黄色底</mark>标出了有分歧的句子,复制和发布时不会带上。</p>
|
| 129 |
+
{!open.length && !book.length && <Empty title="本章没有待处理的分歧">协作 AI 审查过、并且意见不一致的地方,会显示在这里。</Empty>}
|
| 130 |
+
{open.length > 0 && (
|
| 131 |
<div className="peer-sum">
|
| 132 |
<span>本章</span>
|
| 133 |
+
{todo.length > 0 && <Tag tone="warn">待你决定 {todo.length}</Tag>}
|
| 134 |
+
{waiting.length > 0 && <Tag>已决定、等我处理 {waiting.length}</Tag>}
|
|
|
|
| 135 |
</div>
|
| 136 |
+
)}
|
| 137 |
+
<Group title="待你决定" items={todo} open pid={pid} onChange={onChange} />
|
| 138 |
+
<Group title="你已决定,等我处理" items={waiting} open pid={pid} onChange={onChange} />
|
| 139 |
+
<Group title="全书层面(不属于某一章)" items={book} pid={pid} onChange={onChange} />
|
| 140 |
+
<Group title="已处理 / 意见一致(只读)" items={done} pid={pid} onChange={onChange} />
|
| 141 |
</div>
|
| 142 |
)
|
| 143 |
}
|
| 144 |
|
| 145 |
+
export const peerCount = (d?: { items: PeerItem[] } | null) => (d?.items || []).filter(x => x.chapter_id && x.verdict !== 'agree' && !x.resolved && !x.author_decision).length
|
ui-src/src/rooms/Rank.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react'
|
|
| 2 |
import { TrendingUp, RefreshCw, Copy, Send, Sparkles, BookPlus, ArrowUp, ArrowDown, Flame, Lightbulb, FileText, Trash2, ClipboardPaste, ChevronRight } from 'lucide-react'
|
| 3 |
import { get, post, put, del, qs } from '../api'
|
| 4 |
import { copyText, cx, fmtAgo, fmtNum, go, useAsync, useLocal } from '../lib'
|
| 5 |
-
import { Drawer, Empty, ErrorNote, Loading, Segmented, Tabs, Tag, useToast, useConfirm } from '../ui'
|
| 6 |
import { buildPack } from './rankPack'
|
| 7 |
import { FeedTab } from './RankInspire'
|
| 8 |
import { SayToAi } from './Agent'
|
|
@@ -42,7 +42,7 @@ export default function RankRoom({ tab, arg }: { tab: string; arg: string }) {
|
|
| 42 |
<div className="eyebrow"><TrendingUp size={14} />番茄热榜</div>
|
| 43 |
<h1 className="room-title serif">看榜单、读趋势,再定新书总纲</h1>
|
| 44 |
<p className="muted small-note">
|
| 45 |
-
|
| 46 |
</p>
|
| 47 |
</div>
|
| 48 |
<ScrapeBox date={date} onDone={() => ana.reload()} />
|
|
@@ -66,7 +66,7 @@ export default function RankRoom({ tab, arg }: { tab: string; arg: string }) {
|
|
| 66 |
}
|
| 67 |
|
| 68 |
/* ---------------- 抓取状态 ----------------
|
| 69 |
-
|
| 70 |
按钮代码保留,需要手动抓取时把 SHOW_SCRAPE_BUTTON 改成 true。 */
|
| 71 |
const SHOW_SCRAPE_BUTTON = false
|
| 72 |
function ScrapeBox({ date, onDone }: { date?: string; onDone: () => void }) {
|
|
@@ -92,7 +92,7 @@ function ScrapeBox({ date, onDone }: { date?: string; onDone: () => void }) {
|
|
| 92 |
{st?.running ? (
|
| 93 |
<div className="rk-prog"><div className="small-note">{st.step} {st.total ? `${st.done}/${st.total}` : ''}</div><div className="bar"><i style={{ width: `${st.total ? (st.done / st.total) * 100 : 5}%` }} /></div></div>
|
| 94 |
) : SHOW_SCRAPE_BUTTON ? <button className="btn small ghost" onClick={start}><RefreshCw size={13} />立即抓取</button>
|
| 95 |
-
: <div className="small-note muted">
|
| 96 |
</div>
|
| 97 |
)
|
| 98 |
}
|
|
@@ -306,12 +306,12 @@ function PlanTab({ a }: { a: any }) {
|
|
| 306 |
<button key={t.k} className={cx('chip', draft.tags.includes(t.k) && 'on')} onClick={() => set({ tags: draft.tags.includes(t.k) ? draft.tags.filter(x => x !== t.k) : draft.tags.length >= 5 ? draft.tags : [...draft.tags, t.k] })}>{t.k}<em>阅{t.n}/新{t.f}</em></button>))}
|
| 307 |
</div>
|
| 308 |
<h2 className="sheet-title serif rk-mt">3. 你的想法(可选)</h2>
|
| 309 |
-
<
|
| 310 |
<div className="m2-selects">
|
| 311 |
<label className="m2-sel"><span>目标字数(万)</span><select className="input mini" value={draft.words} onChange={e => set({ words: e.target.value })}>{['30', '60', '100', '150', '200', '300'].map(x => <option key={x}>{x}</option>)}</select></label>
|
| 312 |
<label className="m2-sel"><span>人称</span><select className="input mini" value={draft.pov} onChange={e => set({ pov: e.target.value })}><option>第三人称</option><option>第一人称</option></select></label>
|
| 313 |
</div>
|
| 314 |
-
<
|
| 315 |
</>}
|
| 316 |
</section>
|
| 317 |
{!cat && <Empty icon={<FileText size={22} />} title="先���一个题材">也可以在「趋势分析」的题材表里点「规划」直接跳过来。</Empty>}
|
|
@@ -381,7 +381,7 @@ function PlanView({ id, onChange, onDelete }: { id: string; onChange: () => void
|
|
| 381 |
<p className="sheet-note">这个规划正在等 AI 处理。AI 读完任务包后会把总纲直接存到这里;也可以把别处 AI 输出的 JSON 粘贴到下面。</p>
|
| 382 |
<SayToAi text={`请完成「我的规划」里的总纲(规划 ID:${id}),读完任务包后把结果存回去。`} />
|
| 383 |
{st.data?.llm && <button className="btn primary" disabled={!!busy} onClick={gen}><Sparkles size={14} />{busy === 'gen' ? '生成中(约 1–2 分钟)…' : '让服务器上的 AI 直接生成'}</button>}
|
| 384 |
-
<
|
| 385 |
<div className="row end"><button className="btn" disabled={!paste.trim() || !!busy} onClick={savePaste}><ClipboardPaste size={14} />保存总纲</button></div>
|
| 386 |
</section>}
|
| 387 |
{r && <PlanResult r={r} />}
|
|
|
|
| 2 |
import { TrendingUp, RefreshCw, Copy, Send, Sparkles, BookPlus, ArrowUp, ArrowDown, Flame, Lightbulb, FileText, Trash2, ClipboardPaste, ChevronRight } from 'lucide-react'
|
| 3 |
import { get, post, put, del, qs } from '../api'
|
| 4 |
import { copyText, cx, fmtAgo, fmtNum, go, useAsync, useLocal } from '../lib'
|
| 5 |
+
import { AutoText, Drawer, Empty, ErrorNote, Loading, Segmented, Tabs, Tag, useToast, useConfirm } from '../ui'
|
| 6 |
import { buildPack } from './rankPack'
|
| 7 |
import { FeedTab } from './RankInspire'
|
| 8 |
import { SayToAi } from './Agent'
|
|
|
|
| 42 |
<div className="eyebrow"><TrendingUp size={14} />番茄热榜</div>
|
| 43 |
<h1 className="room-title serif">看榜单、读趋势,再定新书总纲</h1>
|
| 44 |
<p className="muted small-note">
|
| 45 |
+
榜单不会自己更新:你在对话里说「抓取今天的番茄热榜」,我才去番茄官网抓分类榜(男频 19 类、女频 18 类,各含阅读榜和新书榜,每榜前 100 本,附官方标签),整理后存进来,一天最多一次。数字由程序统计,「AI 解读」和「总纲」由我读完数据后写。
|
| 46 |
</p>
|
| 47 |
</div>
|
| 48 |
<ScrapeBox date={date} onDone={() => ana.reload()} />
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
/* ---------------- 抓取状态 ----------------
|
| 69 |
+
作者在对话里吩咐后,由写作 AI 调用 POST /fanqie/api/rank/scrape(服务器限制每天最多一次,不再自动定时抓),页面上只显示进度。
|
| 70 |
按钮代码保留,需要手动抓取时把 SHOW_SCRAPE_BUTTON 改成 true。 */
|
| 71 |
const SHOW_SCRAPE_BUTTON = false
|
| 72 |
function ScrapeBox({ date, onDone }: { date?: string; onDone: () => void }) {
|
|
|
|
| 92 |
{st?.running ? (
|
| 93 |
<div className="rk-prog"><div className="small-note">{st.step} {st.total ? `${st.done}/${st.total}` : ''}</div><div className="bar"><i style={{ width: `${st.total ? (st.done / st.total) * 100 : 5}%` }} /></div></div>
|
| 94 |
) : SHOW_SCRAPE_BUTTON ? <button className="btn small ghost" onClick={start}><RefreshCw size={13} />立即抓取</button>
|
| 95 |
+
: <div className="small-note muted">要更新就在对话里告诉我 · 一天最多一次</div>}
|
| 96 |
</div>
|
| 97 |
)
|
| 98 |
}
|
|
|
|
| 306 |
<button key={t.k} className={cx('chip', draft.tags.includes(t.k) && 'on')} onClick={() => set({ tags: draft.tags.includes(t.k) ? draft.tags.filter(x => x !== t.k) : draft.tags.length >= 5 ? draft.tags : [...draft.tags, t.k] })}>{t.k}<em>阅{t.n}/新{t.f}</em></button>))}
|
| 307 |
</div>
|
| 308 |
<h2 className="sheet-title serif rk-mt">3. 你的想法(可选)</h2>
|
| 309 |
+
<AutoText className="serif-input" minRows={3} value={draft.idea} onChange={v => set({ idea: v })} placeholder="一句话设定、想写的人设或桥段,都可以;留空就让 AI 根据数据自己选方向" />
|
| 310 |
<div className="m2-selects">
|
| 311 |
<label className="m2-sel"><span>目标字数(万)</span><select className="input mini" value={draft.words} onChange={e => set({ words: e.target.value })}>{['30', '60', '100', '150', '200', '300'].map(x => <option key={x}>{x}</option>)}</select></label>
|
| 312 |
<label className="m2-sel"><span>人称</span><select className="input mini" value={draft.pov} onChange={e => set({ pov: e.target.value })}><option>第三人称</option><option>第一人称</option></select></label>
|
| 313 |
</div>
|
| 314 |
+
<AutoText className="" minRows={2} value={draft.extra} onChange={v => set({ extra: v })} placeholder="其他要求(可选),例如:不要系统流、主角要有家人羁绊、节奏要快" />
|
| 315 |
</>}
|
| 316 |
</section>
|
| 317 |
{!cat && <Empty icon={<FileText size={22} />} title="先���一个题材">也可以在「趋势分析」的题材表里点「规划」直接跳过来。</Empty>}
|
|
|
|
| 381 |
<p className="sheet-note">这个规划正在等 AI 处理。AI 读完任务包后会把总纲直接存到这里;也可以把别处 AI 输出的 JSON 粘贴到下面。</p>
|
| 382 |
<SayToAi text={`请完成「我的规划」里的总纲(规划 ID:${id}),读完任务包后把结果存回去。`} />
|
| 383 |
{st.data?.llm && <button className="btn primary" disabled={!!busy} onClick={gen}><Sparkles size={14} />{busy === 'gen' ? '生成中(约 1–2 分钟)…' : '让服务器上的 AI 直接生成'}</button>}
|
| 384 |
+
<AutoText className="rk-mt" minRows={6} value={paste} onChange={v => setPaste(v)} placeholder="把 AI 输出的总纲 JSON 粘贴在这里" />
|
| 385 |
<div className="row end"><button className="btn" disabled={!paste.trim() || !!busy} onClick={savePaste}><ClipboardPaste size={14} />保存总纲</button></div>
|
| 386 |
</section>}
|
| 387 |
{r && <PlanResult r={r} />}
|
ui-src/src/rooms/RankInspire.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import React, { useMemo, useState } from 'react'
|
|
| 2 |
import { Bot, Copy, Download, Link2 } from 'lucide-react'
|
| 3 |
import { get, getPassword, qs } from '../api'
|
| 4 |
import { copyText, cx, go, useAsync, useLocal } from '../lib'
|
| 5 |
-
import { ErrorNote, Field, Loading, Segmented, useToast } from '../ui'
|
| 6 |
import { Md } from '../md'
|
| 7 |
|
| 8 |
// 「AI 阅读版」:把番茄热榜原文整理成 AI 好读的格式(Markdown / JSON),复制给 AI 直接创作。
|
|
@@ -77,7 +77,7 @@ export function FeedTab({ a, arg }: { a: any; arg: string }) {
|
|
| 77 |
<Field label="简介"><Segmented value={abs} onChange={setAbs} items={[{ id: '-1', label: '完整' }, { id: '120', label: '前 120 字' }, { id: '0', label: '不要' }]} /></Field>
|
| 78 |
<Field label="格式"><Segmented value={format} onChange={setFormat} items={[{ id: 'md', label: '文本' }, { id: 'json', label: 'JSON' }]} /></Field>
|
| 79 |
<Field label="附上创作任务"><Segmented value={task} onChange={setTask} items={TASKS} /></Field>
|
| 80 |
-
{task && <Field label="你的想法或要求(可不填)"><
|
| 81 |
</div>
|
| 82 |
</section>
|
| 83 |
<section className="sheet">
|
|
|
|
| 2 |
import { Bot, Copy, Download, Link2 } from 'lucide-react'
|
| 3 |
import { get, getPassword, qs } from '../api'
|
| 4 |
import { copyText, cx, go, useAsync, useLocal } from '../lib'
|
| 5 |
+
import { AutoText, ErrorNote, Field, Loading, Segmented, useToast } from '../ui'
|
| 6 |
import { Md } from '../md'
|
| 7 |
|
| 8 |
// 「AI 阅读版」:把番茄热榜原文整理成 AI 好读的格式(Markdown / JSON),复制给 AI 直接创作。
|
|
|
|
| 77 |
<Field label="简介"><Segmented value={abs} onChange={setAbs} items={[{ id: '-1', label: '完整' }, { id: '120', label: '前 120 字' }, { id: '0', label: '不要' }]} /></Field>
|
| 78 |
<Field label="格式"><Segmented value={format} onChange={setFormat} items={[{ id: 'md', label: '文本' }, { id: 'json', label: 'JSON' }]} /></Field>
|
| 79 |
<Field label="附上创作任务"><Segmented value={task} onChange={setTask} items={TASKS} /></Field>
|
| 80 |
+
{task && <Field label="你的想法或要求(可不填)"><AutoText className="one" minRows={1} value={idea} onChange={setIdea} placeholder="例如:女主是兽医,想写轻松一点,60 万字。" /></Field>}
|
| 81 |
</div>
|
| 82 |
</section>
|
| 83 |
<section className="sheet">
|
ui-src/src/rooms/Reader.tsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
-
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
-
import { ChevronLeft, ChevronRight, ArrowLeft, PenLine, Minus, Plus, List, X } from 'lucide-react'
|
| 3 |
-
import { Chapter, projectsApi } from '../api'
|
| 4 |
-
import { cnNum, countWords, cx, go, useLocal } from '../lib'
|
| 5 |
-
import { Empty, ErrorNote, Spinner } from '../ui'
|
|
|
|
|
|
|
| 6 |
import type { BookCtx } from './Book'
|
| 7 |
|
| 8 |
-
// 通读模式:
|
| 9 |
const textCache = new Map<string, string>()
|
| 10 |
async function loadText(pid: string, c: Chapter): Promise<string> {
|
| 11 |
if (!c.current_version_id) return ''
|
|
@@ -16,34 +18,162 @@ async function loadText(pid: string, c: Chapter): Promise<string> {
|
|
| 16 |
return v.text || ''
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
export default function Reader({ ctx, chapterId }: { ctx: BookCtx; chapterId: string }) {
|
| 20 |
const { bundle } = ctx
|
| 21 |
const pid = bundle.project.project_id
|
| 22 |
const list = useMemo(() => [...bundle.chapters].sort((a, b) => a.number - b.number), [bundle.chapters])
|
| 23 |
-
const
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
const ch = list[idx]
|
|
|
|
| 28 |
const prev = idx > 0 ? list[idx - 1] : null
|
| 29 |
const next = idx < list.length - 1 ? list[idx + 1] : null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
const [text, setText] = useState<string | null>(null)
|
| 31 |
const [err, setErr] = useState('')
|
| 32 |
const [progress, setProgress] = useState(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
const scrollRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
useEffect(() => {
|
| 36 |
-
if (!ch) return
|
| 37 |
let alive = true
|
| 38 |
-
|
| 39 |
-
|
| 40 |
loadText(pid, ch).then(t => { if (alive) setText(t) }).catch(e => alive && setErr(e.message))
|
| 41 |
if (next) loadText(pid, next).catch(() => {})
|
| 42 |
scrollRef.current?.scrollTo({ top: 0 })
|
| 43 |
setProgress(0)
|
| 44 |
document.title = `第${ch.number}章 ${ch.title} · ${bundle.project.title}`
|
| 45 |
return () => { alive = false }
|
| 46 |
-
}, [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
useEffect(() => {
|
| 49 |
const onKey = (e: KeyboardEvent) => {
|
|
@@ -51,7 +181,7 @@ export default function Reader({ ctx, chapterId }: { ctx: BookCtx; chapterId: st
|
|
| 51 |
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.tagName === 'SELECT' || t.isContentEditable)) return
|
| 52 |
if (e.key === 'ArrowLeft' && prev) open(prev)
|
| 53 |
else if (e.key === 'ArrowRight' && next) open(next)
|
| 54 |
-
else if (e.key === 'Escape') setTocOpen(false)
|
| 55 |
}
|
| 56 |
window.addEventListener('keydown', onKey)
|
| 57 |
return () => window.removeEventListener('keydown', onKey)
|
|
@@ -63,64 +193,167 @@ export default function Reader({ ctx, chapterId }: { ctx: BookCtx; chapterId: st
|
|
| 63 |
if (!el) return
|
| 64 |
const max = el.scrollHeight - el.clientHeight
|
| 65 |
setProgress(max > 0 ? Math.min(1, el.scrollTop / max) : 1)
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
const paras = (text || '').split(/\n+/).map(s => s.trim()).filter(Boolean)
|
| 72 |
const showVol = ch.volume && (idx === 0 || list[idx - 1].volume !== ch.volume)
|
| 73 |
const words = text ? countWords(text) : (ch as any).word_count || 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
return (
|
| 76 |
-
<div className=
|
| 77 |
<div className="reader-bar">
|
| 78 |
<button className="btn small ghost" onClick={() => go(`book/${pid}/about`)} title="回到作品概览"><ArrowLeft size={14} /><span className="hide-sm">概览</span></button>
|
| 79 |
-
<button className="reader-where" onClick={() => setTocOpen(o => !o)} title="章节目录">
|
| 80 |
<List size={14} />
|
| 81 |
<span className="rw-t">第{ch.number}章 · {ch.title}</span>
|
| 82 |
<em>{idx + 1}/{list.length}</em>
|
| 83 |
</button>
|
| 84 |
<div className="reader-tools">
|
| 85 |
-
<button className=
|
| 86 |
-
|
| 87 |
-
<
|
| 88 |
-
<button className=
|
|
|
|
| 89 |
</div>
|
| 90 |
<i className="reader-progress" style={{ transform: `scaleX(${progress})` }} />
|
| 91 |
</div>
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
{tocOpen && (
|
| 94 |
<div className="reader-toc" role="dialog" aria-label="章节目录">
|
| 95 |
<div className="reader-toc-head"><b>目录</b><button className="icon-btn sm" onClick={() => setTocOpen(false)} title="关闭"><X size={15} /></button></div>
|
| 96 |
<div className="reader-toc-list">
|
| 97 |
-
{list.map((c, i) =>
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
<
|
| 101 |
-
|
| 102 |
-
{(c
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
</div>
|
| 107 |
</div>
|
| 108 |
)}
|
| 109 |
|
| 110 |
-
<div className="reader-scroll" ref={scrollRef} onScroll={onScroll} onClick={() => tocOpen && setTocOpen(false)}>
|
| 111 |
-
<article className=
|
| 112 |
{showVol && <div className="reader-vol">{ch.volume}</div>}
|
| 113 |
<div className="reader-num">第{cnNum(ch.number)}章</div>
|
| 114 |
<h1 className="reader-title">{ch.title}</h1>
|
| 115 |
-
{text !== null && <div className="reader-meta">{words.toLocaleString()} 字</div>}
|
|
|
|
| 116 |
{err ? <ErrorNote error={err} onRetry={() => { setErr(''); setText(null); loadText(pid, ch).then(setText).catch(e => setErr(e.message)) }} />
|
| 117 |
: text === null ? <div className="reader-loading"><Spinner size={16} label="正在翻页…" /></div>
|
| 118 |
-
: paras.length === 0 ? <Empty title="这一章还没有正文"><button className="link-btn" onClick={() => go(`book/${pid}/${
|
| 119 |
-
: <div className="reader-body">{paras.map(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
<nav className="reader-nav">
|
| 121 |
<button className="btn ghost" disabled={!prev} onClick={() => prev && open(prev)}><ChevronLeft size={16} />上一章</button>
|
| 122 |
-
<button className="btn ghost" onClick={
|
| 123 |
-
<button className="btn primary" disabled={!next} onClick={() => next && open(next)}>{next ? '下一章' : '已是最后一章'}<ChevronRight size={16} /></button>
|
| 124 |
</nav>
|
| 125 |
{next && <div className="reader-next-hint">下一章:第{next.number}章 · {next.title}<span className="hide-sm"> · 键盘 ← → 也能翻章</span></div>}
|
| 126 |
</article>
|
|
|
|
| 1 |
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
| 2 |
+
import { ChevronLeft, ChevronRight, ArrowLeft, PenLine, Minus, Plus, List, X, Highlighter, Type, Scale } from 'lucide-react'
|
| 3 |
+
import { Chapter, Note, PeerItem, projectsApi } from '../api'
|
| 4 |
+
import { cnNum, countWords, cx, go, useAsync, useLocal } from '../lib'
|
| 5 |
+
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>()
|
| 12 |
async function loadText(pid: string, c: Chapter): Promise<string> {
|
| 13 |
if (!c.current_version_id) return ''
|
|
|
|
| 18 |
return v.text || ''
|
| 19 |
}
|
| 20 |
|
| 21 |
+
const FONTS = [
|
| 22 |
+
{ id: 'song', label: '宋体', css: 'var(--serif)' },
|
| 23 |
+
{ id: 'hei', label: '黑体', css: 'var(--sans)' },
|
| 24 |
+
{ id: 'kai', label: '楷体', css: '"Kaiti SC", "STKaiti", "KaiTi", "楷体", "Kaiti", var(--serif)' },
|
| 25 |
+
] as const
|
| 26 |
+
const THEMES = [
|
| 27 |
+
{ id: 'auto', label: '跟随', bg: '', ink: '' },
|
| 28 |
+
{ id: 'white', label: '纸白', bg: '#ffffff', ink: '#222222' },
|
| 29 |
+
{ id: 'cream', label: '米黄', bg: '#f6eedb', ink: '#3b3226' },
|
| 30 |
+
{ id: 'green', label: '护眼', bg: '#d8ead2', ink: '#24321f' },
|
| 31 |
+
{ id: 'gray', label: '浅灰', bg: '#e9e9e6', ink: '#2a2a28' },
|
| 32 |
+
{ id: 'night', label: '夜间', bg: '#17181b', ink: '#b8b2a5' },
|
| 33 |
+
] as const
|
| 34 |
+
const LINES = [{ id: 1.7, label: '紧' }, { id: 1.95, label: '中' }, { id: 2.3, label: '松' }]
|
| 35 |
+
|
| 36 |
+
type Para = { text: string; start: number; end: number }
|
| 37 |
+
function splitParas(text: string): Para[] {
|
| 38 |
+
const out: Para[] = []
|
| 39 |
+
const re = /[^\n]+/g
|
| 40 |
+
let m: RegExpExecArray | null
|
| 41 |
+
while ((m = re.exec(text))) {
|
| 42 |
+
const raw = m[0]
|
| 43 |
+
const lead = raw.length - raw.replace(/^[\s ]+/, '').length
|
| 44 |
+
const body = raw.trim()
|
| 45 |
+
if (!body) continue
|
| 46 |
+
const start = m.index + lead
|
| 47 |
+
out.push({ text: text.slice(start, start + body.length), start, end: start + body.length })
|
| 48 |
+
}
|
| 49 |
+
return out
|
| 50 |
+
}
|
| 51 |
+
const clip = <T extends { at: number; to: number }>(list: T[], s: number, e: number) =>
|
| 52 |
+
list.filter(x => x.at >= 0 && x.at < e && x.to > s).map(x => ({ ...x, at: Math.max(x.at, s) - s, to: Math.min(x.to, e) - s }))
|
| 53 |
+
|
| 54 |
+
type Pos = { cid: string; para: number; at: number }
|
| 55 |
+
const localPos = (pid: string): Pos | null => { try { return JSON.parse(localStorage.getItem(`xs_rpos_${pid}`) || 'null') } catch { return null } }
|
| 56 |
+
const localPara = (cid: string): { para: number; ratio: number } | null => { try { return JSON.parse(localStorage.getItem(`xs_rpara_${cid}`) || 'null') } catch { return null } }
|
| 57 |
+
|
| 58 |
export default function Reader({ ctx, chapterId }: { ctx: BookCtx; chapterId: string }) {
|
| 59 |
const { bundle } = ctx
|
| 60 |
const pid = bundle.project.project_id
|
| 61 |
const list = useMemo(() => [...bundle.chapters].sort((a, b) => a.number - b.number), [bundle.chapters])
|
| 62 |
+
const server = useAsync(() => projectsApi.progress(pid).catch(() => null), [pid])
|
| 63 |
+
|
| 64 |
+
// 没指定章节时:打开上次读到的那一章(本机和云端谁新用谁)
|
| 65 |
+
const lp = useMemo(() => localPos(pid), [pid])
|
| 66 |
+
const sp = server.data?.reader
|
| 67 |
+
const lastCid = (() => {
|
| 68 |
+
const lt = lp ? new Date(lp.at).getTime() : 0, st = sp ? new Date(sp.at).getTime() : 0
|
| 69 |
+
return (st > lt ? sp?.chapter_id : lp?.cid) || lp?.cid || sp?.chapter_id || ''
|
| 70 |
+
})()
|
| 71 |
+
const waiting = !chapterId && !lp && server.loading
|
| 72 |
+
|
| 73 |
+
if (!list.length) return <div className="page"><Empty title="还没有章节">先在目录里新建章节,写下正文后就能在这里通读。</Empty></div>
|
| 74 |
+
if (waiting) return <div className="reader-loading"><Spinner size={16} label="找到上次读到的地方…" /></div>
|
| 75 |
+
const idx = Math.max(0, list.findIndex(c => c.chapter_id === (chapterId || lastCid)))
|
| 76 |
+
return <ReaderInner key={pid} ctx={ctx} list={list} idx={idx} serverChapters={server.data?.chapters || {}} />
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function ReaderInner({ ctx, list, idx, serverChapters }: { ctx: BookCtx; list: Chapter[]; idx: number; serverChapters: Record<string, { read_para?: number; read_ratio?: number }> }) {
|
| 80 |
+
const { bundle } = ctx
|
| 81 |
+
const pid = bundle.project.project_id
|
| 82 |
+
const toast = useToast()
|
| 83 |
const ch = list[idx]
|
| 84 |
+
const cid = ch.chapter_id
|
| 85 |
const prev = idx > 0 ? list[idx - 1] : null
|
| 86 |
const next = idx < list.length - 1 ? list[idx + 1] : null
|
| 87 |
+
|
| 88 |
+
const [fs, setFs] = useLocal<number>('xs_read_fs', 19)
|
| 89 |
+
const [font, setFont] = useLocal<string>('xs_read_font', 'song')
|
| 90 |
+
const [theme, setTheme] = useLocal<string>('xs_read_theme', 'auto')
|
| 91 |
+
const [lh, setLh] = useLocal<number>('xs_read_lh', 1.95)
|
| 92 |
+
const [review, setReview] = useLocal('xs_read_review', false)
|
| 93 |
+
const [tocOpen, setTocOpen] = useState(false)
|
| 94 |
+
const [setOpen, setSetOpen] = useState(false)
|
| 95 |
const [text, setText] = useState<string | null>(null)
|
| 96 |
const [err, setErr] = useState('')
|
| 97 |
const [progress, setProgress] = useState(0)
|
| 98 |
+
const [chRatio, setChRatio] = useState<Record<string, number>>(() => {
|
| 99 |
+
const o: Record<string, number> = {}
|
| 100 |
+
for (const c of list) { const l = localPara(c.chapter_id); const r = l?.ratio ?? serverChapters[c.chapter_id]?.read_ratio; if (r != null) o[c.chapter_id] = r }
|
| 101 |
+
return o
|
| 102 |
+
})
|
| 103 |
const scrollRef = useRef<HTMLDivElement>(null)
|
| 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)
|
| 110 |
+
const paras = useMemo(() => splitParas(text || ''), [text])
|
| 111 |
+
const located = useMemo(() => locateNotes(text || '', nb.notes || []).filter(n => n.at >= 0 && n.status === 'open'), [text, nb.notes])
|
| 112 |
+
const disputes = useMemo(() => locateDisputes(text || '', peer.data?.items, cid), [text, peer.data, cid])
|
| 113 |
+
const [sel, setSel] = useState<{ start: number; end: number; top: number; left: number } | null>(null)
|
| 114 |
+
const [pop, setPop] = useState<{ kind: 'note'; n: Note; top: number; left: number } | { kind: 'peer'; x: PeerItem; top: number; left: number } | null>(null)
|
| 115 |
|
| 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 })
|
| 123 |
setProgress(0)
|
| 124 |
document.title = `第${ch.number}章 ${ch.title} · ${bundle.project.title}`
|
| 125 |
return () => { alive = false }
|
| 126 |
+
}, [cid, ch.current_version_id])
|
| 127 |
+
|
| 128 |
+
// 正文到了以后,跳回这一章上次读到的段落(读完的章从头开始)
|
| 129 |
+
useEffect(() => {
|
| 130 |
+
if (text == null) return
|
| 131 |
+
if (!paras.length) { restoring.current = false; return }
|
| 132 |
+
const l = localPara(cid)
|
| 133 |
+
const s = serverChapters[cid]
|
| 134 |
+
const para = l ? l.para : s?.read_para ?? 0
|
| 135 |
+
const ratio = l ? l.ratio : s?.read_ratio ?? 0
|
| 136 |
+
if (!para || ratio >= 0.97) { markOpen(0); setTimeout(() => { restoring.current = false }, 120); return }
|
| 137 |
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
| 138 |
+
const el = pageRef.current?.querySelector(`[data-i="${para}"]`) as HTMLElement | null
|
| 139 |
+
const box = scrollRef.current
|
| 140 |
+
if (el && box) box.scrollTop = el.offsetTop - 70
|
| 141 |
+
setTimeout(() => { restoring.current = false }, 120)
|
| 142 |
+
}))
|
| 143 |
+
}, [text, cid])
|
| 144 |
+
|
| 145 |
+
const currentPara = () => {
|
| 146 |
+
const box = scrollRef.current, page = pageRef.current
|
| 147 |
+
if (!box || !page) return 0
|
| 148 |
+
const ps = page.querySelectorAll<HTMLElement>('.reader-body p')
|
| 149 |
+
const top = box.scrollTop + 80
|
| 150 |
+
for (let i = 0; i < ps.length; i++) if (ps[i].offsetTop + ps[i].offsetHeight > top) return i
|
| 151 |
+
return Math.max(0, ps.length - 1)
|
| 152 |
+
}
|
| 153 |
+
// 只记下「正在读这一章」,不改这一章的阅读进度
|
| 154 |
+
const markOpen = (para: number) => {
|
| 155 |
+
try { localStorage.setItem(`xs_rpos_${pid}`, JSON.stringify({ cid, para, at: new Date().toISOString() })) } catch {}
|
| 156 |
+
clearTimeout(saveTimer.current)
|
| 157 |
+
saveTimer.current = setTimeout(() => { projectsApi.saveProgress(pid, { reader: { chapter_id: cid, para } }).catch(() => {}) }, 2000)
|
| 158 |
+
}
|
| 159 |
+
const saveNow = (forceRatio?: number) => {
|
| 160 |
+
const box = scrollRef.current
|
| 161 |
+
if (!box) return
|
| 162 |
+
const max = box.scrollHeight - box.clientHeight
|
| 163 |
+
const ratio = forceRatio ?? (max > 0 ? Math.min(1, box.scrollTop / max) : 1)
|
| 164 |
+
const para = forceRatio === 0 ? 0 : currentPara()
|
| 165 |
+
const at = new Date().toISOString()
|
| 166 |
+
try {
|
| 167 |
+
localStorage.setItem(`xs_rpos_${pid}`, JSON.stringify({ cid, para, at }))
|
| 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(() => {})
|
| 174 |
+
}, 2000)
|
| 175 |
+
}
|
| 176 |
+
useEffect(() => () => clearTimeout(saveTimer.current), [])
|
| 177 |
|
| 178 |
useEffect(() => {
|
| 179 |
const onKey = (e: KeyboardEvent) => {
|
|
|
|
| 181 |
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.tagName === 'SELECT' || t.isContentEditable)) return
|
| 182 |
if (e.key === 'ArrowLeft' && prev) open(prev)
|
| 183 |
else if (e.key === 'ArrowRight' && next) open(next)
|
| 184 |
+
else if (e.key === 'Escape') { setTocOpen(false); setSetOpen(false); setPop(null); setSel(null) }
|
| 185 |
}
|
| 186 |
window.addEventListener('keydown', onKey)
|
| 187 |
return () => window.removeEventListener('keydown', onKey)
|
|
|
|
| 193 |
if (!el) return
|
| 194 |
const max = el.scrollHeight - el.clientHeight
|
| 195 |
setProgress(max > 0 ? Math.min(1, el.scrollTop / max) : 1)
|
| 196 |
+
if (!restoring.current && text != null) saveNow()
|
| 197 |
}
|
| 198 |
|
| 199 |
+
/* 批阅:选中文字 → 加批注 */
|
| 200 |
+
const offsetIn = (node: Node, off: number): number | null => {
|
| 201 |
+
const el = (node.nodeType === 1 ? node as HTMLElement : node.parentElement)?.closest('p[data-off]') as HTMLElement | null
|
| 202 |
+
if (!el) return null
|
| 203 |
+
const r = document.createRange()
|
| 204 |
+
r.selectNodeContents(el); r.setEnd(node, off)
|
| 205 |
+
return Number(el.dataset.off) + r.toString().length
|
| 206 |
+
}
|
| 207 |
+
const onUp = () => {
|
| 208 |
+
if (!review || text == null) return
|
| 209 |
+
const s = window.getSelection()
|
| 210 |
+
const page = pageRef.current
|
| 211 |
+
if (!s || s.isCollapsed || !page || !page.contains(s.anchorNode) || !page.contains(s.focusNode)) return
|
| 212 |
+
const r = s.getRangeAt(0)
|
| 213 |
+
const a = offsetIn(r.startContainer, r.startOffset), b = offsetIn(r.endContainer, r.endOffset)
|
| 214 |
+
if (a == null || b == null || b <= a || !text.slice(a, b).trim()) return
|
| 215 |
+
const rect = r.getBoundingClientRect(), host = page.getBoundingClientRect()
|
| 216 |
+
setPop(null)
|
| 217 |
+
setSel({ start: a, end: b, top: rect.bottom - host.top + 8, left: Math.max(0, Math.min(rect.left - host.left, host.width - 340)) })
|
| 218 |
+
}
|
| 219 |
+
const createNote = async (f: { type: string; severity: string; comment: string; suggestion: string }) => {
|
| 220 |
+
if (!sel || text == null) return false
|
| 221 |
+
try {
|
| 222 |
+
const n = await projectsApi.createNote(pid, cid, { ...f, severity: f.severity as Note['severity'], quote: text.slice(sel.start, sel.end), start: sel.start, end: sel.end, version_id: ch.current_version_id || null, created_by: 'author' })
|
| 223 |
+
nb.setNotes(l => [...l, n]); setSel(null); window.getSelection()?.removeAllRanges()
|
| 224 |
+
toast('批注已保存,我改这一章时会逐条处理', 'ok'); return true
|
| 225 |
+
} catch (e: any) { toast(e.message, 'err'); return false }
|
| 226 |
+
}
|
| 227 |
+
const showPop = (e: React.MouseEvent, p: { kind: 'note'; n: Note } | { kind: 'peer'; x: PeerItem }) => {
|
| 228 |
+
e.stopPropagation()
|
| 229 |
+
const page = pageRef.current
|
| 230 |
+
if (!page) return
|
| 231 |
+
const rect = (e.target as HTMLElement).getBoundingClientRect(), host = page.getBoundingClientRect()
|
| 232 |
+
setSel(null)
|
| 233 |
+
setPop({ ...p, top: rect.bottom - host.top + 8, left: Math.max(0, Math.min(rect.left - host.left, host.width - 340)) } as any)
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
const renderPara = (p: Para, i: number) => {
|
| 237 |
+
const marks = clip<Located>(located, p.start, p.end)
|
| 238 |
+
const ds = clip<Dispute>(disputes, p.start, p.end)
|
| 239 |
+
if (!marks.length && !ds.length) return <p key={i} data-i={i} data-off={p.start}>{p.text}</p>
|
| 240 |
+
const segs = segmentText(p.text, marks, ds)
|
| 241 |
+
return (
|
| 242 |
+
<p key={i} data-i={i} data-off={p.start}>
|
| 243 |
+
{segs.map((s, k) => s.n
|
| 244 |
+
? <mark key={k} className={cx('nm', `sev-${s.n.severity}`, s.n.type === 'praise' && 'praise', s.d && 'dm')} onClick={e => showPop(e, { kind: 'note', n: s.n! })}>{s.t}</mark>
|
| 245 |
+
: s.d ? <mark key={k} className="dm" onClick={e => { const x = peer.data?.items.find(y => y.item_id === s.d!.id); if (x) showPop(e, { kind: 'peer', x }) }}>{s.t}</mark>
|
| 246 |
+
: <React.Fragment key={k}>{s.t}</React.Fragment>)}
|
| 247 |
+
</p>
|
| 248 |
+
)
|
| 249 |
+
}
|
| 250 |
|
|
|
|
| 251 |
const showVol = ch.volume && (idx === 0 || list[idx - 1].volume !== ch.volume)
|
| 252 |
const words = text ? countWords(text) : (ch as any).word_count || 0
|
| 253 |
+
const th = THEMES.find(t => t.id === theme) || THEMES[0]
|
| 254 |
+
const ff = (FONTS.find(f => f.id === font) || FONTS[0]).css
|
| 255 |
+
const style: React.CSSProperties = { ['--rfs' as any]: `${fs}px`, ['--rlh' as any]: lh, ['--rff' as any]: ff }
|
| 256 |
+
if (th.bg) Object.assign(style, { ['--rbg' as any]: th.bg, ['--rink' as any]: th.ink })
|
| 257 |
+
const openNotes = located.length
|
| 258 |
|
| 259 |
return (
|
| 260 |
+
<div className={cx('reader', th.bg && 'themed', theme === 'night' && 'dark')} style={style}>
|
| 261 |
<div className="reader-bar">
|
| 262 |
<button className="btn small ghost" onClick={() => go(`book/${pid}/about`)} title="回到作品概览"><ArrowLeft size={14} /><span className="hide-sm">概览</span></button>
|
| 263 |
+
<button className="reader-where" onClick={() => { setTocOpen(o => !o); setSetOpen(false) }} title="章节目录">
|
| 264 |
<List size={14} />
|
| 265 |
<span className="rw-t">第{ch.number}章 · {ch.title}</span>
|
| 266 |
<em>{idx + 1}/{list.length}</em>
|
| 267 |
</button>
|
| 268 |
<div className="reader-tools">
|
| 269 |
+
<button className={cx('btn small', review ? 'primary' : 'ghost')} onClick={() => { setReview(!review); setSel(null) }} title="批阅:选中句子加批注">
|
| 270 |
+
<Highlighter size={14} /><span className="hide-sm">{review ? '退出批阅' : '批阅'}</span>{openNotes > 0 && <em className="badge">{openNotes}</em>}
|
| 271 |
+
</button>
|
| 272 |
+
<button className={cx('btn small ghost', setOpen && 'on')} onClick={() => { setSetOpen(o => !o); setTocOpen(false) }} title="字体、字号、背景"><Type size={14} /><span className="hide-sm">阅读设置</span></button>
|
| 273 |
+
<button className="btn small ghost" onClick={() => go(`book/${pid}/${cid}`)} title="在稿纸里编辑这一章"><PenLine size={14} /><span className="hide-sm">编辑</span></button>
|
| 274 |
</div>
|
| 275 |
<i className="reader-progress" style={{ transform: `scaleX(${progress})` }} />
|
| 276 |
</div>
|
| 277 |
|
| 278 |
+
{setOpen && (
|
| 279 |
+
<div className="reader-pop reader-set" role="dialog" aria-label="阅读设置">
|
| 280 |
+
<div className="reader-toc-head"><b>阅读设置</b><button className="icon-btn sm" onClick={() => setSetOpen(false)} title="关闭"><X size={15} /></button></div>
|
| 281 |
+
<div className="rs-row"><span>字号</span>
|
| 282 |
+
<div className="rs-ctl">
|
| 283 |
+
<button className="icon-btn sm" onClick={() => setFs(Math.max(14, fs - 1))} disabled={fs <= 14} title="字号减小"><Minus size={15} /></button>
|
| 284 |
+
<span className="fs-val">{fs}</span>
|
| 285 |
+
<button className="icon-btn sm" onClick={() => setFs(Math.min(30, fs + 1))} disabled={fs >= 30} title="字号增大"><Plus size={15} /></button>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
<div className="rs-row"><span>字体</span>
|
| 289 |
+
<div className="rs-ctl">{FONTS.map(f => <button key={f.id} className={cx('chip', font === f.id && 'on')} style={{ fontFamily: f.css }} onClick={() => setFont(f.id)}>{f.label}</button>)}</div>
|
| 290 |
+
</div>
|
| 291 |
+
<div className="rs-row"><span>行距</span>
|
| 292 |
+
<div className="rs-ctl">{LINES.map(l => <button key={l.id} className={cx('chip', lh === l.id && 'on')} onClick={() => setLh(l.id)}>{l.label}</button>)}</div>
|
| 293 |
+
</div>
|
| 294 |
+
<div className="rs-row"><span>背景</span>
|
| 295 |
+
<div className="rs-ctl">{THEMES.map(t => <button key={t.id} className={cx('rs-swatch', theme === t.id && 'on', t.id === 'auto' && 'auto')} style={t.bg ? { background: t.bg, color: t.ink } : undefined} onClick={() => setTheme(t.id)} title={t.label}>{t.label}</button>)}</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
)}
|
| 299 |
+
|
| 300 |
{tocOpen && (
|
| 301 |
<div className="reader-toc" role="dialog" aria-label="章节目录">
|
| 302 |
<div className="reader-toc-head"><b>目录</b><button className="icon-btn sm" onClick={() => setTocOpen(false)} title="关闭"><X size={15} /></button></div>
|
| 303 |
<div className="reader-toc-list">
|
| 304 |
+
{list.map((c, i) => {
|
| 305 |
+
const r = chRatio[c.chapter_id]
|
| 306 |
+
return (
|
| 307 |
+
<React.Fragment key={c.chapter_id}>
|
| 308 |
+
{c.volume && (i === 0 || list[i - 1].volume !== c.volume) && <div className="reader-toc-vol">{c.volume}</div>}
|
| 309 |
+
<button className={cx('reader-toc-item', c.chapter_id === cid && 'on', !c.current_version_id && 'empty')} onClick={() => open(c)}>
|
| 310 |
+
<span className="n">{c.number}</span><span className="t">{c.title}</span>
|
| 311 |
+
{r != null && r > 0.02 && <span className={cx('rt-read', r >= 0.97 && 'done')} title={r >= 0.97 ? '已读完' : `读到 ${Math.round(r * 100)}%`}>{r >= 0.97 ? '读完' : `${Math.round(r * 100)}%`}</span>}
|
| 312 |
+
{(c as any).word_count ? <em>{(c as any).word_count.toLocaleString()}</em> : null}
|
| 313 |
+
</button>
|
| 314 |
+
</React.Fragment>
|
| 315 |
+
)
|
| 316 |
+
})}
|
| 317 |
</div>
|
| 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>}
|
| 324 |
<div className="reader-num">第{cnNum(ch.number)}章</div>
|
| 325 |
<h1 className="reader-title">{ch.title}</h1>
|
| 326 |
+
{text !== null && <div className="reader-meta">{words.toLocaleString()} 字{disputes.length > 0 && <> · <span className="dm-legend"><mark className="dm">黄色底</mark>是有分歧的句子</span></>}</div>}
|
| 327 |
+
{review && text && <div className="review-tip"><Highlighter size={14} />批阅中:选中任意句子即可批注;点彩色标记查看批注或分歧。复制出去的只有纯文字。</div>}
|
| 328 |
{err ? <ErrorNote error={err} onRetry={() => { setErr(''); setText(null); loadText(pid, ch).then(setText).catch(e => setErr(e.message)) }} />
|
| 329 |
: text === null ? <div className="reader-loading"><Spinner size={16} label="正在翻页…" /></div>
|
| 330 |
+
: paras.length === 0 ? <Empty title="这一章还没有正文"><button className="link-btn" onClick={() => go(`book/${pid}/${cid}`)}>去稿纸里写</button></Empty>
|
| 331 |
+
: <div className="reader-body">{paras.map(renderPara)}</div>}
|
| 332 |
+
|
| 333 |
+
{sel && <NoteForm style={{ top: sel.top, left: sel.left }} quote={(text || '').slice(sel.start, sel.end)} onClose={() => { setSel(null); window.getSelection()?.removeAllRanges() }} onSave={createNote} />}
|
| 334 |
+
{pop && (
|
| 335 |
+
<div className="note-form floating reader-note-pop" style={{ top: pop.top, left: pop.left }} onMouseUp={e => e.stopPropagation()} onClick={e => e.stopPropagation()}>
|
| 336 |
+
<div className="nf-head">
|
| 337 |
+
<b>{pop.kind === 'note' ? <>{NOTE_TYPE[pop.n.type] || '批注'}{pop.n.type !== 'praise' ? ` · ${SEVERITY[pop.n.severity] || ''}` : ''}</> : <><Scale size={13} /> 分歧{pop.x.author_decision ? ' · 你已决定' : ' · 待你决定'}</>}</b>
|
| 338 |
+
<button className="icon-btn sm" onClick={() => setPop(null)} aria-label="关闭"><X size={14} /></button>
|
| 339 |
+
</div>
|
| 340 |
+
{pop.kind === 'note' ? <>
|
| 341 |
+
<p className="rnp-p">{pop.n.comment}</p>
|
| 342 |
+
{pop.n.suggestion && <p className="rnp-p muted">想怎么改:{pop.n.suggestion}</p>}
|
| 343 |
+
{pop.n.reply && <p className="rnp-p muted">AI 回复:{pop.n.reply}</p>}
|
| 344 |
+
</> : <>
|
| 345 |
+
{pop.x.topic && <b className="rnp-p">{pop.x.topic}</b>}
|
| 346 |
+
<p className="rnp-p"><span className="muted">协作 AI:</span>{pop.x.reviewer_said}</p>
|
| 347 |
+
<p className="rnp-p"><span className="muted">写作 AI:</span>{pop.x.my_view}</p>
|
| 348 |
+
</>}
|
| 349 |
+
<div className="pop-actions"><button className="link-btn" onClick={() => { try { localStorage.setItem('xs_inspector_tab', JSON.stringify(pop.kind === 'note' ? 'notes' : 'peer')); localStorage.setItem('xs_inspector_open', 'true') } catch {} go(`book/${pid}/${cid}`) }}>在稿纸里处理</button></div>
|
| 350 |
+
</div>
|
| 351 |
+
)}
|
| 352 |
+
|
| 353 |
<nav className="reader-nav">
|
| 354 |
<button className="btn ghost" disabled={!prev} onClick={() => prev && open(prev)}><ChevronLeft size={16} />上一章</button>
|
| 355 |
+
<button className="btn ghost" onClick={e => { e.stopPropagation(); setTocOpen(true) }}><List size={15} />目录</button>
|
| 356 |
+
<button className="btn primary" disabled={!next} onClick={() => { saveNow(1); next && open(next) }}>{next ? '下一章' : '已是最后一章'}<ChevronRight size={16} /></button>
|
| 357 |
</nav>
|
| 358 |
{next && <div className="reader-next-hint">下一章:第{next.number}章 · {next.title}<span className="hide-sm"> · 键盘 ← → 也能翻章</span></div>}
|
| 359 |
</article>
|
ui-src/src/rooms/Review.tsx
CHANGED
|
@@ -29,26 +29,46 @@ export function locateNotes(text: string, notes: Note[]): Located[] {
|
|
| 29 |
})
|
| 30 |
}
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
/* ---------- 批阅模式:只读正文 + 高亮 + 选中加批注 ---------- */
|
| 33 |
-
export function ReviewText({ text, notes, active, onPick, onCreate }: {
|
| 34 |
text: string; notes: Located[]; active: string; onPick: (id: string) => void
|
| 35 |
onCreate: (n: { quote: string; start: number; end: number; type: string; severity: string; comment: string; suggestion: string }) => Promise<boolean>
|
|
|
|
| 36 |
}) {
|
| 37 |
const ref = useRef<HTMLDivElement>(null)
|
| 38 |
const [sel, setSel] = useState<{ start: number; end: number; quote: string; top: number; left: number } | null>(null)
|
| 39 |
const segs = useMemo(() => {
|
| 40 |
-
const marks = notes.filter(n => n.at >= 0 && n.status === 'open' || n.at >= 0 && n.note_id === active)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
for (const n of marks) {
|
| 44 |
-
if (n.at < pos) continue
|
| 45 |
-
if (n.at > pos) out.push({ t: text.slice(pos, n.at) })
|
| 46 |
-
out.push({ t: text.slice(n.at, n.to), n })
|
| 47 |
-
pos = n.to
|
| 48 |
-
}
|
| 49 |
-
if (pos < text.length) out.push({ t: text.slice(pos) })
|
| 50 |
-
return out
|
| 51 |
-
}, [text, notes, active])
|
| 52 |
|
| 53 |
useEffect(() => {
|
| 54 |
if (!active || !ref.current) return
|
|
@@ -72,10 +92,11 @@ export function ReviewText({ text, notes, active, onPick, onCreate }: {
|
|
| 72 |
|
| 73 |
return (
|
| 74 |
<div className="review-wrap">
|
| 75 |
-
<div ref={ref} className="review-text" onMouseUp={onUp}>
|
| 76 |
{segs.map((s, i) => s.n
|
| 77 |
-
? <mark key={i} data-nid={s.n.note_id} className={cx('nm', `sev-${s.n.severity}`, s.n.type === 'praise' && 'praise', s.n.note_id === active && 'on', s.n.status !== 'open' && 'done')}
|
| 78 |
onClick={e => { e.stopPropagation(); onPick(s.n!.note_id) }} title={s.n.comment}>{s.t}</mark>
|
|
|
|
| 79 |
: <React.Fragment key={i}>{s.t}</React.Fragment>)}
|
| 80 |
{!text && <span className="muted">稿纸还是空的。</span>}
|
| 81 |
</div>
|
|
@@ -85,7 +106,7 @@ export function ReviewText({ text, notes, active, onPick, onCreate }: {
|
|
| 85 |
)
|
| 86 |
}
|
| 87 |
|
| 88 |
-
function NoteForm({ quote, onSave, onClose, style, init }: {
|
| 89 |
quote?: string; onSave: (f: { type: string; severity: string; comment: string; suggestion: string }) => Promise<boolean>; onClose: () => void
|
| 90 |
style?: React.CSSProperties; init?: Partial<Note>
|
| 91 |
}) {
|
|
|
|
| 29 |
})
|
| 30 |
}
|
| 31 |
|
| 32 |
+
/* ---------- 分歧标注:正文里用底色标出有分歧的句子(只是显示,复制、发布都不带) ---------- */
|
| 33 |
+
export type Dispute = { at: number; to: number; id: string; tip: string }
|
| 34 |
+
export type Seg = { t: string; n?: Located; d?: Dispute }
|
| 35 |
+
export function segmentText(text: string, marks: Located[], disputes: Dispute[] = []): Seg[] {
|
| 36 |
+
const pts = new Set<number>([0, text.length])
|
| 37 |
+
for (const m of marks) { pts.add(m.at); pts.add(m.to) }
|
| 38 |
+
for (const d of disputes) { pts.add(d.at); pts.add(d.to) }
|
| 39 |
+
const arr = [...pts].filter(p => p >= 0 && p <= text.length).sort((a, b) => a - b)
|
| 40 |
+
const out: Seg[] = []
|
| 41 |
+
for (let i = 0; i < arr.length - 1; i++) {
|
| 42 |
+
const s = arr[i], e = arr[i + 1]
|
| 43 |
+
if (e <= s) continue
|
| 44 |
+
const n = marks.find(m => m.at <= s && m.to >= e)
|
| 45 |
+
const d = disputes.find(m => m.at <= s && m.to >= e)
|
| 46 |
+
const last = out[out.length - 1]
|
| 47 |
+
if (last && last.n === n && last.d === d) last.t += text.slice(s, e)
|
| 48 |
+
else out.push({ t: text.slice(s, e), n, d })
|
| 49 |
+
}
|
| 50 |
+
return out
|
| 51 |
+
}
|
| 52 |
+
/** 复制时只放纯文字,不带任何颜色、底色 */
|
| 53 |
+
export const plainCopy = (e: React.ClipboardEvent) => {
|
| 54 |
+
const s = window.getSelection()?.toString()
|
| 55 |
+
if (!s) return
|
| 56 |
+
e.preventDefault()
|
| 57 |
+
e.clipboardData.setData('text/plain', s)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
/* ---------- 批阅模式:只读正文 + 高亮 + 选中加批注 ---------- */
|
| 61 |
+
export function ReviewText({ text, notes, active, onPick, onCreate, disputes, onDispute }: {
|
| 62 |
text: string; notes: Located[]; active: string; onPick: (id: string) => void
|
| 63 |
onCreate: (n: { quote: string; start: number; end: number; type: string; severity: string; comment: string; suggestion: string }) => Promise<boolean>
|
| 64 |
+
disputes?: Dispute[]; onDispute?: (id: string) => void
|
| 65 |
}) {
|
| 66 |
const ref = useRef<HTMLDivElement>(null)
|
| 67 |
const [sel, setSel] = useState<{ start: number; end: number; quote: string; top: number; left: number } | null>(null)
|
| 68 |
const segs = useMemo(() => {
|
| 69 |
+
const marks = notes.filter(n => n.at >= 0 && n.status === 'open' || n.at >= 0 && n.note_id === active)
|
| 70 |
+
return segmentText(text, marks, disputes || [])
|
| 71 |
+
}, [text, notes, active, disputes])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
useEffect(() => {
|
| 74 |
if (!active || !ref.current) return
|
|
|
|
| 92 |
|
| 93 |
return (
|
| 94 |
<div className="review-wrap">
|
| 95 |
+
<div ref={ref} className="review-text" onMouseUp={onUp} onCopy={plainCopy}>
|
| 96 |
{segs.map((s, i) => s.n
|
| 97 |
+
? <mark key={i} data-nid={s.n.note_id} className={cx('nm', `sev-${s.n.severity}`, s.n.type === 'praise' && 'praise', s.n.note_id === active && 'on', s.n.status !== 'open' && 'done', s.d && 'dm')}
|
| 98 |
onClick={e => { e.stopPropagation(); onPick(s.n!.note_id) }} title={s.n.comment}>{s.t}</mark>
|
| 99 |
+
: s.d ? <mark key={i} className="dm" title={`分歧:${s.d.tip}`} onClick={() => onDispute?.(s.d!.id)}>{s.t}</mark>
|
| 100 |
: <React.Fragment key={i}>{s.t}</React.Fragment>)}
|
| 101 |
{!text && <span className="muted">稿纸还是空的。</span>}
|
| 102 |
</div>
|
|
|
|
| 106 |
)
|
| 107 |
}
|
| 108 |
|
| 109 |
+
export function NoteForm({ quote, onSave, onClose, style, init }: {
|
| 110 |
quote?: string; onSave: (f: { type: string; severity: string; comment: string; suggestion: string }) => Promise<boolean>; onClose: () => void
|
| 111 |
style?: React.CSSProperties; init?: Partial<Note>
|
| 112 |
}) {
|
ui-src/src/rooms/Shelf.tsx
CHANGED
|
@@ -122,7 +122,7 @@ export function NewProject({ open, onClose, onCreated }: { open: boolean; onClos
|
|
| 122 |
<Field label="发布平台"><input className="input" value={f.target_platform} onChange={e => set('target_platform', e.target.value)} /></Field>
|
| 123 |
<Field label="目标字数"><input className="input" type="number" value={f.target_words} onChange={e => set('target_words', Number(e.target.value) || 0)} /></Field>
|
| 124 |
<Field label="叙事视角"><input className="input" value={f.pov} onChange={e => set('pov', e.target.value)} placeholder="第一人称 / 第三人称有限视角" /></Field>
|
| 125 |
-
<Field label="文风" className="span2"><
|
| 126 |
<Field label="一句话梗概" className="span2"><AutoText value={f.premise} onChange={v => set('premise', v)} placeholder="例如:男主回乡参加爷爷葬礼,却发现遗嘱里没有自己的名字。" minRows={3} /></Field>
|
| 127 |
</div>
|
| 128 |
</Modal>
|
|
|
|
| 122 |
<Field label="发布平台"><input className="input" value={f.target_platform} onChange={e => set('target_platform', e.target.value)} /></Field>
|
| 123 |
<Field label="目标字数"><input className="input" type="number" value={f.target_words} onChange={e => set('target_words', Number(e.target.value) || 0)} /></Field>
|
| 124 |
<Field label="叙事视角"><input className="input" value={f.pov} onChange={e => set('pov', e.target.value)} placeholder="第一人称 / 第三人称有限视角" /></Field>
|
| 125 |
+
<Field label="文风" className="span2"><AutoText className="one" minRows={1} value={f.style} onChange={v => set('style', v)} placeholder="现实、克制、快节奏、强钩子…" /></Field>
|
| 126 |
<Field label="一句话梗概" className="span2"><AutoText value={f.premise} onChange={v => set('premise', v)} placeholder="例如:男主回乡参加爷爷葬礼,却发现遗嘱里没有自己的名字。" minRows={3} /></Field>
|
| 127 |
</div>
|
| 128 |
</Modal>
|
ui-src/src/styles.css
CHANGED
|
@@ -152,6 +152,10 @@ ul, ol { margin: 0; padding: 0; }
|
|
| 152 |
.input.auto { width: auto; }
|
| 153 |
select.input { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
|
| 154 |
.textarea { resize: vertical; line-height: 1.7; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
.serif-input { font-family: var(--serif); font-size: 15px; line-height: 1.85; }
|
| 156 |
.title-input { font-family: var(--serif); font-size: 18px; font-weight: 600; }
|
| 157 |
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
@@ -275,7 +279,8 @@ select.input { appearance: none; padding-right: 28px; background-image: linear-g
|
|
| 275 |
.sl-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; border-bottom: 1px dashed var(--line); }
|
| 276 |
.sl-row:hover { background: var(--bg-2); }
|
| 277 |
.sl-dot { color: var(--accent); font-weight: 700; }
|
| 278 |
-
.sl-row .input { flex: 1; font-family: var(--serif); font-size: 14.5px; }
|
|
|
|
| 279 |
.string-list .add-btn { margin-top: 8px; }
|
| 280 |
|
| 281 |
/* ============================================================
|
|
@@ -568,19 +573,20 @@ select.input { appearance: none; padding-right: 28px; background-image: linear-g
|
|
| 568 |
.quote-box { border-left: 3px solid var(--line-2); padding: 8px 12px; background: var(--bg); border-radius: 0 6px 6px 0; font-size: 13px; color: var(--ink-2); line-height: 1.8; }
|
| 569 |
.quote-label { font-size: 11.5px; color: var(--ink-3); margin-bottom: 4px; font-weight: 600; }
|
| 570 |
|
| 571 |
-
.timeline { list-style: none; position: relative; display: flex; flex-direction: column; }
|
| 572 |
-
.timeline::before { content: ""; position: absolute; left: 7px; top:
|
| 573 |
-
.timeline li { position: relative; display: flex; gap: 12px; padding: 8px 0; }
|
|
|
|
| 574 |
.tl-check { position: relative; z-index: 1; width: 15px; height: 15px; flex: none; margin-top: 3px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-2); display: grid; place-items: center; }
|
| 575 |
.tl-check input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
|
| 576 |
-
.timeline li.current .tl-check { border-color: var(--accent); background: var(--accent); }
|
| 577 |
.tl-check:has(input:checked) { border-color: var(--blue); background: var(--blue); }
|
| 578 |
.tl-body { flex: 1; min-width: 0; }
|
| 579 |
.tl-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; font-weight: 600; }
|
| 580 |
.tl-sub { font-size: 12px; color: var(--ink-3); }
|
| 581 |
.tl-summary { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
|
| 582 |
.tl-actions { display: flex; gap: 10px; margin-top: 4px; opacity: .7; }
|
| 583 |
-
.timeline li:hover .tl-actions { opacity: 1; }
|
| 584 |
.version-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--ink-3); margin-bottom: 14px; }
|
| 585 |
.reader-text { font-family: var(--serif); font-size: 15.5px; line-height: 2; white-space: pre-wrap; word-break: break-word; color: var(--ink); }
|
| 586 |
.diff-legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-3); margin-bottom: 10px; }
|
|
@@ -1105,12 +1111,12 @@ select.input { appearance: none; padding-right: 28px; background-image: linear-g
|
|
| 1105 |
.doc-card b { font-family: var(--serif); font-size: 17px; color: var(--ink); }
|
| 1106 |
.doc-card span { font-size: 13px; line-height: 1.7; }
|
| 1107 |
.doc-card:hover { border-color: var(--accent); transform: translateY(-1px); }
|
| 1108 |
-
.timeline { list-style: none; margin: 10px 0 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
|
| 1109 |
-
.timeline li { position: relative; display: grid; grid-template-columns: 96px 1fr; gap: 12px; }
|
| 1110 |
-
.timeline li::before { content: ''; position: absolute; left: -
|
| 1111 |
.tl-date { font-family: var(--mono); font-size: 12px; color: var(--ink-3); padding-top: 2px; }
|
| 1112 |
-
.timeline b { font-size: 14px; }
|
| 1113 |
-
.timeline p { font-size: 13px; line-height: 1.75; color: var(--ink-2); margin-top: 2px; }
|
| 1114 |
.rule-group { margin-top: 8px; }
|
| 1115 |
.rules { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
|
| 1116 |
.rule { padding: 16px 20px; background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: 4px var(--r) var(--r) 4px; display: flex; flex-direction: column; gap: 10px; scroll-margin: 80px; transition: box-shadow .3s, background .3s; }
|
|
@@ -1161,7 +1167,7 @@ select.input { appearance: none; padding-right: 28px; background-image: linear-g
|
|
| 1161 |
.link-btn.inline { margin-left: 6px; font-family: var(--mono); font-size: 11px; }
|
| 1162 |
@media (max-width: 760px) {
|
| 1163 |
.dodont { grid-template-columns: 1fr; }
|
| 1164 |
-
.timeline li { grid-template-columns: 1fr; gap: 2px; }
|
| 1165 |
.map-table td:first-child { width: auto; }
|
| 1166 |
.rule { padding: 14px; }
|
| 1167 |
}
|
|
@@ -1741,3 +1747,68 @@ kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius
|
|
| 1741 |
.peer-row.final p { font-weight: 500; }
|
| 1742 |
.peer-foot { font-size: 11.5px; }
|
| 1743 |
@media (max-width: 640px) { .peer-row { grid-template-columns: 1fr; gap: 2px; } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
.input.auto { width: auto; }
|
| 153 |
select.input { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
|
| 154 |
.textarea { resize: vertical; line-height: 1.7; }
|
| 155 |
+
.textarea.auto-text { overflow-y: auto; }
|
| 156 |
+
.textarea.one { line-height: 1.55; min-height: 36px; }
|
| 157 |
+
.textarea.bare { border: 0; background: transparent; box-shadow: none; padding: 2px 0; min-height: 0; }
|
| 158 |
+
.textarea.bare:focus { box-shadow: none; }
|
| 159 |
.serif-input { font-family: var(--serif); font-size: 15px; line-height: 1.85; }
|
| 160 |
.title-input { font-family: var(--serif); font-size: 18px; font-weight: 600; }
|
| 161 |
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
|
|
| 279 |
.sl-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; border-bottom: 1px dashed var(--line); }
|
| 280 |
.sl-row:hover { background: var(--bg-2); }
|
| 281 |
.sl-dot { color: var(--accent); font-weight: 700; }
|
| 282 |
+
.sl-row .input, .sl-row .textarea { flex: 1; font-family: var(--serif); font-size: 14.5px; }
|
| 283 |
+
.sl-row .sl-dot, .sl-row .icon-btn { align-self: flex-start; margin-top: 2px; }
|
| 284 |
.string-list .add-btn { margin-top: 8px; }
|
| 285 |
|
| 286 |
/* ============================================================
|
|
|
|
| 573 |
.quote-box { border-left: 3px solid var(--line-2); padding: 8px 12px; background: var(--bg); border-radius: 0 6px 6px 0; font-size: 13px; color: var(--ink-2); line-height: 1.8; }
|
| 574 |
.quote-label { font-size: 11.5px; color: var(--ink-3); margin-bottom: 4px; font-weight: 600; }
|
| 575 |
|
| 576 |
+
.timeline.vt { list-style: none; position: relative; display: flex; flex-direction: column; margin: 0; padding: 0; border: 0; gap: 0; }
|
| 577 |
+
.timeline.vt::before { content: ""; position: absolute; left: 7px; top: 14px; bottom: 14px; width: 1px; background: var(--line-2); }
|
| 578 |
+
.timeline.vt li { position: relative; display: flex; gap: 12px; padding: 8px 0; }
|
| 579 |
+
.timeline.vt li::before { content: none; }
|
| 580 |
.tl-check { position: relative; z-index: 1; width: 15px; height: 15px; flex: none; margin-top: 3px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-2); display: grid; place-items: center; }
|
| 581 |
.tl-check input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
|
| 582 |
+
.timeline.vt li.current .tl-check { border-color: var(--accent); background: var(--accent); }
|
| 583 |
.tl-check:has(input:checked) { border-color: var(--blue); background: var(--blue); }
|
| 584 |
.tl-body { flex: 1; min-width: 0; }
|
| 585 |
.tl-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; font-weight: 600; }
|
| 586 |
.tl-sub { font-size: 12px; color: var(--ink-3); }
|
| 587 |
.tl-summary { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
|
| 588 |
.tl-actions { display: flex; gap: 10px; margin-top: 4px; opacity: .7; }
|
| 589 |
+
.timeline.vt li:hover .tl-actions { opacity: 1; }
|
| 590 |
.version-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--ink-3); margin-bottom: 14px; }
|
| 591 |
.reader-text { font-family: var(--serif); font-size: 15.5px; line-height: 2; white-space: pre-wrap; word-break: break-word; color: var(--ink); }
|
| 592 |
.diff-legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-3); margin-bottom: 10px; }
|
|
|
|
| 1111 |
.doc-card b { font-family: var(--serif); font-size: 17px; color: var(--ink); }
|
| 1112 |
.doc-card span { font-size: 13px; line-height: 1.7; }
|
| 1113 |
.doc-card:hover { border-color: var(--accent); transform: translateY(-1px); }
|
| 1114 |
+
.timeline.gt { list-style: none; margin: 10px 0 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
|
| 1115 |
+
.timeline.gt li { position: relative; display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 0; }
|
| 1116 |
+
.timeline.gt li::before { content: ''; position: absolute; left: -21px; top: 5px; width: 12px; height: 12px; box-sizing: border-box; border-radius: 50%; background: var(--paper); border: 2px solid var(--accent); }
|
| 1117 |
.tl-date { font-family: var(--mono); font-size: 12px; color: var(--ink-3); padding-top: 2px; }
|
| 1118 |
+
.timeline.gt b { font-size: 14px; }
|
| 1119 |
+
.timeline.gt p { font-size: 13px; line-height: 1.75; color: var(--ink-2); margin-top: 2px; }
|
| 1120 |
.rule-group { margin-top: 8px; }
|
| 1121 |
.rules { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
|
| 1122 |
.rule { padding: 16px 20px; background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: 4px var(--r) var(--r) 4px; display: flex; flex-direction: column; gap: 10px; scroll-margin: 80px; transition: box-shadow .3s, background .3s; }
|
|
|
|
| 1167 |
.link-btn.inline { margin-left: 6px; font-family: var(--mono); font-size: 11px; }
|
| 1168 |
@media (max-width: 760px) {
|
| 1169 |
.dodont { grid-template-columns: 1fr; }
|
| 1170 |
+
.timeline.gt li { grid-template-columns: 1fr; gap: 2px; }
|
| 1171 |
.map-table td:first-child { width: auto; }
|
| 1172 |
.rule { padding: 14px; }
|
| 1173 |
}
|
|
|
|
| 1747 |
.peer-row.final p { font-weight: 500; }
|
| 1748 |
.peer-foot { font-size: 11.5px; }
|
| 1749 |
@media (max-width: 640px) { .peer-row { grid-template-columns: 1fr; gap: 2px; } }
|
| 1750 |
+
|
| 1751 |
+
/* ---------- 通读:隐藏侧边栏 ---------- */
|
| 1752 |
+
.shell.reading .rail { display: none !important; }
|
| 1753 |
+
.shell.reading .stage { height: 100%; }
|
| 1754 |
+
.reader { background: var(--rbg, var(--paper)); color: var(--rink, var(--ink)); }
|
| 1755 |
+
.reader.themed .reader-bar { background: color-mix(in srgb, var(--rbg) 92%, var(--rink) 8%); border-bottom-color: color-mix(in srgb, var(--rink) 14%, transparent); color: var(--rink); }
|
| 1756 |
+
.reader.themed .reader-bar .btn.ghost, .reader.themed .reader-where, .reader.themed .reader-where em { color: color-mix(in srgb, var(--rink) 80%, transparent); }
|
| 1757 |
+
.reader.themed .reader-page, .reader.themed .reader-title { color: var(--rink); }
|
| 1758 |
+
.reader.themed .reader-num, .reader.themed .reader-meta, .reader.themed .reader-next-hint { color: color-mix(in srgb, var(--rink) 55%, transparent); }
|
| 1759 |
+
.reader.themed .reader-nav { border-top-color: color-mix(in srgb, var(--rink) 14%, transparent); }
|
| 1760 |
+
.reader.themed .reader-nav .btn.ghost { color: var(--rink); border-color: color-mix(in srgb, var(--rink) 20%, transparent); background: transparent; }
|
| 1761 |
+
.reader.dark .reader-toc, .reader.dark .reader-pop { color-scheme: dark; }
|
| 1762 |
+
.reader-page { position: relative; font-family: var(--rff, var(--serif)); }
|
| 1763 |
+
.reader-title { font-family: var(--rff, var(--serif)); }
|
| 1764 |
+
.reader-body p { line-height: var(--rlh, 1.95); }
|
| 1765 |
+
.reader-page.reviewing .reader-body { cursor: text; }
|
| 1766 |
+
.reader-page .review-tip { font-family: var(--sans); margin: -14px 0 22px; }
|
| 1767 |
+
.reader-bar .btn.on { background: var(--bg-2); }
|
| 1768 |
+
.reader-bar .badge { margin-left: 4px; }
|
| 1769 |
+
.reader-pop { position: absolute; z-index: 30; top: 52px; right: 12px; width: min(380px, calc(100% - 20px)); background: var(--raised); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow-l); }
|
| 1770 |
+
.rs-row { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 10px; padding: 10px 14px; font-size: 13px; }
|
| 1771 |
+
.rs-row > span { color: var(--ink-3); }
|
| 1772 |
+
.rs-ctl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
|
| 1773 |
+
.rs-swatch { min-width: 52px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); font-size: 12px; }
|
| 1774 |
+
.rs-swatch.auto { background: var(--paper); color: var(--ink); }
|
| 1775 |
+
.rs-swatch.on { outline: 2px solid var(--accent); outline-offset: 1px; }
|
| 1776 |
+
.rt-read { font-size: 11px; color: var(--accent); flex: none; }
|
| 1777 |
+
.rt-read.done { color: var(--ink-4); }
|
| 1778 |
+
.reader-note-pop { width: 330px; font-family: var(--sans); font-size: 13px; line-height: 1.7; }
|
| 1779 |
+
.reader-note-pop .rnp-p { margin: 0; white-space: pre-wrap; display: block; }
|
| 1780 |
+
.reader-note-pop .nf-head b { display: inline-flex; align-items: center; gap: 4px; }
|
| 1781 |
+
.reader-body mark.nm, .reader-body mark.dm { cursor: pointer; }
|
| 1782 |
+
.dm-legend mark { font-size: inherit; }
|
| 1783 |
+
|
| 1784 |
+
/* ---------- 分歧标注(只在屏幕上显示,复制 / 发布不带) ---------- */
|
| 1785 |
+
mark.dm { color: inherit; background: color-mix(in srgb, #f2c230 34%, transparent); border-radius: 2px; padding: 0; }
|
| 1786 |
+
mark.nm.dm { box-shadow: inset 0 -0.5em 0 color-mix(in srgb, #f2c230 30%, transparent); }
|
| 1787 |
+
mark.dispute-demo { background: color-mix(in srgb, #f2c230 34%, transparent); color: inherit; border-radius: 2px; padding: 0 2px; }
|
| 1788 |
+
.paper-text-wrap { position: relative; flex: 1 0 auto; display: flex; flex-direction: column; }
|
| 1789 |
+
.paper-text-wrap .paper-text { position: relative; z-index: 1; }
|
| 1790 |
+
.paper-mirror {
|
| 1791 |
+
position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
|
| 1792 |
+
white-space: pre-wrap; overflow-wrap: break-word; word-wrap: break-word;
|
| 1793 |
+
font-family: var(--serif); font-size: var(--fs); line-height: 2.05; letter-spacing: .02em; padding: 18px 0 0; color: transparent;
|
| 1794 |
+
}
|
| 1795 |
+
.paper-mirror mark.dm { color: transparent; }
|
| 1796 |
+
.dispute-tip { margin-top: 14px; font-size: 12px; color: var(--ink-3); text-align: center; font-family: var(--sans); }
|
| 1797 |
+
.dispute-tip .link-btn { margin-left: 6px; }
|
| 1798 |
+
|
| 1799 |
+
/* ---------- 稿纸看到哪儿 ---------- */
|
| 1800 |
+
.eb-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; }
|
| 1801 |
+
.eb-progress i { display: block; height: 100%; background: color-mix(in srgb, var(--accent) 70%, transparent); transition: width .1s linear; }
|
| 1802 |
+
|
| 1803 |
+
/* ---------- 分歧:作者拍板 ---------- */
|
| 1804 |
+
.peer-state { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; margin-left: auto; }
|
| 1805 |
+
.peer-state.todo { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); font-weight: 600; }
|
| 1806 |
+
.peer-state.wait { background: var(--bg-2); color: var(--ink-3); }
|
| 1807 |
+
.peer-quote { font-family: var(--serif); font-size: 13px; padding: 6px 10px; border-radius: 6px; background: color-mix(in srgb, #f2c230 18%, transparent); color: var(--ink-2); }
|
| 1808 |
+
.peer-author { border-top: 1px dashed var(--line); padding-top: 8px; }
|
| 1809 |
+
.peer-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; }
|
| 1810 |
+
.peer-actions .muted:first-child { margin-right: 2px; }
|
| 1811 |
+
.peer-row.author .peer-who { color: var(--warn); }
|
| 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; }
|
ui-src/src/ui.tsx
CHANGED
|
@@ -181,14 +181,26 @@ export function Field({ label, hint, children, className }: { label: React.React
|
|
| 181 |
export function AutoText({ value, onChange, minRows = 2, className, ...rest }: {
|
| 182 |
value: string; onChange: (v: string) => void; minRows?: number; className?: string
|
| 183 |
} & Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onChange'>) {
|
|
|
|
| 184 |
const ref = useRef<HTMLTextAreaElement>(null)
|
| 185 |
-
|
|
|
|
| 186 |
const el = ref.current
|
| 187 |
-
if (!el) return
|
| 188 |
el.style.height = 'auto'
|
| 189 |
-
el.style.height = `${el.scrollHeight + 2}px`
|
| 190 |
-
}
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
|
| 194 |
export function Pager({ page, total, size, onChange }: { page: number; total: number; size: number; onChange: (p: number) => void }) {
|
|
@@ -243,8 +255,9 @@ export function ListEditor({ items, onChange, fields, addLabel, titleKey, empty,
|
|
| 243 |
) : f.long ? (
|
| 244 |
<AutoText value={String(it[f.key] ?? '')} onChange={v => update(i, f.key, v)} placeholder={f.placeholder} minRows={2} />
|
| 245 |
) : (
|
| 246 |
-
|
| 247 |
-
onChange={e => update(i, f.key,
|
|
|
|
| 248 |
)}
|
| 249 |
</label>
|
| 250 |
))}
|
|
@@ -265,7 +278,7 @@ export function StringList({ items, onChange, placeholder, addLabel }: { items:
|
|
| 265 |
{list.map((s, i) => (
|
| 266 |
<div key={i} className="sl-row">
|
| 267 |
<span className="sl-dot">·</span>
|
| 268 |
-
<
|
| 269 |
<button className="icon-btn sm danger" onClick={() => onChange(list.filter((_, j) => j !== i))} aria-label="删除"><X size={14} /></button>
|
| 270 |
</div>
|
| 271 |
))}
|
|
|
|
| 181 |
export function AutoText({ value, onChange, minRows = 2, className, ...rest }: {
|
| 182 |
value: string; onChange: (v: string) => void; minRows?: number; className?: string
|
| 183 |
} & Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onChange'>) {
|
| 184 |
+
// 自动撑高到能显示全部文字;右下角可以往下拖,拖大后的高度会保留
|
| 185 |
const ref = useRef<HTMLTextAreaElement>(null)
|
| 186 |
+
const manual = useRef(0)
|
| 187 |
+
const fit = () => {
|
| 188 |
const el = ref.current
|
| 189 |
+
if (!el || !el.offsetParent) return
|
| 190 |
el.style.height = 'auto'
|
| 191 |
+
el.style.height = `${Math.max(el.scrollHeight + 2, manual.current)}px`
|
| 192 |
+
}
|
| 193 |
+
useEffect(fit, [value])
|
| 194 |
+
useEffect(() => {
|
| 195 |
+
const el = ref.current
|
| 196 |
+
if (!el || typeof ResizeObserver === 'undefined') return
|
| 197 |
+
let w = el.clientWidth
|
| 198 |
+
const ro = new ResizeObserver(() => { if (el.clientWidth !== w) { w = el.clientWidth; fit() } else if (!el.style.height || el.style.height === 'auto') fit() })
|
| 199 |
+
ro.observe(el)
|
| 200 |
+
return () => ro.disconnect()
|
| 201 |
+
}, [])
|
| 202 |
+
const onUp = () => { const el = ref.current; if (el && el.offsetHeight > el.scrollHeight + 4) manual.current = el.offsetHeight }
|
| 203 |
+
return <textarea ref={ref} rows={minRows} className={cx('textarea', 'auto-text', className)} value={value} onChange={e => onChange(e.target.value)} onMouseUp={onUp} onTouchEnd={onUp} {...rest} />
|
| 204 |
}
|
| 205 |
|
| 206 |
export function Pager({ page, total, size, onChange }: { page: number; total: number; size: number; onChange: (p: number) => void }) {
|
|
|
|
| 255 |
) : f.long ? (
|
| 256 |
<AutoText value={String(it[f.key] ?? '')} onChange={v => update(i, f.key, v)} placeholder={f.placeholder} minRows={2} />
|
| 257 |
) : (
|
| 258 |
+
f.type === 'number'
|
| 259 |
+
? <input className="input" type="number" value={it[f.key] ?? ''} placeholder={f.placeholder} onChange={e => update(i, f.key, e.target.value === '' ? '' : Number(e.target.value))} />
|
| 260 |
+
: <AutoText className="one" value={String(it[f.key] ?? '')} onChange={v => update(i, f.key, v)} placeholder={f.placeholder} minRows={1} />
|
| 261 |
)}
|
| 262 |
</label>
|
| 263 |
))}
|
|
|
|
| 278 |
{list.map((s, i) => (
|
| 279 |
<div key={i} className="sl-row">
|
| 280 |
<span className="sl-dot">·</span>
|
| 281 |
+
<AutoText className="bare one" value={s} placeholder={placeholder} minRows={1} onChange={v => onChange(list.map((x, j) => j === i ? v : x))} />
|
| 282 |
<button className="icon-btn sm danger" onClick={() => onChange(list.filter((_, j) => j !== i))} aria-label="删除"><X size={14} /></button>
|
| 283 |
</div>
|
| 284 |
))}
|