feat(web): 审稿改稿闭环——一键采纳/AI改写/正文高亮定位编辑/伏笔确认/草稿自动保存/章节目录
- 冲突「采纳改法」:有补丁瞬时改入终稿并选中;无补丁但可定位则采纳时调 AI(refiner)重写该段套入;定位不到提示手改 - 正文改为行内高亮叠层编辑器(与页面同底色、随内容增高、无滚动条),点冲突卡/锚点整页滚到并选中+闪烁 - 仅对可在正文定位的冲突显示「跳转」/锚点;locate 支持从 where 引号抽原文,杜绝定位失败刷屏 - 伏笔建议卡:新埋一键登记(预填表单)/ 疑似回收一键标记 CLOSED(复用现有端点) - 审稿页草稿自动保存(防抖 PUT /draft),与「验收本章」解耦,刷新不丢 - 写作路由带章号 ?chapter=N + 验收成功面板/大纲页「写下一章」入口;写作目录从大纲列出全部章节 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,8 +25,12 @@ import {
|
||||
groupConflicts,
|
||||
nextUnresolvedInOrder,
|
||||
} from "@/lib/review/grouping";
|
||||
import { applyConflictFix } from "@/lib/review/applyFix";
|
||||
import { locateInDraft } from "@/lib/review/locate";
|
||||
import { conflictSnippet } from "@/lib/review/snippet";
|
||||
import { useAccept } from "@/lib/review/useAccept";
|
||||
import { useAutosave } from "@/lib/autosave/useAutosave";
|
||||
import { useRefine } from "@/lib/style/useRefine";
|
||||
import { useReviewStream } from "@/lib/review/useReviewStream";
|
||||
import type { ReviewConflict, StyleDriftSegment } from "@/lib/review/sse";
|
||||
import { normalizeStyleDrift } from "@/lib/style/style";
|
||||
@@ -58,6 +62,10 @@ export function ReviewReport({
|
||||
}: ReviewReportProps) {
|
||||
const review = useReviewStream();
|
||||
const accept = useAccept();
|
||||
const conflictFix = useRefine(); // 采纳无补丁冲突时,临时调 AI 重写定位段
|
||||
// 审稿页草稿自动保存:采纳/手改/AI 改写后防抖 PUT /draft,改动随时留存、刷新不丢
|
||||
// (与「验收本章」解耦——验收前也能保存,修「采纳后没保存」)。
|
||||
const autosave = useAutosave(project.id, chapterNo, initialDraft);
|
||||
const toast = useToast();
|
||||
|
||||
const [finalText, setFinalText] = useState(initialDraft);
|
||||
@@ -66,6 +74,10 @@ export function ReviewReport({
|
||||
);
|
||||
const [focusedIndex, setFocusedIndex] = useState<number | null>(null);
|
||||
const [missing, setMissing] = useState<Set<number>>(new Set());
|
||||
// 正在 AI 改写的冲突下标(采纳无补丁 → 调 refine 重写定位段;用于卡片 loading/禁用)。
|
||||
const [rewriting, setRewriting] = useState<Set<number>>(new Set());
|
||||
// 可编辑终稿 textarea 引用:供「跳转」/采纳后在正文里选中定位问题区域。
|
||||
const editorRef = useRef<HTMLTextAreaElement>(null);
|
||||
// 回炉中的漂移段(null=未打开 RefineView)。
|
||||
const [refineSegment, setRefineSegment] = useState<StyleDriftSegment | null>(
|
||||
null,
|
||||
@@ -130,6 +142,18 @@ export function ReviewReport({
|
||||
}
|
||||
}, [review.state.phase, conflictCount]);
|
||||
|
||||
// 终稿改动(采纳/手改/AI 改写/直接编辑均经 setFinalText)→ 防抖自动保存草稿。
|
||||
// 跳过首帧:初值=已存草稿,useAutosave 基线即它,无需保存。
|
||||
const autosaveOnChange = autosave.onChange;
|
||||
const skipFirstAutosave = useRef(true);
|
||||
useEffect(() => {
|
||||
if (skipFirstAutosave.current) {
|
||||
skipFirstAutosave.current = false;
|
||||
return;
|
||||
}
|
||||
autosaveOnChange(finalText);
|
||||
}, [finalText, autosaveOnChange]);
|
||||
|
||||
const onReReview = (): void => {
|
||||
setMissing(new Set());
|
||||
void review.start(project.id, chapterNo, finalText);
|
||||
@@ -143,6 +167,65 @@ export function ReviewReport({
|
||||
next.delete(index);
|
||||
return next;
|
||||
});
|
||||
// 采纳改法:①带预出补丁(original→replacement)→ 瞬时改入终稿并选中;
|
||||
// ②有补丁但原文找不到(已手改/漂移)→ 提示手改;③无补丁但能在正文定位 →
|
||||
// 临时调 AI 重写该段并套入;④定位不到(摘要/跨章)→ 提示手改或忽略。
|
||||
if (verdict === "accept") {
|
||||
const c = conflicts[index];
|
||||
if (c) {
|
||||
const out = applyConflictFix(finalText, c.original, c.replacement);
|
||||
if (out.status === "applied") {
|
||||
const at = finalText.indexOf(c.original ?? "");
|
||||
setFinalText(out.text);
|
||||
toast("已采纳改入终稿,验收时请复核。", "success");
|
||||
if (at !== -1 && c.replacement) {
|
||||
selectRegionSoon(at, at + c.replacement.length, index);
|
||||
}
|
||||
} else if (out.status === "not-found") {
|
||||
toast("未在终稿中找到原文(可能已手改),请在左侧正文手改。", "error");
|
||||
} else {
|
||||
void aiFixOnAccept(index, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 无预出补丁的冲突,采纳时临时调 AI(refiner)重写定位到的那段原文,套入终稿并选中。
|
||||
// 定位不到(多为摘要/跨章问题)→ 不调 AI,提示手改/忽略。复用既有 refine 端点(不变量#3)。
|
||||
const aiFixOnAccept = async (
|
||||
index: number,
|
||||
c: ReviewConflict,
|
||||
): Promise<void> => {
|
||||
const loc = locateInDraft(finalText, c);
|
||||
if (loc === null) {
|
||||
toast("这条无法在正文定位(多为摘要/跨章问题),请手改或忽略。", "info");
|
||||
return;
|
||||
}
|
||||
const prevText = finalText;
|
||||
const segment = prevText.slice(loc.start, loc.end);
|
||||
setRewriting((s) => new Set(s).add(index));
|
||||
const res = await conflictFix.refine(
|
||||
project.id,
|
||||
chapterNo,
|
||||
segment,
|
||||
c.suggestion,
|
||||
);
|
||||
setRewriting((s) => {
|
||||
const next = new Set(s);
|
||||
next.delete(index);
|
||||
return next;
|
||||
});
|
||||
if (!res) return; // useRefine 已就失败 toast
|
||||
const at = prevText.indexOf(segment);
|
||||
if (at === -1) {
|
||||
toast("正文已变动,未能自动套用,请手改。", "error");
|
||||
return;
|
||||
}
|
||||
const next =
|
||||
prevText.slice(0, at) + res.refined + prevText.slice(at + segment.length);
|
||||
setFinalText(next);
|
||||
toast("已用 AI 改写并套入正文,请复核。", "success");
|
||||
selectRegionSoon(at, at + res.refined.length, index);
|
||||
};
|
||||
const onNote = (index: number, note: string): void =>
|
||||
setDrafts((prev) => setNote(prev, index, note));
|
||||
@@ -150,6 +233,14 @@ export function ReviewReport({
|
||||
// R2:按 type 分组 + 严重度排序(仅改显示顺序,每条仍携原始 index)。
|
||||
const groups = useMemo(() => groupConflicts(conflicts), [conflicts]);
|
||||
const order = useMemo(() => displayOrder(groups), [groups]);
|
||||
// 能在当前终稿里定位的冲突下标集合——只对这些显示「跳转」/锚点,避免点了定位不到刷错误提示。
|
||||
const locatable = useMemo(() => {
|
||||
const s = new Set<number>();
|
||||
conflicts.forEach((c, i) => {
|
||||
if (locateInDraft(finalText, c) !== null) s.add(i);
|
||||
});
|
||||
return s;
|
||||
}, [conflicts, finalText]);
|
||||
|
||||
const jumpToCard = (index: number): void => {
|
||||
setFocusedIndex(index);
|
||||
@@ -167,11 +258,54 @@ export function ReviewReport({
|
||||
}
|
||||
jumpToCard(next);
|
||||
};
|
||||
const jumpToAnchor = (index: number): void => {
|
||||
// 把命中区滚到视野(页面级 scrollIntoView,无内部滚动条);有对应 <mark> 用它居中,
|
||||
// 否则退回滚动编辑器本体。instant 滚动,天然尊重 prefers-reduced-motion。
|
||||
const scrollRegionIntoView = (index?: number): void => {
|
||||
const mark =
|
||||
index !== undefined
|
||||
? document.getElementById(`draft-mark-${index}`)
|
||||
: null;
|
||||
if (mark) {
|
||||
mark.scrollIntoView({ block: "center", behavior: "auto" });
|
||||
} else {
|
||||
editorRef.current?.scrollIntoView({ block: "center", behavior: "auto" });
|
||||
}
|
||||
};
|
||||
|
||||
// 在正文里选中 [start,end) 并滚动到视野;下一帧执行(等 value 落定)。
|
||||
const selectRegionSoon = (start: number, end: number, index?: number): void => {
|
||||
requestAnimationFrame(() => {
|
||||
const el = editorRef.current;
|
||||
if (!el) return;
|
||||
el.focus();
|
||||
el.setSelectionRange(start, end);
|
||||
scrollRegionIntoView(index);
|
||||
});
|
||||
};
|
||||
|
||||
// 闪烁高亮 <mark>(朱砂脉冲 0.9s);尊重 prefers-reduced-motion(CSS 内降级为描边)。
|
||||
const flashMark = (index: number): void => {
|
||||
const mark = document.getElementById(`draft-mark-${index}`);
|
||||
if (!mark) return;
|
||||
mark.classList.add("draft-mark-flash");
|
||||
window.setTimeout(() => mark.classList.remove("draft-mark-flash"), 900);
|
||||
};
|
||||
|
||||
// 跳转/锚点:在可编辑正文里定位、选中并滚动到该冲突对应区域 + 闪烁;定位不到则提示手动查找。
|
||||
const focusRegion = (index: number): void => {
|
||||
setFocusedIndex(index);
|
||||
document
|
||||
.getElementById(`anchor-${index}`)
|
||||
?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
const c = conflicts[index];
|
||||
const el = editorRef.current;
|
||||
if (!c || !el) return;
|
||||
const loc = locateInDraft(finalText, c);
|
||||
if (loc === null) {
|
||||
toast("未能在正文中定位该处,可能已改动,请手动查找。", "error");
|
||||
return;
|
||||
}
|
||||
el.focus();
|
||||
el.setSelectionRange(loc.start, loc.end);
|
||||
scrollRegionIntoView(index);
|
||||
flashMark(index);
|
||||
};
|
||||
|
||||
const onAccept = async (): Promise<void> => {
|
||||
@@ -252,26 +386,26 @@ export function ReviewReport({
|
||||
) : null}
|
||||
|
||||
<div className="flex-1 overflow-auto px-6 py-6">
|
||||
<div className="mb-2 flex items-start justify-between gap-3">
|
||||
<p className="text-xs text-ink-soft">
|
||||
可直接在下方正文修改(改动自动保存草稿 — 摘要从终稿提炼);点冲突的「跳转」或顶部锚点定位到对应文字。
|
||||
</p>
|
||||
<span className="shrink-0 font-mono text-xs text-ink-soft">
|
||||
{autosave.status === "saving"
|
||||
? "保存中…"
|
||||
: autosave.status === "error"
|
||||
? "保存失败"
|
||||
: (autosave.savedLabel ?? "")}
|
||||
</span>
|
||||
</div>
|
||||
<AnnotatedText
|
||||
text={finalText}
|
||||
value={finalText}
|
||||
onChange={setFinalText}
|
||||
conflicts={conflicts}
|
||||
focusedIndex={focusedIndex}
|
||||
onAnchorClick={jumpToCard}
|
||||
onAnchorClick={focusRegion}
|
||||
editorRef={editorRef}
|
||||
/>
|
||||
<details className="mt-4">
|
||||
<summary className="cursor-pointer text-xs text-ink-soft hover:text-cinnabar">
|
||||
展开/编辑终稿(裁决时可改稿 — 摘要从终稿提炼)
|
||||
</summary>
|
||||
<label htmlFor="final-text" className="sr-only">
|
||||
终稿正文
|
||||
</label>
|
||||
<textarea
|
||||
id="final-text"
|
||||
value={finalText}
|
||||
onChange={(e) => setFinalText(e.target.value)}
|
||||
className="mt-2 min-h-[20vh] w-full resize-y rounded border border-line bg-panel p-3 font-serif text-[16px] leading-[1.9] text-ink focus:border-cinnabar focus:outline-none"
|
||||
/>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -341,9 +475,11 @@ export function ReviewReport({
|
||||
draft={drafts[i] ?? { verdict: null, note: "" }}
|
||||
missing={missing.has(i)}
|
||||
snippet={conflictSnippet(finalText, c.where)}
|
||||
locatable={locatable.has(i)}
|
||||
rewriting={rewriting.has(i)}
|
||||
onVerdict={onVerdict}
|
||||
onNote={onNote}
|
||||
onJump={jumpToAnchor}
|
||||
onJump={focusRegion}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
@@ -357,6 +493,8 @@ export function ReviewReport({
|
||||
<ForeshadowSuggestions
|
||||
suggestions={foreshadow}
|
||||
incomplete={sectionStatus("foreshadow") === "incomplete"}
|
||||
projectId={project.id}
|
||||
chapterNo={chapterNo}
|
||||
/>
|
||||
<PacePanel
|
||||
pace={pace}
|
||||
@@ -380,6 +518,8 @@ export function ReviewReport({
|
||||
|
||||
<section className="mt-4">
|
||||
<AcceptPanel
|
||||
projectId={project.id}
|
||||
chapterNo={chapterNo}
|
||||
conflictCount={conflictCount}
|
||||
unresolvedCount={resolved ? 0 : unresolved}
|
||||
foreshadowCount={foreshadow.length}
|
||||
|
||||
Reference in New Issue
Block a user