Files
writer-work-flow/apps/web/lib/outline/outline.ts
Yaojia Wang bf39f50b2f fix(qa): 实施 4 组设计型 QA 项——规则删除/codex 角色/大纲卷过滤/文风回炉锚点
#5 规则 DELETE + id:暴露 RuleView.id(PK);新增 DELETE /projects/{id}/rules/{rule_id}
  (项目/规则不存在→404,成功→204,按 (id,project_id) 限定);rule_repo 加
  list_for_project/delete;RulesPage 每条加删除(乐观删+回滚+toast)。assemble 侧
  RuleView(缓存前缀)不动,列表另立 RuleListItemView。
#7 codex 角色 relations:写侧本已持久化、读端点 _existing_characters 硬编码 []。
  加 _relations_from_jsonb 解析 {name,kind,note},CodexPage 渲染关系 chip。
#8 角色入库幂等:SqlCharacterWriteRepo.create 改 (project_id,name) app 层 upsert——
  重复入库改更新而非插入;不加 UNIQUE/迁移(线上已有重复行会让约束迁移失败)。
#1 大纲卷过滤:GET /outline 支持可选 ?volume(无参=全部,向后兼容);OutlineEditor
  加「查看:全部/卷N」筛选,与生成目标卷解耦。
H3/#9 文风回炉锚点:StyleDriftSegment 加 text(逐字命中段),style.md 指示审稿输出;
  前端按内容锚点定位回炉目标(idx 仅排序),命中失败 → 提示「无法定位该段」而非
  静默 no-op。style golden fixture 已重生成。

契约变更已 pnpm gen:api(RuleView.id / DELETE rules / outline ?volume)。无迁移
(alembic 无漂移)。门禁绿:ruff/mypy(210)/alembic/pytest 760 · 前端 tsc/lint/vitest 329。
2026-06-25 12:53:03 +02:00

72 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 大纲编辑器纯逻辑按卷分组、伏笔窗口徽标文案、接近回收窗口提示UX §6.7)。
// OutlineChapterView/ForeshadowWindowView 已由 OpenAPI 强类型,无需手动收窄。
import type { ForeshadowWindowView, OutlineChapterView } from "@/lib/api/types";
export interface VolumeGroup {
volume: number;
chapters: OutlineChapterView[];
}
// 按 volume 分组(保持章号升序);卷号升序。
export function groupByVolume(
chapters: readonly OutlineChapterView[] | undefined,
): VolumeGroup[] {
const byVolume = new Map<number, OutlineChapterView[]>();
for (const ch of chapters ?? []) {
const list = byVolume.get(ch.volume) ?? [];
byVolume.set(ch.volume, [...list, ch]);
}
return [...byVolume.entries()]
.sort(([a], [b]) => a - b)
.map(([volume, list]) => ({
volume,
chapters: [...list].sort((a, b) => a.no - b.no),
}));
}
// 视图卷过滤值:"all" = 全部卷;具体数字 = 只看该卷(对齐后端 GET ?volume
export type ViewVolume = number | "all";
// 已存大纲里出现过的卷号(升序、去重)——驱动「全部 / 卷 N」选择器选项。
export function distinctVolumes(
chapters: readonly OutlineChapterView[] | undefined,
): number[] {
const seen = new Set<number>();
for (const ch of chapters ?? []) seen.add(ch.volume);
return [...seen].sort((a, b) => a - b);
}
// 按视图卷过滤:选「全部」返回全部,选具体卷只留该卷(客户端过滤,避免重复请求)。
export function filterByViewVolume(
chapters: readonly OutlineChapterView[] | undefined,
view: ViewVolume,
): OutlineChapterView[] {
const all = [...(chapters ?? [])];
if (view === "all") return all;
return all.filter((ch) => ch.volume === view);
}
// 伏笔窗口徽标文案:`⚑ F-012 (40-60)` / `⚑ F-012 (≤60)` / `⚑ F-012`。
export function windowBadgeLabel(window: ForeshadowWindowView): string {
const from = window.expected_close_from;
const to = window.expected_close_to;
if (typeof from === "number" && typeof to === "number") {
return `${window.code} (${from}-${to})`;
}
if (typeof to === "number") return `${window.code} (≤${to})`;
if (typeof from === "number") return `${window.code} (≥${from})`;
return `${window.code}`;
}
// 接近回收:本章号落在窗口 [from,to] 内提示「本章可回收」UX §6.7 ⚑ 可回收)。
export function isCloseWindow(
chapter: OutlineChapterView,
window: ForeshadowWindowView,
): boolean {
const to = window.expected_close_to;
if (typeof to !== "number") return false;
const from = window.expected_close_from ?? to;
return chapter.no >= from && chapter.no <= to;
}