forked from longtao.wu/droboticflow
🔀 07: merge review target interaction and mode headers into rework-ux-adjust
This commit is contained in:
commit
e3b0f5e177
@ -1,6 +1,6 @@
|
||||
# Ticket 07: 审核意见目标交互重做 + 四面模式头调整
|
||||
|
||||
Status: ready(依赖 06 合入后开工)
|
||||
Status: resolved(2026-10-14,`codex/rua-07` @ `7df73dbc`,基线 4b00fba3 未漂移无合并,闸门全绿见 Answer)
|
||||
Priority: P1(第二轮增补,用户 2026-10-14 晚拍板)
|
||||
Spec: D5(修订版)、D9、US26/US27
|
||||
|
||||
@ -21,13 +21,56 @@ Spec: D5(修订版)、D9、US26/US27
|
||||
|
||||
## 验收
|
||||
|
||||
- [ ] Ctrl+↑/↓ 三档切换到头停住;目标随播放头位置正确推导(跨片/跨动作边界移动后刷新)
|
||||
- [ ] F 直写零弹窗;Ctrl+Enter 提交成功;重复/非法校验行为不回退
|
||||
- [ ] 作用域选择弹层全删;四面(审核普通/专注、返工普通/专注)无死入口、帮助行新语义一致
|
||||
- [ ] G / J/K / 1/2 键行为不回退;既有意见列表键盘遍历已移除
|
||||
- [ ] 纯函数 seam:目标推导+切换次序表驱动;键位映射表新语义断言;四面模式头源码守卫
|
||||
- [ ] 双闸门按名对比基线零新增;lint/format 干净
|
||||
- [x] Ctrl+↑/↓ 三档切换到头停住;目标随播放头位置正确推导(跨片/跨动作边界移动后刷新)
|
||||
- [x] F 直写零弹窗;Ctrl+Enter 提交成功;重复/非法校验行为不回退
|
||||
- [x] 作用域选择弹层全删;四面(审核普通/专注、返工普通/专注)无死入口、帮助行新语义一致
|
||||
- [x] G / J/K / 1/2 键行为不回退;既有意见列表键盘遍历已移除
|
||||
- [x] 纯函数 seam:目标推导+切换次序表驱动;键位映射表新语义断言;四面模式头源码守卫
|
||||
- [x] 双闸门按名对比基线零新增;lint/format 干净
|
||||
|
||||
## Answer
|
||||
|
||||
(实施后填写)
|
||||
**实施**:`codex/rua-07` @ `7df73dbc`(基线=集成分支 tip `4b00fba3`,收尾复核未漂移、无合并;未 push)。提交:`7e700c4c` 认领 → `7df73dbc` 实现+测试(TDD 红→绿)。
|
||||
|
||||
### 改动文件与决策落点
|
||||
|
||||
| 文件 | 决策落点 |
|
||||
|---|---|
|
||||
| `src/lib/review-navigation.js` | 目标模型纯函数(票 05 导航序骨架重写):`reviewTargetScopes` 三档次序;`reviewTargetOptions(position)` 播放头→可用档(切片需画面就绪、动作另需含播放头、时间点需画面+数值时间,与 opinionTarget 契约最小镜像);`nextReviewTargetScope` 档位循环(↓ 正向 切片→动作→时间点、↑ 反向;**空档就近跳过**;两端停住返回 null;未知档按方向进入序列);`reviewTargetPosition` 时间点档=冻结锚点、其余=实时画面、无锚点退回实时;`defaultReviewScope` 沿用 05 |
|
||||
| `src/hooks/useReviewDraft.ts` | **picker 全删**(`m.picker`/`ReviewScopePicker`/`confirmScope`/`moveScope`/`cancelScope`/`scopeOptions`/`scopeChoices`/`scopePicker` 及全部守卫);新增 `m.targetAnchor`(时间点档冻结画面);`beginProblem(position, scope?)`=F 直写:暂停定位→当前选中档(未选按画面默认)→该档无目标按画面兜底→直接开编辑器聚焦;`switchTarget(direction)` 取代 `navigateSelection`(纯函数切档+park 驻留未保存文字+切入时间点档冻结锚点);`selectProblem` 选中时间点条目即以该意见记录位置设锚;`selectScope`/`requestDelete`/`editSelected`/`residentEditor` 全部锚点感知;`m.selectedProblem` 随条目遍历一并移除 |
|
||||
| `src/components/ReviewProblemPanel.tsx` | radiogroup 弹层与 scopeRef 焦点效应删除;常驻编辑区显示「当前目标:当前切片/当前动作/当前时间点 · {目标说明}」(`targetTierNames`);卡片 aria-selected 认有效档(显式选中或常驻绑定档);清除按钮可用性跟有效档 |
|
||||
| `src/lib/review-shortcuts.js` | 命令 `previous-problem`/`next-problem` → `previous-target`/`next-target`;帮助表重写(D9):Ctrl+↑/↓=切换意见目标、F=直接填写、Ctrl+Enter=提交、Esc 去「退出范围选择」、G 行去过时的「不占用卡片导航」注 |
|
||||
| `src/components/review-viewing.ts` | 契约:`onReviewProblemNavigate` → `onReviewTargetSwitch`(注释改目标切换语义);`onReviewProblem` 增可选 `scope`(供显式入口指定目标档) |
|
||||
| `src/components/CaptureAnnotationWorkbench.tsx` / `FinalAcceptanceWorkspace.tsx` | 分发改名接线;「切片问题备注」按钮显式传 `scope="slice"`(防当前档为时间点时误入错档) |
|
||||
| `src/pages/AnnotationOperations.tsx` | 两处接线 `onReviewTargetSwitch={reviewDraft.switchTarget}` |
|
||||
|
||||
### 判断性决定(供 review 检验)
|
||||
|
||||
1. **空档跳过**:播放头不在任何动作内时动作档不可用,切换就近跳到下一可用档(沿用旧弹层 scopeOptions 过滤先例),不停在无目标档上。
|
||||
2. **锚点=切入时刻**(WYSIWYG):切入时间点档的瞬间冻结画面(Ctrl+↑/↓ 切入、F 首次落入、选中时间点条目各按当时画面/记录位置);已在时间点档时编辑所显示的锚定目标、不随播放头漂移——重新锚定=切走再切回。无显式切入前(页面初载)时间点档退回实时画面,目标随播放头。
|
||||
3. **F 不重冻结**:时间点档已显示锚定目标时,F 编辑该目标(所见即所编);「发起时锚定」体现在切入时刻而非 F 时刻。
|
||||
4. **命令改名**:键表命令与 prop 随语义改名(previous-target/onReviewTargetSwitch),防过时命名误导后续维护。
|
||||
5. **四面对齐方式**:四面共用工作台帮助对话框的 `reviewShortcutHelp` 单源(专注/普通、首检/返工双板同渲染路径),改一处即四面一致;源码守卫钉住帮助表三行新语义+全 src 无过时文案。
|
||||
|
||||
### 被取代断言清单(scope-cycle-inline-editor.test.mjs 迁移记录)
|
||||
|
||||
- **删除**(被 review-target-interaction.test.mjs 的目标档表驱动取代):`navigation order: target-bearing cards first…`、`next entry: walks slice→action→timestamps…` 两例。
|
||||
- **保留原样**:`default scope: action→action…`(defaultReviewScope 未变);`expander, summary UI…removed`;`resident inline editor promotes…on focus`。
|
||||
- **改写**:`source guard: hook wires D5 navigation order…` → 目标模型接线(reviewTargetPosition/锚点/档位);`shortcut help describes the slice→action→timestamp cycle` → 新语义(切换意见目标/零弹窗)。
|
||||
- 另更新 `review-shortcuts.test.mjs` 3 处命令名断言(previous/next-problem → previous/next-target)。
|
||||
|
||||
### 闸门(真实退出码,最终提交态复跑)
|
||||
|
||||
| 闸门 | 结果 |
|
||||
|---|---|
|
||||
| `npm run test:frontend:gate` | **exit 0**,14 failures all in baseline(按名对比零新增) |
|
||||
| `npm run lint:web`(tsc --noEmit) | **exit 0** |
|
||||
| `npm run format:check` | **exit 0**(含改动文件零新增告警) |
|
||||
| Go 闸门 | **有据跳过**——`4b00fba3..HEAD` 零 `.go` 文件改动 |
|
||||
| 新钉子单跑(3 文件) | **20 pass / 0 fail**(review-target-interaction 9 例 + scope-cycle-inline-editor 5 例 + review-shortcuts 6 例) |
|
||||
|
||||
### 给 merger 的提示
|
||||
|
||||
- 与 03/05 同文件(useReviewDraft.ts / ReviewProblemPanel.tsx / review-shortcuts.js),本票基于含 05 的集成 tip 开工,语义**取代** 05 的条目导航——合并顺序必须在 05 之后;03 的作用域收敛(slice/action/timestamp)与本票正交。
|
||||
- 契约面变更:`ReviewViewingProps.onReviewProblemNavigate` 改名 `onReviewTargetSwitch`、`onReviewProblem` 增可选第二参——若有分支沿用旧名,tsc 会直接报出。
|
||||
- 后端契约零改动(三档作用域早已存在);时间点意见身份(来源+规范帧)不变,冻结锚点只影响前端目标解析。
|
||||
|
||||
@ -367,7 +367,7 @@ export function CaptureAnnotationWorkbench({
|
||||
onReviewController,
|
||||
onReviewProblem,
|
||||
onReviewSave,
|
||||
onReviewProblemNavigate,
|
||||
onReviewTargetSwitch,
|
||||
onReviewReworkNavigate,
|
||||
onReviewReworkVerdict,
|
||||
onReviewTimestampJump,
|
||||
@ -3123,8 +3123,9 @@ export function CaptureAnnotationWorkbench({
|
||||
const position = reviewController.pauseAndLocate();
|
||||
if (position) onReviewProblem?.(position);
|
||||
} else if (command === "save-note") onReviewSave?.();
|
||||
else if (command === "previous-problem" || command === "next-problem")
|
||||
onReviewProblemNavigate?.(command === "previous-problem" ? -1 : 1);
|
||||
else if (command === "previous-target" || command === "next-target")
|
||||
// 票 07(D5 修订版):Ctrl/⌘+↑/↓ 切换写意见的目标档(页面侧解析三档与锚点)。
|
||||
onReviewTargetSwitch?.(command === "previous-target" ? -1 : 1);
|
||||
else if (command === "jump-timestamp-problem") onReviewTimestampJump?.();
|
||||
else if (command === "next-rework-opinion" || command === "previous-rework-opinion")
|
||||
// 返修接收视图 J/K:定位由页面绑 ReviewViewingController 原语(票 08)。
|
||||
@ -4165,7 +4166,7 @@ export function CaptureAnnotationWorkbench({
|
||||
disabled={reviewWriteLocked}
|
||||
onClick={() => {
|
||||
if (reviewProblemPanel) {
|
||||
onReviewProblem?.({ ...reviewPosition, actionId: null });
|
||||
onReviewProblem?.({ ...reviewPosition, actionId: null }, "slice");
|
||||
return;
|
||||
}
|
||||
const note = parsedQAComments.find(
|
||||
|
||||
@ -89,7 +89,7 @@ export function FinalAcceptanceWorkspace({
|
||||
onReviewController,
|
||||
onReviewProblem,
|
||||
onReviewSave,
|
||||
onReviewProblemNavigate,
|
||||
onReviewTargetSwitch,
|
||||
onReviewTimestampJump,
|
||||
onReviewProblemEdit,
|
||||
onReviewProblemDelete,
|
||||
@ -551,8 +551,8 @@ export function FinalAcceptanceWorkspace({
|
||||
const position = finalController.pauseAndLocate();
|
||||
if (position) onReviewProblem?.(position);
|
||||
} else if (command === "save-note") onReviewSave?.();
|
||||
else if (command === "previous-problem" || command === "next-problem")
|
||||
onReviewProblemNavigate?.(command === "previous-problem" ? -1 : 1);
|
||||
else if (command === "previous-target" || command === "next-target")
|
||||
onReviewTargetSwitch?.(command === "previous-target" ? -1 : 1);
|
||||
else if (command === "jump-timestamp-problem") onReviewTimestampJump?.();
|
||||
else if (command === "edit-problem") onReviewProblemEdit?.();
|
||||
else if (command === "delete-problem") onReviewProblemDelete?.();
|
||||
@ -670,7 +670,7 @@ export function FinalAcceptanceWorkspace({
|
||||
onReviewPositionChange={mappedPosition}
|
||||
onReviewProblem={(position) => onReviewProblem?.(mapReviewPosition(position))}
|
||||
onReviewSave={onReviewSave}
|
||||
onReviewProblemNavigate={onReviewProblemNavigate}
|
||||
onReviewTargetSwitch={onReviewTargetSwitch}
|
||||
onReviewTimestampJump={onReviewTimestampJump}
|
||||
onReviewProblemEdit={onReviewProblemEdit}
|
||||
onReviewProblemDelete={onReviewProblemDelete}
|
||||
|
||||
@ -11,19 +11,16 @@ type Props = {
|
||||
focusedProblemId?: string | null;
|
||||
};
|
||||
const names = { task: "整体意见", slice: "当前切片意见", action: "当前动作意见", timestamp: "时间点意见" };
|
||||
const scopes = { task: "整体", slice: "切片", action: "动作", timestamp: "时间点" };
|
||||
// 票 07(D5 修订版):常驻编辑区的目标档位标签——切到哪档显示哪档。
|
||||
const targetTierNames = { slice: "当前切片", action: "当前动作", timestamp: "当前时间点" };
|
||||
export function ReviewProblemPanel({ review, label, writeLocked = false, focusedProblemId = null }: Props) {
|
||||
const locked = writeLocked || !review.writable || review.loading || !review.draft;
|
||||
const scopeRef = useRef<HTMLDivElement>(null),
|
||||
clearRef = useRef<HTMLDivElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
scopeRef.current?.querySelector<HTMLButtonElement>('[aria-checked="true"]')?.focus();
|
||||
}, [review.scopePicker]);
|
||||
const clearRef = useRef<HTMLDivElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
if (review.confirmClear) clearRef.current?.querySelector<HTMLButtonElement>("[data-cancel]")?.focus();
|
||||
}, [review.confirmClear]);
|
||||
// D5(票 05):编辑器常驻内联——无打开编辑器时绑定默认作用域(按当前目标自动匹配)。
|
||||
const resident = review.editor || review.scopePicker || review.confirmClear || locked ? null : review.residentEditor;
|
||||
// 票 07:编辑器常驻内联,绑定当前所选目标档(未选按画面默认);无弹层。
|
||||
const resident = review.editor || review.confirmClear || locked ? null : review.residentEditor;
|
||||
return (
|
||||
<section
|
||||
aria-label="审查问题草稿"
|
||||
@ -52,7 +49,7 @@ export function ReviewProblemPanel({ review, label, writeLocked = false, focused
|
||||
key={card.scope}
|
||||
data-opinion-scope={card.scope}
|
||||
data-review-focus={cardFocused || undefined}
|
||||
aria-selected={review.selectedScope === card.scope}
|
||||
aria-selected={review.selectedScope === card.scope || resident?.scope === card.scope}
|
||||
disabled={locked || !card.target}
|
||||
onClick={() => review.selectScope(card.scope, true)}
|
||||
ref={cardFocused ? (node) => node?.scrollIntoView({ block: "nearest" }) : undefined}
|
||||
@ -112,49 +109,13 @@ export function ReviewProblemPanel({ review, label, writeLocked = false, focused
|
||||
<div className="flex flex-wrap justify-end gap-2 text-xs">
|
||||
<button
|
||||
type="button"
|
||||
disabled={locked || !review.selectedScope || review.saving}
|
||||
disabled={locked || (!review.selectedScope && !review.residentEditor) || review.saving}
|
||||
onClick={() => review.requestDelete()}
|
||||
className="text-rose-600 disabled:text-slate-400"
|
||||
>
|
||||
清除意见
|
||||
</button>
|
||||
</div>
|
||||
{review.scopePicker && (
|
||||
<div
|
||||
ref={scopeRef}
|
||||
role="radiogroup"
|
||||
aria-label="问题范围"
|
||||
className="rounded border border-orange-300 p-2"
|
||||
onKeyDown={(e) => {
|
||||
if (e.nativeEvent.isComposing || e.keyCode === 229 || e.repeat) return;
|
||||
e.stopPropagation();
|
||||
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
||||
e.preventDefault();
|
||||
review.moveScope(e.key === "ArrowUp" ? -1 : 1);
|
||||
} else if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
review.confirmScope();
|
||||
} else if (e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
review.cancelScope();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{(review.scopeChoices ?? review.cards.map((c) => c.scope)).map((scope) => (
|
||||
<button
|
||||
key={scope}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={review.scopePicker?.scope === scope}
|
||||
disabled={!review.scopeOptions(review.scopePicker).includes(scope)}
|
||||
onClick={() => review.confirmScope(scope)}
|
||||
className="block w-full rounded border px-2 py-1 text-left aria-checked:border-orange-500 disabled:opacity-40"
|
||||
>
|
||||
{scopes[scope]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{review.editor ? (
|
||||
<>
|
||||
<p aria-label="批注对象" className="text-xs text-slate-500">
|
||||
@ -208,7 +169,7 @@ export function ReviewProblemPanel({ review, label, writeLocked = false, focused
|
||||
resident && (
|
||||
<>
|
||||
<p aria-label="批注对象" className="text-xs text-slate-500">
|
||||
当前对象:{label(resident.target)}
|
||||
当前目标:{targetTierNames[resident.scope]} · {label(resident.target)}
|
||||
</p>
|
||||
<textarea
|
||||
ref={review.inputRef}
|
||||
|
||||
@ -37,10 +37,18 @@ export type ReviewViewingProps = {
|
||||
onReviewNavigate?: () => void;
|
||||
onReviewPositionChange?: (position: ReviewPosition) => void;
|
||||
onReviewController?: (controller: ReviewViewingController | null) => void;
|
||||
onReviewProblem?: (position: ReviewPosition) => void;
|
||||
/**
|
||||
* F 键(票 07 / D5 修订版):暂停定位后直接开始给当前选中的意见目标写意见,
|
||||
* 页面侧打开常驻编辑器——不再有作用域选择弹层。scope 供显式入口(如「切片
|
||||
* 问题备注」按钮)指定目标档;缺省由页面按当前选中档/画面默认解析。
|
||||
*/
|
||||
onReviewProblem?: (position: ReviewPosition, scope?: "slice" | "action" | "timestamp") => void;
|
||||
onReviewSave?: () => void;
|
||||
/** Saved-problem list keyboard navigation: selects and seeks only, never enters text. */
|
||||
onReviewProblemNavigate?: (direction: -1 | 1) => void;
|
||||
/**
|
||||
* Ctrl/⌘+↑/↓(票 07 / D5 修订版):切换写意见的目标档(当前切片→当前动作→
|
||||
* 当前时间点,随播放头确定,到头停住),纯选择不进文字。
|
||||
*/
|
||||
onReviewTargetSwitch?: (direction: -1 | 1) => void;
|
||||
/**
|
||||
* 返修接收视图 J/K 逐条跳意见(票 08,R2-Q5:a):定位走 ReviewViewingController
|
||||
* 的 seekAction/seekTime/seekSlice 原语。仅 QC 返修接收视图挂载时传入——
|
||||
|
||||
@ -14,13 +14,12 @@ import {
|
||||
opinionCardScopes,
|
||||
opinionGroups,
|
||||
opinionKey,
|
||||
opinionScopes,
|
||||
opinionTarget,
|
||||
replaceOpinion,
|
||||
type OpinionScope,
|
||||
} from "../lib/review-opinions";
|
||||
import { createIdleFlushScheduler } from "../lib/idle-flush-scheduler.js";
|
||||
import { defaultReviewScope, nextReviewNavigationEntry, reviewNavigationOrder } from "../lib/review-navigation.js";
|
||||
import { defaultReviewScope, nextReviewTargetScope, reviewTargetPosition } from "../lib/review-navigation.js";
|
||||
import { REVIEW_DRAFT_AUTOSAVE_IDLE_MS, collectReviewAutosaveTargets } from "../lib/review-draft-autosave.js";
|
||||
import { confirmationsEqual, notelessUnresolvedConfirmation } from "../lib/review-confirmations";
|
||||
|
||||
@ -36,7 +35,6 @@ export type ReviewEditor = ReviewProblem & {
|
||||
isNew: boolean;
|
||||
legacy: boolean;
|
||||
};
|
||||
export type ReviewScopePicker = { position: ReviewPosition; scope: OpinionScope };
|
||||
/**
|
||||
* 写意图。confirmationsOnly(票 10):核对结论专用载具——problems 原样重存
|
||||
* (同文本零变化),仅承载 confirmations 推进草稿版本;editor 此时为 null。
|
||||
@ -66,10 +64,11 @@ const changed = (e: ReviewEditor) => e.text !== e.baseline;
|
||||
const makeModel = () => ({
|
||||
draft: null as ReviewDraft | null,
|
||||
editor: null as ReviewEditor | null,
|
||||
picker: null as ReviewScopePicker | null,
|
||||
selected: null as OpinionScope | null,
|
||||
selectedProblem: null as ReviewProblem | null,
|
||||
position: null as ReviewPosition | null,
|
||||
// 票 07(D5 修订版):时间点档切入时刻冻结的播放头画面(viewAnchor 冻结机制);
|
||||
// 切片/动作档始终按实时画面解析。null=从未显式切入时间点档。
|
||||
targetAnchor: null as ReviewPosition | null,
|
||||
clear: null as ReviewEditor | null,
|
||||
edits: new Map<string, ReviewEditor>(),
|
||||
queue: new Map<string, Intent>(),
|
||||
@ -414,17 +413,17 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
m.editor = null;
|
||||
};
|
||||
const selectScope = (scope: OpinionScope, edit = false) => {
|
||||
const target = opinionTarget(scope, m.position);
|
||||
// 票 07:目标按档位解析用画面(时间点档=冻结锚点,其余=实时播放头)。
|
||||
const target = opinionTarget(scope, reviewTargetPosition(scope, m.position, m.targetAnchor));
|
||||
if (!target) return false;
|
||||
m.selected = scope;
|
||||
m.selectedProblem = null;
|
||||
if (edit) {
|
||||
if (!writable()) {
|
||||
m.message = "当前页面暂时不能修改审核意见。";
|
||||
notify();
|
||||
return false;
|
||||
}
|
||||
if (m.clear || m.picker) return false;
|
||||
if (m.clear) return false;
|
||||
if (m.editor && opinionKey(m.editor) !== opinionKey(target)) park();
|
||||
// A clear confirmation freezes its own target; do not steal its focus.
|
||||
if (m.clear) {
|
||||
@ -438,8 +437,11 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
notify();
|
||||
return true;
|
||||
};
|
||||
// 票 07(D5 修订版):F 直接开始给当前选中的意见目标写意见——暂停定位后不经
|
||||
// 任何弹层直接打开编辑器(作用域选择弹层已删除)。目标 = 当前选中档(未选按
|
||||
// 画面默认);该档此刻无目标时按画面兜底。首次落入时间点档时冻结画面锚点。
|
||||
const beginProblem = useCallback(
|
||||
(position?: ReviewPosition | null) => {
|
||||
(position?: ReviewPosition | null, scope?: OpinionScope) => {
|
||||
if (!writable() || m.clear) return false;
|
||||
const p = position || controller.current?.pauseAndLocate();
|
||||
if (!p) {
|
||||
@ -453,27 +455,25 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
return false;
|
||||
}
|
||||
m.position = p;
|
||||
// D5(票 05):默认作用域按当前目标自动匹配(动作→动作、切片→切片、其余→时间点)。
|
||||
m.picker = { position: p, scope: defaultReviewScope(m.selected, p) };
|
||||
cancelAnimationFrame(focusFrame.current);
|
||||
let tier = scope ?? defaultReviewScope(m.selected, p);
|
||||
if (!scope && !opinionTarget(tier, reviewTargetPosition(tier, p, m.targetAnchor)))
|
||||
tier = defaultReviewScope(null, p);
|
||||
if (tier === "timestamp" && !m.targetAnchor) m.targetAnchor = p;
|
||||
const target = opinionTarget(tier, reviewTargetPosition(tier, m.position, m.targetAnchor));
|
||||
if (!target) {
|
||||
m.message = "当前画面没有可写意见的对象。";
|
||||
notify();
|
||||
return false;
|
||||
}
|
||||
m.selected = tier;
|
||||
m.editor = editorFor(target);
|
||||
m.error = "";
|
||||
focus(true);
|
||||
notify();
|
||||
return true;
|
||||
},
|
||||
[enabled, itemId, context],
|
||||
);
|
||||
const confirmScope = (scope?: OpinionScope) => {
|
||||
const picker = m.picker;
|
||||
if (!picker) return false;
|
||||
const actual = scope || picker.scope,
|
||||
target = opinionTarget(actual, picker.position);
|
||||
if (!target) return false;
|
||||
m.picker = null;
|
||||
m.selected = actual;
|
||||
m.editor = editorFor(target);
|
||||
focus(true);
|
||||
notify();
|
||||
return true;
|
||||
};
|
||||
const save = async () => {
|
||||
if (!writable()) return false;
|
||||
if (m.pending && m.blocked) {
|
||||
@ -504,8 +504,9 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
return flushRef.current();
|
||||
};
|
||||
const requestDelete = () => {
|
||||
if (!writable() || m.clear || m.picker) return false;
|
||||
const target = m.selected ? opinionTarget(m.selected, m.position) : null;
|
||||
if (!writable() || m.clear) return false;
|
||||
const scope = defaultReviewScope(m.selected, m.position);
|
||||
const target = opinionTarget(scope, reviewTargetPosition(scope, m.position, m.targetAnchor));
|
||||
if (!target || !currentGroup(target).length) {
|
||||
m.message = "请先选择有意见的卡片。";
|
||||
notify();
|
||||
@ -545,12 +546,6 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
cancelDelete();
|
||||
return;
|
||||
}
|
||||
if (m.picker) {
|
||||
m.picker = null;
|
||||
focusWorkbench();
|
||||
notify();
|
||||
return;
|
||||
}
|
||||
const e = m.editor;
|
||||
if (e) {
|
||||
const key = opinionKey(e);
|
||||
@ -667,15 +662,27 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
const selectProblem = (problem: ReviewProblem, navigationSliceId?: string) => {
|
||||
park();
|
||||
m.selected = problem.scope;
|
||||
m.selectedProblem = problem;
|
||||
const anchor = problem.scope === "task" ? problem.viewAnchor : problem;
|
||||
if (anchor?.sliceId) {
|
||||
// 票 07:选中时间点条目即切入时间点档——锚点冻结在该意见的记录位置
|
||||
// (时间点身份 = 来源 + 规范帧,记录画面即 atSeconds 所在帧)。
|
||||
if (problem.scope === "timestamp" && problem.sliceId) {
|
||||
m.targetAnchor = {
|
||||
time: problem.atSeconds,
|
||||
timeBasis: problem.timeBasis === "slice-seconds" ? "slice-seconds" : "capture-seconds",
|
||||
sliceId: problem.sliceId,
|
||||
navigationSliceId: navigationSliceId || problem.sliceId,
|
||||
sourceItemId: problem.sourceItemId,
|
||||
actionId: null,
|
||||
selectedActionId: null,
|
||||
};
|
||||
} else if (problem.scope !== "timestamp") m.targetAnchor = null;
|
||||
const seekTo = problem.scope === "task" ? problem.viewAnchor : problem;
|
||||
if (seekTo?.sliceId) {
|
||||
controller.current?.pause();
|
||||
if (m.position?.sliceId === anchor.sliceId && (m.position.sourceItemId || "") === (anchor.sourceItemId || "")) {
|
||||
controller.current?.seekTime(anchor.atSeconds);
|
||||
if (m.position?.sliceId === seekTo.sliceId && (m.position.sourceItemId || "") === (seekTo.sourceItemId || "")) {
|
||||
controller.current?.seekTime(seekTo.atSeconds);
|
||||
} else {
|
||||
m.recall = { target: { ...problem, ...anchor }, navigationSliceId, time: anchor.atSeconds };
|
||||
if (!controller.current?.seekSlice(navigationSliceId || anchor.sliceId)) m.recall = null;
|
||||
m.recall = { target: { ...problem, ...seekTo }, navigationSliceId, time: seekTo.atSeconds };
|
||||
if (!controller.current?.seekSlice(navigationSliceId || seekTo.sliceId)) m.recall = null;
|
||||
}
|
||||
}
|
||||
m.userNavigation = false;
|
||||
@ -791,7 +798,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
document.removeEventListener("click", click, true);
|
||||
};
|
||||
}, [context]);
|
||||
// D5(票 05):卡片清单保持 切片/动作;Ctrl/⌘+↑/↓ 的统一导航序(含时间点条目)见 navigateSelection。
|
||||
// D5(票 07):卡片清单保持 切片/动作(看历史=列表点击);时间点条目在下方列表。
|
||||
const cards = opinionCardScopes.map((scope) => {
|
||||
const target = opinionTarget(scope, m.position);
|
||||
return {
|
||||
@ -805,7 +812,6 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
currentDraft: () => m.draft,
|
||||
draft: m.draft,
|
||||
editor: m.editor,
|
||||
scopePicker: m.picker,
|
||||
selectedScope: m.selected,
|
||||
confirmClear: m.clear,
|
||||
dirty: dirty(),
|
||||
@ -824,7 +830,6 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
saveAll,
|
||||
reload,
|
||||
beginProblem,
|
||||
confirmScope,
|
||||
selectScope,
|
||||
selectProblem,
|
||||
requestDelete,
|
||||
@ -834,38 +839,28 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
onPosition,
|
||||
onController,
|
||||
onNavigate: navigation,
|
||||
// D5(票 05):导航序 = 切片卡→动作卡→时间点条目(时间升序),到头停住;
|
||||
// 时间点不再是列表外的孤岛,落到时间点条目经 selectProblem 定位回看。
|
||||
navigateSelection: (direction: -1 | 1, _navigationSliceId?: unknown) => {
|
||||
if (m.picker || m.clear) return;
|
||||
// JS 纯函数库的宽类型在边界收窄:入参由 OpinionScope/ReviewProblem 构造。
|
||||
const next = nextReviewNavigationEntry(
|
||||
reviewNavigationOrder({
|
||||
cards: cards.map((c) => ({ scope: c.scope, hasTarget: Boolean(c.target) })),
|
||||
timestampProblems: m.draft?.problems || [],
|
||||
}),
|
||||
{ scope: m.selected, timestampId: m.selectedProblem?.id },
|
||||
// 票 07(D5 修订版):Ctrl/⌘+↑/↓ 切换写意见的目标——当前切片→当前动作→
|
||||
// 当前时间点(播放头解析,空档跳过,到头停住)。既有意见条目的键盘遍历已移除
|
||||
// (看历史=列表点击/G 跳时间点)。切入时间点档时冻结画面锚点。
|
||||
switchTarget: (direction: -1 | 1) => {
|
||||
if (m.clear) return;
|
||||
const next = nextReviewTargetScope(
|
||||
defaultReviewScope(m.selected, m.position),
|
||||
m.position,
|
||||
direction,
|
||||
) as { kind: "card"; scope: OpinionScope } | { kind: "timestamp"; problem: ReviewProblem } | null;
|
||||
) as OpinionScope | null;
|
||||
if (!next) return;
|
||||
if (next.kind === "card") selectScope(next.scope);
|
||||
else selectProblem(next.problem);
|
||||
},
|
||||
editSelected: () => (m.selected ? selectScope(m.selected, true) : false),
|
||||
scopeOptions: (picker: ReviewScopePicker | null) =>
|
||||
opinionScopes.filter((scope) => Boolean(picker && opinionTarget(scope, picker.position))),
|
||||
moveScope: (direction: -1 | 1) => {
|
||||
if (!m.picker) return;
|
||||
const scopes = opinionScopes.filter((s) => opinionTarget(s, m.picker!.position));
|
||||
const i = scopes.indexOf(m.picker.scope);
|
||||
m.picker = { ...m.picker, scope: scopes[Math.max(0, Math.min(scopes.length - 1, i + direction))] };
|
||||
notify();
|
||||
},
|
||||
cancelScope: () => {
|
||||
m.picker = null;
|
||||
park();
|
||||
if (m.clear) {
|
||||
notify();
|
||||
return;
|
||||
}
|
||||
m.selected = next;
|
||||
if (next === "timestamp") m.targetAnchor = m.position;
|
||||
focusWorkbench();
|
||||
notify();
|
||||
},
|
||||
editSelected: () => selectScope(defaultReviewScope(m.selected, m.position), true),
|
||||
setText: (text: string) => {
|
||||
if (!sessionRef.current.writable || !m.editor) return;
|
||||
m.editor = { ...m.editor, text };
|
||||
@ -899,20 +894,18 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
|
||||
if (m.clear) return;
|
||||
m.editor = m.edits.get(opinionKey(e)) || e;
|
||||
m.selected = e.scope;
|
||||
m.selectedProblem = e;
|
||||
focus(true);
|
||||
notify();
|
||||
},
|
||||
// D5(票 05):常驻内联编辑器的绑定——无打开编辑器/选择器/确认框时,
|
||||
// 默认作用域按当前目标自动匹配,textarea 常驻内联(聚焦即进入编辑态)。
|
||||
// 票 07(D5 修订版):常驻内联编辑器绑定当前所选目标(未选按画面默认档)——
|
||||
// 档位解析用画面(时间点档=冻结锚点),textarea 常驻内联(聚焦即进入编辑态)。
|
||||
residentEditor: (() => {
|
||||
if (m.picker || m.clear) return null;
|
||||
if (m.clear) return null;
|
||||
const scope = defaultReviewScope(m.selected, m.position);
|
||||
const target = opinionTarget(scope, m.position);
|
||||
const target = opinionTarget(scope, reviewTargetPosition(scope, m.position, m.targetAnchor));
|
||||
if (!target) return null;
|
||||
return { scope, target, text: editorFor(target).text };
|
||||
})(),
|
||||
scopeChoices: opinionScopes,
|
||||
timestampProblems: m.draft?.problems.filter((p) => p.scope === "timestamp") || [],
|
||||
confirmations: m.confirmations,
|
||||
// D7 复审核对结论:upsert 到草稿确认集;随下一次保存(含 8s 自动落盘)提交。
|
||||
|
||||
@ -1,51 +1,69 @@
|
||||
// 票 05(spec D5 / ADR 0009):审核意见统一导航序的纯函数。
|
||||
// Ctrl/⌘+↑/↓ 的导航序 = 卡片作用域(仅计有有效目标者,次序由调用方按
|
||||
// opinionCardScopes 传入)在前,时间点意见(按 atSeconds 升序,与 G 键跳转同序)
|
||||
// 在后;时间点不再是「列表外的孤岛」,纳入同一导航序,到头停住。
|
||||
// 票 07(spec D5 修订版 / ADR 0009):审核意见「目标」模型的纯函数。
|
||||
// 目标三档 = 当前切片 / 当前动作 / 当前时间点,由播放头位置实时解析
|
||||
// (哪个切片包含播放头、哪个动作包含播放头、时间点=播放头位置);
|
||||
// Ctrl/⌘+↑/↓ 在三档间切换(切片→动作→时间点,到头停住,空档就近跳过)。
|
||||
// 取代票 05 的「既有意见条目导航序」:条目遍历已移除,看历史=列表点击/G 跳时间点。
|
||||
|
||||
/** 目标档位次序(D5):切片 → 动作 → 时间点。 */
|
||||
export const reviewTargetScopes = ["slice", "action", "timestamp"];
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* cards: { scope: string, hasTarget: boolean }[];
|
||||
* timestampProblems: { scope: string, atSeconds?: number, [key: string]: unknown }[];
|
||||
* }} input
|
||||
* @returns {({ kind: "card", scope: string } | { kind: "timestamp", problem: Record<string, unknown> })[]}
|
||||
*/
|
||||
export function reviewNavigationOrder({ cards, timestampProblems }) {
|
||||
return [
|
||||
...cards.filter((c) => c.hasTarget && c.scope !== "timestamp").map((c) => ({ kind: "card", scope: c.scope })),
|
||||
...timestampProblems
|
||||
.filter((p) => p.scope === "timestamp")
|
||||
.sort((a, b) => (a.atSeconds ?? 0) - (b.atSeconds ?? 0))
|
||||
.map((p) => ({ kind: "timestamp", problem: p })),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 在导航序上按方向取下一项;两端再按同方向返回 null(到头停住)。
|
||||
* 当前项不在序列内(未选/已删除)时按按键方向进入序列。
|
||||
* 播放头→可用目标档位。目标解析的权威在 review-opinions.ts 的 opinionTarget:
|
||||
* 切片需就绪画面(sliceId)、动作另需播放头落在动作内(actionId)、时间点需
|
||||
* 就绪画面(sliceId + 数值 time);此处按同一契约做最小镜像(纯 JS,供
|
||||
* node --test 直接加载),源码守卫测试钉住两处一致。
|
||||
*
|
||||
* @param {({ kind: "card", scope: string } | { kind: "timestamp", problem: { id?: string } })[]} order
|
||||
* @param {{ scope?: string | null, timestampId?: string | null }} current
|
||||
* @param {-1 | 1} direction
|
||||
* @param {{ sliceId?: string | null, actionId?: string | null, time?: number } | null | undefined} position
|
||||
* @returns {("slice" | "action" | "timestamp")[]}
|
||||
*/
|
||||
export function nextReviewNavigationEntry(order, current, direction) {
|
||||
const index = order.findIndex((entry) =>
|
||||
entry.kind === "card"
|
||||
? entry.scope === current?.scope && entry.scope !== "timestamp"
|
||||
: entry.problem.id != null && entry.problem.id === current?.timestampId,
|
||||
);
|
||||
const next =
|
||||
index < 0
|
||||
? direction > 0
|
||||
? 0
|
||||
: order.length - 1
|
||||
: Math.max(0, Math.min(order.length - 1, index + direction));
|
||||
if (index >= 0 && next === index) return null;
|
||||
return order[next] || null;
|
||||
export function reviewTargetOptions(position) {
|
||||
if (!position?.sliceId) return [];
|
||||
const options = ["slice"];
|
||||
if (position.actionId) options.push("action");
|
||||
if (typeof position.time === "number") options.push("timestamp");
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 作用域默认值按当前目标自动匹配(票 05 / D5):
|
||||
* 档位切换(D5 修订版):direction=1(↓)沿 切片→动作→时间点 前进,-1(↑)反向;
|
||||
* 播放头解析不出的空档就近跳过(不停在无目标的档位上),两端再按同方向停住
|
||||
* (返回 null)。当前档未选/历史整体(task)等未知值时,按按键方向进入可用
|
||||
* 序列首/尾(与既有卡片导航的进入语义一致)。
|
||||
*
|
||||
* @param {string | null | undefined} current
|
||||
* @param {{ sliceId?: string | null, actionId?: string | null, time?: number } | null | undefined} position
|
||||
* @param {-1 | 1} direction
|
||||
* @returns {"slice" | "action" | "timestamp" | null}
|
||||
*/
|
||||
export function nextReviewTargetScope(current, position, direction) {
|
||||
const options = reviewTargetOptions(position);
|
||||
if (!options.length) return null;
|
||||
const at = current != null ? reviewTargetScopes.indexOf(current) : -1;
|
||||
if (at < 0) return direction > 0 ? options[0] : options[options.length - 1];
|
||||
for (let i = at + direction; i >= 0 && i < reviewTargetScopes.length; i += direction) {
|
||||
if (options.includes(reviewTargetScopes[i])) return reviewTargetScopes[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标档位解析用画面:时间点档用切入该档时刻冻结的播放头画面(沿用 viewAnchor
|
||||
* 冻结机制,票 07),切片/动作档跟随实时播放头(含播放头的切片/动作)。
|
||||
* 尚无冻结锚点(从未显式切入时间点档)时退回实时画面。
|
||||
*
|
||||
* @param {string | null | undefined} scope
|
||||
* @param {T | null | undefined} live
|
||||
* @param {T | null | undefined} frozen
|
||||
* @returns {T | null | undefined}
|
||||
* @template T
|
||||
*/
|
||||
export function reviewTargetPosition(scope, live, frozen) {
|
||||
if (scope === "timestamp") return frozen ?? live;
|
||||
return live;
|
||||
}
|
||||
|
||||
/**
|
||||
* 作用域默认值按当前目标自动匹配(票 05 / D5,票 07 沿用):
|
||||
* 已选目标是动作→动作、切片→切片、其余(时间点/历史整体/未知)→时间点;
|
||||
* 未选时按画面位置兜底:有动作→动作、有切片→切片、都无→时间点。
|
||||
*
|
||||
@ -55,8 +73,7 @@ export function nextReviewNavigationEntry(order, current, direction) {
|
||||
*/
|
||||
export function defaultReviewScope(selectedScope, position) {
|
||||
if (selectedScope != null) {
|
||||
if (selectedScope === "action" || selectedScope === "slice" || selectedScope === "timestamp")
|
||||
return selectedScope;
|
||||
if (selectedScope === "action" || selectedScope === "slice" || selectedScope === "timestamp") return selectedScope;
|
||||
return "timestamp";
|
||||
}
|
||||
if (position?.actionId) return "action";
|
||||
|
||||
@ -16,9 +16,10 @@ export function reviewShortcut(
|
||||
if ((ctrlKey || metaKey) && !altKey && !shiftKey) {
|
||||
if (["ArrowLeft", "ArrowRight"].includes(key))
|
||||
return repeat ? "consume" : key === "ArrowLeft" ? "previous-slice" : "next-slice";
|
||||
// Saved-problem review navigation stops at both ends and never enters text.
|
||||
if (key === "ArrowUp") return "previous-problem";
|
||||
if (key === "ArrowDown") return "next-problem";
|
||||
// 票 07(D5 修订版):Ctrl/⌘+↑/↓ 切换写意见的目标(当前切片/当前动作/当前
|
||||
// 时间点,由播放头确定),到头停住——取代票 05 的既有意见条目遍历。
|
||||
if (key === "ArrowUp") return "previous-target";
|
||||
if (key === "ArrowDown") return "next-target";
|
||||
return null;
|
||||
}
|
||||
if (shiftKey && !altKey && !ctrlKey && !metaKey) {
|
||||
@ -62,14 +63,16 @@ export const reviewShortcutHelp = [
|
||||
{ keys: "Ctrl / ⌘ + ← / →", label: "上一片/下一片;到首尾停止" },
|
||||
{ keys: "↑ / ↓", label: "上一个/下一个动作;暂停在起始帧,到首尾停止" },
|
||||
{ keys: "B", label: "从当前片头复查,片尾暂停" },
|
||||
{ keys: "F", label: "暂停并选择意见范围;编辑已有意见,没有则填写" },
|
||||
{ keys: "G", label: "跳到下一个时间点意见并显示内容(循环;D5 独立键,不占用卡片导航)" },
|
||||
// 票 07(D5 修订版 + D9):四面(审核普通/专注、返工普通/专注)共用本帮助表——
|
||||
// Ctrl/⌘+↑/↓ 切换意见目标、F 直接填写、Ctrl/⌘+Enter 提交,全程零弹窗。
|
||||
{ keys: "Ctrl / ⌘ + ↑ / ↓", label: "切换意见目标:当前切片 → 当前动作 → 当前时间点(随播放头确定),到头停住" },
|
||||
{ keys: "F", label: "暂停并直接给当前选中的意见目标填写意见;该目标已有意见则编辑" },
|
||||
{ keys: "Ctrl / ⌘ + Enter", label: "提交当前意见;删空已有内容后确认清除,不会提交审核决定" },
|
||||
{ keys: "G", label: "跳到下一个时间点意见并显示内容(循环)" },
|
||||
{ keys: "J / K", label: "下一条/上一条返修意见,定位到意见位置(返修复审时可用;与标注员同一肌肉记忆)" },
|
||||
{ keys: "1 / 2", label: "已解决/仍有问题(聚焦退回意见行时可用;2 须填写质检备注,返修复审时可用)" },
|
||||
{ keys: "Ctrl / ⌘ + ↑ / ↓", label: "在当前切片、当前动作与时间点意见之间移动;到首尾停止" },
|
||||
{ keys: "Enter", label: "编辑选中的意见卡片;点击卡片也可编辑" },
|
||||
{ keys: "Ctrl / ⌘ + Enter", label: "保存当前意见;删空已有内容后确认清除,不会提交审核决定" },
|
||||
{ keys: "Shift + Delete(Mac 也可用 Shift + Backspace)", label: "清除选中卡片的本轮意见,确认后保存为“无”" },
|
||||
{ keys: "Esc", label: "关闭帮助或清除确认;退出范围选择或文字输入并返回工作台" },
|
||||
{ keys: "Esc", label: "关闭帮助或清除确认;退出文字输入并返回工作台" },
|
||||
{ keys: "?", label: "打开快捷键帮助" },
|
||||
];
|
||||
|
||||
@ -6499,9 +6499,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
atSeconds: p.atSeconds ?? 0,
|
||||
text: p.text,
|
||||
}))}
|
||||
onReviewProblemNavigate={(direction) =>
|
||||
reviewDraft.navigateSelection(direction, reviewProblemNavigationSlice)
|
||||
}
|
||||
onReviewTargetSwitch={(direction) => reviewDraft.switchTarget(direction)}
|
||||
onReviewProblemEdit={() => reviewDraft.editSelected()}
|
||||
onReviewProblemDelete={() => reviewDraft.requestDelete()}
|
||||
onReviewEscape={reviewDraft.escape}
|
||||
@ -6883,9 +6881,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
atSeconds: p.atSeconds ?? 0,
|
||||
text: p.text,
|
||||
}))}
|
||||
onReviewProblemNavigate={(direction) =>
|
||||
reviewDraft.navigateSelection(direction, reviewProblemNavigationSlice)
|
||||
}
|
||||
onReviewTargetSwitch={(direction) => reviewDraft.switchTarget(direction)}
|
||||
onReviewProblemEdit={() => reviewDraft.editSelected()}
|
||||
onReviewProblemDelete={() => reviewDraft.requestDelete()}
|
||||
onReviewEscape={reviewDraft.escape}
|
||||
|
||||
@ -26,11 +26,12 @@ test("F is the only letter recording a problem; Q no longer records", () => {
|
||||
assert.equal(parse("f", { keyCode: 229 }), null);
|
||||
});
|
||||
|
||||
test("saved problem navigation, editing and deletion stay outside native text fields", () => {
|
||||
test("target switching (Ctrl/⌘+↑/↓), editing and deletion stay outside native text fields", () => {
|
||||
const parse = (key, extra = {}, context = {}) => reviewShortcut({ key, ...extra }, context);
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true }), "previous-problem");
|
||||
assert.equal(parse("ArrowDown", { metaKey: true }), "next-problem");
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true, repeat: true }), "previous-problem");
|
||||
// 票 07(D5 修订版):Ctrl/⌘+↑/↓ 切换写意见的目标(取代票 05 的意见条目遍历)。
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true }), "previous-target");
|
||||
assert.equal(parse("ArrowDown", { metaKey: true }), "next-target");
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true, repeat: true }), "previous-target");
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true }, { editable: true }), null);
|
||||
assert.equal(parse("ArrowDown", { ctrlKey: true }, { editable: true, noteInput: true }), null);
|
||||
assert.equal(parse("Enter"), "edit-problem");
|
||||
|
||||
148
tests/frontend/review-target-interaction.test.mjs
Normal file
148
tests/frontend/review-target-interaction.test.mjs
Normal file
@ -0,0 +1,148 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import * as reviewNavigation from "../../src/lib/review-navigation.js";
|
||||
import { reviewShortcut } from "../../src/lib/review-shortcuts.js";
|
||||
|
||||
// 票 07(spec D5 修订版):Ctrl/⌘+↑/↓ 切换写意见的目标——当前切片 → 当前动作 →
|
||||
// 当前时间点,由播放头位置解析;F 直接开始给当前选中目标写意见(无作用域弹层);
|
||||
// Ctrl/⌘+Enter 提交。接缝:src/lib/review-navigation.js 纯函数(node --test 直接加载);
|
||||
// 键位映射 review-shortcuts.js;TS 模块按仓库先例以源码守卫钉住(见文末)。
|
||||
|
||||
const { reviewTargetOptions, nextReviewTargetScope, reviewTargetPosition } = reviewNavigation;
|
||||
|
||||
test("target options: playhead resolves the three tiers (slice / action / timestamp)", () => {
|
||||
const pos = (extra = {}) => ({ time: 4, sliceId: "s1", actionId: null, ...extra });
|
||||
// 画面就绪:含播放头的切片 + 时间点恒可用;动作仅在播放头落在动作内时可用。
|
||||
assert.deepEqual(reviewTargetOptions(pos()), ["slice", "timestamp"]);
|
||||
assert.deepEqual(reviewTargetOptions(pos({ actionId: "a1" })), ["slice", "action", "timestamp"]);
|
||||
// 画面未就绪(无切片):三档皆不可用。
|
||||
assert.deepEqual(reviewTargetOptions({ time: 4, sliceId: "", actionId: "a1" }), []);
|
||||
assert.deepEqual(reviewTargetOptions(null), []);
|
||||
});
|
||||
|
||||
test("target cycle: slice→action→timestamp both directions, skipping unavailable tiers, stops at ends", () => {
|
||||
const pos = (extra = {}) => ({ time: 4, sliceId: "s1", actionId: null, ...extra });
|
||||
const withAction = pos({ actionId: "a1" });
|
||||
// ↓ 正向:切片→动作→时间点,两端再按同方向停住(返回 null)。
|
||||
assert.equal(nextReviewTargetScope("slice", withAction, 1), "action");
|
||||
assert.equal(nextReviewTargetScope("action", withAction, 1), "timestamp");
|
||||
assert.equal(nextReviewTargetScope("timestamp", withAction, 1), null);
|
||||
// ↑ 反向:时间点→动作→切片,到头停住。
|
||||
assert.equal(nextReviewTargetScope("timestamp", withAction, -1), "action");
|
||||
assert.equal(nextReviewTargetScope("action", withAction, -1), "slice");
|
||||
assert.equal(nextReviewTargetScope("slice", withAction, -1), null);
|
||||
// 播放头不在任何动作内:动作档不可用,切换就近跳过(不停在空档上)。
|
||||
assert.equal(nextReviewTargetScope("slice", pos(), 1), "timestamp");
|
||||
assert.equal(nextReviewTargetScope("timestamp", pos(), -1), "slice");
|
||||
// 当前档此刻无目标(如动作档但播放头在动作间隙):沿方向进入最近的可用档。
|
||||
assert.equal(nextReviewTargetScope("action", pos(), 1), "timestamp");
|
||||
assert.equal(nextReviewTargetScope("action", pos(), -1), "slice");
|
||||
// 未选/历史整体等未知档:按按键方向进入可用序列首/尾(与既有进入语义一致)。
|
||||
assert.equal(nextReviewTargetScope(null, withAction, 1), "slice");
|
||||
assert.equal(nextReviewTargetScope(null, withAction, -1), "timestamp");
|
||||
assert.equal(nextReviewTargetScope("task", withAction, -1), "timestamp");
|
||||
// 画面未就绪:无处可切。
|
||||
assert.equal(nextReviewTargetScope("slice", null, 1), null);
|
||||
});
|
||||
|
||||
test("target position: timestamp tier freezes the entry frame, slice/action follow the playhead", () => {
|
||||
const live = { time: 30, sliceId: "s9" };
|
||||
const frozen = { time: 5, sliceId: "s1" };
|
||||
assert.equal(reviewTargetPosition("timestamp", live, frozen), frozen, "时间点档用切入时刻冻结的画面");
|
||||
assert.equal(reviewTargetPosition("slice", live, frozen), live);
|
||||
assert.equal(reviewTargetPosition("action", live, frozen), live);
|
||||
// 从未显式切入时间点档(无锚点):退回实时画面,目标随播放头解析。
|
||||
assert.equal(reviewTargetPosition("timestamp", live, null), live);
|
||||
});
|
||||
|
||||
test("keymap: Ctrl/⌘+↑/↓ dispatch target switching; F starts writing directly", () => {
|
||||
const parse = (key, extra = {}, context = {}) => reviewShortcut({ key, ...extra }, context);
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true }), "previous-target");
|
||||
assert.equal(parse("ArrowDown", { metaKey: true }), "next-target");
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true, repeat: true }), "previous-target");
|
||||
// 文本框内保持原生键位(光标移动),不切换目标。
|
||||
assert.equal(parse("ArrowUp", { ctrlKey: true }, { editable: true }), null);
|
||||
assert.equal(parse("ArrowDown", { metaKey: true }, { editable: true, noteInput: true }), null);
|
||||
assert.equal(parse("ArrowUp", { altKey: true }), null);
|
||||
// F=直接填写:分发为开始写意见(不再有选择作用域的动作)。
|
||||
assert.equal(parse("f"), "problem");
|
||||
assert.equal(parse("f", { repeat: true }), "consume");
|
||||
assert.equal(parse("f", {}, { editable: true }), null);
|
||||
});
|
||||
|
||||
const read = (path) => fs.readFileSync(new URL(path, import.meta.url), "utf8");
|
||||
|
||||
test("source guard: scope picker interaction fully removed", () => {
|
||||
const hook = read("../../src/hooks/useReviewDraft.ts");
|
||||
const panel = read("../../src/components/ReviewProblemPanel.tsx");
|
||||
for (const source of [hook, panel]) {
|
||||
assert.doesNotMatch(source, /scopePicker/, "两段式作用域弹层应全删");
|
||||
assert.doesNotMatch(source, /confirmScope|moveScope|cancelScope|scopeOptions|scopeChoices/);
|
||||
assert.doesNotMatch(source, /ReviewScopePicker/);
|
||||
}
|
||||
assert.doesNotMatch(panel, /role="radiogroup"/);
|
||||
assert.doesNotMatch(panel, /问题范围/);
|
||||
});
|
||||
|
||||
test("source guard: hook wires the target model (switch, freeze anchor, F direct write)", () => {
|
||||
const hook = read("../../src/hooks/useReviewDraft.ts");
|
||||
assert.match(
|
||||
hook,
|
||||
/import \{ defaultReviewScope, nextReviewTargetScope, reviewTargetPosition \} from "\.\.\/lib\/review-navigation\.js";/,
|
||||
);
|
||||
// Ctrl+↑/↓ = 目标档位切换(复用纯函数),到头停住;切入时间点档冻结画面。
|
||||
assert.match(hook, /switchTarget: \(direction: -1 \| 1\) =>/);
|
||||
assert.match(
|
||||
hook,
|
||||
/nextReviewTargetScope\(\s*defaultReviewScope\(m\.selected, m\.position\),\s*m\.position,\s*direction,/,
|
||||
);
|
||||
assert.match(hook, /if \(next === "timestamp"\) m\.targetAnchor = m\.position;/);
|
||||
// F 直写:定位后直接打开当前目标编辑器(无 picker)。
|
||||
assert.match(hook, /m\.editor = editorFor\(target\);/);
|
||||
// 目标解析走 reviewTargetPosition(时间点档锚点冻结)。
|
||||
assert.match(hook, /reviewTargetPosition\(scope, m\.position, m\.targetAnchor\)/);
|
||||
// 05 的既有意见条目导航已被目标切换取代。
|
||||
assert.doesNotMatch(hook, /navigateSelection|nextReviewNavigationEntry|reviewNavigationOrder|selectedProblem/);
|
||||
});
|
||||
|
||||
test("source guard: resident editor binds the selected target with a tier label", () => {
|
||||
const panel = read("../../src/components/ReviewProblemPanel.tsx");
|
||||
assert.match(panel, /const resident =/);
|
||||
assert.match(panel, /onFocus=\{\(\) => review\.selectScope\(resident\.scope, true\)\}/);
|
||||
// 意见区常驻显示所选目标:档位标签(当前切片/当前动作/当前时间点)+目标说明。
|
||||
assert.match(panel, /当前目标:\{targetTierNames\[resident\.scope\]\}/);
|
||||
assert.match(panel, /const targetTierNames = \{ slice: "当前切片", action: "当前动作", timestamp: "当前时间点" \};/);
|
||||
});
|
||||
|
||||
test("source guard: four mode heads share the new-semantics help with no stale copy", () => {
|
||||
const help = read("../../src/lib/review-shortcuts.js");
|
||||
// 三个核心语义行(D9:审核/返工 × 普通/专注 四面共用本帮助表)。
|
||||
assert.match(help, /\{ keys: "F", label: "[^"]*直接[^"]*" \}/);
|
||||
assert.match(help, /\{ keys: "Ctrl \/ ⌘ \+ ↑ \/ ↓", label: "切换意见目标[^"]*" \}/);
|
||||
assert.match(help, /\{ keys: "Ctrl \/ ⌘ \+ Enter", label: "提交[^"]*" \}/);
|
||||
// 过时文案(旧弹层、旧导航语义)不得残留在任何源文件。
|
||||
for (const stale of ["选择意见范围", "意见之间移动", "退出范围选择"]) {
|
||||
assert.doesNotMatch(help, new RegExp(stale), `帮助表不得残留:${stale}`);
|
||||
}
|
||||
const workbench = read("../../src/components/CaptureAnnotationWorkbench.tsx");
|
||||
const acceptance = read("../../src/components/FinalAcceptanceWorkspace.tsx");
|
||||
const operations = read("../../src/pages/AnnotationOperations.tsx");
|
||||
for (const source of [workbench, acceptance, operations]) {
|
||||
assert.doesNotMatch(source, /选择意见范围|退出范围选择/, "模式头与入口不得残留过时文案");
|
||||
assert.doesNotMatch(source, /onReviewProblemNavigate/, "旧导航 prop 应改名 onReviewTargetSwitch");
|
||||
}
|
||||
// 四面(审核普通/专注、返工普通/专注)经同一帮助表渲染(工作台 isReviewViewing 分支)。
|
||||
assert.match(workbench, /: isReviewViewing\n\s+\? reviewShortcutHelp/);
|
||||
});
|
||||
|
||||
test("source guard: workbench and acceptance dispatch target switching to the page", () => {
|
||||
const workbench = read("../../src/components/CaptureAnnotationWorkbench.tsx");
|
||||
const acceptance = read("../../src/components/FinalAcceptanceWorkspace.tsx");
|
||||
for (const source of [workbench, acceptance]) {
|
||||
assert.match(source, /command === "previous-target" \|\| command === "next-target"/);
|
||||
assert.match(source, /onReviewTargetSwitch\?\.\(command === "previous-target" \? -1 : 1\)/);
|
||||
}
|
||||
const viewing = read("../../src/components/review-viewing.ts");
|
||||
assert.match(viewing, /onReviewTargetSwitch\?: \(direction: -1 \| 1\) => void;/);
|
||||
});
|
||||
@ -3,53 +3,13 @@ import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import * as reviewNavigation from "../../src/lib/review-navigation.js";
|
||||
|
||||
const { reviewNavigationOrder } = reviewNavigation;
|
||||
|
||||
// 票 05(spec D5 / ADR 0009):Ctrl/⌘+↑/↓ 的导航序纳入时间点意见;
|
||||
// 作用域默认值按当前目标自动匹配;编辑器常驻内联。
|
||||
// 票 05 钉子的存留部分(spec D5 / ADR 0009)。票 07(D5 修订版)把 Ctrl/⌘+↑/↓
|
||||
// 从「既有意见条目导航」改为「切换写意见的目标档」:导航序断言(05 测试 1/2)已被
|
||||
// review-target-interaction.test.mjs 的目标档位表驱动取代并删除;此处保留仍成立的
|
||||
// 默认作用域、常驻编辑器与删除净守卫,帮助行守卫改写为新语义。
|
||||
// 接缝:src/lib/review-navigation.js 为纯函数(node --test 直接加载);
|
||||
// TS 模块(useReviewDraft / ReviewProblemPanel)按仓库先例以源码守卫钉住(见文末)。
|
||||
|
||||
test("navigation order: target-bearing cards first, then timestamp entries by time", () => {
|
||||
const ts = (id, atSeconds) => ({ id, scope: "timestamp", atSeconds });
|
||||
const order = reviewNavigationOrder({
|
||||
cards: [
|
||||
{ scope: "slice", hasTarget: true },
|
||||
{ scope: "action", hasTarget: false },
|
||||
{ scope: "timestamp", hasTarget: true }, // 防御:卡片清单不应携带时间点,带了也不重复计
|
||||
],
|
||||
timestampProblems: [ts("b", 9.5), { id: "x", scope: "slice", atSeconds: 1 }, ts("a", 2.25)],
|
||||
});
|
||||
assert.deepEqual(order, [
|
||||
{ kind: "card", scope: "slice" },
|
||||
{ kind: "timestamp", problem: ts("a", 2.25) },
|
||||
{ kind: "timestamp", problem: ts("b", 9.5) },
|
||||
]);
|
||||
});
|
||||
|
||||
test("next entry: walks slice→action→timestamps, stops at both ends", () => {
|
||||
const { nextReviewNavigationEntry } = reviewNavigation;
|
||||
const order = [
|
||||
{ kind: "card", scope: "slice" },
|
||||
{ kind: "card", scope: "action" },
|
||||
{ kind: "timestamp", problem: { id: "t1", scope: "timestamp", atSeconds: 3 } },
|
||||
{ kind: "timestamp", problem: { id: "t2", scope: "timestamp", atSeconds: 8 } },
|
||||
];
|
||||
const at = (current, direction) => nextReviewNavigationEntry(order, current, direction);
|
||||
assert.deepEqual(at({ scope: "slice" }, 1), { kind: "card", scope: "action" });
|
||||
assert.deepEqual(at({ scope: "action" }, 1), order[2]);
|
||||
assert.deepEqual(at({ scope: "timestamp", timestampId: "t1" }, 1), order[3]);
|
||||
// 到头停住:两端再按同方向不产生新目标。
|
||||
assert.equal(at({ scope: "timestamp", timestampId: "t2" }, 1), null);
|
||||
assert.equal(at({ scope: "slice" }, -1), null);
|
||||
assert.deepEqual(at({ scope: "timestamp", timestampId: "t1" }, -1), { kind: "card", scope: "action" });
|
||||
// 未选/失效选择:按按键方向进入序列(与既有卡片导航的进入语义一致)。
|
||||
assert.deepEqual(at({ scope: null }, 1), order[0]);
|
||||
assert.deepEqual(at({ scope: null }, -1), order[3]);
|
||||
assert.deepEqual(at({ scope: "timestamp", timestampId: "gone" }, 1), order[0]);
|
||||
assert.deepEqual(at({ scope: "task" }, -1), order[3]);
|
||||
});
|
||||
|
||||
test("default scope: action→action, slice→slice, everything else→timestamp; no selection follows position", () => {
|
||||
const { defaultReviewScope } = reviewNavigation;
|
||||
const pos = (extra = {}) => ({ sliceId: "s1", time: 4, ...extra });
|
||||
@ -68,25 +28,19 @@ test("default scope: action→action, slice→slice, everything else→timestamp
|
||||
|
||||
const read = (path) => fs.readFileSync(new URL(path, import.meta.url), "utf8");
|
||||
|
||||
test("source guard: hook wires D5 navigation order, default scope, and resident editor", () => {
|
||||
test("source guard: hook wires the target model and resident editor", () => {
|
||||
const source = read("../../src/hooks/useReviewDraft.ts");
|
||||
assert.match(
|
||||
source,
|
||||
/import \{ defaultReviewScope, nextReviewNavigationEntry, reviewNavigationOrder \} from "\.\.\/lib\/review-navigation\.js";/,
|
||||
/import \{ defaultReviewScope, nextReviewTargetScope, reviewTargetPosition \} from "\.\.\/lib\/review-navigation\.js";/,
|
||||
);
|
||||
// beginProblem 的 picker 默认作用域按当前目标自动匹配。
|
||||
assert.match(source, /scope: defaultReviewScope\(m\.selected, p\)/);
|
||||
// Ctrl+↑/↓ 走统一导航序:卡片(有目标者)在前,时间点条目在后,到头停住。
|
||||
assert.match(source, /cards: cards\.map\(\(c\) => \(\{ scope: c\.scope, hasTarget: Boolean\(c\.target\) \}\)\),/);
|
||||
assert.match(source, /\{ scope: m\.selected, timestampId: m\.selectedProblem\?\.id \},/);
|
||||
assert.match(source, /if \(next\.kind === "card"\) selectScope\(next\.scope\);/);
|
||||
assert.match(source, /else selectProblem\(next\.problem\);/);
|
||||
// selectProblem 记录当前时间点条目,供导航续走。
|
||||
assert.match(source, /m\.selectedProblem = problem;/);
|
||||
// 目标档解析用画面:时间点档=切入时刻冻结锚点,其余=实时播放头。
|
||||
assert.match(source, /reviewTargetPosition\(scope, m\.position, m\.targetAnchor\)/);
|
||||
// 常驻内联编辑器的绑定(无打开编辑器时)。
|
||||
assert.match(source, /residentEditor:/);
|
||||
// 时间点锚点 = 打开 picker 时的画面(冻结),确认时不随播放头漂移。
|
||||
assert.match(source, /opinionTarget\(actual, picker\.position\)/);
|
||||
// 选择列表条目记录当前档位(时间点条目同时冻结锚点)。
|
||||
assert.match(source, /m\.selected = problem\.scope;/);
|
||||
assert.match(source, /m\.targetAnchor = \{/);
|
||||
});
|
||||
|
||||
test("source guard: expander, summary UI and their state fully removed", () => {
|
||||
@ -107,8 +61,9 @@ test("source guard: resident inline editor promotes into edit state on focus", (
|
||||
assert.match(panel, /onFocus=\{\(\) => review\.selectScope\(resident\.scope, true\)\}/);
|
||||
});
|
||||
|
||||
test("source guard: shortcut help describes the slice→action→timestamp cycle", () => {
|
||||
test("source guard: shortcut help describes target switching with zero popups (07 rewrite)", () => {
|
||||
const help = read("../../src/lib/review-shortcuts.js");
|
||||
assert.match(help, /Ctrl \/ ⌘ \+ ↑ \/ ↓[\s\S]{0,140}时间点/);
|
||||
assert.match(help, /Ctrl \/ ⌘ \+ ↑ \/ ↓[\s\S]{0,80}切换意见目标/);
|
||||
assert.doesNotMatch(help, /选择整体/);
|
||||
assert.doesNotMatch(help, /选择意见范围/);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user