forked from longtao.wu/droboticflow
The quick path validated raw actions before archiving and bypassed the server slice application. Share its archive-aware validation and authoritative save with panel edits, await Enter confirmation, retain failed choices, and preserve pre-drag persisted undo. Cover both directions, recovery, and keyboard/mouse confirmation through the real page and HTTP API.
6672 lines
323 KiB
TypeScript
6672 lines
323 KiB
TypeScript
import { checkSliceEditResolution } from "../lib/slice-edit-drag-quick-path.js";
|
||
import { formatAnnotationTime } from "../lib/annotation-time.js";
|
||
import { userErrorMessage } from "../lib/user-error-message.js";
|
||
import { reviewCommandRequiresWrite, reviewShortcut, reviewShortcutHelp } from "../lib/review-shortcuts.js";
|
||
import type { ReviewViewingProps, ReviewViewingController, ReviewPosition, ReviewNavigation } from "./review-viewing";
|
||
import { ReviewCaptionDetails, ReviewVideoCaption, type ReviewCaption } from "./ReviewCaptions";
|
||
import { reviewCaptionAtTime } from "../lib/review-captions.js";
|
||
import { sliceEditActionsWithDrafts, workbenchDraftsFingerprint } from "../lib/annotation-autosave.js";
|
||
import { DiscardReasonFields, type DiscardReasonChoice } from "./DiscardReasonFields";
|
||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||
import { cancelActionPartition, lastActionFrame, moveActionBoundary } from "../lib/action-frame-boundary.js";
|
||
import { actionJudgment, completeActionPartitions } from "../lib/continuous-actions.js";
|
||
import { adjacentAnnotation } from "../lib/annotation-list-navigation.js";
|
||
import { WorkspaceDictionaryPanel } from "./WorkspaceDictionaryPanel";
|
||
import { SliceNameDictionaryPicker } from "./SliceNameDictionaryPicker";
|
||
import type { CSSProperties, ChangeEvent, PointerEvent as ReactPointerEvent } from "react";
|
||
import {
|
||
AlertCircle,
|
||
AlertTriangle,
|
||
Ban,
|
||
BookOpen,
|
||
Check,
|
||
CheckCircle2,
|
||
ChevronLeft,
|
||
ChevronRight,
|
||
Expand,
|
||
MessageSquare,
|
||
Pause,
|
||
Play,
|
||
Plus,
|
||
RotateCcw,
|
||
Tag,
|
||
Trash2,
|
||
Undo2,
|
||
Volume2,
|
||
X,
|
||
} from "lucide-react";
|
||
import type { ReworkEmphasisView, ReworkLocatePlan, ReworkOpinionView } from "../lib/rework-emphasis-types";
|
||
import type { AnnotationLabelRecord, AnnotationSegment, SemanticLabelDefinition, SliceSegment } from "../types";
|
||
import {
|
||
CAPTURE_PLAYBACK_RATES,
|
||
capturePlaybackBounds,
|
||
sliceDictionaryNameIssue,
|
||
annotationEventOverlaps,
|
||
annotationConfirmationInterval,
|
||
annotationSegmentsForSlice,
|
||
archivedAnnotationsForSlice,
|
||
annotationDraftAtPlayhead,
|
||
annotationDraftCheckAtPlayhead,
|
||
annotationCoverageGaps,
|
||
frameBoundaryAtOrBefore,
|
||
frameBoundaryAligned,
|
||
mapCameraBoundaryTime,
|
||
replaceAnnotationSharedBoundaries,
|
||
nearestFrameBoundaryIndex,
|
||
parseSegmentCommentsFromText,
|
||
serializeSegmentCommentsToText,
|
||
sliceCutIssue,
|
||
sliceIndexAtPlayhead,
|
||
stepFrameBoundary,
|
||
} from "../lib/annotation-workbench.js";
|
||
import { buildBrowserPlayableVideoURL } from "../lib/video-preview.js";
|
||
import { MoviVideo, moviElementReady } from "./MoviVideo";
|
||
import { loadMoviPlayer, moviRuntimeMode } from "../lib/movi-player";
|
||
import { ReworkOpinionRail } from "./ReworkOpinionRail";
|
||
import { ReworkProblemSubtitles } from "./ReworkProblemSubtitles";
|
||
import { reworkLocatePlan, reworkSubtitleRows } from "../lib/rework-emphasis.js";
|
||
import { cn } from "../lib/utils";
|
||
import { intervalStyle } from "../lib/timeline-viewport.js";
|
||
import {
|
||
annotationShortcut,
|
||
annotationShortcutHelpForContext,
|
||
dictionaryKeyDown,
|
||
sliceEditConflictListShortcut,
|
||
sliceEditConflictListShortcutHelp,
|
||
sliceEditPanelShortcut,
|
||
sliceEditPanelShortcutHelp,
|
||
stageConfirmationShortcut,
|
||
} from "../lib/annotation-shortcuts.js";
|
||
import { applyConflictListChoice, conflictListFocusStep } from "../lib/slice-edit-conflict-list.js";
|
||
import {
|
||
resolveSliceEditConflicts,
|
||
restoreSliceEditWorkspace,
|
||
scanSliceEditConflicts,
|
||
snapshotSliceEditWorkspace,
|
||
} from "../lib/slice-edit-conflict.js";
|
||
import type { SliceEditAutoFollow, SliceEditChoice, SliceEditConflictEntry } from "../lib/slice-edit-conflict-types";
|
||
import {
|
||
coarsePendingSliceBoundary,
|
||
mergePendingSliceBoundary,
|
||
movePendingSliceBoundary,
|
||
setPendingSliceDisposition,
|
||
setPendingSliceName,
|
||
splitPendingSlice,
|
||
stepPendingSliceBoundary,
|
||
} from "../lib/slice-edit-panel-ops.js";
|
||
import { SliceEditConflictList } from "./SliceEditConflictList";
|
||
import { SliceEditPanel, type SliceEditPanelDiscardDraft } from "./SliceEditPanel";
|
||
import { ReworkChangesPanel } from "./ReworkChangesPanel";
|
||
import { sliceTimelineIssue } from "../lib/annotation-timeline.js";
|
||
import { useCaptureVideoTransport } from "../hooks/useCaptureVideoTransport";
|
||
|
||
type Phase = "slice" | "materializing" | "annotate";
|
||
type Boundary = { index: number; field: "end" } | null;
|
||
type PointerPoint = { x: number; time: number };
|
||
type BoundaryGesture = { x: number; time: number; secondsPerPixel: number };
|
||
type SplitPreview = { sliceIndex: number; time: number } | null;
|
||
// 切片重设面板的会话状态(票 04):目标切片 + 预览结构 + 打开时快照 + 焦点边界。
|
||
type SliceEditPanelState = {
|
||
sliceId: string;
|
||
pendingSlices: SliceSegment[];
|
||
snapshot: { slices: SliceSegment[]; actions: AnnotationSegment[] };
|
||
baseSnapshot: { slices: SliceSegment[]; actions: AnnotationSegment[] };
|
||
draftsFingerprint: string;
|
||
focusBoundary: "start" | "end";
|
||
};
|
||
type EndSelection = { id: string; start: number; end: number; limit: number; confirmed: boolean; isNew: boolean };
|
||
export type SliceEditor = { annotation: AnnotationSegment; endSelection: EndSelection | null };
|
||
export type AnnotationEditState = {
|
||
sliceId: string;
|
||
time: number;
|
||
segments: AnnotationSegment[];
|
||
editor: SliceEditor | null;
|
||
revealAnnotation?: { id: string; start: number };
|
||
};
|
||
|
||
export type AnnotationDraft = {
|
||
sliceId: string;
|
||
annotation: AnnotationSegment;
|
||
selectingEnd: boolean;
|
||
isNew: boolean;
|
||
};
|
||
|
||
export type ReworkNotice = {
|
||
stageName: string;
|
||
reviewRound?: number;
|
||
reasonCodes?: string[];
|
||
comment?: string;
|
||
problemSliceIds?: string[];
|
||
};
|
||
|
||
type Props = ReviewViewingProps & {
|
||
key?: string;
|
||
taskId: string;
|
||
videoSource: string;
|
||
rightVideoSource?: string;
|
||
clipStart: number;
|
||
clipEnd: number;
|
||
sourceIsFullVideo?: boolean;
|
||
mediaSourceOffsets?: { left: number; right: number };
|
||
slices: SliceSegment[];
|
||
segments: AnnotationSegment[];
|
||
labels?: SemanticLabelDefinition[];
|
||
discardReasons?: AnnotationLabelRecord[];
|
||
discardReasonsLoading?: boolean;
|
||
discardReasonsAllowManual?: boolean;
|
||
operationError?: string;
|
||
operationNotice?: string;
|
||
discardReasonsError?: string;
|
||
onRefreshDiscardReasons?: () => void;
|
||
sliceDictionary?: { id: string; name: string }[];
|
||
sliceDictionaryLoading?: boolean;
|
||
sliceDictionaryError?: string;
|
||
onRefreshSliceDictionary?: () => void;
|
||
statuses: Record<string, NonNullable<SliceSegment["annotationStatus"]>>;
|
||
phase: Phase;
|
||
adaptiveLayout?: boolean;
|
||
focusedLayout?: boolean;
|
||
viewportSuspended?: boolean;
|
||
/**
|
||
* Acceptance final review (acceptance-fixes defect 1): when provided, the top
|
||
* progress slider represents the WHOLE source video — thumb at
|
||
* offset + currentTime over duration — and seeks through the host's slice
|
||
* navigation instead of only the current clip.
|
||
*/
|
||
totalProgress?: { offset: number; duration: number; onSeekTotal?: (time: number) => void };
|
||
frameBoundaries?: number[];
|
||
frameTimelineStatus?: "loading" | "ready" | "error";
|
||
onRetryFrameTimeline?: () => void;
|
||
onAlignSliceBoundaries?: () => void;
|
||
rightMediaBoundaries?: number[];
|
||
unifiedBoundaries?: boolean;
|
||
readOnly?: boolean;
|
||
readOnlyStatusLabel?: string;
|
||
isQualityReview?: boolean;
|
||
/**
|
||
* Captions (video overlay + side panel) are viewable for ANY claimed task in
|
||
* the review workbenches, regardless of who views it or which layout is
|
||
* active. Unlike isQualityReview this never unlocks review/edit controls —
|
||
* it only widens caption visibility (2026-10-12 relaxation).
|
||
*/
|
||
captionsViewable?: boolean;
|
||
reviewWriteLocked?: boolean;
|
||
reviewMode?: "quality" | "acceptance";
|
||
reviewCaption?: ReviewCaption;
|
||
reviewCaptionStatus?: "loading" | "ready" | "error";
|
||
reviewNavigation?: ReviewNavigation;
|
||
reviewComment?: string;
|
||
onReviewCommentChange?: (comment: string) => void;
|
||
onApprove?: () => void;
|
||
onReject?: () => void;
|
||
reworkNotice?: ReworkNotice;
|
||
/** 返工强调层:按"退回基线 vs 当前工作区"算出的红/灰/跳过投影;null=非返工或旧格式退回(走遗留文本匹配)。 */
|
||
reworkEmphasis?: ReworkEmphasisView | null;
|
||
/**
|
||
* QC 返修接收视图的强调层(票 08/09):输入是已保存工作区(ADR 0006:31),
|
||
* 与标注员侧 reworkEmphasis(实时草稿)语义分开;审查视角下渲染意见字幕与
|
||
* 轨道红/灰(复用标注员同款视觉),不解锁任何编辑能力。null=非返修复审。
|
||
*/
|
||
reviewReworkEmphasis?: ReworkEmphasisView | null;
|
||
/** 标注员一键"不改了"(skip=true)/撤销(skip=false),由页面落库到 rework-handling。 */
|
||
onReworkSkipToggle?: (opinionId: string, skipped: boolean) => void;
|
||
onChange: (segments: AnnotationSegment[]) => void;
|
||
onPlayheadChange?: (time: number) => void;
|
||
onDraftsChange?: (drafts: AnnotationDraft[]) => void;
|
||
/** 换片通知(A01 草稿落盘触发):选中切片变化时上报;初始挂载不触发。 */
|
||
onSelectedSliceChange?: (sliceId: string) => void;
|
||
onSliceNameChange?: (sliceId: string, name: string) => void;
|
||
onSliceDispositionChange?: (
|
||
sliceId: string,
|
||
disposition: "keep" | "discard",
|
||
reason: DiscardReasonChoice,
|
||
) => Promise<boolean>;
|
||
onSliceBoundaryChange?: (sliceId: string, field: "start" | "end", value: number) => void;
|
||
onSliceBoundaryEditStart?: (sliceId: string) => void;
|
||
onSliceBoundaryEditEnd?: () => void;
|
||
onAnnotationEdit?: (before: AnnotationEditState, after: AnnotationEditState) => void;
|
||
onAnnotationDraftEdit?: () => void;
|
||
onHistoryCommand?: (direction: "undo" | "redo") => Promise<void> | void;
|
||
historyReveal?: {
|
||
sliceId: string;
|
||
time: number;
|
||
revision: number;
|
||
editor?: SliceEditor | null;
|
||
revealAnnotation?: { id: string; start: number };
|
||
} | null;
|
||
onSplitSlice?: (sliceIndex: number, at: number) => string | undefined | Promise<string | undefined>;
|
||
onDeleteSlice?: (sliceIndex: number) => void;
|
||
onMergeSliceBoundary?: (sliceId: string, direction: "shrink" | "expand") => void;
|
||
/**
|
||
* 切片重设面板 Enter 应用(票 04,spec §2 R1-Q1/R1-Q4):把面板预览的整套结构
|
||
* (切片 + 冲突解析后的动作产物)作为一次原子落库交给页面侧(applySliceChange
|
||
* 同款:一条可撤销历史 + 状态重推导)。返回 false 表示页面当前不接受改动。
|
||
*/
|
||
onApplySliceEdit?: (
|
||
slices: SliceSegment[],
|
||
segments: AnnotationSegment[],
|
||
focusSliceId: string,
|
||
) => boolean | Promise<boolean>;
|
||
/**
|
||
* 切片重设面板会话通道(验收修复 C):面板打开(true)与整体关闭(false,
|
||
* Enter 应用或 Esc 取消)时通知页面——页面据此暂停草稿自动落盘(快照引用
|
||
* 保持稳定),并在会话释放后立即补一次落盘。
|
||
*/
|
||
onSliceEditSessionChange?: (open: boolean) => void;
|
||
/**
|
||
* 票 05(spec §2 R2-Q3):结构快捷入口(拖动释放/悬停+拆分)撞出的冲突条目。
|
||
* 非空时工作台就地弹出与 04 面板同款的 SliceEditConflictList(同一键盘模型、同一
|
||
* 默认语义,锚在释放分界处);Enter → onSliceEditQuickConflictApply(页面 03 引擎
|
||
* 落定 + 自检 + 原子落库,成功时返回焦点切片 id 供选中),Esc →
|
||
* onSliceEditQuickConflictCancel(拖动来源回退快照;拆分来源未落库直接丢弃)。
|
||
*/
|
||
sliceEditQuickConflict?: {
|
||
entries: SliceEditConflictEntry[];
|
||
anchorTime: number;
|
||
autoFollows?: SliceEditAutoFollow[];
|
||
beforeSlices?: SliceSegment[];
|
||
afterSlices?: SliceSegment[];
|
||
} | null;
|
||
onSliceEditQuickConflictApply?: (
|
||
decisions: Partial<Record<string, SliceEditChoice>>,
|
||
) => string | undefined | void | Promise<string | undefined | void>;
|
||
onSliceEditQuickConflictCancel?: () => void;
|
||
sliceEditAppliedRevision?: number;
|
||
onConfirmSlices?: () => void;
|
||
canConfirmSlices?: boolean;
|
||
onConfirmAnnotations?: (
|
||
segments: AnnotationSegment[],
|
||
sliceId: string,
|
||
before?: AnnotationEditState,
|
||
) => Promise<boolean> | boolean | void;
|
||
problemSliceIds?: string[];
|
||
onProblemSliceIdsChange?: (ids: string[]) => void;
|
||
/** 票 06:仅首标(从未送检)任务由页面传入;不传即不渲染入口。 */
|
||
onRequestReslice?: () => void;
|
||
onReleaseTask?: () => void;
|
||
claimLocked?: boolean;
|
||
onSubmitTask?: () => void;
|
||
canSubmitTask?: boolean;
|
||
submissionBlockerReason?: string;
|
||
saving?: boolean;
|
||
initialSliceId?: string;
|
||
onReturnToPool?: () => void;
|
||
mediaOnly?: boolean;
|
||
onMediaDuration?: (duration: number) => void;
|
||
browserReadyMedia?: boolean;
|
||
seekRequest?: { time: number; revision: number } | null;
|
||
cameraPreferenceKey?: string;
|
||
continuousActions?: boolean;
|
||
progressSaved?: boolean;
|
||
onSaveProgress?: (segments: AnnotationSegment[]) => Promise<boolean>;
|
||
initialCameraVisibility?: { left: boolean; right: boolean };
|
||
onCameraVisibilityChange?: (value: { left: boolean; right: boolean }) => void;
|
||
};
|
||
|
||
import { annotationTimelineColors as colors } from "../lib/annotation-colors.js";
|
||
|
||
const formatTime = formatAnnotationTime;
|
||
|
||
const frameStep = 1 / 30;
|
||
|
||
function clamp(value: number, lower: number, upper: number) {
|
||
return Math.max(lower, Math.min(upper, value));
|
||
}
|
||
|
||
// Match the explicit 16px range thumb: its center travels from 8px to width-8px.
|
||
function timelinePosition(time: number, lower: number, upper: number) {
|
||
const ratio = clamp((time - lower) / Math.max(upper - lower, 0.001), 0, 1);
|
||
return `calc(${ratio * 100}% + ${8 - 16 * ratio}px)`;
|
||
}
|
||
|
||
function pointForEvent(
|
||
event: ReactPointerEvent<HTMLElement>,
|
||
root: HTMLElement,
|
||
lower: number,
|
||
upper: number,
|
||
): PointerPoint {
|
||
const bounds = root.getBoundingClientRect();
|
||
const ratio = clamp((event.clientX - bounds.left - root.clientLeft - 8) / Math.max(root.clientWidth - 16, 1), 0, 1);
|
||
return { x: event.clientX, time: lower + (upper - lower) * ratio };
|
||
}
|
||
|
||
export function CaptureAnnotationWorkbench({
|
||
taskId,
|
||
videoSource,
|
||
rightVideoSource,
|
||
clipStart,
|
||
clipEnd,
|
||
sourceIsFullVideo = false,
|
||
mediaSourceOffsets,
|
||
slices,
|
||
segments: providedSegments,
|
||
labels = [],
|
||
discardReasons = [],
|
||
discardReasonsLoading = false,
|
||
discardReasonsAllowManual = false,
|
||
operationError = "",
|
||
operationNotice = "",
|
||
discardReasonsError = "",
|
||
onRefreshDiscardReasons,
|
||
sliceDictionary = [],
|
||
sliceDictionaryLoading = false,
|
||
sliceDictionaryError = "",
|
||
onRefreshSliceDictionary,
|
||
statuses,
|
||
phase,
|
||
adaptiveLayout = false,
|
||
focusedLayout = false,
|
||
viewportSuspended = false,
|
||
totalProgress,
|
||
frameBoundaries = [],
|
||
frameTimelineStatus = "ready",
|
||
onRetryFrameTimeline,
|
||
onAlignSliceBoundaries,
|
||
rightMediaBoundaries = [],
|
||
unifiedBoundaries = false,
|
||
readOnly: providedReadOnly = false,
|
||
readOnlyStatusLabel = "任务",
|
||
isQualityReview = false,
|
||
captionsViewable = false,
|
||
reviewWriteLocked = false,
|
||
reviewMode = "quality",
|
||
reviewCaption: providedReviewCaption,
|
||
reviewCaptionStatus,
|
||
reviewNavigation,
|
||
onReviewNavigate,
|
||
onReviewPositionChange,
|
||
onReviewController,
|
||
onReviewProblem,
|
||
onReviewSave,
|
||
onReviewTargetSwitch,
|
||
onReviewReworkNavigate,
|
||
onReviewReworkVerdict,
|
||
onReviewTimestampJump,
|
||
reviewTimestampOpinions,
|
||
onReviewProblemEdit,
|
||
onReviewProblemDelete,
|
||
onReviewEscape,
|
||
reviewProblemPanel,
|
||
reviewComment = "",
|
||
onReviewCommentChange,
|
||
onApprove,
|
||
onReject,
|
||
reworkNotice,
|
||
reworkEmphasis = null,
|
||
reviewReworkEmphasis = null,
|
||
onReworkSkipToggle,
|
||
onChange,
|
||
onPlayheadChange,
|
||
onDraftsChange,
|
||
onSliceNameChange,
|
||
onSliceDispositionChange,
|
||
onSliceBoundaryChange,
|
||
onSliceBoundaryEditStart,
|
||
onSliceBoundaryEditEnd,
|
||
sliceEditQuickConflict = null,
|
||
onSliceEditQuickConflictApply,
|
||
onSliceEditQuickConflictCancel,
|
||
sliceEditAppliedRevision,
|
||
onAnnotationEdit,
|
||
onAnnotationDraftEdit,
|
||
onHistoryCommand,
|
||
historyReveal,
|
||
onSplitSlice,
|
||
onDeleteSlice,
|
||
onMergeSliceBoundary,
|
||
onApplySliceEdit,
|
||
onSliceEditSessionChange,
|
||
onConfirmSlices,
|
||
canConfirmSlices = false,
|
||
onConfirmAnnotations,
|
||
problemSliceIds = [],
|
||
onProblemSliceIdsChange,
|
||
onRequestReslice,
|
||
onReleaseTask,
|
||
claimLocked = false,
|
||
onSubmitTask,
|
||
canSubmitTask = false,
|
||
submissionBlockerReason = "",
|
||
saving: externalSaving = false,
|
||
initialSliceId = "",
|
||
onReturnToPool,
|
||
mediaOnly = false,
|
||
onMediaDuration,
|
||
browserReadyMedia = false,
|
||
seekRequest,
|
||
cameraPreferenceKey = "",
|
||
continuousActions = false,
|
||
progressSaved = true,
|
||
onSaveProgress,
|
||
onSelectedSliceChange,
|
||
initialCameraVisibility,
|
||
onCameraVisibilityChange,
|
||
}: Props) {
|
||
const isReviewViewing = isQualityReview || Boolean(providedReviewCaption) || Boolean(reviewNavigation);
|
||
const timelineReady = frameTimelineStatus === "ready";
|
||
// Reviewing may allow opinions and decisions, never annotation authoring.
|
||
// Keep this invariant here so pointer, keyboard and legacy viewing paths agree.
|
||
const reviewReadOnly = providedReadOnly || !timelineReady || reviewWriteLocked;
|
||
const readOnly = providedReadOnly || !timelineReady || isReviewViewing || mediaOnly;
|
||
const reviewWritableRef = useRef(!reviewReadOnly);
|
||
reviewWritableRef.current = !reviewReadOnly;
|
||
// Editable continuous tracks expose explicit pending intervals, including
|
||
// legacy empty workspaces; frozen review records and loading states stay raw.
|
||
const segments = useMemo(
|
||
() =>
|
||
continuousActions && phase === "annotate" && !readOnly && !isReviewViewing
|
||
? (completeActionPartitions(slices, providedSegments) as AnnotationSegment[])
|
||
: providedSegments,
|
||
[continuousActions, phase, readOnly, isReviewViewing, slices, providedSegments],
|
||
);
|
||
const workbenchRef = useRef<HTMLElement>(null);
|
||
const suspendedDialogsRef = useRef<HTMLDialogElement[] | null>(null);
|
||
const descriptionInputRef = useRef<HTMLTextAreaElement>(null);
|
||
const descriptionEditorRef = useRef<HTMLDivElement>(null);
|
||
const sliceDictionaryTriggerRef = useRef<HTMLButtonElement>(null);
|
||
const descriptionDictionaryTriggerRef = useRef<HTMLButtonElement>(null);
|
||
const descriptionDictionaryRef = useRef<HTMLDivElement>(null);
|
||
const shortcutHelpRef = useRef<HTMLDialogElement>(null);
|
||
const stageDialogRef = useRef<HTMLDialogElement>(null);
|
||
const [stageConfirmation, setStageConfirmation] = useState<"slice" | "annotate" | "drafts" | null>(null);
|
||
const stageEnterReleasedRef = useRef(false);
|
||
const stageDispatchingRef = useRef(false);
|
||
useEffect(() => {
|
||
if (stageConfirmation) {
|
||
stageDialogRef.current?.showModal();
|
||
stageDialogRef.current?.focus();
|
||
} else stageDialogRef.current?.close();
|
||
}, [stageConfirmation]);
|
||
const dispositionDialogRef = useRef<HTMLDivElement>(null);
|
||
const [dispositionOpen, setDispositionOpen] = useState(false);
|
||
const closeDisposition = () => {
|
||
setDispositionOpen(false);
|
||
requestAnimationFrame(focusWorkbench);
|
||
};
|
||
const [dispositionDraft, setDispositionDraft] = useState<DiscardReasonChoice & { sliceId: string; discard: boolean }>(
|
||
{ sliceId: "", reasonNote: "", discard: false },
|
||
);
|
||
const [dispositionError, setDispositionError] = useState("");
|
||
const saveInFlightRef = useRef(false);
|
||
const [descriptionSaving, setDescriptionSaving] = useState(false);
|
||
const saving = externalSaving || descriptionSaving;
|
||
const annotationWritableRef = useRef(!readOnly && !saving);
|
||
annotationWritableRef.current = !readOnly && !saving;
|
||
const focusWorkbench = () => workbenchRef.current?.focus({ preventScroll: true });
|
||
const focusDescriptionEditor = () => descriptionEditorRef.current?.focus({ preventScroll: true });
|
||
const leftVideoRef = useRef<HTMLVideoElement>(null);
|
||
const rightVideoRef = useRef<HTMLVideoElement>(null);
|
||
// The transport's seek queue assumes the video nodes answer
|
||
// HTMLMediaElement properties from the first render, so the workbench only
|
||
// hands its videos to <movi-player> once the custom element is defined.
|
||
// Until then (or under the runtime kill-switch) it renders native <video>,
|
||
// which is exactly the E′ direct path — fully functional on its own.
|
||
const [moviVideoReady, setMoviVideoReady] = useState(() => moviElementReady());
|
||
const [opinionMarkerOpen, setOpinionMarkerOpen] = useState<string | null>(null);
|
||
useEffect(() => {
|
||
if (browserReadyMedia || moviRuntimeMode() !== "movi") return;
|
||
if (moviElementReady()) {
|
||
setMoviVideoReady(true);
|
||
return;
|
||
}
|
||
let cancelled = false;
|
||
loadMoviPlayer()
|
||
.then(() => {
|
||
if (!cancelled) setMoviVideoReady(true);
|
||
})
|
||
.catch(() => {
|
||
// Module load failed: stay on the native branch for this session.
|
||
if (!cancelled) setMoviVideoReady(false);
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [browserReadyMedia]);
|
||
const useMoviVideo = !browserReadyMedia && moviVideoReady;
|
||
const videoSurfaceRef = useRef<HTMLDivElement>(null);
|
||
const sliceTrackRef = useRef<HTMLDivElement>(null);
|
||
const annotationTrackRef = useRef<HTMLDivElement>(null);
|
||
const sliceDragRef = useRef<{ index: number; gesture: BoundaryGesture } | null>(null);
|
||
const annotationBoundaryDragRef = useRef<{
|
||
index: number;
|
||
before: AnnotationEditState;
|
||
gesture: BoundaryGesture;
|
||
after?: AnnotationEditState;
|
||
} | null>(null);
|
||
const [selectedAnnotationBoundary, setSelectedAnnotationBoundary] = useState<{ index: number } | null>(null);
|
||
const [annotationSplitPreview, setAnnotationSplitPreview] = useState<{ segmentIndex: number; time: number } | null>(
|
||
null,
|
||
);
|
||
const [hoveredSegment, setHoveredSegment] = useState<{ segment: AnnotationSegment; index: number } | null>(null);
|
||
const [selectedSliceId, setSelectedSliceId] = useState(() => initialSliceId || slices[0]?.id || "");
|
||
// A01 草稿落盘:换片上报(初始挂载不触发;slices 整体重置时由 key 重挂载自然跳过)。
|
||
const notifiedSelectedSliceRef = useRef(selectedSliceId);
|
||
useEffect(() => {
|
||
if (notifiedSelectedSliceRef.current !== selectedSliceId) {
|
||
notifiedSelectedSliceRef.current = selectedSliceId;
|
||
onSelectedSliceChange?.(selectedSliceId);
|
||
}
|
||
}, [selectedSliceId, onSelectedSliceChange]);
|
||
const [currentTime, setCurrentTime] = useState(clipStart);
|
||
const [captionsVisible, setCaptionsVisible] = useState(true);
|
||
const [sliceZoom, setSliceZoom] = useState(false);
|
||
const [playbackRate, setPlaybackRate] = useState(1);
|
||
const [showLeft, setShowLeft] = useState(initialCameraVisibility?.left ?? true);
|
||
// Ordinary layouts load the left stream only until the right checkbox is
|
||
// explicitly selected. Focused camera preferences are applied separately.
|
||
const [showRight, setShowRight] = useState(initialCameraVisibility?.right ?? false);
|
||
const cameraStorageKey = cameraPreferenceKey
|
||
? `${isQualityReview || providedReviewCaption ? "review" : "annotation"}-camera-default:${cameraPreferenceKey}`
|
||
: "";
|
||
const readCameraDefault = () => {
|
||
try {
|
||
const value = cameraStorageKey && localStorage.getItem(cameraStorageKey);
|
||
return value === "right" || value === "both" ? value : "left";
|
||
} catch {
|
||
return "left";
|
||
}
|
||
};
|
||
const [defaultCamera, setDefaultCamera] = useState(readCameraDefault);
|
||
const initialInspection = () => {
|
||
if (!rightVideoSource) return "left" as const;
|
||
if (providedReviewCaption && initialCameraVisibility)
|
||
return initialCameraVisibility.left && initialCameraVisibility.right
|
||
? null
|
||
: initialCameraVisibility.right
|
||
? ("right" as const)
|
||
: ("left" as const);
|
||
const preference = readCameraDefault();
|
||
return preference === "both" ? null : (preference as "left" | "right");
|
||
};
|
||
const [inspectionCamera, setInspectionCamera] = useState<"left" | "right" | null>(initialInspection);
|
||
const effectiveShowLeft = focusedLayout ? inspectionCamera !== "right" || !rightVideoSource : showLeft;
|
||
const effectiveShowRight = Boolean(rightVideoSource) && (focusedLayout ? inspectionCamera !== "left" : showRight);
|
||
const inspectCamera = (camera: "left" | "right" | null) => {
|
||
if (camera === inspectionCamera) return;
|
||
transport.prepareCameraChange();
|
||
setInspectionCamera(camera);
|
||
if (providedReviewCaption) onCameraVisibilityChange?.({ left: camera !== "right", right: camera !== "left" });
|
||
};
|
||
useEffect(() => {
|
||
const preference = readCameraDefault();
|
||
setDefaultCamera(preference);
|
||
setInspectionCamera(initialInspection());
|
||
}, [taskId, cameraStorageKey]);
|
||
const [selectedBoundary, setSelectedBoundary] = useState<Boundary>(null);
|
||
// 切片重设面板(票 04,spec §2 R1-Q1/R2-Q4/R2-Q5):E 进入的专注浮层。打开期间
|
||
// 一切结构变更只进 pendingSlices 预览(轨道实时可见),Enter 应用、Esc 取消;
|
||
// snapshot 为打开时的工作区快照(03 引擎),冲突解析的基线与 Esc 回退都以它为准。
|
||
const [sliceEditPanel, setSliceEditPanel] = useState<SliceEditPanelState | null>(null);
|
||
// D6 驻留(rework-ux-adjust 04):J/K 导航收起面板时未应用改动转存于此——重新
|
||
// 打开(E 或 J/K 落回切片问题)且工作区未变时原样恢复;Esc 显式全弃、Enter 应用
|
||
// 后清空;工作区已变则作废旧预览按现状新开(与 Enter 外部改动守卫同一口径)。
|
||
const [sliceEditPanelStash, setSliceEditPanelStash] = useState<SliceEditPanelState | null>(null);
|
||
// Enter 撞出冲突时的清单状态(条目来自 03 引擎 scanSliceEditConflicts;键盘模型
|
||
// seam ③ + slice-edit-conflict-list 纯函数)。source 区分宿主:"panel" = 04 面板
|
||
// Enter(apply/cancel 走面板自己的流);"quick" = 05 结构快捷入口(拖动释放/悬停+
|
||
// 拆分,Enter/Esc 分发回页面回调)——两者共用同一组件与键盘模型。
|
||
const [sliceEditConflictList, setSliceEditConflictList] = useState<{
|
||
entries: SliceEditConflictEntry[];
|
||
autoFollows: SliceEditAutoFollow[];
|
||
decisions: Partial<Record<string, SliceEditChoice>>;
|
||
focus: number;
|
||
source: "panel" | "quick";
|
||
} | null>(null);
|
||
// 面板内 G 的舍弃原因草稿(预览,不落库;确认后随 Enter 一并应用)。
|
||
const [sliceEditDiscardDraft, setSliceEditDiscardDraft] = useState<SliceEditPanelDiscardDraft | null>(null);
|
||
const discardDraftWasOpenRef = useRef(false);
|
||
useLayoutEffect(() => {
|
||
const closed = discardDraftWasOpenRef.current && !sliceEditDiscardDraft;
|
||
discardDraftWasOpenRef.current = Boolean(sliceEditDiscardDraft);
|
||
// Removing the focused child dialog sends focus to BODY. Reclaim it after
|
||
// the DOM commit, without stealing a deliberate focus on another control.
|
||
if (closed && sliceEditPanel && document.activeElement === document.body)
|
||
workbenchRef.current?.focus({ preventScroll: true });
|
||
}, [sliceEditDiscardDraft, sliceEditPanel]);
|
||
|
||
// R2-Q5 旁路锁定提示:面板/清单打开期间按 J/K、拖手柄、点其它切片时的可见反馈
|
||
// (短暂停留后自动消失,复用 E 提示的恒定占位槽渲染)。
|
||
const [sliceEditLocked, setSliceEditLocked] = useState(false);
|
||
const sliceEditLockedTimerRef = useRef<number | null>(null);
|
||
const [splitPreview, setSplitPreview] = useState<SplitPreview>(null);
|
||
const [editingAnnotation, setEditingAnnotation] = useState<AnnotationSegment | null>(null);
|
||
const [parkedEditors, setParkedEditors] = useState<Record<string, SliceEditor>>({});
|
||
// 意见定位决策(reworkLocatePlan)用的停泊视图:sliceId → 停泊编辑器动作 id。
|
||
// 目标片有停泊草稿时跳转不自动开新编辑器,交回 selectSlice 恢复停泊态。
|
||
const parkedAnnotationBySlice = useMemo(() => {
|
||
const ids: Record<string, string> = {};
|
||
for (const entry of Object.entries(parkedEditors) as Array<[string, SliceEditor]>) {
|
||
ids[entry[0]] = entry[1].annotation.id;
|
||
}
|
||
return ids;
|
||
}, [parkedEditors]);
|
||
const [workPosition, setWorkPosition] = useState<number | null>(null);
|
||
const [reviewPlayback, setReviewPlayback] = useState(false);
|
||
// Review and navigation must never move an unfinished action's end point.
|
||
const endTrackingSuspended = useRef(false);
|
||
const [endSelection, setEndSelectionState] = useState<EndSelection | null>(null);
|
||
const endSelectionRef = useRef<EndSelection | null>(null);
|
||
const setEndSelection = useCallback((value: EndSelection | null) => {
|
||
endSelectionRef.current = value ? { ...value } : null;
|
||
setEndSelectionState(value);
|
||
}, []);
|
||
const selectingEnd = Boolean(
|
||
editingAnnotation && endSelection?.id === editingAnnotation.id && !endSelection.confirmed,
|
||
);
|
||
const isNewAnnotation = Boolean(editingAnnotation && endSelection?.id === editingAnnotation.id && endSelection.isNew);
|
||
useEffect(() => {
|
||
if (endSelectionRef.current?.id !== editingAnnotation?.id) setEndSelection(null);
|
||
}, [editingAnnotation?.id, setEndSelection]);
|
||
useEffect(() => {
|
||
if (phase !== "annotate" || readOnly) setEndSelection(null);
|
||
}, [phase, readOnly, setEndSelection]);
|
||
const [showDictionary, setShowDictionary] = useState(false);
|
||
const [expandedDescription, setExpandedDescription] = useState(false);
|
||
useEffect(() => setExpandedDescription(false), [editingAnnotation?.id]);
|
||
// Normal and focused layouts share this task's temporary camera choice.
|
||
// Only a new task/account above applies the saved default again.
|
||
useEffect(() => {
|
||
if (showDictionary && !focusedLayout)
|
||
(
|
||
descriptionDictionaryRef.current?.querySelector<HTMLButtonElement>("[data-dictionary-option]") ||
|
||
descriptionDictionaryRef.current
|
||
)?.focus();
|
||
}, [showDictionary, focusedLayout]);
|
||
const [error, setError] = useState("");
|
||
const [showRejectModal, setShowRejectModal] = useState(false);
|
||
const [generalRejectReason, setGeneralRejectReason] = useState("");
|
||
|
||
useEffect(() => {
|
||
// Drafts and review bookmarks belong to one task and editing stage only.
|
||
setStageConfirmation(null);
|
||
stageDispatchingRef.current = false;
|
||
setParkedEditors({});
|
||
setWorkPosition(null);
|
||
setReviewPlayback(false);
|
||
endTrackingSuspended.current = false;
|
||
setEndSelection(null);
|
||
setEditingAnnotation(null);
|
||
setShowDictionary(false);
|
||
shortcutHelpRef.current?.close();
|
||
setSelectedBoundary(null);
|
||
setSelectedAnnotationBoundary(null);
|
||
setSplitPreview(null);
|
||
setAnnotationSplitPreview(null);
|
||
setHoveredSegment(null);
|
||
sliceDragRef.current = null;
|
||
annotationBoundaryDragRef.current = null;
|
||
setError("");
|
||
}, [taskId, phase]);
|
||
|
||
const fallbackSlice = useMemo<SliceSegment>(
|
||
() => ({
|
||
id: "fallback-slice-0",
|
||
name: "切片 001",
|
||
start: clipStart,
|
||
end: clipEnd > clipStart ? clipEnd : clipStart + 1,
|
||
status: "pending",
|
||
}),
|
||
[clipStart, clipEnd],
|
||
);
|
||
const selectedSliceIndex = Math.max(
|
||
0,
|
||
slices.findIndex((slice) => slice.id === selectedSliceId),
|
||
);
|
||
const selectedSlice = (slices && slices.length > 0 ? slices[selectedSliceIndex] || slices[0] : null) || fallbackSlice;
|
||
const entryFocusKeyRef = useRef("");
|
||
useEffect(() => {
|
||
if (!timelineReady || viewportSuspended) return;
|
||
const key = `${taskId}:${phase}:${focusedLayout}`;
|
||
if (entryFocusKeyRef.current === key) return;
|
||
const frame = requestAnimationFrame(() => {
|
||
const root = workbenchRef.current;
|
||
if (!root || root.closest("[inert]")) return;
|
||
entryFocusKeyRef.current = key;
|
||
const active = document.activeElement;
|
||
// Task entry controls live outside the workbench. Hand keyboard ownership
|
||
// over once the task is ready, but never interrupt typing or an open dialog.
|
||
if (
|
||
document.querySelector("dialog[open], [role='dialog']") ||
|
||
(active instanceof HTMLElement &&
|
||
(active.closest("textarea, [contenteditable='true']") ||
|
||
(active instanceof HTMLInputElement && !active.readOnly && active.type !== "range")))
|
||
)
|
||
return;
|
||
if (!root.contains(active)) root.focus({ preventScroll: true });
|
||
});
|
||
return () => cancelAnimationFrame(frame);
|
||
}, [taskId, phase, focusedLayout, timelineReady, viewportSuspended]);
|
||
useEffect(() => {
|
||
// This side panel is non-modal: timeline and previous/next clicks can change
|
||
// the visible slice. Never leave a confirmation bound to the former slice.
|
||
if (dispositionOpen && dispositionDraft.sliceId !== selectedSlice?.id) {
|
||
setDispositionOpen(false);
|
||
setDispositionError("");
|
||
}
|
||
}, [selectedSlice?.id, dispositionOpen, dispositionDraft.sliceId]);
|
||
// 切片重设面板只在 annotate 相的可编辑工作台内存在;阶段流转/只读化时整体取消
|
||
// (预览本就不落库,丢弃即回退)。不随 slices.length < 2 退出:面板内合并到单切片
|
||
// 合法(拆分可再补回),守卫只在进入时拦。
|
||
useEffect(() => {
|
||
if (
|
||
(sliceEditPanel || sliceEditConflictList) &&
|
||
(phase !== "annotate" || readOnly || isQualityReview || mediaOnly)
|
||
) {
|
||
// 票 05:快路径清单随阶段/只读化一并取消——页面回退拖动几何(或丢弃未落库
|
||
// 改动),不留悬空待决结构。
|
||
if (sliceEditConflictList?.source === "quick") onSliceEditQuickConflictCancel?.();
|
||
setSliceEditPanel(null);
|
||
setSliceEditConflictList(null);
|
||
setSliceEditDiscardDraft(null);
|
||
}
|
||
}, [
|
||
sliceEditPanel,
|
||
sliceEditConflictList,
|
||
phase,
|
||
readOnly,
|
||
isQualityReview,
|
||
mediaOnly,
|
||
onSliceEditQuickConflictCancel,
|
||
]);
|
||
// 票 05:拖动/悬停+释放撞出的冲突条目 → 同一清单组件与键盘模型(source 标记来
|
||
// 源,Enter/Esc 分发回页面);条目清空时只收 quick 来源(面板来源由面板自己的流
|
||
// 收尾)。页面只在开/关时改这个 prop,选择状态留在本地不被重置。
|
||
useEffect(() => {
|
||
if (!sliceEditQuickConflict) {
|
||
setSliceEditConflictList((list) => (list?.source === "quick" ? null : list));
|
||
return;
|
||
}
|
||
setSliceEditConflictList({
|
||
entries: sliceEditQuickConflict.entries,
|
||
autoFollows: sliceEditQuickConflict.autoFollows ?? [],
|
||
decisions: {},
|
||
focus: 0,
|
||
source: "quick",
|
||
});
|
||
}, [sliceEditQuickConflict]);
|
||
useEffect(
|
||
() => () => {
|
||
if (sliceEditLockedTimerRef.current !== null) window.clearTimeout(sliceEditLockedTimerRef.current);
|
||
},
|
||
[],
|
||
);
|
||
const playbackBounds = capturePlaybackBounds(phase, selectedSlice, clipStart, clipEnd, reviewPlayback);
|
||
const playheadSliceIndex = sliceIndexAtPlayhead(slices, currentTime);
|
||
const playheadSlice = playheadSliceIndex >= 0 ? slices[playheadSliceIndex] : null;
|
||
const selectedDiscarded = selectedSlice.deliveryDisposition === "discard";
|
||
const showDispositionPanel =
|
||
(phase === "slice" || readOnly || isQualityReview || dispositionOpen) && (selectedDiscarded || dispositionOpen);
|
||
const canEditDisposition = phase === "slice" && !readOnly && !isQualityReview && !!onSliceDispositionChange;
|
||
const sliceNameIssue = sliceDictionaryNameIssue(
|
||
slices,
|
||
sliceDictionary,
|
||
sliceDictionaryLoading,
|
||
sliceDictionaryError,
|
||
);
|
||
const source = browserReadyMedia ? videoSource : buildBrowserPlayableVideoURL(videoSource);
|
||
const rightSource = browserReadyMedia ? rightVideoSource : buildBrowserPlayableVideoURL(rightVideoSource);
|
||
const exactFrames = frameBoundaries.length > 1;
|
||
const sliceAligned =
|
||
!unifiedBoundaries ||
|
||
(frameBoundaryAligned(frameBoundaries, selectedSlice.start) &&
|
||
frameBoundaryAligned(frameBoundaries, selectedSlice.end));
|
||
const annotationGaps = annotationCoverageGaps(selectedSlice, segments);
|
||
const annotationSegments = useMemo(
|
||
() => annotationSegmentsForSlice(selectedSlice, segments).sort((left, right) => left.start - right.start),
|
||
[segments, selectedSlice],
|
||
);
|
||
const annotationForRender = useMemo(() => {
|
||
if (!editingAnnotation) return annotationSegments;
|
||
const found = annotationSegments.some((segment) => segment.id === editingAnnotation.id);
|
||
return (
|
||
found
|
||
? annotationSegments.map((segment) => (segment.id === editingAnnotation.id ? editingAnnotation : segment))
|
||
: [...annotationSegments, editingAnnotation]
|
||
).sort((left, right) => left.start - right.start);
|
||
}, [annotationSegments, editingAnnotation]);
|
||
// 弃用片动作栏(I4):栏保留挂载,只读展示随片归档动作(审核证据,
|
||
// SliceSegment.discardedAnnotations);非弃用片行为不变,仍显示活动标注列表。
|
||
const actionListForRender = selectedDiscarded ? archivedAnnotationsForSlice(selectedSlice) : annotationForRender;
|
||
|
||
const [showActionJSON, setShowActionJSON] = useState(false);
|
||
const actionListRef = useRef<HTMLDivElement>(null);
|
||
const listSelectedIndex = annotationForRender.findIndex((action) => action.id === editingAnnotation?.id);
|
||
const previousListIndex = useRef(-1);
|
||
useEffect(() => {
|
||
const list = actionListRef.current;
|
||
const row = list?.querySelector<HTMLElement>("[aria-selected='true']");
|
||
if (list && row) {
|
||
const wrap = Math.abs(previousListIndex.current - listSelectedIndex) > 6;
|
||
list.scrollTo({
|
||
top: Math.max(0, row.offsetTop - list.clientHeight * 0.4),
|
||
behavior: wrap ? "instant" : "smooth",
|
||
});
|
||
}
|
||
previousListIndex.current = listSelectedIndex;
|
||
}, [editingAnnotation?.id, listSelectedIndex]);
|
||
const displayedAction = annotationForRender.find(
|
||
(action) => currentTime >= action.start - 1e-7 && currentTime < action.end - 1e-7,
|
||
);
|
||
const reviewCaption =
|
||
providedReviewCaption ||
|
||
(isQualityReview || captionsViewable
|
||
? reviewCaptionAtTime({
|
||
time: currentTime,
|
||
slice: playheadSlice,
|
||
actions: annotationSegmentsForSlice(playheadSlice, segments),
|
||
status: reviewCaptionStatus || frameTimelineStatus,
|
||
})
|
||
: null);
|
||
const displayedActionSaved = displayedAction && segments.find((action) => action.id === displayedAction.id);
|
||
const previewSaved =
|
||
progressSaved && displayedAction && JSON.stringify(displayedAction) === JSON.stringify(displayedActionSaved);
|
||
const lowerAnnotation = selectedSlice?.start ?? clipStart;
|
||
const upperAnnotation = selectedSlice?.end ?? clipEnd;
|
||
|
||
// The slider, blocks and playhead share the complete capture/slice range.
|
||
// Navigation selects actions directly; it must never rescale only one track.
|
||
const visibleSlices = slices;
|
||
const visibleDescriptions = annotationForRender;
|
||
const sliceZoomPadding = Math.max(1, (selectedSlice.end - selectedSlice.start) / 2);
|
||
const sliceTimelineStart = sliceZoom ? Math.max(clipStart, selectedSlice.start - sliceZoomPadding) : clipStart;
|
||
const sliceTimelineEnd = sliceZoom ? Math.min(clipEnd, selectedSlice.end + sliceZoomPadding) : clipEnd;
|
||
const descriptionTimelineStart = lowerAnnotation;
|
||
const descriptionTimelineEnd = upperAnnotation;
|
||
|
||
const outstandingDrafts = useMemo<AnnotationDraft[]>(() => {
|
||
const editors: Record<string, SliceEditor> = { ...parkedEditors };
|
||
delete editors[selectedSlice.id];
|
||
if (editingAnnotation && !isQualityReview)
|
||
editors[selectedSlice.id] = { annotation: editingAnnotation, endSelection };
|
||
return Object.entries(editors).flatMap(([sliceId, editor]) => {
|
||
const saved = segments.find((segment) => segment.id === editor.annotation.id);
|
||
const selectingEnd = Boolean(editor.endSelection && !editor.endSelection.confirmed);
|
||
// A split can already be in the parent's local segments while its blank
|
||
// description still needs explicit save/cancel in this editor.
|
||
if (
|
||
!selectingEnd &&
|
||
saved &&
|
||
(continuousActions || saved.description?.trim() || saved.isInvalid) &&
|
||
JSON.stringify(saved) === JSON.stringify(editor.annotation)
|
||
)
|
||
return [];
|
||
return [{ sliceId, annotation: editor.annotation, selectingEnd, isNew: !saved }];
|
||
});
|
||
}, [parkedEditors, selectedSlice.id, editingAnnotation, endSelection, segments, isQualityReview, continuousActions]);
|
||
useEffect(() => {
|
||
onDraftsChange?.(outstandingDrafts);
|
||
}, [outstandingDrafts, onDraftsChange]);
|
||
|
||
const [qaDraftComment, setQaDraftComment] = useState<string>("");
|
||
const [sliceProblemDraft, setSliceProblemDraft] = useState<string | null>(null);
|
||
|
||
const parsedQAComments = useMemo(() => {
|
||
if (!reviewComment) return [];
|
||
return parseSegmentCommentsFromText(reviewComment).segmentComments;
|
||
}, [reviewComment]);
|
||
|
||
const parsedReworkComments = useMemo(() => {
|
||
if (!reworkNotice?.comment) return [];
|
||
return parseSegmentCommentsFromText(reworkNotice.comment).segmentComments;
|
||
}, [reworkNotice?.comment]);
|
||
|
||
const currentSavedQAComment = (() => {
|
||
if (!editingAnnotation || !selectedSlice) return "";
|
||
const segIndex = annotationSegments.findIndex((s) => s.id === editingAnnotation.id);
|
||
const sliceLabel = selectedSlice.name || `切片 ${selectedSliceIndex + 1}`;
|
||
return (
|
||
parsedQAComments.find(
|
||
(c) =>
|
||
(c.sliceId ? c.sliceId === selectedSlice.id : c.sliceName === sliceLabel) &&
|
||
(c.segmentId
|
||
? c.segmentId === editingAnnotation.id
|
||
: c.segmentIndex === segIndex ||
|
||
(c.timeRange && c.timeRange.includes(formatTime(editingAnnotation.start - lowerAnnotation)))),
|
||
)?.comment || ""
|
||
);
|
||
})();
|
||
useEffect(() => {
|
||
setQaDraftComment(currentSavedQAComment);
|
||
}, [editingAnnotation?.id, selectedSlice?.id, reviewComment]);
|
||
|
||
const saveSegmentQAComment = () => {
|
||
if (reviewReadOnly) return;
|
||
if (reviewWriteLocked || !selectedSlice || !editingAnnotation) return;
|
||
const segIndex = annotationSegments.findIndex((s) => s.id === editingAnnotation.id);
|
||
const sliceLabel = selectedSlice.name || `切片 ${selectedSliceIndex + 1}`;
|
||
const timeRange = `${formatTime(editingAnnotation.start - lowerAnnotation)}-${formatTime(editingAnnotation.end - lowerAnnotation)}`;
|
||
|
||
const { segmentComments: currentList, generalComment } = parseSegmentCommentsFromText(reviewComment || "");
|
||
|
||
const existingIdx = currentList.findIndex((c) =>
|
||
c.sliceId
|
||
? c.sliceId === selectedSlice.id && c.segmentId === editingAnnotation.id
|
||
: c.sliceName === sliceLabel && (c.segmentIndex === segIndex || c.timeRange === timeRange),
|
||
);
|
||
|
||
const updatedItem = {
|
||
sliceId: selectedSlice.id,
|
||
segmentId: editingAnnotation.id,
|
||
rawHeader: "",
|
||
sliceName: sliceLabel,
|
||
segmentIndex: segIndex >= 0 ? segIndex : 0,
|
||
timeRange,
|
||
tag: "",
|
||
comment: qaDraftComment.trim(),
|
||
};
|
||
|
||
let nextList = [...currentList];
|
||
if (existingIdx >= 0) {
|
||
if (!qaDraftComment.trim()) {
|
||
nextList.splice(existingIdx, 1);
|
||
} else {
|
||
nextList[existingIdx] = updatedItem;
|
||
}
|
||
} else if (qaDraftComment.trim()) {
|
||
nextList.push(updatedItem);
|
||
}
|
||
|
||
const nextSerialized = serializeSegmentCommentsToText(nextList, generalComment);
|
||
onReviewCommentChange?.(nextSerialized);
|
||
|
||
const sliceHasComment = nextList.some((c) => c.sliceName === sliceLabel);
|
||
if (sliceHasComment) {
|
||
if (!problemSliceIds.includes(selectedSlice.id)) {
|
||
onProblemSliceIdsChange?.([...problemSliceIds, selectedSlice.id]);
|
||
}
|
||
} else {
|
||
onProblemSliceIdsChange?.(problemSliceIds.filter((id) => id !== selectedSlice.id));
|
||
}
|
||
};
|
||
|
||
const deleteSegmentQAComment = (targetSliceLabel?: string, targetSegIdx?: number, targetTimeRange?: string) => {
|
||
if (reviewReadOnly) return;
|
||
if (reviewWriteLocked) return;
|
||
const { segmentComments: currentList, generalComment } = parseSegmentCommentsFromText(reviewComment || "");
|
||
const nextList = currentList.filter((c) => {
|
||
if (targetSliceLabel !== undefined && c.sliceName === targetSliceLabel) {
|
||
if (targetSegIdx !== undefined && c.segmentIndex === targetSegIdx) return false;
|
||
if (targetTimeRange !== undefined && c.timeRange === targetTimeRange) return false;
|
||
}
|
||
return true;
|
||
});
|
||
|
||
const nextSerialized = serializeSegmentCommentsToText(nextList, generalComment);
|
||
onReviewCommentChange?.(nextSerialized);
|
||
|
||
if (selectedSlice) {
|
||
const sliceLabel = selectedSlice.name || `切片 ${selectedSliceIndex + 1}`;
|
||
const hasRemaining = nextList.some((c) => c.sliceName === sliceLabel);
|
||
if (!hasRemaining) {
|
||
onProblemSliceIdsChange?.(problemSliceIds.filter((id) => id !== selectedSlice.id));
|
||
}
|
||
}
|
||
};
|
||
|
||
// Only explicit edits change intervals; submission requires full coverage.
|
||
|
||
const snap = useCallback(
|
||
(time: number) => {
|
||
if (!exactFrames) return Number(time.toFixed(3));
|
||
const index = nearestFrameBoundaryIndex(frameBoundaries, time);
|
||
return index < 0 ? Number(time.toFixed(3)) : frameBoundaries[index];
|
||
},
|
||
[exactFrames, frameBoundaries],
|
||
);
|
||
|
||
const toMedia = useCallback(
|
||
(time: number) => (sourceIsFullVideo ? time + (mediaSourceOffsets?.left || 0) : time - clipStart),
|
||
[clipStart, sourceIsFullVideo, mediaSourceOffsets?.left],
|
||
);
|
||
const toRightMedia = useCallback(
|
||
(time: number) =>
|
||
sourceIsFullVideo && unifiedBoundaries
|
||
? mapCameraBoundaryTime(frameBoundaries, rightMediaBoundaries, time) + (mediaSourceOffsets?.right || 0)
|
||
: toMedia(time),
|
||
[sourceIsFullVideo, unifiedBoundaries, frameBoundaries, rightMediaBoundaries, toMedia, mediaSourceOffsets?.right],
|
||
);
|
||
|
||
const followAnnotationEnd = useCallback(
|
||
(time: number): number | null => {
|
||
const selection = endSelectionRef.current;
|
||
if (endTrackingSuspended.current || !selection || selection.confirmed || !Number.isFinite(time)) return null;
|
||
const end = clamp(time, selection.start, selection.limit);
|
||
selection.end = end;
|
||
setEditingAnnotation((current) => {
|
||
if (
|
||
!current ||
|
||
current.id !== selection.id ||
|
||
endSelectionRef.current?.confirmed ||
|
||
endSelectionRef.current?.id !== selection.id
|
||
)
|
||
return current;
|
||
return current.end === end ? current : { ...current, end };
|
||
});
|
||
return end;
|
||
},
|
||
[snap],
|
||
);
|
||
|
||
const transport = useCaptureVideoTransport({
|
||
leftRef: leftVideoRef,
|
||
rightRef: rightVideoRef,
|
||
showLeft: effectiveShowLeft,
|
||
showRight: effectiveShowRight,
|
||
leftSource: source,
|
||
rightSource,
|
||
enabled: phase !== "materializing",
|
||
initialTime: selectedSlice.start,
|
||
playbackRate,
|
||
toLeft: toMedia,
|
||
toRight: toRightMedia,
|
||
fromLeft: (time) => (sourceIsFullVideo ? time - (mediaSourceOffsets?.left || 0) : clipStart + time),
|
||
fromRight: (time) =>
|
||
sourceIsFullVideo && unifiedBoundaries
|
||
? mapCameraBoundaryTime(rightMediaBoundaries, frameBoundaries, time - (mediaSourceOffsets?.right || 0))
|
||
: sourceIsFullVideo
|
||
? time
|
||
: clipStart + time,
|
||
onMediaDuration,
|
||
onTimeUpdate(rawAbsolute, ended) {
|
||
const absolute = unifiedBoundaries
|
||
? rawAbsolute >= playbackBounds.end - 0.000001 || ended
|
||
? playbackBounds.end
|
||
: Math.max(playbackBounds.start, frameBoundaryAtOrBefore(frameBoundaries, rawAbsolute))
|
||
: rawAbsolute;
|
||
const following = !endTrackingSuspended.current && endSelectionRef.current && !endSelectionRef.current.confirmed;
|
||
const reviewEndFrame = exactFrames
|
||
? lastActionFrame(frameBoundaries, playbackBounds)
|
||
: playbackBounds.end - frameStep;
|
||
const bounded =
|
||
isReviewViewing && absolute >= playbackBounds.end - 0.000001
|
||
? Math.max(playbackBounds.start, reviewEndFrame)
|
||
: (followAnnotationEnd(absolute) ??
|
||
clamp(
|
||
absolute,
|
||
playbackBounds.start,
|
||
unifiedBoundaries ? playbackBounds.end : playbackBounds.end - 0.000001,
|
||
));
|
||
setCurrentTime(bounded);
|
||
onPlayheadChange?.(bounded);
|
||
const stopAt = following ? endSelectionRef.current!.limit : playbackBounds.end;
|
||
if (absolute >= stopAt - 0.000001 || (following && absolute < endSelectionRef.current!.start)) {
|
||
transport.pause();
|
||
transport.seek(bounded);
|
||
}
|
||
return bounded;
|
||
},
|
||
});
|
||
const { isPlaying } = transport;
|
||
const transportRef = useRef(transport);
|
||
transportRef.current = transport;
|
||
const publishSeekTarget = useCallback(
|
||
(time: number) => {
|
||
const next =
|
||
followAnnotationEnd(time) ?? clamp(time, clipStart, unifiedBoundaries ? clipEnd : clipEnd - 0.000001);
|
||
setCurrentTime(next);
|
||
onPlayheadChange?.(next);
|
||
return next;
|
||
},
|
||
[clipStart, clipEnd, unifiedBoundaries, followAnnotationEnd, onPlayheadChange],
|
||
);
|
||
const seek = useCallback(
|
||
(time: number, autoplay = false) => {
|
||
transportRef.current.seek(publishSeekTarget(time), autoplay);
|
||
},
|
||
[publishSeekTarget],
|
||
);
|
||
const pausePlayback = useCallback(() => transportRef.current.pause(), []);
|
||
useEffect(() => {
|
||
if (viewportSuspended) {
|
||
pausePlayback();
|
||
// Native modal dialogs occupy the browser top layer and escape ancestor
|
||
// inertness. Temporarily close them so viewport recovery stays reachable.
|
||
suspendedDialogsRef.current = Array.from(
|
||
workbenchRef.current?.querySelectorAll<HTMLDialogElement>("dialog[open]") || [],
|
||
);
|
||
suspendedDialogsRef.current.forEach((dialog) => dialog.close());
|
||
} else if (suspendedDialogsRef.current) {
|
||
const dialogs = suspendedDialogsRef.current;
|
||
dialogs.forEach((dialog) => {
|
||
if (dialog.isConnected) dialog.showModal();
|
||
});
|
||
if (!dialogs.some((dialog) => dialog.isConnected)) workbenchRef.current?.focus({ preventScroll: true });
|
||
suspendedDialogsRef.current = null;
|
||
}
|
||
}, [viewportSuspended, pausePlayback]);
|
||
const previewSeek = (time: number) => transport.preview(publishSeekTarget(time));
|
||
const sliderDragging = useRef(false);
|
||
const sliderEvents = {
|
||
onPointerDown: (event: ReactPointerEvent<HTMLInputElement>) => {
|
||
if (isReviewViewing) onReviewNavigate?.();
|
||
sliderDragging.current = true;
|
||
event.currentTarget.setPointerCapture(event.pointerId);
|
||
transport.beginScrub();
|
||
},
|
||
onChange: (event: { currentTarget: HTMLInputElement }) => {
|
||
if (isReviewViewing) onReviewNavigate?.();
|
||
const next = snap(Number(event.currentTarget.value));
|
||
if (sliderDragging.current) previewSeek(next);
|
||
else seek(next); // keyboard and click/programmatic positioning remain exact
|
||
},
|
||
onPointerUp: () => {
|
||
sliderDragging.current = false;
|
||
transport.finishScrub();
|
||
focusWorkbench();
|
||
},
|
||
onPointerCancel: () => {
|
||
sliderDragging.current = false;
|
||
transport.finishScrub();
|
||
focusWorkbench();
|
||
},
|
||
onLostPointerCapture: () => {
|
||
sliderDragging.current = false;
|
||
transport.finishScrub();
|
||
focusWorkbench();
|
||
},
|
||
onBlur: () => {
|
||
sliderDragging.current = false;
|
||
transport.finishScrub();
|
||
},
|
||
};
|
||
|
||
useEffect(() => {
|
||
// The authoritative grid arrives asynchronously after task metadata.
|
||
// Keep a provisional playhead inside the newly resolved slice range.
|
||
if (currentTime < playbackBounds.start || currentTime > playbackBounds.end) {
|
||
seek(clamp(currentTime, playbackBounds.start, playbackBounds.end));
|
||
}
|
||
}, [currentTime, playbackBounds.start, playbackBounds.end, seek]);
|
||
|
||
const selectSlice = (
|
||
slice: SliceSegment,
|
||
time = slice.start,
|
||
rememberPosition = true,
|
||
{ bypassSliceEditLock = false }: { bypassSliceEditLock?: boolean } = {},
|
||
) => {
|
||
if (saving || !timelineReady || phase === "materializing") return;
|
||
// R2-Q5:面板打开期间点选其它切片 → 先 Enter 应用或 Esc 取消(目标片本身可重选定位)。
|
||
// D6 例外:J/K 返修跳转携带面板联动意图时旁路本锁(跳转自身负责开/切/收面板),
|
||
// 鼠标点选路径锁定不变。
|
||
if (!bypassSliceEditLock && sliceEditPanel && slice.id !== sliceEditPanel.sliceId) {
|
||
notifySliceEditLocked();
|
||
return;
|
||
}
|
||
// Review watching navigation is always allowed with unsaved problem text;
|
||
// the edit target stays fixed and never steals focus back.
|
||
if (
|
||
isQualityReview &&
|
||
slice.id !== selectedSlice.id &&
|
||
(qaDraftComment !== currentSavedQAComment || Boolean(sliceProblemDraft?.trim()))
|
||
) {
|
||
setError("请先保存或取消当前审核批注,再切换切片。");
|
||
return;
|
||
}
|
||
if (rememberPosition) setWorkPosition((original) => original ?? currentTime);
|
||
endTrackingSuspended.current = true;
|
||
pausePlayback();
|
||
setReviewPlayback(false);
|
||
if (slice.id !== selectedSlice.id) {
|
||
const restored = parkedEditors[slice.id];
|
||
const leaving = editingAnnotation
|
||
? {
|
||
annotation: editingAnnotation,
|
||
endSelection: endSelectionRef.current ? { ...endSelectionRef.current } : null,
|
||
}
|
||
: null;
|
||
setParkedEditors((editors) => {
|
||
const next = { ...editors };
|
||
delete next[slice.id];
|
||
if (leaving) next[selectedSlice.id] = leaving;
|
||
else delete next[selectedSlice.id];
|
||
return next;
|
||
});
|
||
setEditingAnnotation(restored?.annotation ?? null);
|
||
setEndSelection(restored?.endSelection ?? null);
|
||
}
|
||
if (isReviewViewing && slice.id !== selectedSlice.id) onReviewNavigate?.();
|
||
setSelectedSliceId(slice.id);
|
||
setSelectedBoundary(null);
|
||
setSelectedAnnotationBoundary(null);
|
||
setShowDictionary(false);
|
||
setError("");
|
||
seek(time);
|
||
focusWorkbench();
|
||
};
|
||
|
||
const navigateSlice = (direction: -1 | 1) => {
|
||
const target = slices[selectedSliceIndex + direction];
|
||
if (target) selectSlice(target);
|
||
};
|
||
const appliedHistoryRevision = useRef<number | null>(null);
|
||
useEffect(() => {
|
||
if (!historyReveal || appliedHistoryRevision.current === historyReveal.revision) return;
|
||
if ("editor" in historyReveal && phase !== "annotate") return;
|
||
const affected = slices.find((slice) => slice.id === historyReveal.sliceId);
|
||
if (!affected) return;
|
||
appliedHistoryRevision.current = historyReveal.revision;
|
||
selectSlice(affected, historyReveal.time, false);
|
||
if ("editor" in historyReveal) {
|
||
// selectSlice parks the outgoing editor; replace only the affected one.
|
||
setEditingAnnotation(historyReveal.editor?.annotation ?? null);
|
||
setEndSelection(historyReveal.editor?.endSelection ?? null);
|
||
endTrackingSuspended.current = false;
|
||
setParkedEditors((editors) => {
|
||
const next = { ...editors };
|
||
delete next[affected.id];
|
||
return next;
|
||
});
|
||
if (historyReveal.editor && historyReveal.editor.endSelection?.confirmed !== false)
|
||
requestAnimationFrame(focusDescriptionEditor);
|
||
}
|
||
setSplitPreview(null);
|
||
setAnnotationSplitPreview(null);
|
||
}, [historyReveal, slices, phase]);
|
||
const reviewSlice = () => {
|
||
if (saving || !timelineReady || phase === "materializing") return;
|
||
if (isReviewViewing) onReviewNavigate?.();
|
||
setWorkPosition((original) => original ?? currentTime);
|
||
endTrackingSuspended.current = true;
|
||
pausePlayback();
|
||
setReviewPlayback(true);
|
||
setSelectedBoundary(null);
|
||
seek(selectedSlice.start, true);
|
||
focusWorkbench();
|
||
};
|
||
const returnToWork = () => {
|
||
if (workPosition === null || saving || !timelineReady || phase === "materializing") return;
|
||
const time = snap(clamp(workPosition, clipStart, clipEnd));
|
||
const owner = slices[sliceIndexAtPlayhead(slices, time)];
|
||
if (!owner) return;
|
||
selectSlice(owner, time, false);
|
||
setWorkPosition(null);
|
||
};
|
||
|
||
const togglePlay = () => {
|
||
if (saving || phase === "materializing") return;
|
||
if (!transport.master()) return;
|
||
const ordinaryBounds = capturePlaybackBounds(phase, selectedSlice, clipStart, clipEnd);
|
||
setReviewPlayback(false);
|
||
if (!isPlaying) {
|
||
const selection = endSelectionRef.current;
|
||
if (selection && !selection.confirmed && endTrackingSuspended.current) {
|
||
endTrackingSuspended.current = false;
|
||
seek(selection.end, true);
|
||
return;
|
||
}
|
||
if (selection && !selection.confirmed && currentTime >= selection.limit - 0.000001) {
|
||
setError("已到可用区间末尾,请确认结束点或向前逐帧调整。");
|
||
return;
|
||
}
|
||
if ((!selection || selection.confirmed) && currentTime >= ordinaryBounds.end - 0.000001) {
|
||
seek(ordinaryBounds.start, true);
|
||
return;
|
||
}
|
||
transport.play();
|
||
} else {
|
||
transport.pauseAtFrame();
|
||
}
|
||
};
|
||
|
||
const appliedSeekRevision = useRef<number | null>(null);
|
||
useEffect(() => {
|
||
if (!seekRequest || appliedSeekRevision.current === seekRequest.revision) return;
|
||
appliedSeekRevision.current = seekRequest.revision;
|
||
seek(seekRequest.time);
|
||
}, [seekRequest, seek]);
|
||
|
||
// ---- 返工强调层(rework emphasis,返工界面重设计)----
|
||
// 审查视角(质检/终审)不渲染标注员强调层,那里保留审查意见面板。
|
||
const reworkActive = Boolean(reworkEmphasis?.active) && !isReviewViewing && !isQualityReview;
|
||
const reworkSliceBuckets = reworkEmphasis?.sliceStates || new Map();
|
||
const reworkActionBuckets = reworkEmphasis?.actionStates || new Map();
|
||
// QC 返修接收视图的红/灰上轨道(票 09,R1-Q6):接收视图挂载时轨道复用标注员
|
||
// 同款视觉(红块/灰块/计数徽标,零 QC 专属新增轨道元素)——判定输入是已保存
|
||
// 工作区的强调层(reviewReworkEmphasis),与标注员实时草稿语义互斥。
|
||
const receiveEmphasisActive = Boolean(reviewReworkEmphasis?.active) && isReviewViewing;
|
||
const trackSliceBuckets = reworkActive
|
||
? reworkSliceBuckets
|
||
: receiveEmphasisActive
|
||
? reviewReworkEmphasis?.sliceStates || new Map()
|
||
: new Map();
|
||
const trackActionBuckets = reworkActive
|
||
? reworkActionBuckets
|
||
: receiveEmphasisActive
|
||
? reviewReworkEmphasis?.actionStates || new Map()
|
||
: new Map();
|
||
const trackChanges = reworkActive
|
||
? reworkEmphasis?.changes
|
||
: receiveEmphasisActive
|
||
? reviewReworkEmphasis?.changes
|
||
: undefined;
|
||
const changedSliceIds = new Set(trackChanges?.items.map((item) => item.sliceId) || []);
|
||
const changedActionIds = new Set(trackChanges?.items.flatMap((item) => item.actionIds) || []);
|
||
const locateChange = (sliceId: string | null, time: number, actionId?: string) => {
|
||
if (sliceEditPanel || sliceEditConflictList) {
|
||
notifySliceEditLocked();
|
||
return;
|
||
}
|
||
const target = slices.find((slice) => slice.id === sliceId);
|
||
if (target) selectSlice(target, time);
|
||
else {
|
||
pausePlayback();
|
||
seek(time);
|
||
}
|
||
if (target?.id === selectedSlice.id && actionId) {
|
||
const action = segments.find((candidate) => candidate.id === actionId);
|
||
if (action) seekAnnotation(action, "start");
|
||
}
|
||
};
|
||
// 意见字幕(跟播放头匹配):切片排=播放头所在切片;动作/时间点排=播放头所在动作。
|
||
// 播放头不在任何切片(未分配区间)时无字幕;选中切片会定位到其起点,天然跟随。
|
||
const reworkSubtitleRowList = reworkActive
|
||
? reworkSubtitleRows(reworkSliceBuckets.get(playheadSlice?.id ?? ""), {
|
||
actionId: displayedAction?.id ?? null,
|
||
})
|
||
: [];
|
||
// QC 返修接收视图的意见字幕(票 08):同一三排渲染,输入是已保存工作区的
|
||
// 强调层(reviewReworkEmphasis);与标注员侧互斥——审查视角不进 reworkActive。
|
||
const reviewReworkSubtitleRowList =
|
||
reviewReworkEmphasis?.active && isReviewViewing
|
||
? reworkSubtitleRows((reviewReworkEmphasis.sliceStates || new Map()).get(playheadSlice?.id ?? ""), {
|
||
actionId: displayedAction?.id ?? null,
|
||
})
|
||
: [];
|
||
const [reworkFocus, setReworkFocus] = useState<{ opinionId: string; round: number; seq: number } | null>(null);
|
||
useEffect(() => {
|
||
if (!focusedLayout && reworkFocus)
|
||
workbenchRef.current
|
||
?.querySelector<HTMLElement>('[data-testid="rework-slice-opinions"] [data-rework-focus="true"]')
|
||
?.scrollIntoView({ block: "nearest" });
|
||
}, [focusedLayout, reworkFocus?.opinionId, reworkFocus?.round, reworkFocus?.seq]);
|
||
const reworkJumpIndexRef = useRef(-1);
|
||
const jumpReworkProblem = (direction: 1 | -1) => {
|
||
const order = reworkEmphasis?.jumpOrder || [];
|
||
if (!order.length) return;
|
||
const count = order.length;
|
||
reworkJumpIndexRef.current = (((reworkJumpIndexRef.current + direction) % count) + count) % count;
|
||
const target = order[reworkJumpIndexRef.current];
|
||
setReworkFocus({ opinionId: target.opinion.id, round: target.opinion.round, seq: (reworkFocus?.seq || 0) + 1 });
|
||
// I1:跨片跳到锚定动作的意见时镜像点击路径,自动打开该动作编辑器;
|
||
// 同片仍只 seek 不重开面板(现状保持)。决策规则见 reworkLocatePlan。
|
||
executeReworkLocatePlan(
|
||
reworkLocatePlan({
|
||
mode: "jump",
|
||
opinion: target.opinion,
|
||
anchor: target.anchor,
|
||
selectedSliceId: selectedSlice.id,
|
||
slices,
|
||
segments,
|
||
parkedAnnotationBySlice,
|
||
}) as ReworkLocatePlan,
|
||
);
|
||
};
|
||
/** 卡片/标记点击定位:切片内时间用绝对秒;动作卡片跳到所属动作。 */
|
||
const sliceIdCovering = (start: number, end: number) => {
|
||
const inside = slices.find((slice) => start >= slice.start - 1e-6 && end <= slice.end + 1e-6);
|
||
if (inside) return inside.id;
|
||
const overlapping = slices.find((slice) => start < slice.end && end > slice.start);
|
||
return overlapping?.id || null;
|
||
};
|
||
const locateReworkOpinion = (opinion: ReworkOpinionView) => {
|
||
setReworkFocus({ opinionId: opinion.id, round: opinion.round, seq: (reworkFocus?.seq || 0) + 1 });
|
||
// 点击路径与 J/K 跳转共用 reworkLocatePlan:跨片锚定动作同样自动打开
|
||
// 编辑器(I1 对齐),同片点击仍走 seekAnnotation 点开动作(既有行为)。
|
||
executeReworkLocatePlan(
|
||
reworkLocatePlan({
|
||
mode: "click",
|
||
opinion,
|
||
anchor: typeof opinion.atSeconds === "number" ? opinion.atSeconds : null,
|
||
selectedSliceId: selectedSlice.id,
|
||
slices,
|
||
segments,
|
||
parkedAnnotationBySlice,
|
||
}) as ReworkLocatePlan,
|
||
);
|
||
};
|
||
const toggleReworkSkip = (opinionId: string, skipped: boolean) => {
|
||
onReworkSkipToggle?.(opinionId, skipped);
|
||
};
|
||
/** 意见卡上的动作编号(当前切片内 #N),找不到时退化为纯"动作"。 */
|
||
const actionIndexLabel = (actionId?: string) => {
|
||
if (!actionId) return "";
|
||
const inSlice = segments.filter((seg) => sliceIdCovering(seg.start, seg.end) === selectedSlice.id);
|
||
const index = inSlice.findIndex((seg) => seg.id === actionId);
|
||
return index >= 0 ? ` #${index + 1}` : "";
|
||
};
|
||
/** 意见栏(右栏,跨切片)用:意见所属切片的显示名 "003 · 名称"。 */
|
||
const reworkSliceLabelOf = (sliceId: string | null) => {
|
||
if (!sliceId) return null;
|
||
const index = slices.findIndex((item) => item.id === sliceId);
|
||
if (index < 0) return null;
|
||
return `${String(index + 1).padStart(3, "0")} · ${slices[index].name || "未命名"}`;
|
||
};
|
||
/** 意见栏用:动作在其所属切片内的序号(1 起),跨切片可辨识。 */
|
||
const reworkActionIndexOf = (actionId: string) => {
|
||
const segment = segments.find((item) => item.id === actionId);
|
||
if (!segment) return null;
|
||
const owner = sliceIdCovering(segment.start, segment.end);
|
||
if (!owner) return null;
|
||
const inSlice = segments.filter((seg) => sliceIdCovering(seg.start, seg.end) === owner);
|
||
const index = inSlice.findIndex((seg) => seg.id === actionId);
|
||
return index >= 0 ? index + 1 : null;
|
||
};
|
||
const reworkRail =
|
||
reworkActive && focusedLayout && reworkEmphasis ? (
|
||
<div className="capture-rework-sidebar">
|
||
{reworkEmphasis.changes && <ReworkChangesPanel changes={reworkEmphasis.changes} onLocate={locateChange} />}
|
||
<ReworkOpinionRail
|
||
emphasis={reworkEmphasis}
|
||
focus={reworkFocus}
|
||
onLocate={locateReworkOpinion}
|
||
onSkipToggle={onReworkSkipToggle}
|
||
sliceLabelOf={reworkSliceLabelOf}
|
||
actionIndexOf={reworkActionIndexOf}
|
||
/>
|
||
</div>
|
||
) : null;
|
||
|
||
const step = (direction: -1 | 1) => {
|
||
if (!selectedSlice || !timelineReady || saving || phase === "materializing") return;
|
||
if (isReviewViewing) onReviewNavigate?.();
|
||
pausePlayback();
|
||
const selection = endSelectionRef.current;
|
||
if (selection && !selection.confirmed && !reviewPlayback) {
|
||
endTrackingSuspended.current = false;
|
||
const candidate = exactFrames
|
||
? stepFrameBoundary(frameBoundaries, selection.end, direction)
|
||
: selection.end + direction * frameStep;
|
||
seek(candidate);
|
||
setError("");
|
||
return;
|
||
}
|
||
if (selectedBoundary && phase === "slice" && !readOnly && !isQualityReview) {
|
||
const owner = slices[selectedBoundary.index];
|
||
const current = owner?.end;
|
||
if (!owner || current == null) return;
|
||
const next = exactFrames
|
||
? stepFrameBoundary(frameBoundaries, current, direction)
|
||
: current + direction * frameStep;
|
||
onSliceBoundaryChange?.(owner.id, "end", snap(next));
|
||
seek(snap(next));
|
||
return;
|
||
}
|
||
const candidate = exactFrames
|
||
? stepFrameBoundary(frameBoundaries, currentTime, direction)
|
||
: currentTime + direction * frameStep;
|
||
seek(
|
||
clamp(
|
||
candidate,
|
||
playbackBounds.start,
|
||
isReviewViewing
|
||
? exactFrames
|
||
? lastActionFrame(frameBoundaries, playbackBounds)
|
||
: playbackBounds.end - frameStep
|
||
: unifiedBoundaries
|
||
? playbackBounds.end
|
||
: playbackBounds.end - 0.000001,
|
||
),
|
||
);
|
||
};
|
||
|
||
const updateSliceBoundaryAt = (index: number, time: number, preview = false) => {
|
||
if (readOnly || saving) return;
|
||
const current = slices[index];
|
||
const following = slices[index + 1];
|
||
if (!current || !following) return;
|
||
const minimum = exactFrames ? stepFrameBoundary(frameBoundaries, current.start, 1) : current.start + 0.001;
|
||
const maximum = exactFrames ? stepFrameBoundary(frameBoundaries, following.end, -1) : following.end - 0.001;
|
||
const next = clamp(snap(time), minimum, maximum);
|
||
onSliceBoundaryChange?.(current.id, "end", next);
|
||
if (preview) previewSeek(next);
|
||
else seek(next);
|
||
};
|
||
|
||
/** 验收修复 D:标注相、面板外的 Shift+←/→ —— 选中切片分界 0.5s 粗步进。
|
||
* 共享分界统一表示为 owner.end(与拖动手柄/selectedBoundary 同一模型):优先用
|
||
* 点选/拖动留下的 selectedBoundary;否则沿用面板默认焦点规则(选中片尾分界,
|
||
* 尾片退回首分界=前邻的尾分界)。提交走 onSliceBoundaryChange(页面 adjustSlice
|
||
* 的提交式管线:无冲突立即生效/有冲突弹 04 清单/Esc=挪动未发生),与 slice 相
|
||
* ←/→ 的既有路径同一条。 */
|
||
const coarseNudgeSliceBoundary = (direction: -1 | 1) => {
|
||
if (readOnly || saving) return;
|
||
if (phase !== "annotate" || slices.length < 2 || selectedDiscarded) return;
|
||
let index = selectedBoundary?.index;
|
||
if (index == null || index < 0 || index >= slices.length - 1)
|
||
index = selectedSliceIndex < slices.length - 1 ? selectedSliceIndex : selectedSliceIndex - 1;
|
||
const current = slices[index];
|
||
const following = slices[index + 1];
|
||
if (!current || !following) return;
|
||
const minimum = exactFrames ? stepFrameBoundary(frameBoundaries, current.start, 1) : current.start + 0.001;
|
||
const maximum = exactFrames ? stepFrameBoundary(frameBoundaries, following.end, -1) : following.end - 0.001;
|
||
const next = clamp(snap(current.end + direction * 0.5), minimum, maximum);
|
||
if (next === current.end) return;
|
||
pausePlayback();
|
||
onSliceBoundaryChange?.(current.id, "end", next);
|
||
setSelectedBoundary({ index, field: "end" });
|
||
seek(next);
|
||
};
|
||
|
||
const beginSliceBoundaryDrag = (event: ReactPointerEvent<HTMLButtonElement>, index: number) => {
|
||
// R2-Q7:a 全局解锁:annotate 相同样可拖动共享分界(首标与返修同一编辑路径)。
|
||
if (readOnly || saving || (phase !== "slice" && phase !== "annotate") || !sliceTrackRef.current) return;
|
||
// R2-Q5/R2-Q3:面板或冲突清单(04 Enter / 05 快路径释放)打开期间拖手柄锁定。
|
||
if (sliceEditConflictList || sliceEditPanelOpen) {
|
||
notifySliceEditLocked();
|
||
return;
|
||
}
|
||
event.preventDefault();
|
||
event.stopPropagation();
|
||
sliceDragRef.current = {
|
||
index,
|
||
gesture: {
|
||
x: event.clientX,
|
||
time: slices[index].end,
|
||
secondsPerPixel: (sliceTimelineEnd - sliceTimelineStart) / Math.max(sliceTrackRef.current.clientWidth - 16, 1),
|
||
},
|
||
};
|
||
onSliceBoundaryEditStart?.(slices[index].id);
|
||
transport.beginScrub();
|
||
setSelectedBoundary({ index, field: "end" });
|
||
event.currentTarget.setPointerCapture(event.pointerId);
|
||
};
|
||
|
||
const updateSliceDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
|
||
if (readOnly || saving || !sliceDragRef.current || !sliceTrackRef.current) return;
|
||
const { index, gesture } = sliceDragRef.current;
|
||
// Keep the gesture scale fixed as the edge changes the visible page range.
|
||
// Global adjacent-frame limits below permit motion past the visible edge.
|
||
const time = gesture.time + (event.clientX - gesture.x) * gesture.secondsPerPixel;
|
||
updateSliceBoundaryAt(index, time, true);
|
||
};
|
||
|
||
const releaseSliceDrag = () => {
|
||
if (!sliceDragRef.current) return;
|
||
sliceDragRef.current = null;
|
||
if (!readOnly && !saving) onSliceBoundaryEditEnd?.();
|
||
transport.finishScrub();
|
||
focusWorkbench();
|
||
};
|
||
|
||
// —— 切片重设面板(票 04,spec §2 R1-Q1/R1-Q3/R1-Q4/R2-Q4/R2-Q5)——
|
||
// R2-Q5 旁路锁定提示:冲突清单 J/K、拖手柄、悬停+/垃圾桶、点其它切片被拦且有
|
||
// 提示(rework-ux-adjust 04 · D6 后面板内 J/K 放行给返工跳转,不再进本提示)。
|
||
const notifySliceEditLocked = () => {
|
||
setSliceEditLocked(true);
|
||
if (sliceEditLockedTimerRef.current !== null) window.clearTimeout(sliceEditLockedTimerRef.current);
|
||
sliceEditLockedTimerRef.current = window.setTimeout(() => {
|
||
sliceEditLockedTimerRef.current = null;
|
||
setSliceEditLocked(false);
|
||
}, 2500);
|
||
};
|
||
/** 快照一致性口径(Enter 外部改动守卫与 D6 驻留重开复用):当前工作区与快照
|
||
* 按值逐片/逐动作对比(快照经 snapshotSliceEditWorkspace 深拷贝,引用比较恒不
|
||
* 相等——验收实测曾使 Enter 一律被拒;真正的外部改写仍会被拦下)。 */
|
||
const workspaceDiffersFromSnapshot = (snapshot: { slices: SliceSegment[]; actions: AnnotationSegment[] }) => {
|
||
const byStart = <T extends { start: number }>(list: T[]) =>
|
||
[...list].sort((left, right) => left.start - right.start);
|
||
return (
|
||
JSON.stringify(byStart(slices)) !== JSON.stringify(byStart(snapshot.slices)) ||
|
||
JSON.stringify(byStart(segments)) !== JSON.stringify(byStart(snapshot.actions))
|
||
);
|
||
};
|
||
const sliceEditFocusBoundaryFor = (pendingSlices: SliceSegment[], sliceId: string): "start" | "end" => {
|
||
const index = pendingSlices.findIndex((slice) => slice.id === sliceId);
|
||
// 默认焦点落在可动的一侧:尾帧(非尾片)否则首帧(非首片)。
|
||
return index >= 0 && index < pendingSlices.length - 1 ? "end" : index > 0 ? "start" : "end";
|
||
};
|
||
const openSliceEditPanel = (targetSlice?: SliceSegment) => {
|
||
if (readOnly || saving) return;
|
||
// D1(rework-ux-adjust 04):单切片任务同样直开面板——面板内 C 可加边界,旧的
|
||
// 「仅一个切片」toast 分支整体删除;目标缺省为当前选中片(E 路径),J/K 联动
|
||
// 传入意见锚定的切片。
|
||
const target = targetSlice ?? selectedSlice;
|
||
if (!target) return;
|
||
// 活跃编辑会话守卫(非连续模式):正在编辑的描述先保存或取消(连续模式下
|
||
// 活跃编辑即焦点在描述输入内,键表已拦下 E)。
|
||
if (!continuousActions && editingAnnotation) {
|
||
setError("请先保存或取消当前描述,再进入切片重设面板。");
|
||
return;
|
||
}
|
||
// 验收修复 C:停泊草稿(其他片的未保存描述)不再拦 E——面板打开期间页面暂停
|
||
// 草稿自动落盘,segments 引用保持稳定(应用时快照一致性校验照常工作);停泊
|
||
// 草稿随会话释放后的补存一并处理。
|
||
pausePlayback();
|
||
// D6 驻留:收起期间工作区未变时恢复未应用改动(快照/预览原样沿用,Esc 仍回退
|
||
// 到最初打开前);工作区已变则作废旧预览按现状新开(与 Enter 外部改动守卫同
|
||
// 一口径——旧预览应用必然被拦,不静默丢,Esc 前改动一直可见可回退)。
|
||
const stash =
|
||
sliceEditPanelStash &&
|
||
!workspaceDiffersFromSnapshot(sliceEditPanelStash.baseSnapshot) &&
|
||
sliceEditPanelStash.draftsFingerprint === workbenchDraftsFingerprint(outstandingDrafts)
|
||
? sliceEditPanelStash
|
||
: null;
|
||
const baseSnapshot = stash ? stash.baseSnapshot : snapshotSliceEditWorkspace({ slices, actions: segments });
|
||
const snapshot = stash
|
||
? stash.snapshot
|
||
: snapshotSliceEditWorkspace({
|
||
slices,
|
||
actions: continuousActions ? sliceEditActionsWithDrafts(segments, outstandingDrafts).actions : segments,
|
||
});
|
||
const pendingSlices = stash ? stash.pendingSlices : restoreSliceEditWorkspace(snapshot).slices;
|
||
setSliceEditPanelStash(null);
|
||
// 目标片已被预览合并掉时保留预览内的目标(面板渲染 pendingSlices,sliceId
|
||
// 必须指向其中之一;无驻留时预览即现状,目标必在其中)。
|
||
const sliceId = stash && !pendingSlices.some((slice) => slice.id === target.id) ? stash.sliceId : target.id;
|
||
setSliceEditPanel({
|
||
sliceId,
|
||
pendingSlices,
|
||
snapshot,
|
||
baseSnapshot,
|
||
draftsFingerprint: workbenchDraftsFingerprint(outstandingDrafts),
|
||
focusBoundary: sliceEditFocusBoundaryFor(pendingSlices, sliceId),
|
||
});
|
||
setSliceEditConflictList(null);
|
||
setSliceEditDiscardDraft(null);
|
||
setError("");
|
||
onSliceEditSessionChange?.(true);
|
||
focusWorkbench();
|
||
};
|
||
/** D6 跳转联动打开:J/K 落切片问题时的自动打开/切换目标。面板已开 → 切换目标
|
||
* (目标已被预览合并掉则不切,保住未应用改动);未开 → 软守卫(非连续模式的
|
||
* 活跃编辑会话不自动开面板、不弹错——导航照常发生,用户先处理编辑器再按 E)。
|
||
* 跨片跳转的切选在 executeReworkLocatePlan 已先完成(selectSlice 旁路面板锁)。 */
|
||
const openSliceEditPanelForJump = (sliceId: string) => {
|
||
const panel = sliceEditPanel;
|
||
if (panel) {
|
||
if (panel.pendingSlices.some((slice) => slice.id === sliceId)) {
|
||
setSliceEditPanel({
|
||
...panel,
|
||
sliceId,
|
||
focusBoundary: sliceEditFocusBoundaryFor(panel.pendingSlices, sliceId),
|
||
});
|
||
}
|
||
return;
|
||
}
|
||
if (!continuousActions && editingAnnotation) return;
|
||
const target = slices.find((slice) => slice.id === sliceId);
|
||
if (target) openSliceEditPanel(target);
|
||
};
|
||
const cancelSliceEditPanel = () => {
|
||
if (saving || sliceEditApplyingRef.current) return;
|
||
// Esc/E 整体回退:预览从未落库,丢弃预览即回到打开面板时的快照(R1-Q1);
|
||
// D6 驻留一并清空——Esc 是显式全弃,收起驻留不允许在取消后复活。
|
||
setSliceEditPanel(null);
|
||
setSliceEditPanelStash(null);
|
||
setSliceEditConflictList(null);
|
||
setSliceEditDiscardDraft(null);
|
||
setError("");
|
||
onSliceEditSessionChange?.(false);
|
||
focusWorkbench();
|
||
};
|
||
/** D6 收起驻留:J/K 落到动作/时间点问题时收起面板(右上编辑界面/跳播走既有
|
||
* 路径)——未应用改动转存驻留、会话释放(页面侧补存机制随之恢复),重开仍在。 */
|
||
const collapseSliceEditPanelForNavigation = () => {
|
||
if (!sliceEditPanel) return;
|
||
setSliceEditPanelStash(sliceEditPanel);
|
||
setSliceEditPanel(null);
|
||
setSliceEditDiscardDraft(null);
|
||
setError("");
|
||
onSliceEditSessionChange?.(false);
|
||
};
|
||
const sliceEditPanelOpen = Boolean(sliceEditPanel) && phase === "annotate";
|
||
const applySliceEditPanelOp = (
|
||
result: { slices?: SliceSegment[]; selectedSliceId?: string; issue?: string },
|
||
options: { closeDraft?: boolean } = {},
|
||
) => {
|
||
if (result.issue || !result.slices) {
|
||
setError(result.issue || "当前改动不可用。");
|
||
return;
|
||
}
|
||
setError("");
|
||
if (options.closeDraft) setSliceEditDiscardDraft(null);
|
||
setSliceEditPanel((panel) =>
|
||
panel
|
||
? {
|
||
...panel,
|
||
pendingSlices: result.slices as SliceSegment[],
|
||
sliceId:
|
||
result.selectedSliceId && result.slices.some((slice) => slice.id === result.selectedSliceId)
|
||
? result.selectedSliceId
|
||
: panel.sliceId,
|
||
}
|
||
: panel,
|
||
);
|
||
};
|
||
const panelFrameBoundaries = exactFrames ? frameBoundaries : null;
|
||
const panelNudgeBoundary = (field: "start" | "end", direction: -1 | 1, count: number, coarse = false) => {
|
||
const panel = sliceEditPanel;
|
||
if (!panel) return;
|
||
const result = coarse
|
||
? coarsePendingSliceBoundary(panel.pendingSlices, panel.sliceId, field, direction, panelFrameBoundaries)
|
||
: stepPendingSliceBoundary(panel.pendingSlices, panel.sliceId, field, direction, count, panelFrameBoundaries);
|
||
applySliceEditPanelOp(result);
|
||
};
|
||
const panelSetBoundary = (field: "start" | "end", value: number) => {
|
||
const panel = sliceEditPanel;
|
||
if (!panel) return;
|
||
const target = panel.pendingSlices.find((slice) => slice.id === panel.sliceId);
|
||
if (!target) return;
|
||
// 数字输入单位与显示一致:精确帧模式为帧号,否则为秒。
|
||
const time = exactFrames ? (Number.isInteger(value) ? (frameBoundaries[value] ?? target[field]) : NaN) : value;
|
||
applySliceEditPanelOp(
|
||
movePendingSliceBoundary(panel.pendingSlices, panel.sliceId, field, time, panelFrameBoundaries),
|
||
);
|
||
};
|
||
const panelSplitAtPlayhead = () => {
|
||
const panel = sliceEditPanel;
|
||
if (!panel) return;
|
||
const revision = Date.now();
|
||
const result = splitPendingSlice(
|
||
panel.pendingSlices,
|
||
panel.sliceId,
|
||
currentTime,
|
||
() => [`${panel.sliceId}-pe-${revision}`, `${panel.sliceId}-pf-${revision}`],
|
||
panelFrameBoundaries,
|
||
);
|
||
applySliceEditPanelOp(result);
|
||
};
|
||
const panelMergeBoundary = (side: "start" | "end") => {
|
||
const panel = sliceEditPanel;
|
||
if (!panel) return;
|
||
applySliceEditPanelOp(mergePendingSliceBoundary(panel.pendingSlices, panel.sliceId, side));
|
||
};
|
||
const panelDiscardDraftOpen = () => {
|
||
const panel = sliceEditPanel;
|
||
if (!panel) return;
|
||
const target = panel.pendingSlices.find((slice) => slice.id === panel.sliceId);
|
||
if (!target) return;
|
||
if (sliceEditDiscardDraft) {
|
||
setSliceEditDiscardDraft(null);
|
||
return;
|
||
}
|
||
setSliceEditDiscardDraft(
|
||
target.deliveryDisposition === "discard"
|
||
? {
|
||
discard: false,
|
||
reason: target.discardReason,
|
||
reasonLabelId: target.discardReasonLabelId,
|
||
reasonVersion: target.discardReasonVersion,
|
||
reasonNote: target.discardReasonNote || "",
|
||
}
|
||
: { discard: true, reasonNote: "" },
|
||
);
|
||
if (target.deliveryDisposition !== "discard") onRefreshDiscardReasons?.();
|
||
};
|
||
const sliceEditApplyingRef = useRef(false);
|
||
const commitSliceEditPanel = async (choices: Partial<Record<string, SliceEditChoice>>) => {
|
||
const panel = sliceEditPanel;
|
||
if (!panel || sliceEditApplyingRef.current) return;
|
||
// 经由具名输入绕开 JSDoc 推断的窄参数类型(引擎实现源是 JS + JSDoc)。
|
||
const resolveInput = {
|
||
baseSlices: panel.snapshot.slices,
|
||
pendingSlices: panel.pendingSlices,
|
||
actions: panel.snapshot.actions,
|
||
choices,
|
||
};
|
||
const resolution = resolveSliceEditConflicts(resolveInput);
|
||
// Enter 落库前自检(03 引擎的 Go 守卫前端镜像):状态白名单 + 「动作完整落在
|
||
// 恰好一个切片」(ADR 0007 / T3 钉死)。逐片无缝铺满校验刻意不跑——标注相草稿
|
||
// 允许留空缺口(词汇表「保存进度」),那是提交守卫而非结构改动守卫。
|
||
const issues = checkSliceEditResolution(resolution, { baseSlices: panel.snapshot.slices });
|
||
if (issues.length) {
|
||
setError(`切片改动未通过提交自检:${issues[0].message};尚未应用,请调整选择或按 Esc 回退。`);
|
||
return;
|
||
}
|
||
sliceEditApplyingRef.current = true;
|
||
let applied: boolean | void;
|
||
try {
|
||
applied = await onApplySliceEdit?.(
|
||
resolution.slices as SliceSegment[],
|
||
resolution.actions as AnnotationSegment[],
|
||
panel.sliceId,
|
||
);
|
||
} catch (cause) {
|
||
setError(userErrorMessage(cause) || "切片改动保存失败,草稿和预览已保留,请核对后重试。");
|
||
return;
|
||
} finally {
|
||
sliceEditApplyingRef.current = false;
|
||
}
|
||
if (applied === false) {
|
||
setError("当前状态暂不能应用切片改动,请稍后重试,或按 Esc 取消。");
|
||
return;
|
||
}
|
||
// Only clear editors after the shared slice/draft transaction is confirmed.
|
||
// Leaving stale parked editors would let the next autosave overwrite the
|
||
// conflict resolver's adjusted boundaries with pre-edit ranges.
|
||
setEditingAnnotation(null);
|
||
setParkedEditors({});
|
||
setEndSelection(null);
|
||
onDraftsChange?.([]);
|
||
// 应用成功:面板与 D6 驻留一并清空(预览已落库,旧快照无回退意义)。
|
||
setSliceEditPanel(null);
|
||
setSliceEditPanelStash(null);
|
||
setSliceEditConflictList(null);
|
||
setSliceEditDiscardDraft(null);
|
||
setError("");
|
||
onSliceEditSessionChange?.(false);
|
||
if (resolution.slices.some((slice) => slice.id === panel.sliceId)) setSelectedSliceId(panel.sliceId);
|
||
focusWorkbench();
|
||
};
|
||
const applySliceEditPanel = () => {
|
||
if (readOnly || saving) return;
|
||
const panel = sliceEditPanel;
|
||
if (!panel) return;
|
||
if (!continuousActions && editingAnnotation) {
|
||
setError("请先保存或取消当前描述,再应用切片改动。");
|
||
return;
|
||
}
|
||
// 面板期间外部改动守卫:快照经 snapshotSliceEditWorkspace 深拷贝(Esc 幂等回退
|
||
// 依赖拷贝语义),引用比较恒不相等曾使 Enter 一律被拒(验收实测「面板期间工作
|
||
// 区发生了其它修改」);改按值比较(与预览一致性检查、D6 驻留重开同一口径
|
||
// workspaceDiffersFromSnapshot),真正的外部改动(其他页面/服务器侧改写)仍被拦下。
|
||
const byStart = <T extends { start: number }>(list: T[]) =>
|
||
[...list].sort((left, right) => left.start - right.start);
|
||
if (
|
||
workspaceDiffersFromSnapshot(panel.baseSnapshot) ||
|
||
panel.draftsFingerprint !== workbenchDraftsFingerprint(outstandingDrafts)
|
||
) {
|
||
setError("面板期间工作区发生了其它修改,请按 Esc 取消后重试。");
|
||
return;
|
||
}
|
||
if (JSON.stringify(byStart(panel.pendingSlices)) === JSON.stringify(byStart(slices))) {
|
||
// 预览与现状逐字节一致:Enter 直接收起(页面侧对无变化会拒绝写入);驻留
|
||
// 一并清空(无未应用改动可言,D6)。
|
||
setSliceEditPanel(null);
|
||
setSliceEditPanelStash(null);
|
||
setSliceEditDiscardDraft(null);
|
||
setError("");
|
||
onSliceEditSessionChange?.(false);
|
||
focusWorkbench();
|
||
return;
|
||
}
|
||
if (sliceEditActionsWithDrafts(segments, outstandingDrafts).unresolved.length) {
|
||
setError("仍有描述尚未确认结束点,请定位草稿完成区间后继续;切片预览会保留。");
|
||
stageEnterReleasedRef.current = true;
|
||
setStageConfirmation("drafts");
|
||
return;
|
||
}
|
||
const scan = scanSliceEditConflicts({
|
||
baseSlices: panel.snapshot.slices,
|
||
pendingSlices: panel.pendingSlices,
|
||
actions: panel.snapshot.actions,
|
||
});
|
||
if (scan.clean) {
|
||
commitSliceEditPanel({});
|
||
return;
|
||
}
|
||
// autoFollows(工单 02):静默跟随的贴边无效动作 → 清单折叠提示行,不再无声。
|
||
setSliceEditConflictList({
|
||
entries: scan.entries,
|
||
autoFollows: scan.autoFollows,
|
||
decisions: {},
|
||
focus: 0,
|
||
source: "panel",
|
||
});
|
||
};
|
||
|
||
// 票 05:清单 Enter/Esc 按来源分发——quick(拖动释放/悬停+)交回页面(落定产
|
||
// 物/回退快照;成功时返回焦点切片 id 供选中),panel 维持 04 面板自己的流
|
||
// (commitSliceEditPanel / cancelSliceEditPanel)。键盘分发与清单按钮共用本组助手。
|
||
// A quick edit can succeed without a conflict list. Its frozen drafts are
|
||
// already in the authoritative workspace; never replay their old geometry.
|
||
useEffect(() => {
|
||
if (!sliceEditAppliedRevision) return;
|
||
setEditingAnnotation(null);
|
||
setParkedEditors({});
|
||
setEndSelection(null);
|
||
onDraftsChange?.([]);
|
||
}, [sliceEditAppliedRevision]);
|
||
const quickConflictApplyingRef = useRef(false);
|
||
const [quickConflictApplying, setQuickConflictApplying] = useState(false);
|
||
const applySliceEditConflictList = async (decisions: Partial<Record<string, SliceEditChoice>>) => {
|
||
if (!sliceEditConflictList) return;
|
||
if (sliceEditConflictList.source === "quick") {
|
||
if (saving || readOnly || quickConflictApplyingRef.current) return;
|
||
quickConflictApplyingRef.current = true;
|
||
setQuickConflictApplying(true);
|
||
setError("");
|
||
try {
|
||
const applied = await onSliceEditQuickConflictApply?.(decisions);
|
||
if (typeof applied === "string") {
|
||
if (applied) setSelectedSliceId(applied);
|
||
focusWorkbench();
|
||
}
|
||
} catch (cause) {
|
||
setError(userErrorMessage(cause) || "切片改动保存失败,选择和预览已保留,请核对后重试。");
|
||
} finally {
|
||
quickConflictApplyingRef.current = false;
|
||
setQuickConflictApplying(false);
|
||
}
|
||
return;
|
||
}
|
||
commitSliceEditPanel(decisions);
|
||
};
|
||
const cancelSliceEditConflictList = () => {
|
||
if (!sliceEditConflictList || saving || quickConflictApplyingRef.current) return;
|
||
if (sliceEditConflictList.source === "quick") {
|
||
onSliceEditQuickConflictCancel?.();
|
||
return;
|
||
}
|
||
cancelSliceEditPanel();
|
||
};
|
||
const insertSlice = async (index: number, time: number) => {
|
||
// R2-Q7:a 全局解锁:悬停"+"新增分界在 annotate 相同样可用。
|
||
if (readOnly || isQualityReview || saving || (phase !== "slice" && phase !== "annotate")) return;
|
||
// R2-Q5/R2-Q3:面板或冲突清单打开期间悬停"+"锁定(结构改动统一走单一处置入口)。
|
||
if (sliceEditConflictList || sliceEditPanelOpen) {
|
||
notifySliceEditLocked();
|
||
return;
|
||
}
|
||
const slice = slices[index];
|
||
if (!slice) return;
|
||
const point = snap(time);
|
||
const issue = sliceCutIssue(slice, point);
|
||
if (issue) {
|
||
setError(issue);
|
||
return;
|
||
}
|
||
setError("");
|
||
pausePlayback();
|
||
setReviewPlayback(false);
|
||
const nextSelectedSliceId = await onSplitSlice?.(index, point);
|
||
if (nextSelectedSliceId) setSelectedSliceId(nextSelectedSliceId);
|
||
setSplitPreview(null);
|
||
seek(point);
|
||
requestAnimationFrame(focusWorkbench);
|
||
};
|
||
|
||
const annotationEditState = (): AnnotationEditState => ({
|
||
sliceId: selectedSlice.id,
|
||
time: currentTime,
|
||
segments,
|
||
editor: editingAnnotation ? { annotation: editingAnnotation, endSelection: endSelectionRef.current } : null,
|
||
revealAnnotation: editingAnnotation ? { id: editingAnnotation.id, start: editingAnnotation.start } : undefined,
|
||
});
|
||
const recordEditorEdit = (editor: SliceEditor | null, nextSegments = segments, time = currentTime) => {
|
||
const before = annotationEditState();
|
||
const after = {
|
||
...before,
|
||
editor,
|
||
segments: nextSegments,
|
||
time,
|
||
revealAnnotation: editor ? { id: editor.annotation.id, start: editor.annotation.start } : before.revealAnnotation,
|
||
};
|
||
if (JSON.stringify(before) !== JSON.stringify(after)) onAnnotationEdit?.(before, after);
|
||
};
|
||
|
||
const updateEditingAnnotation = (patch: Partial<AnnotationSegment>) => {
|
||
if (readOnly || saving) return;
|
||
if (
|
||
!editingAnnotation ||
|
||
Object.entries(patch).every(([key, value]) => editingAnnotation[key as keyof AnnotationSegment] === value)
|
||
)
|
||
return;
|
||
onAnnotationDraftEdit?.();
|
||
setEditingAnnotation((current) => (current ? { ...current, ...patch } : current));
|
||
};
|
||
|
||
const chooseTemplate = (definition: SemanticLabelDefinition) => {
|
||
updateEditingAnnotation({ labelId: "", label: "", description: definition.description?.trim() || definition.name });
|
||
setShowDictionary(false);
|
||
focusDescriptionEditor();
|
||
};
|
||
|
||
const editAnnotationBoundary = (field: "start" | "end", time: number) => {
|
||
if (readOnly || saving) return;
|
||
if (!editingAnnotation || !selectedSlice || !Number.isFinite(time)) return;
|
||
if (continuousActions) {
|
||
if (outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
setError("请先保存或取消当前文字,再调整边界。");
|
||
return;
|
||
}
|
||
const own = annotationSegments.findIndex((action) => action.id === editingAnnotation.id);
|
||
const index = field === "end" ? own : own - 1;
|
||
const left = annotationSegments[index],
|
||
right = annotationSegments[index + 1];
|
||
if (!left || !right || !exactFrames) {
|
||
setError("切片首尾边界固定。");
|
||
return;
|
||
}
|
||
const at = clamp(
|
||
snap(time),
|
||
stepFrameBoundary(frameBoundaries, left.start, 1),
|
||
stepFrameBoundary(frameBoundaries, right.end, -1),
|
||
);
|
||
const changed = moveActionBoundary(annotationSegments, left.id, at);
|
||
const next = segments
|
||
.filter((action) => !annotationSegments.some((old) => old.id === action.id))
|
||
.concat(changed)
|
||
.sort((a, b) => a.start - b.start);
|
||
const editor = changed.find((action) => action.id === editingAnnotation.id);
|
||
recordEditorEdit({ annotation: editor, endSelection: null }, next, at);
|
||
onChange(next);
|
||
setEditingAnnotation(editor);
|
||
seek(at);
|
||
setError("");
|
||
return;
|
||
}
|
||
if (field === "end") {
|
||
if (!selectingEnd && !beginEndSelection()) return;
|
||
seek(snap(time));
|
||
setError("");
|
||
return;
|
||
}
|
||
if (selectingEnd || isNewAnnotation) return;
|
||
if (Math.abs(editingAnnotation.start - selectedSlice.start) <= 1e-6) {
|
||
setError("切片首边界固定,请使用分割动作划分区间。");
|
||
return;
|
||
}
|
||
const previous = annotationSegments.find(
|
||
(s) => s.id !== editingAnnotation.id && Math.abs(s.end - editingAnnotation.start) <= 1e-6,
|
||
);
|
||
const minimum =
|
||
previous && exactFrames ? stepFrameBoundary(frameBoundaries, previous.start, 1) : selectedSlice.start;
|
||
const maximum = exactFrames
|
||
? stepFrameBoundary(frameBoundaries, editingAnnotation.end, -1)
|
||
: editingAnnotation.end - 0.001;
|
||
const value = clamp(snap(time), minimum, maximum);
|
||
const candidate = { ...editingAnnotation, [field]: value };
|
||
if (replaceAnnotationSharedBoundaries(segments, candidate).some((s) => s.end <= s.start)) {
|
||
setError("该边界会与已有描述重叠,请调整相邻描述或拖动共用边界。");
|
||
return;
|
||
}
|
||
recordEditorEdit({ annotation: candidate, endSelection });
|
||
updateEditingAnnotation({ [field]: value });
|
||
setError("");
|
||
seek(value);
|
||
};
|
||
|
||
const addAnnotation = () => {
|
||
if (
|
||
!selectedSlice ||
|
||
editingAnnotation ||
|
||
readOnly ||
|
||
isQualityReview ||
|
||
mediaOnly ||
|
||
phase !== "annotate" ||
|
||
saving
|
||
)
|
||
return;
|
||
if (!sliceAligned) {
|
||
setError("旧切片边界未对齐统一帧边界,请原地调整切片边界(拖动分界或 E 模式)后再标注;不会自动移动已有描述。");
|
||
return;
|
||
}
|
||
const { draft, reason } = annotationDraftCheckAtPlayhead(selectedSlice, segments, currentTime);
|
||
if (!draft) {
|
||
setError(
|
||
reason === "occupied"
|
||
? "已有动作描述覆盖此位置,请选择空白区间或使用「在播放头分割动作」。"
|
||
: reason === "end"
|
||
? "已到当前切片末尾,请向前定位后新增动作描述。"
|
||
: "播放点不在当前切片内,请重新定位。",
|
||
);
|
||
return;
|
||
}
|
||
pausePlayback();
|
||
setReviewPlayback(false);
|
||
endTrackingSuspended.current = false;
|
||
const id = `description-${Date.now()}`;
|
||
const annotation: AnnotationSegment = {
|
||
id,
|
||
start: draft.start,
|
||
end: draft.start,
|
||
description: "",
|
||
label: "",
|
||
labelId: "",
|
||
source: "manual",
|
||
confidence: 1,
|
||
};
|
||
const selection = { id, ...draft, confirmed: false, isNew: true };
|
||
recordEditorEdit({ annotation, endSelection: selection }, segments, draft.start);
|
||
setEditingAnnotation(annotation);
|
||
setEndSelection(selection);
|
||
seek(draft.start);
|
||
setError("");
|
||
focusWorkbench();
|
||
};
|
||
|
||
const beginEndSelection = () => {
|
||
if (!editingAnnotation || saving || readOnly) return false;
|
||
const draft = annotationDraftAtPlayhead(selectedSlice, segments, editingAnnotation.start, editingAnnotation.id);
|
||
if (!draft) {
|
||
setError("当前动作起点与其他区间冲突,请先调整边界。");
|
||
return false;
|
||
}
|
||
const following = annotationSegments.find(
|
||
(s) => s.id !== editingAnnotation.id && Math.abs(s.start - editingAnnotation.end) <= 1e-6,
|
||
);
|
||
if (!following && !isNewAnnotation && Math.abs(editingAnnotation.end - selectedSlice.end) <= 1e-6) {
|
||
setError("切片末边界固定,请使用分割动作划分区间。");
|
||
return false;
|
||
}
|
||
if (following && exactFrames) draft.limit = stepFrameBoundary(frameBoundaries, following.end, -1);
|
||
pausePlayback();
|
||
setReviewPlayback(false);
|
||
endTrackingSuspended.current = false;
|
||
const selection = {
|
||
id: editingAnnotation.id,
|
||
...draft,
|
||
end: editingAnnotation.end,
|
||
confirmed: false,
|
||
isNew: isNewAnnotation,
|
||
};
|
||
recordEditorEdit({ annotation: editingAnnotation, endSelection: selection }, segments, editingAnnotation.end);
|
||
setEndSelection(selection);
|
||
seek(editingAnnotation.end);
|
||
setError("");
|
||
return true;
|
||
};
|
||
|
||
const confirmEndSelection = () => {
|
||
const selection = endSelectionRef.current;
|
||
if (
|
||
!selection ||
|
||
selection.confirmed ||
|
||
!editingAnnotation ||
|
||
saving ||
|
||
readOnly ||
|
||
isQualityReview ||
|
||
phase !== "annotate"
|
||
)
|
||
return;
|
||
const time = selection.end;
|
||
pausePlayback();
|
||
const end = followAnnotationEnd(time) ?? selection.end;
|
||
if (end <= selection.start + 0.001) {
|
||
setError("请播放或向后逐帧定位,结束点必须晚于起点。");
|
||
return;
|
||
}
|
||
recordEditorEdit(
|
||
{ annotation: { ...editingAnnotation, end }, endSelection: { ...selection, end, confirmed: true } },
|
||
segments,
|
||
end,
|
||
);
|
||
setEditingAnnotation((current) => (current?.id === selection.id ? { ...current, end } : current));
|
||
setEndSelection({ ...selection, end, confirmed: true });
|
||
seek(end);
|
||
setError("");
|
||
focusDescriptionEditor();
|
||
};
|
||
|
||
const confirmAnnotation = async (forceInvalid = false) => {
|
||
if (
|
||
!editingAnnotation ||
|
||
!selectedSlice ||
|
||
saving ||
|
||
saveInFlightRef.current ||
|
||
readOnly ||
|
||
isQualityReview ||
|
||
phase !== "annotate"
|
||
)
|
||
return;
|
||
if (selectingEnd) {
|
||
setError("请先确认结束点,再保存描述。");
|
||
return;
|
||
}
|
||
const { start, end } = annotationConfirmationInterval(editingAnnotation, selectedSlice);
|
||
|
||
const isInvalid = Boolean(
|
||
forceInvalid ||
|
||
editingAnnotation.isInvalid ||
|
||
editingAnnotation.description === "无效片段" ||
|
||
editingAnnotation.label === "无效片段",
|
||
);
|
||
|
||
const description = isInvalid ? "无效片段" : editingAnnotation.description?.trim() || "";
|
||
const label = isInvalid
|
||
? "无效片段"
|
||
: !description && continuousActions
|
||
? ""
|
||
: editingAnnotation.label?.trim() || description || "未命名";
|
||
|
||
const candidate: AnnotationSegment = {
|
||
...editingAnnotation,
|
||
start,
|
||
end,
|
||
description,
|
||
label,
|
||
...(continuousActions
|
||
? { status: isInvalid ? ("invalid" as const) : description ? ("described" as const) : ("pending" as const) }
|
||
: {}),
|
||
};
|
||
if (isInvalid) {
|
||
candidate.isInvalid = true;
|
||
candidate.labelId = "";
|
||
} else {
|
||
delete candidate.isInvalid;
|
||
if (!description && continuousActions) {
|
||
candidate.labelId = "";
|
||
delete candidate.phrases;
|
||
delete candidate.handedness;
|
||
}
|
||
}
|
||
|
||
if (!candidate.description && !continuousActions) {
|
||
setError("请直接填写描述,或从字典选择后修改。");
|
||
return;
|
||
}
|
||
if (candidate.end <= candidate.start + 0.001) {
|
||
setError("描述区间结束时间必须晚于开始时间。");
|
||
return;
|
||
}
|
||
if (
|
||
!Number.isFinite(candidate.start) ||
|
||
!Number.isFinite(candidate.end) ||
|
||
candidate.start < selectedSlice.start ||
|
||
candidate.end > selectedSlice.end
|
||
) {
|
||
setError("描述区间必须位于当前切片内,且结束时间必须晚于开始时间。");
|
||
return;
|
||
}
|
||
const next = replaceAnnotationSharedBoundaries(segments, candidate);
|
||
if (next.some((s) => s.end <= s.start || annotationEventOverlaps(next, s, s.id, 0.000001))) {
|
||
setError("描述区间不能与已有描述重叠。");
|
||
return;
|
||
}
|
||
if (
|
||
unifiedBoundaries &&
|
||
(!frameBoundaryAligned(frameBoundaries, candidate.start) || !frameBoundaryAligned(frameBoundaries, candidate.end))
|
||
) {
|
||
setError("描述边界未对齐统一帧边界,请先逐帧定位确认。");
|
||
return;
|
||
}
|
||
saveInFlightRef.current = true;
|
||
setDescriptionSaving(true);
|
||
try {
|
||
const accepted = await onConfirmAnnotations?.(next, selectedSlice.id, annotationEditState());
|
||
if (accepted === false) {
|
||
setError("保存描述失败,请检查或稍后重试。");
|
||
return;
|
||
}
|
||
onChange(next);
|
||
setEndSelection(null);
|
||
setEditingAnnotation(forceInvalid ? candidate : null);
|
||
setError("");
|
||
focusWorkbench();
|
||
} catch (err: any) {
|
||
setError(err?.message || "保存描述异常,请稍后重试。");
|
||
} finally {
|
||
saveInFlightRef.current = false;
|
||
setDescriptionSaving(false);
|
||
}
|
||
};
|
||
|
||
const closeStageConfirmation = () => {
|
||
setStageConfirmation(null);
|
||
stageDialogRef.current?.close();
|
||
focusWorkbench();
|
||
};
|
||
const requestStageConfirmation = (keyboard = false) => {
|
||
if (saving || readOnly || isQualityReview || mediaOnly) return;
|
||
if (continuousActions && keyboard && phase === "annotate") {
|
||
if (editingAnnotation) void confirmAnnotation();
|
||
return;
|
||
}
|
||
// Saving a draft is its own command, even when validation fails.
|
||
if (keyboard && outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
void confirmAnnotation();
|
||
return;
|
||
}
|
||
stageEnterReleasedRef.current = !keyboard;
|
||
if (outstandingDrafts.length) {
|
||
pausePlayback();
|
||
setStageConfirmation("drafts");
|
||
return;
|
||
}
|
||
if (phase === "slice" && (!canConfirmSlices || sliceNameIssue)) {
|
||
setError(sliceNameIssue || "请先确认切片完整覆盖并对齐统一帧边界。");
|
||
return;
|
||
}
|
||
if (phase === "annotate" && !canSubmitTask) {
|
||
setError(submissionBlockerReason || "当前任务暂时不能提交,请检查切片和描述。");
|
||
return;
|
||
}
|
||
pausePlayback();
|
||
stageDispatchingRef.current = false;
|
||
setStageConfirmation(phase);
|
||
};
|
||
const confirmStage = () => {
|
||
if (stageDispatchingRef.current || saving || readOnly || outstandingDrafts.length) return;
|
||
const requested = stageConfirmation;
|
||
if (requested !== phase || (requested !== "slice" && requested !== "annotate")) return;
|
||
if (requested === "slice" ? !canConfirmSlices || Boolean(sliceNameIssue) : !canSubmitTask) return;
|
||
stageDispatchingRef.current = true;
|
||
closeStageConfirmation();
|
||
if (requested === "slice") onConfirmSlices?.();
|
||
else onSubmitTask?.();
|
||
};
|
||
|
||
const markSelectedInvalid = () => confirmAnnotation(true);
|
||
const saveProgress = async () => {
|
||
if (!onSaveProgress || !canEdit || saveInFlightRef.current) return;
|
||
if (outstandingDrafts.length) {
|
||
setError("请先保存或取消当前文字,再保存进度。");
|
||
return;
|
||
}
|
||
saveInFlightRef.current = true;
|
||
setDescriptionSaving(true);
|
||
try {
|
||
if (await onSaveProgress(segments)) setError("");
|
||
} catch (cause) {
|
||
setError(cause instanceof Error ? cause.message : "保存进度失败");
|
||
} finally {
|
||
saveInFlightRef.current = false;
|
||
setDescriptionSaving(false);
|
||
focusWorkbench();
|
||
}
|
||
};
|
||
const markUnannotatedInvalid = async () => {
|
||
if (readOnly || saving || editingAnnotation || !sliceAligned || !selectedSlice || !annotationGaps.length) return;
|
||
if (
|
||
unifiedBoundaries &&
|
||
annotationGaps.some(
|
||
(gap) => !frameBoundaryAligned(frameBoundaries, gap.start) || !frameBoundaryAligned(frameBoundaries, gap.end),
|
||
)
|
||
) {
|
||
setError("已有描述未对齐统一帧边界,请先调整边界。");
|
||
return;
|
||
}
|
||
const next = [
|
||
...segments,
|
||
...annotationGaps.map((gap, index) => ({
|
||
id: `invalid-${Date.now()}-${index}`,
|
||
start: gap.start,
|
||
end: gap.end,
|
||
labelId: "",
|
||
label: "无效片段",
|
||
description: "无效片段",
|
||
isInvalid: true,
|
||
source: "manual" as const,
|
||
})),
|
||
];
|
||
try {
|
||
// A false result includes a stale task response: do not move its focus.
|
||
if ((await onConfirmAnnotations?.(next, selectedSlice.id, annotationEditState())) === false) return;
|
||
onChange(next);
|
||
setError("");
|
||
focusWorkbench();
|
||
} catch (e) {
|
||
setError(e instanceof Error ? e.message : "保存失败");
|
||
focusWorkbench();
|
||
}
|
||
};
|
||
|
||
const beginAnnotationBoundaryDrag = (event: ReactPointerEvent<HTMLButtonElement>, index: number) => {
|
||
if (readOnly || saving || phase !== "annotate" || selectingEnd || !annotationTrackRef.current) return;
|
||
if (continuousActions && outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
setError("请先保存或取消当前文字,再调整边界。");
|
||
return;
|
||
}
|
||
if (Math.abs(annotationSegments[index]?.end - annotationSegments[index + 1]?.start) > 0.000001) {
|
||
setError("这两段之间有未标注区间,请先补标,不会自动拉伸描述填空。");
|
||
return;
|
||
}
|
||
event.preventDefault();
|
||
event.stopPropagation();
|
||
annotationBoundaryDragRef.current = {
|
||
index,
|
||
before: annotationEditState(),
|
||
gesture: {
|
||
x: event.clientX,
|
||
time: annotationSegments[index].end,
|
||
secondsPerPixel:
|
||
(descriptionTimelineEnd - descriptionTimelineStart) /
|
||
Math.max(annotationTrackRef.current.clientWidth - 16, 1),
|
||
},
|
||
};
|
||
transport.beginScrub();
|
||
setSelectedAnnotationBoundary({ index });
|
||
event.currentTarget.setPointerCapture(event.pointerId);
|
||
};
|
||
|
||
const updateAnnotationBoundaryDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
|
||
if (readOnly || saving || selectingEnd) return;
|
||
if (!annotationBoundaryDragRef.current) {
|
||
if (annotationTrackRef.current) {
|
||
const point = pointForEvent(
|
||
event,
|
||
annotationTrackRef.current,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
);
|
||
const segIndex = annotationSegments.findIndex((s) => point.time > s.start + 0.05 && point.time < s.end - 0.05);
|
||
if (segIndex >= 0) {
|
||
setAnnotationSplitPreview({ segmentIndex: segIndex, time: snap(point.time) });
|
||
} else {
|
||
setAnnotationSplitPreview(null);
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
if (!annotationTrackRef.current || !selectedSlice) return;
|
||
const { index, gesture } = annotationBoundaryDragRef.current;
|
||
const time = gesture.time + (event.clientX - gesture.x) * gesture.secondsPerPixel;
|
||
const current = annotationSegments[index];
|
||
const following = annotationSegments[index + 1];
|
||
if (!current || !following) return;
|
||
|
||
const minimum = exactFrames ? stepFrameBoundary(frameBoundaries, current.start, 1) : current.start + 0.033;
|
||
const maximum = exactFrames ? stepFrameBoundary(frameBoundaries, following.end, -1) : following.end - 0.033;
|
||
const nextTime = clamp(snap(time), minimum, maximum);
|
||
|
||
const updated = segments.map((seg) => {
|
||
if (seg.id === current.id) return { ...seg, end: nextTime };
|
||
if (seg.id === following.id) return { ...seg, start: nextTime };
|
||
return seg;
|
||
});
|
||
const editor = editingAnnotation
|
||
? {
|
||
annotation: updated.find((segment) => segment.id === editingAnnotation.id) || editingAnnotation,
|
||
endSelection,
|
||
}
|
||
: null;
|
||
annotationBoundaryDragRef.current.after = { ...annotationEditState(), segments: updated, editor, time: nextTime };
|
||
onChange(updated);
|
||
if (editingAnnotation?.id === current.id) updateEditingAnnotation({ end: nextTime });
|
||
if (editingAnnotation?.id === following.id) updateEditingAnnotation({ start: nextTime });
|
||
previewSeek(nextTime);
|
||
};
|
||
|
||
const releaseAnnotationBoundaryDrag = () => {
|
||
if (!annotationBoundaryDragRef.current) return;
|
||
const edit = annotationBoundaryDragRef.current;
|
||
annotationBoundaryDragRef.current = null;
|
||
if (
|
||
!readOnly &&
|
||
!saving &&
|
||
edit.after &&
|
||
JSON.stringify(edit.before.segments) !== JSON.stringify(edit.after.segments)
|
||
)
|
||
onAnnotationEdit?.(edit.before, edit.after);
|
||
setSelectedAnnotationBoundary(null);
|
||
transport.finishScrub();
|
||
focusWorkbench();
|
||
};
|
||
|
||
const insertAnnotationSplit = (segmentIndex: number, time: number) => {
|
||
if (
|
||
readOnly ||
|
||
isQualityReview ||
|
||
saving ||
|
||
phase !== "annotate" ||
|
||
!selectedSlice ||
|
||
(!continuousActions && editingAnnotation)
|
||
)
|
||
return;
|
||
if (outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
setError("请先保存或取消当前动作描述,再切分。");
|
||
return;
|
||
}
|
||
const target = annotationSegments[segmentIndex];
|
||
if (!target) return;
|
||
const splitPoint = snap(time);
|
||
if (splitPoint <= target.start + 0.000001 || splitPoint >= target.end - 0.000001) return;
|
||
|
||
const firstSegment: AnnotationSegment = {
|
||
...target,
|
||
end: splitPoint,
|
||
};
|
||
const secondSegment: AnnotationSegment = {
|
||
id: `description-${selectedSlice.id}-${Date.now()}`,
|
||
...(continuousActions ? { status: "pending" as const } : {}),
|
||
labelId: "",
|
||
label: "",
|
||
description: "",
|
||
start: splitPoint,
|
||
end: target.end,
|
||
confidence: 1,
|
||
source: "manual",
|
||
};
|
||
|
||
const next = segments.flatMap((seg) => {
|
||
if (seg.id === target.id) {
|
||
return [firstSegment, secondSegment];
|
||
}
|
||
return [seg];
|
||
});
|
||
|
||
const selectedPart = continuousActions ? firstSegment : secondSegment;
|
||
pausePlayback();
|
||
recordEditorEdit({ annotation: selectedPart, endSelection: null }, next, splitPoint);
|
||
onChange(next);
|
||
setAnnotationSplitPreview(null);
|
||
setEditingAnnotation(selectedPart);
|
||
setEndSelection(null);
|
||
seek(splitPoint);
|
||
requestAnimationFrame(focusWorkbench);
|
||
};
|
||
|
||
const deleteAnnotationLeavingBlank = async (segmentId: string) => {
|
||
if (!selectedSlice || saving || readOnly || isQualityReview || selectedDiscarded) return;
|
||
const next = segments.filter((s) => s.id !== segmentId);
|
||
const target = segments.find((segment) => segment.id === segmentId);
|
||
try {
|
||
const accepted = await onConfirmAnnotations?.(next, selectedSlice.id, {
|
||
...annotationEditState(),
|
||
revealAnnotation: target ? { id: target.id, start: target.start } : undefined,
|
||
});
|
||
if (accepted === false) return;
|
||
onChange(next);
|
||
setEndSelection(null);
|
||
setEditingAnnotation(null);
|
||
setError("");
|
||
focusWorkbench();
|
||
} catch (cause) {
|
||
setError(cause instanceof Error ? cause.message : "保存描述失败");
|
||
}
|
||
};
|
||
|
||
const cancelAnnotationSplit = (segmentId: string) => {
|
||
if (!canEdit || phase !== "annotate" || annotationSegments.length < 2) return;
|
||
if (outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
setError("请先保存或取消当前动作描述,再取消切分。");
|
||
return;
|
||
}
|
||
const index = annotationSegments.findIndex((segment) => segment.id === segmentId);
|
||
if (index < 0) return;
|
||
const neighbor = annotationSegments[index + 1] || annotationSegments[index - 1];
|
||
const changed = cancelActionPartition(annotationSegments, segmentId) as AnnotationSegment[];
|
||
if (changed === annotationSegments) return;
|
||
const merged = changed.find((segment) => segment.id === neighbor.id);
|
||
if (!merged) return;
|
||
const next = segments
|
||
.filter((segment) => !annotationSegments.some((previous) => previous.id === segment.id))
|
||
.concat(changed)
|
||
.sort((left, right) => left.start - right.start);
|
||
const time = exactFrames ? lastActionFrame(frameBoundaries, merged) : merged.start;
|
||
pausePlayback();
|
||
recordEditorEdit({ annotation: merged, endSelection: null }, next, time);
|
||
onChange(next);
|
||
setEditingAnnotation(merged);
|
||
setEndSelection(null);
|
||
setSelectedAnnotationBoundary(null);
|
||
setAnnotationSplitPreview(null);
|
||
setError("");
|
||
seek(time);
|
||
requestAnimationFrame(focusWorkbench);
|
||
};
|
||
|
||
const descriptionNavigationRef = useRef(false);
|
||
const selectDescription = (segment: AnnotationSegment) => {
|
||
if (saving || !timelineReady) return false;
|
||
if (
|
||
isQualityReview &&
|
||
editingAnnotation &&
|
||
segment.id !== editingAnnotation.id &&
|
||
qaDraftComment !== currentSavedQAComment
|
||
) {
|
||
setError("请先保存或取消当前审核批注,再切换动作。");
|
||
return false;
|
||
}
|
||
if (
|
||
editingAnnotation &&
|
||
segment.id !== editingAnnotation.id &&
|
||
(endSelectionRef.current || outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id))
|
||
) {
|
||
setError("请先保存或取消当前动作描述,再切换动作。");
|
||
return false;
|
||
}
|
||
setEditingAnnotation(segment);
|
||
setError("");
|
||
return true;
|
||
};
|
||
|
||
const seekAnnotation = (segment: AnnotationSegment, edge: "start" | "end") => {
|
||
if (phase !== "annotate" || saving || !timelineReady || selectedDiscarded) return;
|
||
if (selectingEnd) {
|
||
setError("请先确认当前动作的结束点,再定位已标注动作。");
|
||
return;
|
||
}
|
||
if (!selectDescription(segment)) return;
|
||
if (isReviewViewing) onReviewNavigate?.();
|
||
descriptionNavigationRef.current = segment.id !== editingAnnotation?.id;
|
||
setWorkPosition((original) => original ?? currentTime);
|
||
pausePlayback();
|
||
setReviewPlayback(false);
|
||
setSelectedAnnotationBoundary(null);
|
||
setAnnotationSplitPreview(null);
|
||
seek(
|
||
isReviewViewing
|
||
? segment.start
|
||
: continuousActions && edge === "end" && exactFrames
|
||
? lastActionFrame(frameBoundaries, segment)
|
||
: segment[edge],
|
||
);
|
||
focusWorkbench();
|
||
};
|
||
|
||
/** 跨片定位后打开意见锚定的动作编辑器(I1:J/K 与点击路径对齐)。
|
||
* 仅在 reworkLocatePlan 判定目标片可编辑(非弃用、无停泊草稿)时到达:
|
||
* selectSlice 已把目标片停泊态恢复为当前编辑态,这里直接展示锚定动作;
|
||
* 滚动语义与 seekAnnotation 一致——动作栏行滚入视野,不额外滚动页面。 */
|
||
const openAnchoredEditor = (segment: AnnotationSegment) => {
|
||
descriptionNavigationRef.current = segment.id !== editingAnnotation?.id;
|
||
setEditingAnnotation(segment);
|
||
setEndSelection(null);
|
||
};
|
||
|
||
/** 意见定位执行器:J/K 跳转与意见卡点击共用 reworkLocatePlan 的计划。
|
||
* D6(rework-ux-adjust 04):跳转计划带面板联动意图——切片问题自动打开/切换
|
||
* E 面板目标,动作/时间点问题收起面板(未应用改动驻留);携带意图的切选旁路
|
||
* 面板的点选锁(点击路径计划不带意图,行为不变)。 */
|
||
const executeReworkLocatePlan = (plan: ReworkLocatePlan) => {
|
||
if (plan.kind === "select") {
|
||
selectSlice(plan.slice, plan.time, false, { bypassSliceEditLock: plan.sliceEdit !== undefined });
|
||
if (plan.openActionId) {
|
||
const segment = segments.find((item) => item.id === plan.openActionId);
|
||
if (segment) openAnchoredEditor(segment);
|
||
}
|
||
} else if (plan.kind === "annotate") {
|
||
seekAnnotation(plan.segment, "start");
|
||
} else if (plan.time != null) {
|
||
// 定位即暂停,不自动播放:播放由播放键/空格触发(用户确认)。
|
||
pausePlayback();
|
||
seek(plan.time);
|
||
}
|
||
if (plan.sliceEdit === "close") collapseSliceEditPanelForNavigation();
|
||
else if (plan.sliceEdit) openSliceEditPanelForJump(plan.sliceEdit.sliceId);
|
||
};
|
||
|
||
const navigateAnnotation = (direction: -1 | 1, count = 1) => {
|
||
let target = adjacentAnnotation(annotationForRender, editingAnnotation?.id, currentTime, direction);
|
||
if (continuousActions && !isReviewViewing && annotationForRender.length) {
|
||
const selectedIndex = annotationForRender.findIndex((action) => action.id === editingAnnotation?.id);
|
||
// The first unselected step follows the playhead, just like the original
|
||
// navigation. Further steps wrap within this slice.
|
||
const firstIndex =
|
||
selectedIndex < 0 ? annotationForRender.findIndex((action) => action.id === target?.id) : selectedIndex;
|
||
const steps = selectedIndex < 0 ? count - 1 : count;
|
||
const length = annotationForRender.length;
|
||
target = annotationForRender[(((firstIndex + direction * steps) % length) + length) % length];
|
||
}
|
||
if (target) seekAnnotation(target, "start");
|
||
};
|
||
|
||
const reviewActions = reviewNavigation?.actions || annotationSegments;
|
||
const reviewSelectedActionId = reviewNavigation?.selectedActionId || editingAnnotation?.id || null;
|
||
const reviewPosition: ReviewPosition = {
|
||
time: currentTime,
|
||
timeBasis: mediaOnly ? "slice-seconds" : "capture-seconds",
|
||
sliceId: selectedSlice.id,
|
||
navigationSliceId: selectedSlice.id,
|
||
actionId: reviewCaption?.action?.id || null,
|
||
// D10(票 08):当前动作区间随位置上报(与 actionId 同一来源对象),供时间点卡动作归属。
|
||
actionStart: reviewCaption?.action?.start ?? null,
|
||
actionEnd: reviewCaption?.action?.end ?? null,
|
||
// review-r3(D10 三审增补):当前切片动作清单随位置上报,供动作间隙归属兜底。
|
||
actions: reviewActions,
|
||
selectedActionId: reviewSelectedActionId,
|
||
};
|
||
const reviewPositionCallback = useRef(onReviewPositionChange);
|
||
reviewPositionCallback.current = onReviewPositionChange;
|
||
useEffect(() => {
|
||
if (!isReviewViewing) return;
|
||
// Publish one frame later so the controller attach effect below has run:
|
||
// a remounted viewer must be steerable before a pending problem recall
|
||
// flushes its recorded frame through that controller.
|
||
const frame = requestAnimationFrame(() => reviewPositionCallback.current?.(reviewPosition));
|
||
return () => cancelAnimationFrame(frame);
|
||
}, [
|
||
isReviewViewing,
|
||
currentTime,
|
||
selectedSlice.id,
|
||
reviewPosition.actionId,
|
||
reviewSelectedActionId,
|
||
timelineReady,
|
||
onReviewPositionChange,
|
||
]);
|
||
const selectReviewAction = (id: string) => {
|
||
onReviewNavigate?.();
|
||
const action = reviewActions.find((candidate) => candidate.id === id);
|
||
if (!action || saving || !timelineReady) return false;
|
||
if (reviewNavigation) {
|
||
if (!reviewNavigation.onSelectAction(id)) return false;
|
||
pausePlayback();
|
||
setReviewPlayback(false);
|
||
seek(action.start);
|
||
focusWorkbench();
|
||
} else {
|
||
if (!selectDescription(action as AnnotationSegment)) return false;
|
||
seekAnnotation(action as AnnotationSegment, "start");
|
||
}
|
||
return true;
|
||
};
|
||
const navigateReviewAction = (direction: -1 | 1) => {
|
||
const target = adjacentAnnotation(reviewActions, reviewSelectedActionId, currentTime, direction);
|
||
if (target) selectReviewAction(target.id);
|
||
};
|
||
const pauseAndLocateReview = (): ReviewPosition | null => {
|
||
if (
|
||
!timelineReady ||
|
||
transport.isPositioning ||
|
||
!transport.master() ||
|
||
transport.master()!.readyState < 2 ||
|
||
transport.master()!.seeking
|
||
) {
|
||
setError("视频尚在定位,请画面就绪后记录问题。");
|
||
return null;
|
||
}
|
||
const time = transport.pauseAtFrame();
|
||
setReviewPlayback(false);
|
||
const owner = slices[sliceIndexAtPlayhead(slices, time)] || selectedSlice;
|
||
const actions = reviewNavigation?.actions || annotationSegmentsForSlice(owner, segments);
|
||
const action =
|
||
owner.deliveryDisposition === "discard"
|
||
? null
|
||
: actions.find((candidate) => time >= candidate.start && time < candidate.end);
|
||
if (reviewNavigation && action) {
|
||
if (!reviewNavigation.onSelectAction(action.id)) return null;
|
||
} else if (!reviewNavigation) {
|
||
setSelectedSliceId(owner.id);
|
||
setEditingAnnotation((action as AnnotationSegment) || null);
|
||
}
|
||
const position: ReviewPosition = {
|
||
time,
|
||
timeBasis: mediaOnly ? "slice-seconds" : "capture-seconds",
|
||
sliceId: owner.id,
|
||
navigationSliceId: owner.id,
|
||
actionId: action?.id || null,
|
||
actionStart: action?.start ?? null,
|
||
actionEnd: action?.end ?? null,
|
||
actions,
|
||
selectedActionId: action?.id || null,
|
||
};
|
||
reviewPositionCallback.current?.(position);
|
||
return position;
|
||
};
|
||
const reviewControllerCurrent = useRef<ReviewViewingController | null>(null);
|
||
reviewControllerCurrent.current = {
|
||
pause: pausePlayback,
|
||
pauseAndLocate: pauseAndLocateReview,
|
||
focus: focusWorkbench,
|
||
playPause: togglePlay,
|
||
step,
|
||
navigateSlice: (direction) =>
|
||
reviewNavigation ? reviewNavigation.onNavigateSlice(direction) : navigateSlice(direction),
|
||
navigateAction: navigateReviewAction,
|
||
reviewSlice,
|
||
showHelp: () => shortcutHelpRef.current?.showModal(),
|
||
seekAction: selectReviewAction,
|
||
seekSlice: (id) => {
|
||
const target = slices.find((slice) => slice.id === id);
|
||
if (!target) return false;
|
||
selectSlice(target);
|
||
return true;
|
||
},
|
||
seekTime: (time) => {
|
||
if (!Number.isFinite(time)) return;
|
||
// Opinion/J-K anchors use the capture clock, and may belong to another
|
||
// slice. Move selection and playhead together, otherwise the bounds
|
||
// effect immediately clamps the new frame back into the previous slice.
|
||
const owner = slices[sliceIndexAtPlayhead(slices, time)];
|
||
if (owner && owner.id !== selectedSlice.id) {
|
||
selectSlice(owner, time, false);
|
||
return;
|
||
}
|
||
// A second command can return to this render's slice before the first
|
||
// selection commits. Publish it even when its id appears unchanged.
|
||
// Same-slice recall also remains available while metadata is loading.
|
||
if (owner) setSelectedSliceId(owner.id);
|
||
pausePlayback();
|
||
seek(time);
|
||
focusWorkbench();
|
||
},
|
||
};
|
||
const reviewController = useMemo<ReviewViewingController>(
|
||
() => ({
|
||
pause: () => reviewControllerCurrent.current?.pause(),
|
||
pauseAndLocate: () => reviewControllerCurrent.current?.pauseAndLocate() || null,
|
||
focus: () => reviewControllerCurrent.current?.focus(),
|
||
playPause: () => reviewControllerCurrent.current?.playPause(),
|
||
step: (direction) => reviewControllerCurrent.current?.step(direction),
|
||
navigateSlice: (direction) => reviewControllerCurrent.current?.navigateSlice(direction),
|
||
navigateAction: (direction) => reviewControllerCurrent.current?.navigateAction(direction),
|
||
reviewSlice: () => reviewControllerCurrent.current?.reviewSlice(),
|
||
showHelp: () => reviewControllerCurrent.current?.showHelp(),
|
||
seekAction: (id) => reviewControllerCurrent.current?.seekAction(id) || false,
|
||
seekSlice: (id) => reviewControllerCurrent.current?.seekSlice(id) || false,
|
||
seekTime: (time) => reviewControllerCurrent.current?.seekTime(time),
|
||
}),
|
||
[],
|
||
);
|
||
useEffect(() => {
|
||
if (!isReviewViewing) return;
|
||
onReviewController?.(reviewController);
|
||
return () => onReviewController?.(null);
|
||
}, [isReviewViewing, onReviewController, reviewController]);
|
||
|
||
const selectedSliceStatus = selectedSlice ? statuses[selectedSlice.id] || "pending" : "pending";
|
||
const videoClass =
|
||
(focusedLayout && inspectionCamera) || !(effectiveShowLeft && effectiveShowRight) ? "grid-cols-1" : "grid-cols-2";
|
||
useEffect(() => {
|
||
if (descriptionNavigationRef.current) {
|
||
descriptionNavigationRef.current = false;
|
||
return;
|
||
}
|
||
if (editingAnnotation?.id) {
|
||
descriptionEditorRef.current?.scrollIntoView({ block: "end", behavior: "instant" });
|
||
}
|
||
}, [editingAnnotation?.id]);
|
||
|
||
const canEdit =
|
||
!readOnly &&
|
||
!isQualityReview &&
|
||
!mediaOnly &&
|
||
!saving &&
|
||
(phase === "slice" || !selectedDiscarded) &&
|
||
phase !== "materializing";
|
||
const canDeleteSliceAtIndex = (index: number) => {
|
||
const target = slices[index];
|
||
const neighbor = index < slices.length - 1 ? slices[index + 1] : slices[index - 1];
|
||
return Boolean(
|
||
canEdit &&
|
||
(phase === "slice" || phase === "annotate") &&
|
||
onDeleteSlice &&
|
||
slices.length > 1 &&
|
||
target &&
|
||
neighbor,
|
||
);
|
||
};
|
||
const deleteSliceAtIndex = (index: number) => {
|
||
if (!canDeleteSliceAtIndex(index)) return;
|
||
// R2-Q5/R2-Q3:面板或冲突清单打开期间垃圾桶合并锁定(结构改动统一走单一处置入口)。
|
||
if (sliceEditConflictList || sliceEditPanelOpen) {
|
||
notifySliceEditLocked();
|
||
return;
|
||
}
|
||
const target = slices[index];
|
||
const neighbor = index < slices.length - 1 ? slices[index + 1] : slices[index - 1];
|
||
onDeleteSlice?.(index);
|
||
if (target.id === selectedSlice.id && neighbor) setSelectedSliceId(neighbor.id);
|
||
pausePlayback();
|
||
setSelectedBoundary(null);
|
||
focusWorkbench();
|
||
};
|
||
const sliceBoundaryIssue = timelineReady ? sliceTimelineIssue(slices, clipStart, clipEnd, frameBoundaries) : "";
|
||
const changePlaybackRate = (rate: number) => {
|
||
if (saving || phase === "materializing" || !CAPTURE_PLAYBACK_RATES.includes(rate)) return;
|
||
setPlaybackRate(rate);
|
||
if (leftVideoRef.current) leftVideoRef.current.playbackRate = rate;
|
||
if (rightVideoRef.current) rightVideoRef.current.playbackRate = rate;
|
||
};
|
||
const closeDescriptionDictionary = () => {
|
||
setShowDictionary(false);
|
||
focusWorkbench();
|
||
};
|
||
const openDisposition = (restore = false) => {
|
||
// 切片级舍弃在 annotate 相经切片编辑模式的 G 打开(R1-Q3:a 复用现有弹窗)。
|
||
if (
|
||
saving ||
|
||
readOnly ||
|
||
isQualityReview ||
|
||
mediaOnly ||
|
||
(phase !== "slice" && phase !== "annotate") ||
|
||
!onSliceDispositionChange
|
||
)
|
||
return;
|
||
if (outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
setError("请先保存或取消当前描述,再设置舍弃原因。");
|
||
return;
|
||
}
|
||
setDispositionDraft((previous) =>
|
||
selectedDiscarded && !restore
|
||
? {
|
||
sliceId: selectedSlice.id,
|
||
discard: true,
|
||
reason: selectedSlice.discardReason,
|
||
reasonLabelId: selectedSlice.discardReasonLabelId,
|
||
reasonVersion: selectedSlice.discardReasonVersion,
|
||
reasonNote: selectedSlice.discardReasonNote || "",
|
||
}
|
||
: previous.sliceId === selectedSlice.id
|
||
? { ...previous, discard: !restore }
|
||
: { sliceId: selectedSlice.id, reasonNote: "", discard: !restore },
|
||
);
|
||
if (!restore) onRefreshDiscardReasons?.();
|
||
setDispositionError("");
|
||
setShowDictionary(false);
|
||
setDispositionOpen(true);
|
||
requestAnimationFrame(() => {
|
||
const panel = dispositionDialogRef.current;
|
||
const target =
|
||
panel?.querySelector<HTMLElement>("input, textarea") || panel?.querySelector<HTMLElement>("button");
|
||
target?.focus();
|
||
});
|
||
};
|
||
const splitAtPlayhead = () => {
|
||
if (!canEdit || (!continuousActions && editingAnnotation)) return;
|
||
if (outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
setError("请先保存或取消当前描述,再切分。");
|
||
return;
|
||
}
|
||
if (phase === "slice") {
|
||
if (!onSplitSlice) return;
|
||
if (playheadSliceIndex < 0) {
|
||
setError("播放点不在有效切片内,请重新定位后再拆分。");
|
||
return;
|
||
}
|
||
insertSlice(playheadSliceIndex, currentTime);
|
||
} else
|
||
insertAnnotationSplit(
|
||
annotationSegments.findIndex((s) => currentTime > s.start && currentTime < s.end),
|
||
currentTime,
|
||
);
|
||
};
|
||
|
||
const boundaryHoldRef = useRef<{ stop: () => void } | null>(null);
|
||
const stopBoundaryHold = () => {
|
||
boundaryHoldRef.current?.stop();
|
||
boundaryHoldRef.current = null;
|
||
};
|
||
useEffect(() => {
|
||
const released = (event: KeyboardEvent) => {
|
||
if (["Shift", "ArrowLeft", "ArrowRight"].includes(event.key)) stopBoundaryHold();
|
||
};
|
||
const blurred = () => stopBoundaryHold();
|
||
window.addEventListener("keyup", released);
|
||
window.addEventListener("blur", blurred);
|
||
return () => {
|
||
window.removeEventListener("keyup", released);
|
||
window.removeEventListener("blur", blurred);
|
||
stopBoundaryHold();
|
||
};
|
||
}, [taskId, phase]);
|
||
useEffect(() => {
|
||
stopBoundaryHold();
|
||
}, [selectedSlice.id, editingAnnotation?.id]);
|
||
useEffect(() => {
|
||
if (readOnly || viewportSuspended || saving || showDictionary || stageConfirmation) stopBoundaryHold();
|
||
if (readOnly || saving) {
|
||
const scrubbing = Boolean(sliceDragRef.current || annotationBoundaryDragRef.current);
|
||
sliceDragRef.current = null;
|
||
annotationBoundaryDragRef.current = null;
|
||
if (scrubbing) transport.finishScrub();
|
||
setSplitPreview(null);
|
||
setAnnotationSplitPreview(null);
|
||
}
|
||
}, [readOnly, viewportSuspended, saving, showDictionary, stageConfirmation]);
|
||
const startBoundaryHold = (direction: -1 | 1) => {
|
||
if (!continuousActions || !canEdit || !exactFrames || boundaryHoldRef.current) return;
|
||
if (outstandingDrafts.some((draft) => draft.sliceId === selectedSlice.id)) {
|
||
setError("请先保存或取消当前文字,再调整边界。");
|
||
return;
|
||
}
|
||
const items = phase === "slice" ? slices : annotationSegments;
|
||
const id = phase === "slice" ? selectedSlice.id : editingAnnotation?.id;
|
||
const index = items.findIndex((item) => item.id === id);
|
||
const current = items[index],
|
||
following = items[index + 1];
|
||
if (!current || !following) return;
|
||
pausePlayback();
|
||
const before = annotationEditState();
|
||
let nextSegments = segments;
|
||
let last = current.end;
|
||
let nextEditor = editingAnnotation;
|
||
let stopped = false;
|
||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||
let interval: ReturnType<typeof setInterval> | undefined;
|
||
if (phase === "slice") onSliceBoundaryEditStart?.(current.id);
|
||
const finish = () => {
|
||
if (stopped) return;
|
||
stopped = true;
|
||
clearTimeout(timer);
|
||
clearInterval(interval);
|
||
if (phase === "slice" && annotationWritableRef.current) onSliceBoundaryEditEnd?.();
|
||
else if (phase !== "slice" && annotationWritableRef.current && nextSegments !== segments)
|
||
onAnnotationEdit?.(before, {
|
||
...before,
|
||
segments: nextSegments,
|
||
time: last,
|
||
editor: nextEditor ? { annotation: nextEditor, endSelection: null } : null,
|
||
});
|
||
boundaryHoldRef.current = null;
|
||
};
|
||
const move = (count: number) => {
|
||
if (stopped) return;
|
||
if (!annotationWritableRef.current) {
|
||
finish();
|
||
return;
|
||
}
|
||
const active = document.activeElement;
|
||
if (
|
||
!workbenchRef.current?.contains(active) ||
|
||
(active instanceof HTMLElement &&
|
||
active.matches("input, textarea, select, button, a, [contenteditable], [role='button']")) ||
|
||
workbenchRef.current?.querySelector("dialog[open], [role='dialog']")
|
||
) {
|
||
finish();
|
||
return;
|
||
}
|
||
let next = last;
|
||
for (let frame = 0; frame < count; frame++) next = stepFrameBoundary(frameBoundaries, next, direction);
|
||
next = clamp(next, current.start, following.end);
|
||
if (next === last) {
|
||
finish();
|
||
return;
|
||
}
|
||
const merged = next <= current.start || next >= following.end;
|
||
last = next;
|
||
if (phase === "slice") {
|
||
if (merged) {
|
||
onMergeSliceBoundary?.(current.id, next <= current.start ? "shrink" : "expand");
|
||
if (next <= current.start) setSelectedSliceId(following.id);
|
||
} else onSliceBoundaryChange?.(current.id, "end", next);
|
||
} else {
|
||
const changed = moveActionBoundary(annotationSegments, current.id, next);
|
||
nextSegments = segments
|
||
.filter((item) => !annotationSegments.some((old) => old.id === item.id))
|
||
.concat(changed)
|
||
.sort((a, b) => a.start - b.start);
|
||
nextEditor = changed.find((item) => item.id === (next <= current.start ? following.id : current.id)) || null;
|
||
onChange(nextSegments);
|
||
setEditingAnnotation(nextEditor);
|
||
setEndSelection(null);
|
||
}
|
||
seek(next);
|
||
if (merged) finish();
|
||
};
|
||
boundaryHoldRef.current = { stop: finish };
|
||
move(1);
|
||
if (!stopped)
|
||
timer = setTimeout(() => {
|
||
move(1);
|
||
if (!stopped) interval = setInterval(() => move(1), 100);
|
||
}, 1000);
|
||
};
|
||
|
||
if (!selectedSlice) {
|
||
return (
|
||
<div className="rounded-md border border-[color:var(--app-border)] bg-[color:var(--app-panel)] p-6 text-sm text-[color:var(--app-text)]">
|
||
没有可编辑的 Capture 切片。
|
||
</div>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<section
|
||
ref={workbenchRef}
|
||
className="capture-workbench relative min-w-0 max-w-full rounded-md border border-[color:var(--app-border)] bg-[color:var(--app-panel)] text-[color:var(--app-text)] shadow-[0_8px_28px_rgba(15,23,42,0.06)]"
|
||
data-testid="capture-annotation-workbench"
|
||
data-stage={phase}
|
||
data-slice-edit-open={Boolean(sliceEditPanel || sliceEditConflictList) || undefined}
|
||
data-focused-layout={focusedLayout || undefined}
|
||
data-quality-review={isQualityReview || undefined}
|
||
data-continuous-actions={continuousActions || undefined}
|
||
data-camera-inspection={focusedLayout ? inspectionCamera || undefined : undefined}
|
||
data-adaptive-slice={adaptiveLayout && phase === "slice" && !mediaOnly && !isQualityReview ? true : undefined}
|
||
tabIndex={0}
|
||
onPointerDownCapture={(event) => {
|
||
stopBoundaryHold();
|
||
if (
|
||
!(event.target as HTMLElement).closest(
|
||
"input, textarea, select, button, a, [contenteditable], dialog, [role='dialog']",
|
||
)
|
||
) {
|
||
event.currentTarget.focus({ preventScroll: true });
|
||
}
|
||
}}
|
||
onBlurCapture={(event) => {
|
||
const next = event.relatedTarget;
|
||
if (
|
||
!event.currentTarget.contains(next as Node) ||
|
||
(next instanceof HTMLElement &&
|
||
next.matches("input, textarea, select, button, a, [contenteditable], [role='button']"))
|
||
)
|
||
stopBoundaryHold();
|
||
}}
|
||
onKeyUpCapture={(event) => {
|
||
if (event.key === "Enter") stageEnterReleasedRef.current = true;
|
||
}}
|
||
onKeyDown={(event) => {
|
||
const target = event.target as HTMLElement;
|
||
// A dictionary/help/review dialog owns its keys, even if focus escaped it.
|
||
if (
|
||
workbenchRef.current?.querySelector(
|
||
"dialog[open], [role='dialog']:not(dialog), [data-dictionary-open='true']",
|
||
)
|
||
)
|
||
return;
|
||
// 冲突清单(票 04,R2-Q2):清单开着时全权接管——↑/↓ 条目、1/2/3 处置、
|
||
// Enter 按默认应用、Esc 取消整个待应用改动集;播放族 "pass" 放行给全局表
|
||
// (视频是参照物),J/K "locked" 给提示,其余键整体吞掉(面板键不生效)。
|
||
if (sliceEditConflictList && phase === "annotate") {
|
||
if (saving || quickConflictApplyingRef.current) {
|
||
event.preventDefault();
|
||
return;
|
||
}
|
||
const command = sliceEditConflictListShortcut(
|
||
{
|
||
key: event.key,
|
||
ctrlKey: event.ctrlKey,
|
||
metaKey: event.metaKey,
|
||
altKey: event.altKey,
|
||
shiftKey: event.shiftKey,
|
||
repeat: event.repeat,
|
||
defaultPrevented: event.defaultPrevented,
|
||
isComposing: event.nativeEvent.isComposing,
|
||
keyCode: event.nativeEvent.keyCode,
|
||
},
|
||
{
|
||
editable:
|
||
target.isContentEditable ||
|
||
Boolean(target.closest("input:not([readonly]), textarea:not([readonly]), select")),
|
||
},
|
||
);
|
||
if (command && command !== "pass") {
|
||
event.preventDefault();
|
||
if (command === "consume") return;
|
||
if (command === "locked") {
|
||
notifySliceEditLocked();
|
||
return;
|
||
}
|
||
if (command === "cancel") {
|
||
cancelSliceEditConflictList();
|
||
return;
|
||
}
|
||
if (command === "prev-entry" || command === "next-entry") {
|
||
setSliceEditConflictList((list) =>
|
||
list
|
||
? {
|
||
...list,
|
||
focus: conflictListFocusStep(list.entries.length, list.focus, command === "prev-entry" ? -1 : 1),
|
||
}
|
||
: list,
|
||
);
|
||
return;
|
||
}
|
||
if (command === "apply-defaults") {
|
||
applySliceEditConflictList(sliceEditConflictList.decisions);
|
||
return;
|
||
}
|
||
const position = Number(command.slice("choose-".length));
|
||
setSliceEditConflictList((list) => {
|
||
if (!list) return list;
|
||
const next = applyConflictListChoice(
|
||
list.entries,
|
||
{ focus: list.focus, decisions: list.decisions },
|
||
position,
|
||
);
|
||
return { ...list, focus: next.focus, decisions: next.decisions };
|
||
});
|
||
return;
|
||
}
|
||
if (command === "pass") {
|
||
// 空格/?/B/V:落到全局表按原语义分发(播放/倍速/定位保持自由)。
|
||
} else return; // null:文字输入、输入法、修饰组合让位原生
|
||
}
|
||
// 切片重设面板(票 04,R1-Q1/R1-Q3/R2-Q5):面板开着时面板命令优先,播放族
|
||
// 与 J/K 返修跳转放行(rework-ux-adjust 04 · D6:跳转落到切片问题自动开/切
|
||
// 面板目标,其余问题收起面板、未应用改动驻留;非返工任务 J/K 无绑定自然
|
||
// 落空),其余键吞掉——模式外全局键位不受影响(互不串扰)。
|
||
else if (sliceEditPanel && phase === "annotate") {
|
||
const command = sliceEditPanelShortcut(
|
||
{
|
||
key: event.key,
|
||
ctrlKey: event.ctrlKey,
|
||
metaKey: event.metaKey,
|
||
altKey: event.altKey,
|
||
shiftKey: event.shiftKey,
|
||
repeat: event.repeat,
|
||
defaultPrevented: event.defaultPrevented,
|
||
isComposing: event.nativeEvent.isComposing,
|
||
keyCode: event.nativeEvent.keyCode,
|
||
},
|
||
{
|
||
editable:
|
||
target.isContentEditable ||
|
||
Boolean(target.closest("input:not([readonly]), textarea:not([readonly]), select")),
|
||
},
|
||
);
|
||
if (command && command !== "pass") {
|
||
event.preventDefault();
|
||
if (command === "consume") return;
|
||
if (command === "cancel") {
|
||
if (sliceEditDiscardDraft) {
|
||
setSliceEditDiscardDraft(null); // 一层一层退:先关舍弃草稿
|
||
return;
|
||
}
|
||
cancelSliceEditPanel();
|
||
return;
|
||
}
|
||
if (saving) return;
|
||
if (command === "apply") {
|
||
applySliceEditPanel();
|
||
return;
|
||
}
|
||
if (command === "nudge-boundary")
|
||
panelNudgeBoundary(sliceEditPanel.focusBoundary, event.key === "ArrowLeft" ? -1 : 1, 1);
|
||
else if (command === "coarse-nudge-boundary")
|
||
panelNudgeBoundary(sliceEditPanel.focusBoundary, event.key === "ArrowLeft" ? -1 : 1, 1, true);
|
||
else if (command === "switch-boundary")
|
||
setSliceEditPanel((panel) =>
|
||
panel ? { ...panel, focusBoundary: panel.focusBoundary === "start" ? "end" : "start" } : panel,
|
||
);
|
||
else if (command === "split") panelSplitAtPlayhead();
|
||
else if (command === "discard") panelDiscardDraftOpen();
|
||
else if (command === "dictionary") {
|
||
if (!sliceEditDiscardDraft)
|
||
workbenchRef.current
|
||
?.querySelector<HTMLButtonElement>(
|
||
"[data-slice-edit-dictionary-trigger] button[aria-haspopup='dialog']:not(:disabled)",
|
||
)
|
||
?.click();
|
||
}
|
||
return;
|
||
}
|
||
if (command === "pass") {
|
||
// 空格/?/1/2/B/V 与 J/K(D6 解锁):落到全局表按原语义分发——J/K 由下方
|
||
// 返工分支跳转意见,播放/倍速/定位保持自由。
|
||
} else return; // null:让位原生(面板数字输入、IME、修饰组合)
|
||
}
|
||
if (isReviewViewing) {
|
||
const command = reviewShortcut(
|
||
{
|
||
...event,
|
||
key: event.key,
|
||
ctrlKey: event.ctrlKey,
|
||
metaKey: event.metaKey,
|
||
altKey: event.altKey,
|
||
shiftKey: event.shiftKey,
|
||
repeat: event.repeat,
|
||
defaultPrevented: event.defaultPrevented,
|
||
isComposing: event.nativeEvent.isComposing,
|
||
keyCode: event.nativeEvent.keyCode,
|
||
},
|
||
{
|
||
editable:
|
||
target.isContentEditable ||
|
||
Boolean(target.closest("textarea, select, input:not([type='range']):not([readonly])")),
|
||
nativeControl: Boolean(target.closest("button, a, input, select, [role='button']")),
|
||
noteInput: Boolean(target.closest("[data-review-note-input]")),
|
||
// 返修接收视图挂载时 J/K 才进审查键表(review-shortcuts 的 reworkOpinions 上下文)。
|
||
reworkOpinions: Boolean(onReviewReworkNavigate),
|
||
},
|
||
);
|
||
if (!command) return;
|
||
event.preventDefault();
|
||
if (reviewReadOnly && reviewCommandRequiresWrite(command)) return;
|
||
if (command === "escape") {
|
||
onReviewEscape?.();
|
||
reviewController.focus();
|
||
} else if (command === "help") reviewController.showHelp();
|
||
else if (!saving && !viewportSuspended) {
|
||
if (command === "play") reviewController.playPause();
|
||
else if (command === "step-back" || command === "step-forward")
|
||
reviewController.step(command === "step-back" ? -1 : 1);
|
||
else if (command === "previous-slice" || command === "next-slice")
|
||
reviewController.navigateSlice(command === "previous-slice" ? -1 : 1);
|
||
else if (command === "previous-action" || command === "next-action")
|
||
reviewController.navigateAction(command === "previous-action" ? -1 : 1);
|
||
else if (command === "review-slice") reviewController.reviewSlice();
|
||
else if (command === "problem") {
|
||
const position = reviewController.pauseAndLocate();
|
||
if (position) onReviewProblem?.(position);
|
||
} else if (command === "save-note") onReviewSave?.();
|
||
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)。
|
||
onReviewReworkNavigate?.(command === "next-rework-opinion" ? 1 : -1);
|
||
else if (command === "rework-verdict-resolved" || command === "rework-verdict-unresolved")
|
||
// 判定键 1/2(R1-Q7):作用于聚焦的退回意见行;聚焦板/锁定/空备注由页面判定。
|
||
onReviewReworkVerdict?.(command === "rework-verdict-resolved");
|
||
else if (command === "edit-problem") onReviewProblemEdit?.();
|
||
else if (command === "delete-problem") onReviewProblemDelete?.();
|
||
}
|
||
return;
|
||
}
|
||
// 返工强调层:J/K 跳到下一条/上一条未修改意见(当前未占用键,零冲突)。
|
||
if (
|
||
reworkActive &&
|
||
!event.ctrlKey &&
|
||
!event.metaKey &&
|
||
!event.altKey &&
|
||
!event.shiftKey &&
|
||
(event.key === "j" || event.key === "k")
|
||
) {
|
||
if (
|
||
target.isContentEditable ||
|
||
Boolean(target.closest("input:not([readonly]), textarea:not([readonly]), select"))
|
||
)
|
||
return;
|
||
event.preventDefault();
|
||
if (!event.repeat && !saving && phase !== "materializing") jumpReworkProblem(event.key === "j" ? 1 : -1);
|
||
return;
|
||
}
|
||
const action = annotationShortcut(
|
||
{
|
||
key: event.key,
|
||
ctrlKey: event.ctrlKey,
|
||
metaKey: event.metaKey,
|
||
altKey: event.altKey,
|
||
shiftKey: event.shiftKey,
|
||
repeat: event.repeat,
|
||
defaultPrevented: event.defaultPrevented,
|
||
isComposing: event.nativeEvent.isComposing,
|
||
keyCode: event.nativeEvent.keyCode,
|
||
},
|
||
{
|
||
editable:
|
||
target.isContentEditable ||
|
||
(Boolean(target.closest("input:not([readonly]), textarea:not([readonly]), select")) &&
|
||
!target.matches("input[type='range']")),
|
||
descriptionInput: target === descriptionInputRef.current,
|
||
descriptionEditor: target === descriptionEditorRef.current,
|
||
nativeControl: Boolean(target.closest("button, a, input, select, [role='button']")),
|
||
selectingEnd,
|
||
phase,
|
||
continuousActions,
|
||
// 验收修复 D:连续动作上下文的活跃动作编辑器决定 Shift+←/→ 归属
|
||
// (动作边界连发 vs 切片分界粗步进)。
|
||
actionEditor: Boolean(editingAnnotation),
|
||
},
|
||
);
|
||
if (!action) return;
|
||
event.preventDefault();
|
||
if (action === "consume") return;
|
||
if (action !== "adjust-boundary") stopBoundaryHold();
|
||
if (action === "escape") {
|
||
focusWorkbench();
|
||
return;
|
||
}
|
||
if (action === "help") {
|
||
shortcutHelpRef.current?.showModal();
|
||
return;
|
||
}
|
||
if (saving || phase === "materializing") return;
|
||
if (action === "play") togglePlay();
|
||
else if (action === "step") step(event.key === "ArrowLeft" ? -1 : 1);
|
||
else if (action === "navigate-slice") navigateSlice(event.key === "ArrowLeft" ? -1 : 1);
|
||
else if (action === "navigate-annotation" || action === "navigate-annotation-six")
|
||
navigateAnnotation(event.key === "ArrowUp" ? -1 : 1, action === "navigate-annotation-six" ? 6 : 1);
|
||
else if ((action === "annotation-start" || action === "annotation-end") && editingAnnotation)
|
||
seekAnnotation(editingAnnotation, action === "annotation-start" ? "start" : "end");
|
||
else if (action === "review-slice") reviewSlice();
|
||
else if (action === "return-work") returnToWork();
|
||
else if (action === "slow" || action === "normal") changePlaybackRate(action === "slow" ? 0.5 : 1);
|
||
else if (
|
||
(action === "undo" || action === "redo") &&
|
||
!readOnly &&
|
||
!isQualityReview &&
|
||
!mediaOnly &&
|
||
!annotationBoundaryDragRef.current
|
||
)
|
||
void onHistoryCommand?.(action);
|
||
else if (action === "discard-dictionary") openDisposition();
|
||
else if (action === "save") requestStageConfirmation(true);
|
||
else if (action === "toggle-slice-edit" && phase === "annotate" && !readOnly && !isQualityReview && !mediaOnly)
|
||
openSliceEditPanel();
|
||
else if (canEdit) {
|
||
if (action === "adjust-boundary") startBoundaryHold(event.key === "ArrowLeft" ? -1 : 1);
|
||
else if (action === "coarse-nudge-boundary") coarseNudgeSliceBoundary(event.key === "ArrowLeft" ? -1 : 1);
|
||
else if (action === "split") splitAtPlayhead();
|
||
else if (action === "delete-selected") {
|
||
if (phase === "slice") deleteSliceAtIndex(selectedSliceIndex);
|
||
else if (
|
||
phase === "annotate" &&
|
||
editingAnnotation &&
|
||
annotationSegments.some((segment) => segment.id === editingAnnotation.id)
|
||
)
|
||
continuousActions
|
||
? cancelAnnotationSplit(editingAnnotation.id)
|
||
: void deleteAnnotationLeavingBlank(editingAnnotation.id);
|
||
} else if (action === "mark-invalid" && phase === "annotate") void markSelectedInvalid();
|
||
// 票 04(R1-Q1):E 改派切片重设面板(专注浮层 + Enter 应用/Esc 回退);旧
|
||
// 切片编辑模式自此刻起无入口,06 票随旧横幅一并清除。rework-ux-adjust 04
|
||
// (D1):单切片任务同样直开(面板内 C 可加边界),unavailable 提示分支删除。
|
||
else if (action === "new" && phase === "annotate" && sliceAligned) addAnnotation();
|
||
else if (action === "confirm-end" && selectingEnd && editingAnnotation) confirmEndSelection();
|
||
else if (action === "edit-description" && editingAnnotation && !selectingEnd)
|
||
descriptionInputRef.current?.focus();
|
||
else if (action === "dictionary") {
|
||
if (phase === "slice" && !selectedDiscarded) sliceDictionaryTriggerRef.current?.click();
|
||
else if (editingAnnotation) descriptionDictionaryTriggerRef.current?.click();
|
||
}
|
||
}
|
||
}}
|
||
>
|
||
{!sliceEditPanel && (operationError || error) ? (
|
||
<div
|
||
role="alert"
|
||
className="sticky top-0 z-50 rounded border border-rose-300 bg-rose-50 px-3 py-2 text-xs text-rose-800 dark:bg-rose-950 dark:text-rose-200"
|
||
>
|
||
{userErrorMessage(operationError || error)}
|
||
</div>
|
||
) : null}
|
||
{continuousActions && phase === "annotate" && (
|
||
<aside className="capture-action-list" aria-label="当前切片动作列表">
|
||
<strong>动作 · {actionListForRender.length}</strong>
|
||
<div ref={actionListRef} role="listbox" aria-label="动作区间" className="capture-action-list-scroll">
|
||
{actionListForRender.map((action, index) => (
|
||
<button
|
||
key={action.id}
|
||
type="button"
|
||
role="option"
|
||
aria-selected={editingAnnotation?.id === action.id}
|
||
disabled={selectedDiscarded}
|
||
data-rework-red={(trackActionBuckets.get(action.id)?.red.length || 0) > 0 || undefined}
|
||
data-rework-changed={changedActionIds.has(action.id) || undefined}
|
||
onClick={() => seekAnnotation(action, "start")}
|
||
>
|
||
<span>
|
||
#{index + 1} ·{" "}
|
||
{changedActionIds.has(action.id) && <span className="capture-change-badge">本轮改动</span>}{" "}
|
||
{(trackActionBuckets.get(action.id)?.red.length || 0) > 0 ? (
|
||
<span className="font-bold text-rose-600 dark:text-rose-400">
|
||
意见 {trackActionBuckets.get(action.id)!.red.length} ·{" "}
|
||
</span>
|
||
) : null}
|
||
{actionJudgment(action) === "pending"
|
||
? "待标注"
|
||
: actionJudgment(action) === "invalid"
|
||
? "无效"
|
||
: "已描述"}
|
||
</span>
|
||
<small>
|
||
{formatTime(action.start - selectedSlice.start)}–{formatTime(action.end - selectedSlice.start)}
|
||
</small>
|
||
<span title={action.description}>{action.description || "待标注"}</span>
|
||
</button>
|
||
))}
|
||
</div>
|
||
</aside>
|
||
)}
|
||
<dialog
|
||
ref={stageDialogRef}
|
||
tabIndex={-1}
|
||
aria-label={
|
||
stageConfirmation === "drafts"
|
||
? "请先处理未保存草稿"
|
||
: stageConfirmation === "slice"
|
||
? "确认生成切片"
|
||
: "确认提交质检"
|
||
}
|
||
onCancel={(event) => {
|
||
event.preventDefault();
|
||
closeStageConfirmation();
|
||
}}
|
||
onClose={() => {
|
||
if (viewportSuspended) return;
|
||
setStageConfirmation(null);
|
||
focusWorkbench();
|
||
}}
|
||
onKeyDown={(event) => {
|
||
event.stopPropagation();
|
||
const action = stageConfirmationShortcut(
|
||
{ ...event, isComposing: event.nativeEvent.isComposing, keyCode: event.nativeEvent.keyCode },
|
||
{ enterReleased: stageEnterReleasedRef.current },
|
||
);
|
||
if (!action) return;
|
||
event.preventDefault();
|
||
if (action === "cancel") closeStageConfirmation();
|
||
else if (action === "confirm") {
|
||
if (stageConfirmation !== "drafts") confirmStage();
|
||
else (event.target as HTMLElement).closest<HTMLButtonElement>("button")?.click();
|
||
}
|
||
}}
|
||
className="fixed inset-0 m-auto max-h-[85dvh] w-[min(560px,calc(100vw-32px))] overflow-y-auto rounded-xl border border-[color:var(--app-border)] bg-[color:var(--app-panel)] p-5 text-[color:var(--app-text)] shadow-xl backdrop:bg-black/60"
|
||
>
|
||
<h3 className="text-lg font-semibold">
|
||
{stageConfirmation === "drafts"
|
||
? "请先处理未保存草稿"
|
||
: stageConfirmation === "slice"
|
||
? "确认生成切片"
|
||
: "确认提交质检"}
|
||
</h3>
|
||
{stageConfirmation === "drafts" ? (
|
||
<div className="mt-3 space-y-2">
|
||
<p className="text-sm">以下切片仍有草稿。请逐一保存或取消编辑,再提交阶段。</p>
|
||
{outstandingDrafts.map((draft) => {
|
||
const slice = slices.find((item) => item.id === draft.sliceId);
|
||
return (
|
||
<button
|
||
key={draft.sliceId}
|
||
type="button"
|
||
className="block w-full rounded border p-3 text-left text-sm"
|
||
onClick={() => {
|
||
closeStageConfirmation();
|
||
if (sliceEditPanel) collapseSliceEditPanelForNavigation();
|
||
if (slice) selectSlice(slice, slice.start, false, { bypassSliceEditLock: true });
|
||
}}
|
||
>
|
||
{slice?.name || draft.sliceId} · {draft.selectingEnd ? "尚未确认结束点" : "描述尚未保存"}
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
) : (
|
||
<div className="mt-3 space-y-2 text-sm">
|
||
{reworkActive && reworkEmphasis && reworkEmphasis.unclearedCount > 0 && stageConfirmation !== "slice" ? (
|
||
<div className="rounded-lg border border-rose-500 bg-rose-50 p-3 text-rose-900 dark:border-rose-700 dark:bg-rose-950/40 dark:text-rose-100">
|
||
<p className="font-semibold">
|
||
⚠ 本轮打回还有 {reworkEmphasis.unclearedCount} 条未修改意见(软提醒,不拦截送检)
|
||
</p>
|
||
<ul className="mt-1.5 max-h-28 space-y-1 overflow-y-auto text-xs">
|
||
{reworkEmphasis.jumpOrder
|
||
.filter((entry) => entry.state === "red")
|
||
.map(({ opinion }) => (
|
||
<li key={opinion.id} className="flex items-start gap-1.5">
|
||
<span className="mt-0.5 shrink-0 rounded bg-rose-600 px-1 py-0.5 text-[10px] font-bold text-white">
|
||
{opinion.scope === "task"
|
||
? "整体"
|
||
: opinion.scope === "slice"
|
||
? "切片"
|
||
: opinion.scope === "action"
|
||
? "动作"
|
||
: `${formatTime(opinion.atSeconds ?? 0)}`}
|
||
</span>
|
||
<span className="min-w-0 flex-1 break-words">{opinion.text}</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
<p className="mt-1.5 text-xs text-rose-700 dark:text-rose-300">
|
||
确认已全部处理可继续送检;认为是误报的意见请先在
|
||
{focusedLayout ? "右侧意见栏" : "下方意见卡"}点「不改了」留痕。
|
||
</p>
|
||
</div>
|
||
) : null}
|
||
<p>
|
||
{slices.length} 个切片 · 保留 {slices.filter((slice) => slice.deliveryDisposition !== "discard").length}{" "}
|
||
个 · 舍弃 {slices.filter((slice) => slice.deliveryDisposition === "discard").length} 个
|
||
</p>
|
||
<p>
|
||
已保存描述 {segments.length} 条 · 明确无效{" "}
|
||
{segments.filter((segment) => segment.isInvalid || segment.description === "无效片段").length} 条
|
||
</p>
|
||
<ul className="max-h-48 space-y-1 overflow-y-auto">
|
||
{slices.map((slice) => (
|
||
<li key={slice.id}>
|
||
{slice.deliveryDisposition === "discard" ? "舍弃片段" : slice.name || slice.id}:
|
||
{slice.deliveryDisposition === "discard"
|
||
? `舍弃(${slice.discardReason || "已记录原因"})`
|
||
: `${annotationSegmentsForSlice(slice, segments).length} 条描述,${annotationCoverageGaps(slice, segments).length} 段语义留空`}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
<p>
|
||
{continuousActions
|
||
? "保留切片的所有动作区间必须保存为描述或无效后才能送检;舍弃片段保留审核证据。"
|
||
: "语义留空合法,保留的媒体仍参与审核和交付;舍弃片段保留审核证据。"}
|
||
</p>
|
||
<p>
|
||
{stageConfirmation === "slice" ? "生成完成后才进入描述编辑。" : "审核数据完成后才流转质检。"}
|
||
开始后不能通过撤销回退阶段。
|
||
</p>
|
||
<p className="text-xs text-slate-500">松开按键后,单独按 Enter 确认;Esc 取消。</p>
|
||
</div>
|
||
)}
|
||
<div className="mt-5 flex justify-end gap-2">
|
||
<button type="button" onClick={closeStageConfirmation} className="rounded border px-4 py-2 text-sm">
|
||
返回编辑
|
||
</button>
|
||
{stageConfirmation !== "drafts" && (
|
||
<button
|
||
type="button"
|
||
onClick={confirmStage}
|
||
disabled={saving || readOnly}
|
||
className="rounded bg-orange-500 px-4 py-2 text-sm font-semibold text-white disabled:opacity-50"
|
||
>
|
||
{stageConfirmation === "slice" ? "确认生成" : "确认送检"}
|
||
</button>
|
||
)}
|
||
</div>
|
||
</dialog>
|
||
<dialog
|
||
ref={shortcutHelpRef}
|
||
aria-label={isReviewViewing ? "审查快捷键帮助" : "标注快捷键帮助"}
|
||
onClose={focusWorkbench}
|
||
onKeyDown={(event) => event.stopPropagation()}
|
||
className="fixed inset-0 m-auto max-h-[85dvh] w-[min(520px,calc(100vw-32px))] overflow-y-auto rounded-xl border border-[color:var(--app-border)] bg-[color:var(--app-panel)] p-5 text-[color:var(--app-text)] shadow-xl backdrop:bg-black/40"
|
||
>
|
||
<div className="mb-3 flex items-center justify-between gap-3">
|
||
<h2 className="font-semibold">
|
||
快捷键 ·{" "}
|
||
{isReviewViewing ? "审查" : phase === "slice" ? "切片" : phase === "annotate" ? "逐片标注" : "处理中"}
|
||
</h2>
|
||
<button type="button" autoFocus aria-label="关闭快捷键帮助" onClick={() => shortcutHelpRef.current?.close()}>
|
||
<X className="h-5 w-5" />
|
||
</button>
|
||
</div>
|
||
<table className="w-full text-left text-sm">
|
||
<thead>
|
||
<tr>
|
||
<th className="py-2">按键</th>
|
||
<th>操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{sliceEditConflictList && phase === "annotate" ? (
|
||
<tr className="border-t border-amber-300 bg-amber-50/60 dark:border-amber-700 dark:bg-amber-950/30">
|
||
<td colSpan={2} className="py-2 text-xs font-semibold text-amber-700 dark:text-amber-300">
|
||
冲突清单已打开 · 以下为清单键位,Enter 应用或 Esc 取消后恢复全局键位
|
||
</td>
|
||
</tr>
|
||
) : sliceEditPanel && phase === "annotate" ? (
|
||
<tr className="border-t border-orange-300 bg-orange-50/60 dark:border-orange-700 dark:bg-orange-950/30">
|
||
<td colSpan={2} className="py-2 text-xs font-semibold text-orange-700 dark:text-orange-300">
|
||
切片重设面板已打开 · 以下为面板键位,Enter 应用或 Esc 取消后恢复全局键位
|
||
</td>
|
||
</tr>
|
||
) : null}
|
||
{(sliceEditConflictList && phase === "annotate"
|
||
? sliceEditConflictListShortcutHelp
|
||
: sliceEditPanel && phase === "annotate"
|
||
? sliceEditPanelShortcutHelp
|
||
: isReviewViewing
|
||
? reviewShortcutHelp
|
||
: annotationShortcutHelpForContext(phase, {
|
||
continuousActions,
|
||
editing: Boolean(editingAnnotation),
|
||
selectingEnd,
|
||
}).filter(
|
||
(item) =>
|
||
item.phases.includes(phase) && (!item.edit || (!readOnly && !isQualityReview && !mediaOnly)),
|
||
)
|
||
).map((item) => (
|
||
<tr key={item.keys} className="border-t border-[color:var(--app-border)]">
|
||
<td className="whitespace-nowrap py-2 pr-4 font-mono text-xs">{item.keys}</td>
|
||
<td className="py-2">{item.label}</td>
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
{reworkActive && (
|
||
<>
|
||
<p className="mt-3 border-t border-[color:var(--app-border)] pt-2 text-xs font-semibold text-rose-700 dark:text-rose-300">
|
||
本任务处于返工模式(第 {reworkEmphasis?.round} 轮打回)
|
||
</p>
|
||
<table className="w-full text-left text-sm">
|
||
<tbody>
|
||
<tr className="border-t border-[color:var(--app-border)]">
|
||
<td className="whitespace-nowrap py-2 pr-4 font-mono text-xs">J / K</td>
|
||
<td className="py-2">
|
||
跳到下一条/上一条退回意见,未修改优先(选中所在切片并定位画面;专注布局同时在右侧意见栏滑动)
|
||
</td>
|
||
</tr>
|
||
<tr className="border-t border-[color:var(--app-border)]">
|
||
<td className="py-2 pr-4 text-rose-600 dark:text-rose-300">红色块/红标记</td>
|
||
<td className="py-2">该位置有未修改退回意见;改动对应切片/动作/边界后自动消红</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</>
|
||
)}
|
||
<p className="mt-3 text-xs text-slate-500">
|
||
仅工作台获得焦点时生效。填写文字、中文输入法选词和字典弹层中不触发工作台快捷键;描述框内可用 Ctrl / ⌘ + Enter
|
||
保存。按钮不可用时,对应快捷键也不可用。
|
||
</p>
|
||
{!isReviewViewing && (
|
||
<p className="mt-2 text-xs text-slate-500">
|
||
重新切片(仅首标任务可见)和释放任务只使用按钮;结构微调用原地编辑。
|
||
</p>
|
||
)}
|
||
</dialog>
|
||
{!timelineReady && (
|
||
<div
|
||
role={frameTimelineStatus === "error" ? "alert" : "status"}
|
||
data-testid="frame-timeline-status"
|
||
className="flex flex-wrap items-center gap-3 border-b border-blue-200 bg-blue-50 px-5 py-3 text-sm text-blue-800 dark:border-blue-900 dark:bg-blue-950/30 dark:text-blue-200"
|
||
>
|
||
<span>
|
||
{frameTimelineStatus === "error"
|
||
? "视频时间范围加载失败,已有内容已保留。"
|
||
: "正在加载统一帧范围…就绪前不能切分、逐帧、编辑或确认,可先播放预览。"}
|
||
</span>
|
||
{frameTimelineStatus === "error" && onRetryFrameTimeline && (
|
||
<button type="button" onClick={onRetryFrameTimeline} className="rounded border border-blue-400 px-3 py-1">
|
||
重试加载统一帧范围
|
||
</button>
|
||
)}
|
||
</div>
|
||
)}
|
||
{!mediaOnly && (
|
||
<header className="flex flex-wrap items-center justify-between gap-4 border-b border-slate-200 px-5 py-3">
|
||
<div className="text-sm text-slate-500">项目 / 工作流 / Capture</div>
|
||
{providedReadOnly && !isQualityReview ? (
|
||
<div className="flex min-w-0 flex-col items-start gap-2">
|
||
<span className="rounded-md bg-blue-500/10 px-3 py-1 text-xs font-semibold text-blue-600 dark:bg-blue-500/20 dark:text-blue-400">
|
||
{readOnlyStatusLabel}(只读查看)
|
||
</span>
|
||
{operationNotice && !focusedLayout && (
|
||
<p
|
||
role="status"
|
||
data-testid="workbench-operation-status"
|
||
className="whitespace-normal rounded border border-blue-300 bg-blue-50 px-2 py-2 text-xs text-blue-800 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-200"
|
||
>
|
||
{operationNotice}
|
||
</p>
|
||
)}
|
||
</div>
|
||
) : isQualityReview ? (
|
||
<div className="flex items-center gap-2">
|
||
<span className="rounded-md bg-blue-500/10 px-3 py-1 text-xs font-semibold text-blue-600 dark:bg-blue-500/20 dark:text-blue-400">
|
||
质检审核模式{reviewReadOnly ? "(只读查看)" : ""}
|
||
</span>
|
||
</div>
|
||
) : (
|
||
<div className="flex items-center gap-3 text-sm font-medium">
|
||
<span
|
||
className={cn(
|
||
"inline-flex items-center gap-2",
|
||
phase === "slice" ? "text-orange-600" : "text-emerald-600",
|
||
)}
|
||
>
|
||
{phase === "slice" ? (
|
||
<span className="grid h-6 w-6 place-items-center rounded-full bg-orange-500 text-xs text-white">
|
||
1
|
||
</span>
|
||
) : (
|
||
<Check className="h-5 w-5" />
|
||
)}
|
||
切片
|
||
</span>
|
||
<span className="h-px w-20 bg-slate-200" />
|
||
<span
|
||
className={cn(
|
||
"inline-flex items-center gap-2",
|
||
phase === "annotate" ? "text-orange-600" : "text-slate-400",
|
||
)}
|
||
>
|
||
<span
|
||
className={cn(
|
||
"grid h-6 w-6 place-items-center rounded-full border text-xs",
|
||
phase === "annotate" ? "border-orange-500 bg-orange-500 text-white" : "border-slate-300",
|
||
)}
|
||
>
|
||
2
|
||
</span>
|
||
逐片标注
|
||
</span>
|
||
</div>
|
||
)}
|
||
<div className="flex items-center gap-3">
|
||
{isQualityReview && onReleaseTask ? (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={onReleaseTask}
|
||
className="rounded border border-slate-300 px-2.5 py-1 text-xs font-medium text-slate-600 hover:bg-slate-100 hover:text-slate-900 dark:border-[#34363b] dark:text-gray-300 dark:hover:bg-[#1a1b1e] dark:hover:text-white"
|
||
>
|
||
释放领取
|
||
</button>
|
||
) : null}
|
||
<button
|
||
type="button"
|
||
onClick={onReturnToPool}
|
||
className="text-sm text-slate-500 hover:text-slate-900 dark:hover:text-white"
|
||
>
|
||
{claimLocked ? "返回我的任务" : "返回任务池"}
|
||
</button>
|
||
</div>
|
||
</header>
|
||
)}
|
||
|
||
{phase === "materializing" ? (
|
||
<div className="grid min-h-96 place-items-center p-10 text-center">
|
||
<div>
|
||
<div className="mx-auto mb-4 h-9 w-9 animate-spin rounded-full border-4 border-slate-200 border-t-orange-500" />
|
||
<div className="font-semibold text-[color:var(--app-text)]">正在切片</div>
|
||
<p className="mt-2 text-sm text-slate-500">左右视频、PTS 和 IMU 正在按确认边界生成。</p>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="capture-workbench-body">
|
||
{reworkNotice && !reworkActive && (
|
||
<details className="capture-rework-details" open={!focusedLayout}>
|
||
<summary>返工说明</summary>
|
||
<div
|
||
data-testid="rework-notice-banner"
|
||
className="mb-4 rounded-xl border border-rose-300 bg-rose-50/90 p-4 text-slate-800 shadow-sm dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-200"
|
||
>
|
||
<div className="flex items-center gap-2 text-sm font-bold text-rose-700 dark:text-rose-400">
|
||
<AlertCircle className="h-4 w-4 shrink-0" />
|
||
<span>{reworkNotice.stageName || "审核打回"}</span>
|
||
</div>
|
||
{reworkNotice.reasonCodes && reworkNotice.reasonCodes.length > 0 && (
|
||
<div className="mt-2 flex flex-wrap gap-1.5">
|
||
{reworkNotice.reasonCodes.map((code) => (
|
||
<span
|
||
key={code}
|
||
className="rounded-md border border-rose-200 bg-white/80 px-2 py-0.5 text-xs font-medium text-rose-800 dark:border-rose-800 dark:bg-rose-900/40 dark:text-rose-300"
|
||
>
|
||
{code}
|
||
</span>
|
||
))}
|
||
</div>
|
||
)}
|
||
{reworkNotice.comment && (
|
||
<div className="mt-2 text-xs leading-relaxed text-slate-700 dark:text-rose-200">
|
||
<span className="font-semibold text-rose-800 dark:text-rose-300">审核评价:</span>
|
||
{reworkNotice.comment.replace(/\[ref=[^\]]*\]\s*/g, "")}
|
||
</div>
|
||
)}
|
||
{reworkNotice.problemSliceIds && reworkNotice.problemSliceIds.length > 0 && (
|
||
<div className="mt-1.5 text-[11px] text-slate-500 dark:text-rose-400">
|
||
涉及问题切片:{reworkNotice.problemSliceIds.join(", ")}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</details>
|
||
)}
|
||
{reworkNotice && reworkActive && !focusedLayout && (
|
||
<div
|
||
data-testid="rework-notice-pointer"
|
||
className="mb-2 flex flex-wrap items-center gap-2 rounded-lg border border-slate-300 bg-[color:var(--app-panel)] px-3 py-1.5 text-xs text-[color:var(--app-text)]"
|
||
>
|
||
<AlertCircle className="h-3.5 w-3.5 shrink-0" />
|
||
<span>{reworkNotice.stageName || "审核打回"}</span>
|
||
<span className="font-normal text-rose-600 dark:text-rose-300">
|
||
{focusedLayout ? "全部意见在右侧栏,按 J 逐条定位" : "意见已标注在下方切片/动作上,按 J 定位下一条"}
|
||
</span>
|
||
</div>
|
||
)}
|
||
{reworkActive && !focusedLayout && reworkEmphasis?.changes && (
|
||
<ReworkChangesPanel changes={reworkEmphasis.changes} onLocate={locateChange} />
|
||
)}
|
||
<div
|
||
className={cn(
|
||
"p-5 pb-3 bg-[color:var(--app-panel)]",
|
||
isQualityReview && "capture-review-video-panel",
|
||
phase === "annotate" && !focusedLayout && !isQualityReview && "md:sticky md:top-0 z-30 !p-2",
|
||
)}
|
||
data-testid="capture-video-panel"
|
||
>
|
||
<div className="capture-camera-selection mb-2 flex gap-4 text-sm font-medium text-[color:var(--app-text)]">
|
||
{!mediaOnly && (
|
||
<>
|
||
<label className="capture-slice-navigator">
|
||
<span className="sr-only">切片列表</span>
|
||
<select
|
||
aria-label="切片列表"
|
||
value={selectedSlice.id}
|
||
disabled={saving || !timelineReady}
|
||
onChange={(event) => {
|
||
const slice = slices.find((item) => item.id === event.target.value);
|
||
if (slice) selectSlice(slice);
|
||
}}
|
||
>
|
||
{slices.map((slice, index) => (
|
||
<option key={slice.id} value={slice.id}>
|
||
{String(index + 1).padStart(3, "0")} ·{" "}
|
||
{slice.deliveryDisposition === "discard"
|
||
? `舍弃:${slice.discardReason || "未记录原因"}`
|
||
: `保留:${slice.name || "未命名"}`}{" "}
|
||
· {formatTime(slice.start)}–{formatTime(slice.end)}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
<button
|
||
type="button"
|
||
className="capture-slice-zoom"
|
||
aria-pressed={sliceZoom}
|
||
onClick={() => setSliceZoom((value) => !value)}
|
||
>
|
||
{sliceZoom ? "全段概览" : "放大当前片"}
|
||
</button>
|
||
</>
|
||
)}
|
||
<button
|
||
type="button"
|
||
className="capture-caption-toggle"
|
||
aria-pressed={captionsVisible}
|
||
onClick={() => setCaptionsVisible((value) => !value)}
|
||
>
|
||
{captionsVisible ? "隐藏字幕" : "显示字幕"}
|
||
</button>
|
||
{focusedLayout ? (
|
||
<div className="capture-camera-inspection-controls" aria-label="单路相机检查">
|
||
<button
|
||
type="button"
|
||
aria-pressed={inspectionCamera === "left"}
|
||
disabled={!source}
|
||
onClick={() => inspectCamera("left")}
|
||
>
|
||
放大左相机
|
||
</button>
|
||
{rightSource ? (
|
||
<button
|
||
type="button"
|
||
aria-pressed={inspectionCamera === "right"}
|
||
disabled={!rightSource}
|
||
onClick={() => inspectCamera("right")}
|
||
>
|
||
放大右相机
|
||
</button>
|
||
) : null}
|
||
<button type="button" disabled={!inspectionCamera} onClick={() => inspectCamera(null)}>
|
||
恢复双画面
|
||
</button>
|
||
<label>
|
||
默认视图{" "}
|
||
<select
|
||
aria-label="默认相机视图"
|
||
value={defaultCamera}
|
||
onChange={(event) => {
|
||
setDefaultCamera(event.target.value);
|
||
try {
|
||
if (cameraStorageKey) localStorage.setItem(cameraStorageKey, event.target.value);
|
||
} catch {
|
||
/* Browser storage can be unavailable. */
|
||
}
|
||
focusWorkbench();
|
||
}}
|
||
>
|
||
<option value="left">左相机</option>
|
||
<option value="right">右相机</option>
|
||
<option value="both">双目</option>
|
||
</select>
|
||
</label>
|
||
{inspectionCamera && phase === "slice" && !readOnly && !isQualityReview ? (
|
||
<button
|
||
type="button"
|
||
title="在播放头分割当前切片(C)"
|
||
aria-keyshortcuts="C"
|
||
disabled={
|
||
!canEdit ||
|
||
!onSplitSlice ||
|
||
!playheadSlice ||
|
||
currentTime <= playheadSlice.start + 0.001 ||
|
||
currentTime >= playheadSlice.end - 0.001
|
||
}
|
||
onClick={splitAtPlayhead}
|
||
>
|
||
在播放头分割切片
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
) : (
|
||
<div className="capture-camera-visibility-controls">
|
||
<label className="inline-flex items-center gap-2">
|
||
<input
|
||
type="checkbox"
|
||
checked={showLeft}
|
||
onChange={(event) => {
|
||
const left = event.target.checked || !showRight;
|
||
if (left !== showLeft) transport.prepareCameraChange();
|
||
setShowLeft(left);
|
||
onCameraVisibilityChange?.({ left, right: showRight });
|
||
}}
|
||
className="accent-orange-500"
|
||
/>
|
||
左相机
|
||
</label>
|
||
{rightSource ? (
|
||
<label className="inline-flex items-center gap-2">
|
||
<input
|
||
type="checkbox"
|
||
checked={showRight}
|
||
onChange={(event) => {
|
||
const right = event.target.checked || !showLeft;
|
||
if (right !== showRight) transport.prepareCameraChange();
|
||
setShowRight(right);
|
||
onCameraVisibilityChange?.({ left: showLeft, right });
|
||
}}
|
||
className="accent-orange-500"
|
||
/>
|
||
右相机
|
||
</label>
|
||
) : null}
|
||
</div>
|
||
)}
|
||
</div>
|
||
<div
|
||
ref={videoSurfaceRef}
|
||
className={cn("capture-video-surface grid overflow-hidden rounded-md bg-slate-950", videoClass)}
|
||
>
|
||
{useMoviVideo ? (
|
||
<MoviVideo
|
||
ref={leftVideoRef}
|
||
src={effectiveShowLeft ? source : ""}
|
||
data-camera="left"
|
||
className={cn(
|
||
"h-[clamp(120px,28dvh,280px)] w-full bg-black object-contain",
|
||
phase === "annotate" && !mediaOnly && !focusedLayout && "!h-[clamp(100px,24vh,240px)]",
|
||
mediaOnly && !focusedLayout && "!h-[clamp(120px,20dvh,200px)]",
|
||
!effectiveShowLeft && "hidden",
|
||
)}
|
||
preload={effectiveShowLeft ? "auto" : "none"}
|
||
playsInline
|
||
{...transport.mediaEvents("left")}
|
||
onClick={() => {
|
||
if (!saving && !viewportSuspended) {
|
||
togglePlay();
|
||
focusWorkbench();
|
||
}
|
||
}}
|
||
/>
|
||
) : (
|
||
<video
|
||
ref={leftVideoRef}
|
||
src={effectiveShowLeft ? source : undefined}
|
||
data-camera="left"
|
||
className={cn(
|
||
"h-[clamp(120px,28dvh,280px)] w-full bg-black object-contain",
|
||
phase === "annotate" && !mediaOnly && !focusedLayout && "!h-[clamp(100px,24vh,240px)]",
|
||
mediaOnly && !focusedLayout && "!h-[clamp(120px,20dvh,200px)]",
|
||
!effectiveShowLeft && "hidden",
|
||
)}
|
||
preload={effectiveShowLeft ? "auto" : "none"}
|
||
playsInline
|
||
{...transport.mediaEvents("left")}
|
||
onClick={() => {
|
||
if (!saving && !viewportSuspended) {
|
||
togglePlay();
|
||
focusWorkbench();
|
||
}
|
||
}}
|
||
/>
|
||
)}
|
||
{rightSource ? (
|
||
useMoviVideo ? (
|
||
<MoviVideo
|
||
ref={rightVideoRef}
|
||
src={effectiveShowRight ? rightSource : ""}
|
||
data-camera="right"
|
||
className={cn(
|
||
"h-[clamp(120px,28dvh,280px)] w-full bg-black object-contain",
|
||
phase === "annotate" && !mediaOnly && !focusedLayout && "!h-[clamp(100px,24vh,240px)]",
|
||
mediaOnly && !focusedLayout && "!h-[clamp(120px,20dvh,200px)]",
|
||
!effectiveShowRight && "hidden",
|
||
)}
|
||
preload={effectiveShowRight ? "auto" : "none"}
|
||
muted
|
||
playsInline
|
||
{...transport.mediaEvents("right")}
|
||
onClick={() => {
|
||
if (!saving && !viewportSuspended) {
|
||
togglePlay();
|
||
focusWorkbench();
|
||
}
|
||
}}
|
||
/>
|
||
) : (
|
||
<video
|
||
ref={rightVideoRef}
|
||
src={effectiveShowRight ? rightSource : undefined}
|
||
data-camera="right"
|
||
className={cn(
|
||
"h-[clamp(120px,28dvh,280px)] w-full bg-black object-contain",
|
||
phase === "annotate" && !mediaOnly && !focusedLayout && "!h-[clamp(100px,24vh,240px)]",
|
||
mediaOnly && !focusedLayout && "!h-[clamp(120px,20dvh,200px)]",
|
||
!effectiveShowRight && "hidden",
|
||
)}
|
||
preload={effectiveShowRight ? "auto" : "none"}
|
||
muted
|
||
playsInline
|
||
{...transport.mediaEvents("right")}
|
||
onClick={() => {
|
||
if (!saving && !viewportSuspended) {
|
||
togglePlay();
|
||
focusWorkbench();
|
||
}
|
||
}}
|
||
/>
|
||
)
|
||
) : null}
|
||
{captionsVisible && reviewCaption && (
|
||
<>
|
||
{effectiveShowLeft && (
|
||
<ReviewVideoCaption
|
||
videoRef={leftVideoRef}
|
||
surfaceRef={videoSurfaceRef}
|
||
caption={reviewCaption}
|
||
viewKey={`${source}:${effectiveShowLeft}:${effectiveShowRight}:${focusedLayout}:${useMoviVideo}`}
|
||
camera="left"
|
||
/>
|
||
)}
|
||
{effectiveShowRight && (
|
||
<ReviewVideoCaption
|
||
videoRef={rightVideoRef}
|
||
surfaceRef={videoSurfaceRef}
|
||
caption={reviewCaption}
|
||
viewKey={`${rightSource}:${effectiveShowLeft}:${effectiveShowRight}:${focusedLayout}:${useMoviVideo}`}
|
||
camera="right"
|
||
/>
|
||
)}
|
||
</>
|
||
)}
|
||
</div>
|
||
<div className="capture-caption-strip" hidden={!captionsVisible} data-testid="workbench-caption-strip">
|
||
{!reviewCaption && continuousActions && phase === "annotate" && displayedAction && (
|
||
<div className="capture-action-overlay" onClick={(event) => event.stopPropagation()}>
|
||
<span>
|
||
{actionJudgment(displayedAction) === "pending" ? "待标注" : displayedAction.description || "无效"}
|
||
</span>
|
||
<button type="button" onClick={() => setShowActionJSON((value) => !value)}>
|
||
JSON {showActionJSON ? "收起" : "展开"}
|
||
</button>
|
||
{showActionJSON && (
|
||
<pre aria-label="动作 JSON 编辑预览">
|
||
{JSON.stringify(
|
||
{
|
||
preview: true,
|
||
saved: Boolean(previewSaved),
|
||
保存状态: previewSaved ? "已保存" : "未保存",
|
||
timeBasis: "capture-seconds; end-exclusive",
|
||
...displayedAction,
|
||
},
|
||
null,
|
||
2,
|
||
)}
|
||
</pre>
|
||
)}
|
||
</div>
|
||
)}
|
||
{(reworkSubtitleRowList.length > 0 || reviewReworkSubtitleRowList.length > 0) && (
|
||
<ReworkProblemSubtitles rows={reworkActive ? reworkSubtitleRowList : reviewReworkSubtitleRowList} />
|
||
)}
|
||
</div>
|
||
<div className="capture-media-controls flex flex-wrap items-center gap-3 rounded-b-md bg-slate-950 px-4 py-2 text-sm text-white">
|
||
{(!mediaOnly || isReviewViewing) && (
|
||
<>
|
||
<button
|
||
type="button"
|
||
onClick={() => (isReviewViewing ? reviewController.navigateSlice(-1) : navigateSlice(-1))}
|
||
disabled={saving || !timelineReady || (reviewNavigation?.sliceIndex ?? selectedSliceIndex) === 0}
|
||
aria-keyshortcuts="Control+ArrowLeft Meta+ArrowLeft"
|
||
title="上一片(Ctrl / ⌘ + ←)"
|
||
>
|
||
上一片
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => (isReviewViewing ? reviewController.navigateSlice(1) : navigateSlice(1))}
|
||
disabled={
|
||
saving ||
|
||
!timelineReady ||
|
||
(reviewNavigation?.sliceIndex ?? selectedSliceIndex) >=
|
||
(reviewNavigation?.sliceCount ?? slices.length) - 1
|
||
}
|
||
aria-keyshortcuts="Control+ArrowRight Meta+ArrowRight"
|
||
title="下一片(Ctrl / ⌘ + →)"
|
||
>
|
||
下一片
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={reviewSlice}
|
||
disabled={saving || !timelineReady}
|
||
aria-keyshortcuts="B"
|
||
title="从当前片头复查到片尾(B)"
|
||
>
|
||
复查本片
|
||
</button>
|
||
{!isReviewViewing && (
|
||
<button
|
||
type="button"
|
||
onClick={returnToWork}
|
||
disabled={saving || !timelineReady || workPosition === null}
|
||
aria-keyshortcuts="V"
|
||
title="回到最初工作位置并暂停(V)"
|
||
>
|
||
返回工作点
|
||
</button>
|
||
)}
|
||
</>
|
||
)}
|
||
{isReviewViewing && (
|
||
<span className="text-xs text-slate-300" aria-label="审查导航位置">
|
||
切片 {(reviewNavigation?.sliceIndex ?? selectedSliceIndex) + 1}/
|
||
{reviewNavigation?.sliceCount ?? slices.length} · 动作{" "}
|
||
{Math.max(0, reviewActions.findIndex((action) => action.id === reviewSelectedActionId) + 1)}/
|
||
{reviewActions.length}
|
||
</span>
|
||
)}
|
||
<button
|
||
type="button"
|
||
onClick={() => step(-1)}
|
||
disabled={saving || !timelineReady}
|
||
title="上一帧(←,填写文本时不触发)"
|
||
aria-keyshortcuts="ArrowLeft"
|
||
className="inline-flex items-center gap-1.5 hover:text-orange-200"
|
||
>
|
||
<ChevronLeft className="h-4 w-4" />
|
||
上一帧
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={togglePlay}
|
||
disabled={saving}
|
||
title="播放/暂停(Space,填写文本时不触发)"
|
||
aria-keyshortcuts="Space"
|
||
className="inline-flex items-center gap-1.5 font-medium hover:text-orange-200"
|
||
>
|
||
{isPlaying ? <Pause className="h-4 w-4" /> : <Play className="h-4 w-4" />}
|
||
{isPlaying ? "暂停" : "播放"}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => step(1)}
|
||
disabled={saving || !timelineReady}
|
||
title="下一帧(→,填写文本时不触发)"
|
||
aria-keyshortcuts="ArrowRight"
|
||
className="inline-flex items-center gap-1.5 hover:text-orange-200"
|
||
>
|
||
下一帧
|
||
<ChevronRight className="h-4 w-4" />
|
||
</button>
|
||
<span className="min-w-0 break-words font-mono text-xs text-slate-200">
|
||
帧 {exactFrames ? nearestFrameBoundaryIndex(frameBoundaries, currentTime) : "—"} ·{" "}
|
||
{phase === "slice" ? (
|
||
<>
|
||
Capture {formatTime(currentTime - clipStart)} / {formatTime(clipEnd - clipStart)}
|
||
</>
|
||
) : (
|
||
<>
|
||
片内 {formatTime(currentTime - selectedSlice.start)} /{" "}
|
||
{formatTime(selectedSlice.end - selectedSlice.start)}
|
||
</>
|
||
)}{" "}
|
||
{!mediaOnly && <> · 原视频 {formatTime(currentTime)}</>}
|
||
</span>
|
||
{transport.isPositioning && (
|
||
<span role="status" className="text-xs text-amber-300">
|
||
定位中,时间为目标位置…
|
||
</span>
|
||
)}
|
||
{transport.mediaError && (
|
||
<span role="alert" className="text-xs text-rose-300">
|
||
{userErrorMessage(transport.mediaError)}{" "}
|
||
<button
|
||
type="button"
|
||
className="underline"
|
||
onClick={() => {
|
||
transport.retry();
|
||
focusWorkbench();
|
||
}}
|
||
>
|
||
重新加载视频
|
||
</button>
|
||
</span>
|
||
)}
|
||
<span className="ml-auto inline-flex items-center gap-3">
|
||
<select
|
||
aria-label="播放速度"
|
||
title="1:0.5× 慢放;2:1.0× 正常速度"
|
||
value={playbackRate}
|
||
disabled={saving}
|
||
onChange={(event) => changePlaybackRate(Number(event.target.value))}
|
||
className="rounded border border-slate-600 bg-slate-950 px-1 py-0.5 text-white"
|
||
>
|
||
{CAPTURE_PLAYBACK_RATES.map((rate) => (
|
||
<option key={rate} value={rate}>
|
||
{rate === 1 ? "1.0" : rate}×
|
||
</option>
|
||
))}
|
||
</select>
|
||
<button
|
||
type="button"
|
||
aria-label="快捷键帮助"
|
||
title="快捷键帮助(?)"
|
||
onClick={() => shortcutHelpRef.current?.showModal()}
|
||
className="whitespace-nowrap rounded border border-slate-600 px-2 py-0.5 text-xs"
|
||
>
|
||
快捷键 ?
|
||
</button>
|
||
<Volume2 className="h-4 w-4" />
|
||
<Expand className="h-4 w-4" />
|
||
</span>
|
||
</div>
|
||
{reviewCaption && isQualityReview && (
|
||
<div className="review-qa-side-panel">
|
||
<ReviewCaptionDetails caption={reviewCaption} />
|
||
{isQualityReview && reviewProblemPanel}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div
|
||
className={cn("capture-timeline-editor border-y border-slate-200", mediaOnly ? "px-2 py-1" : "px-5 py-3")}
|
||
>
|
||
<input
|
||
type="range"
|
||
aria-label={totalProgress ? "总视频播放位置" : "Capture 播放位置"}
|
||
min={totalProgress ? 0 : clipStart}
|
||
max={totalProgress ? totalProgress.duration : clipEnd}
|
||
step="any"
|
||
value={totalProgress ? totalProgress.offset + currentTime : currentTime}
|
||
{...sliderEvents}
|
||
{...(totalProgress?.onSeekTotal
|
||
? {
|
||
onChange: (event: ChangeEvent<HTMLInputElement>) =>
|
||
totalProgress.onSeekTotal?.(Number(event.currentTarget.value)),
|
||
}
|
||
: {})}
|
||
style={
|
||
{
|
||
"--played": totalProgress
|
||
? timelinePosition(totalProgress.offset + currentTime, 0, totalProgress.duration)
|
||
: timelinePosition(currentTime, clipStart, clipEnd),
|
||
} as CSSProperties
|
||
}
|
||
className={cn("annotation-time-range w-full accent-orange-500", !mediaOnly && "mb-2")}
|
||
/>
|
||
{!mediaOnly && (
|
||
<>
|
||
<div
|
||
className={cn(
|
||
"capture-slice-list-heading mb-2 flex flex-wrap items-center gap-2 text-sm font-semibold text-[color:var(--app-text)]",
|
||
phase === "annotate" && !isQualityReview && "hidden",
|
||
)}
|
||
>
|
||
<span>{phase === "slice" ? "Capture 切片" : "切片选择(已锁定)"}</span>
|
||
{phase === "slice" && !readOnly && !isQualityReview && (
|
||
<button
|
||
type="button"
|
||
title="在播放头分割当前切片(C)"
|
||
aria-keyshortcuts="C"
|
||
disabled={
|
||
!canEdit ||
|
||
!onSplitSlice ||
|
||
!playheadSlice ||
|
||
currentTime <= playheadSlice.start + 0.001 ||
|
||
currentTime >= playheadSlice.end - 0.001
|
||
}
|
||
onClick={splitAtPlayhead}
|
||
className="rounded border px-2 py-1 text-xs disabled:opacity-40"
|
||
>
|
||
在播放头分割切片
|
||
</button>
|
||
)}
|
||
{isQualityReview && (
|
||
<button
|
||
type="button"
|
||
className="inline-flex items-center gap-2 rounded-lg border border-orange-400 bg-orange-50 px-3 py-2 text-sm font-semibold text-orange-800 shadow-sm hover:bg-orange-100 dark:bg-orange-950/40 dark:text-orange-200"
|
||
disabled={reviewReadOnly}
|
||
onClick={() => {
|
||
if (reviewProblemPanel) {
|
||
onReviewProblem?.({ ...reviewPosition, actionId: null }, "slice");
|
||
return;
|
||
}
|
||
const note = parsedQAComments.find(
|
||
(c) =>
|
||
(c.sliceId ? c.sliceId === selectedSlice.id : c.sliceName === selectedSlice.name) &&
|
||
c.segmentIndex === undefined &&
|
||
!c.segmentId,
|
||
);
|
||
setSliceProblemDraft(note?.comment || "");
|
||
}}
|
||
>
|
||
<MessageSquare className="h-4 w-4" />
|
||
切片问题备注
|
||
</button>
|
||
)}
|
||
|
||
{phase === "annotate" ? (
|
||
<span className="capture-slice-list-hint text-xs font-normal text-slate-400">
|
||
点击切片切换标注对象
|
||
</span>
|
||
) : (
|
||
<span className="capture-slice-list-hint text-xs font-normal text-slate-400">
|
||
播放器与时间轴已同步
|
||
</span>
|
||
)}
|
||
</div>
|
||
{phase === "slice" && error && !focusedLayout ? (
|
||
<p role="alert" className="mb-2 text-xs text-red-600">
|
||
{userErrorMessage(error)}
|
||
</p>
|
||
) : null}
|
||
{reworkActive && !focusedLayout && reworkEmphasis && reworkEmphasis.totalOpinions > 0 ? (
|
||
<div
|
||
data-testid="rework-emphasis-strip"
|
||
className="mb-2 rounded-lg border border-rose-400 bg-rose-50 px-3 py-2 text-xs text-rose-900 shadow-sm dark:border-rose-700 dark:bg-rose-950/40 dark:text-rose-100"
|
||
>
|
||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 font-semibold">
|
||
<span>
|
||
第 {reworkEmphasis.round} 轮打回 ·
|
||
意见已标注在下方切片/动作上,改动对应内容后标记已修改,仍需复审
|
||
</span>
|
||
<span className="rounded-full bg-rose-600 px-2 py-0.5 text-[11px] font-bold text-white">
|
||
未修改 {reworkEmphasis.unclearedCount}
|
||
</span>
|
||
{reworkEmphasis.clearedCount > 0 && (
|
||
<span className="font-normal text-slate-500 dark:text-slate-400">
|
||
已修改待复审 {reworkEmphasis.clearedCount}
|
||
</span>
|
||
)}
|
||
{reworkEmphasis.skippedCount > 0 && (
|
||
<span className="font-normal text-slate-500 dark:text-slate-400">
|
||
标记不改 {reworkEmphasis.skippedCount}
|
||
</span>
|
||
)}
|
||
<span className="ml-auto font-normal text-slate-500 dark:text-slate-400">
|
||
J / K 跳转未修改意见
|
||
</span>
|
||
</div>
|
||
{reworkEmphasis.task.red.length > 0 || reworkEmphasis.task.skipped.length > 0 ? (
|
||
<ul className="mt-1.5 space-y-1">
|
||
{[...reworkEmphasis.task.red, ...reworkEmphasis.task.skipped].map((opinion) => (
|
||
<li
|
||
key={opinion.id}
|
||
data-rework-focus={
|
||
(reworkFocus?.opinionId === opinion.id && reworkFocus.round === opinion.round) ||
|
||
undefined
|
||
}
|
||
className={cn(
|
||
"flex flex-wrap items-center gap-2 rounded border px-2 py-1",
|
||
reworkEmphasis.task.red.some((item) => item.id === opinion.id)
|
||
? "border-rose-400 bg-white/80 dark:bg-rose-900/30"
|
||
: "border-slate-300 bg-white/50 dark:border-slate-600 dark:bg-slate-800/40",
|
||
)}
|
||
>
|
||
<span className="rounded bg-rose-600 px-1.5 py-0.5 text-[10px] font-bold text-white">
|
||
整体
|
||
</span>
|
||
<span className="min-w-0 flex-1 break-words">{opinion.text}</span>
|
||
{onReworkSkipToggle &&
|
||
(reworkEmphasis.task.skipped.some((item) => item.id === opinion.id) ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => toggleReworkSkip(opinion.id, false)}
|
||
className="rounded border border-slate-400 px-2 py-0.5 text-[11px] font-medium text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-700"
|
||
>
|
||
撤销不改
|
||
</button>
|
||
) : (
|
||
<button
|
||
type="button"
|
||
onClick={() => toggleReworkSkip(opinion.id, true)}
|
||
className="rounded border border-rose-400 px-2 py-0.5 text-[11px] font-medium text-rose-700 hover:bg-rose-100 dark:text-rose-300 dark:hover:bg-rose-900/40"
|
||
>
|
||
不改了
|
||
</button>
|
||
))}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
{/* 恒定占位槽(批 0 I2a 遗产):面板/清单锁定提示以绝对定位浮层渲染
|
||
于此——提示出现/消失时间轴轨道像素级零位移。rework-ux-adjust 04
|
||
(D1)后单切片 E 提示删除(直开面板),槽内只剩锁定提示。 */}
|
||
{phase === "annotate" ? (
|
||
<div data-testid="slice-edit-banner-slot" className="relative z-10 mb-1 h-8">
|
||
{sliceEditLocked ? (
|
||
<div
|
||
data-testid="slice-edit-locked-notice"
|
||
role="status"
|
||
className="absolute inset-x-0 top-0 flex flex-wrap items-center rounded-md border border-amber-300 bg-amber-50 px-2.5 py-1.5 text-[11px] font-medium text-amber-800 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200"
|
||
>
|
||
面板期间已锁定该操作:先 Enter 应用或 Esc 取消
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
<div
|
||
ref={sliceTrackRef}
|
||
data-testid="capture-slice-timeline"
|
||
className="relative isolate h-24 w-full min-w-0 overflow-hidden select-none"
|
||
onPointerMove={updateSliceDrag}
|
||
onPointerUp={releaseSliceDrag}
|
||
onPointerCancel={releaseSliceDrag}
|
||
onLostPointerCapture={releaseSliceDrag}
|
||
onPointerLeave={() => {
|
||
releaseSliceDrag();
|
||
setSplitPreview(null);
|
||
}}
|
||
>
|
||
<div className="absolute inset-x-0 top-4 h-px bg-slate-200" />
|
||
{isReviewViewing && reviewTimestampOpinions && reviewTimestampOpinions.length > 0 && (
|
||
<div
|
||
aria-label="时间点意见标记"
|
||
className="absolute inset-x-0 top-0 z-20 h-4"
|
||
onPointerDown={(e) => e.stopPropagation()}
|
||
>
|
||
{(() => {
|
||
// §4.3:点位标记不涂红父切片;近邻聚合,重叠可展开选择。
|
||
const span = Math.max(sliceTimelineEnd - sliceTimelineStart, 0.001);
|
||
const sorted = [...reviewTimestampOpinions].sort((a, b) => a.atSeconds - b.atSeconds);
|
||
const clusters: { key: string; opinions: typeof sorted; left: number }[] = [];
|
||
for (const opinion of sorted) {
|
||
const left = Math.min(
|
||
100,
|
||
Math.max(0, ((opinion.atSeconds - sliceTimelineStart) / span) * 100),
|
||
);
|
||
const last = clusters[clusters.length - 1];
|
||
if (last && Math.abs(last.left - left) < 0.8) last.opinions.push(opinion);
|
||
else clusters.push({ key: opinion.id, opinions: [opinion], left });
|
||
}
|
||
return clusters.map((cluster) => (
|
||
<div key={cluster.key} className="absolute top-0" style={{ left: `${cluster.left}%` }}>
|
||
<button
|
||
type="button"
|
||
aria-label={`时间点意见 ${cluster.opinions.length > 1 ? `${cluster.opinions.length} 条` : cluster.opinions[0].text.slice(0, 12)}`}
|
||
title={cluster.opinions.map((o) => `${formatTime(o.atSeconds)} ${o.text}`).join("\n")}
|
||
onClick={(e) => {
|
||
e.stopPropagation();
|
||
if (cluster.opinions.length > 1)
|
||
setOpinionMarkerOpen(opinionMarkerOpen === cluster.key ? null : cluster.key);
|
||
else reviewController.seekTime(cluster.opinions[0].atSeconds);
|
||
}}
|
||
className="-translate-x-1/2 rounded-full border border-orange-500 bg-orange-400 px-1 text-[9px] font-bold leading-3 text-white shadow"
|
||
>
|
||
{cluster.opinions.length > 1 ? cluster.opinions.length : "•"}
|
||
</button>
|
||
{cluster.opinions.length > 1 && opinionMarkerOpen === cluster.key && (
|
||
<div className="absolute left-0 top-4 z-30 max-h-24 w-44 overflow-auto rounded border border-orange-300 bg-white p-1 text-left text-[10px] shadow-lg dark:border-orange-700 dark:bg-[#151619]">
|
||
{cluster.opinions.map((o) => (
|
||
<button
|
||
key={o.id}
|
||
type="button"
|
||
onClick={(e) => {
|
||
e.stopPropagation();
|
||
setOpinionMarkerOpen(null);
|
||
reviewController.seekTime(o.atSeconds);
|
||
}}
|
||
className="block w-full truncate rounded px-1 py-0.5 text-left text-slate-600 hover:bg-orange-50 dark:text-slate-300 dark:hover:bg-orange-950/30"
|
||
>
|
||
{formatTime(o.atSeconds)} {o.text}
|
||
</button>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
));
|
||
})()}
|
||
</div>
|
||
)}
|
||
{reworkActive && reworkEmphasis && reworkEmphasis.markers.length > 0 && (
|
||
<div
|
||
aria-label="返工时间点意见标记"
|
||
data-testid="rework-timestamp-markers"
|
||
className="absolute inset-x-0 bottom-0 z-20 h-4"
|
||
onPointerDown={(e) => e.stopPropagation()}
|
||
>
|
||
{(() => {
|
||
// 返工模式:未修改=红(可点定位),已修改待复审/不改/历史=灰点保留。
|
||
const span = Math.max(sliceTimelineEnd - sliceTimelineStart, 0.001);
|
||
const visible = reworkEmphasis.markers.filter(
|
||
(m) => m.atSeconds >= sliceTimelineStart - 0.001 && m.atSeconds <= sliceTimelineEnd + 0.001,
|
||
);
|
||
const sorted = [...visible].sort((a, b) => a.atSeconds - b.atSeconds);
|
||
const clusters: { key: string; opinions: typeof sorted; left: number; red: boolean }[] = [];
|
||
for (const opinion of sorted) {
|
||
const left = Math.min(
|
||
100,
|
||
Math.max(0, ((opinion.atSeconds - sliceTimelineStart) / span) * 100),
|
||
);
|
||
const isRed = opinion.state === "red";
|
||
const last = clusters[clusters.length - 1];
|
||
if (last && Math.abs(last.left - left) < 0.8 && last.red === isRed) {
|
||
last.opinions.push(opinion);
|
||
} else {
|
||
clusters.push({
|
||
key: `${opinion.id}:${opinion.state}`,
|
||
opinions: [opinion],
|
||
left,
|
||
red: isRed,
|
||
});
|
||
}
|
||
}
|
||
return clusters.map((cluster) => (
|
||
<div key={cluster.key} className="absolute bottom-0" style={{ left: `${cluster.left}%` }}>
|
||
<button
|
||
type="button"
|
||
aria-label={`返工时间点意见 ${cluster.opinions.length > 1 ? `${cluster.opinions.length} 条` : cluster.opinions[0].text.slice(0, 12)}`}
|
||
title={cluster.opinions
|
||
.map((o) => `${formatTime(o.atSeconds)}${o.state === "red" ? " ⚠" : ""} ${o.text}`)
|
||
.join("\n")}
|
||
onClick={(e) => {
|
||
e.stopPropagation();
|
||
locateReworkOpinion(cluster.opinions[0]);
|
||
}}
|
||
className={cn(
|
||
"-translate-x-1/2 rounded-full border px-1 text-[9px] font-bold leading-3 text-white shadow",
|
||
cluster.red
|
||
? "border-rose-600 bg-rose-500"
|
||
: "border-slate-400 bg-slate-400 dark:bg-slate-600",
|
||
)}
|
||
>
|
||
{cluster.opinions.length > 1 ? cluster.opinions.length : "•"}
|
||
</button>
|
||
</div>
|
||
));
|
||
})()}
|
||
</div>
|
||
)}
|
||
<div className="timeline-block-track capture-slice-blocks absolute inset-x-0 top-4 h-16">
|
||
{(sliceEditPanel ? sliceEditPanel.pendingSlices : visibleSlices).map((slice) => {
|
||
// 面板打开期间轨道渲染预览结构(R1-Q1"轨道实时可见");选中/焦点、
|
||
// 序号与颜色都按预览集推导,红块(焦点边界)由下方高亮条反馈。
|
||
const trackSlices = sliceEditPanel ? sliceEditPanel.pendingSlices : slices;
|
||
const index = trackSlices.findIndex((item) => item.id === slice.id);
|
||
const style = intervalStyle(slice.start, slice.end, sliceTimelineStart, sliceTimelineEnd);
|
||
const selected = sliceEditPanel
|
||
? slice.id === sliceEditPanel.sliceId
|
||
: slice.id === selectedSlice.id;
|
||
// 09:标注员返修与 QC 接收视图共用轨道红/灰(trackSliceBuckets);
|
||
// 04:面板预览集里的新切片(拆分子片)无意见桶,自然落 0。
|
||
const reworkRedHere = trackSliceBuckets.get(slice.id)?.red.length || 0;
|
||
const reworkDoneHere = trackSliceBuckets.get(slice.id);
|
||
const reworkTotalHere = reworkDoneHere
|
||
? reworkDoneHere.red.length +
|
||
reworkDoneHere.gray.length +
|
||
reworkDoneHere.skipped.length +
|
||
reworkDoneHere.old.length
|
||
: 0;
|
||
return (
|
||
<div
|
||
key={slice.id}
|
||
data-slice-id={slice.id}
|
||
data-selected={selected || undefined}
|
||
data-rework-changed={changedSliceIds.has(slice.id) || undefined}
|
||
data-rework-red={reworkRedHere > 0 || undefined}
|
||
className="absolute top-0 h-full"
|
||
style={style}
|
||
>
|
||
<div
|
||
className={cn(
|
||
"capture-slice-block absolute inset-y-0 left-0 right-1 overflow-hidden rounded-md border py-1.5 pl-2 pr-7 text-center text-xs transition",
|
||
slice.deliveryDisposition === "discard"
|
||
? "border-slate-400 bg-slate-100 text-slate-600 bg-[repeating-linear-gradient(135deg,transparent,transparent_8px,#cbd5e155_8px,#cbd5e155_10px)]"
|
||
: colors[index % colors.length],
|
||
reworkRedHere > 0 &&
|
||
"border-rose-500 bg-rose-100/90 text-rose-950 ring-2 ring-rose-400 dark:bg-rose-950/50 dark:text-rose-100",
|
||
selected && reworkRedHere === 0 && "ring-2 ring-orange-400 ring-offset-1",
|
||
selected && reworkRedHere > 0 && "ring-2 ring-orange-500 ring-offset-1",
|
||
phase === "annotate" && "cursor-pointer",
|
||
)}
|
||
title={
|
||
reworkTotalHere > 0
|
||
? `退回意见:未修改 ${reworkDoneHere!.red.length} · 已修改待复审 ${reworkDoneHere!.gray.length} · 标记不改 ${reworkDoneHere!.skipped.length}`
|
||
: undefined
|
||
}
|
||
onMouseMove={(event) => {
|
||
if ((phase !== "slice" && phase !== "annotate") || readOnly || !sliceTrackRef.current)
|
||
return;
|
||
// 面板打开期间不再给悬停"+"预览(R2-Q5 锁定,避免误触落库入口)。
|
||
if (sliceEditPanel) return;
|
||
const point = pointForEvent(
|
||
event,
|
||
sliceTrackRef.current,
|
||
sliceTimelineStart,
|
||
sliceTimelineEnd,
|
||
);
|
||
setSplitPreview(
|
||
point.time > slice.start + 0.05 && point.time < slice.end - 0.05
|
||
? { sliceIndex: index, time: point.time }
|
||
: null,
|
||
);
|
||
}}
|
||
onClick={() => selectSlice(slice)}
|
||
>
|
||
{changedSliceIds.has(slice.id) && <span className="capture-change-badge">本轮改动</span>}
|
||
<div
|
||
title={
|
||
slice.deliveryDisposition === "discard"
|
||
? slice.discardReason
|
||
: slice.name || `切片 ${String(index + 1).padStart(3, "0")}`
|
||
}
|
||
className="truncate font-semibold flex items-center justify-center gap-1"
|
||
>
|
||
<span className="truncate">
|
||
{slice.deliveryDisposition === "discard"
|
||
? slice.discardReason || "已舍弃"
|
||
: slice.name || `切片 ${String(index + 1).padStart(3, "0")}`}
|
||
</span>
|
||
</div>
|
||
{reworkRedHere > 0 && (
|
||
<span
|
||
aria-label={`${reworkRedHere} 条未修改退回意见`}
|
||
className="absolute -top-1.5 right-0 z-10 rounded-full bg-rose-600 px-1.5 text-[10px] font-bold leading-4 text-white shadow"
|
||
>
|
||
{reworkRedHere}
|
||
</span>
|
||
)}
|
||
<div className="mt-1 truncate font-mono text-[10px] text-slate-500">
|
||
{formatTime(slice.start)}–{formatTime(slice.end)}
|
||
</div>
|
||
{slice.deliveryDisposition === "discard" && (
|
||
<div className="truncate text-[10px] font-semibold" title={slice.discardReason}>
|
||
已舍弃 · 不交付
|
||
</div>
|
||
)}
|
||
{(phase === "slice" || phase === "annotate") && !readOnly ? (
|
||
<button
|
||
type="button"
|
||
aria-label="删除切片"
|
||
disabled={!canDeleteSliceAtIndex(index) || sliceEditPanelOpen}
|
||
title={
|
||
sliceEditPanelOpen
|
||
? "面板期间锁定:先 Enter 应用或 Esc 取消"
|
||
: "取消切分,合并后重新定义"
|
||
}
|
||
onMouseEnter={() => setSplitPreview(null)}
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
deleteSliceAtIndex(index);
|
||
}}
|
||
className="absolute right-1 top-1 rounded p-1 text-slate-500 hover:bg-white hover:text-red-600"
|
||
>
|
||
<Trash2 className="h-3.5 w-3.5" />
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
{(phase === "slice" || phase === "annotate") &&
|
||
!readOnly &&
|
||
index < (sliceEditPanel ? sliceEditPanel.pendingSlices.length : slices.length) - 1 ? (
|
||
<button
|
||
type="button"
|
||
aria-label="拖动切片边界"
|
||
disabled={readOnly || saving || sliceEditPanelOpen}
|
||
title={sliceEditPanelOpen ? "面板期间锁定:先 Enter 应用或 Esc 取消" : undefined}
|
||
onMouseEnter={() => setSplitPreview(null)}
|
||
onPointerDown={(event) => beginSliceBoundaryDrag(event, index)}
|
||
className={cn(
|
||
"absolute -right-2 top-4 z-10 grid h-8 w-4 place-items-center rounded-full border bg-white text-slate-500 shadow",
|
||
selectedBoundary?.index === index && "border-orange-400 text-orange-600",
|
||
)}
|
||
>
|
||
<span className="h-4 border-l-2 border-r-2 border-slate-400" />
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
{(phase === "slice" || phase === "annotate") && splitPreview ? (
|
||
<>
|
||
<div
|
||
className="pointer-events-none absolute bottom-4 top-4 z-10 w-px bg-orange-400"
|
||
style={{
|
||
left: timelinePosition(splitPreview.time, sliceTimelineStart, sliceTimelineEnd),
|
||
}}
|
||
/>
|
||
<button
|
||
type="button"
|
||
aria-label="在此新增切片"
|
||
data-testid="slice-insert-button"
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
insertSlice(splitPreview.sliceIndex, splitPreview.time);
|
||
}}
|
||
className="absolute top-20 z-20 grid h-6 w-6 -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full bg-orange-500 text-white shadow"
|
||
style={{
|
||
left: timelinePosition(splitPreview.time, sliceTimelineStart, sliceTimelineEnd),
|
||
}}
|
||
>
|
||
<Plus className="h-4 w-4" />
|
||
</button>
|
||
</>
|
||
) : null}
|
||
{sliceEditPanel
|
||
? (() => {
|
||
// R1-Q3 红块实时反馈:面板焦点边界(首/尾帧之一)高亮在轨道上。
|
||
const target = sliceEditPanel.pendingSlices.find((item) => item.id === sliceEditPanel.sliceId);
|
||
if (!target) return null;
|
||
return (
|
||
<div
|
||
data-testid="slice-edit-panel-boundary-highlight"
|
||
className="pointer-events-none absolute bottom-0 top-0 z-10 w-0.5 bg-orange-500"
|
||
style={{
|
||
left: timelinePosition(
|
||
target[sliceEditPanel.focusBoundary],
|
||
sliceTimelineStart,
|
||
sliceTimelineEnd,
|
||
),
|
||
}}
|
||
/>
|
||
);
|
||
})()
|
||
: null}
|
||
<div
|
||
data-testid="capture-playhead"
|
||
className="pointer-events-none absolute bottom-0 top-0 w-px bg-blue-600"
|
||
style={{
|
||
left: timelinePosition(currentTime, sliceTimelineStart, sliceTimelineEnd),
|
||
}}
|
||
/>
|
||
</div>
|
||
{reworkActive && reworkEmphasis && !focusedLayout
|
||
? (() => {
|
||
const bucket = reworkSliceBuckets.get(selectedSlice.id);
|
||
const red = bucket?.red || [];
|
||
const skipped = bucket?.skipped || [];
|
||
const gray = bucket?.gray || [];
|
||
const old = bucket?.old || [];
|
||
const list = [
|
||
...red.map((op) => ({ op, state: "red" as const })),
|
||
...skipped.map((op) => ({ op, state: "skipped" as const })),
|
||
...gray.map((op) => ({ op, state: "gray" as const })),
|
||
...old.map((op) => ({ op, state: "old" as const })),
|
||
];
|
||
if (!list.length) return null;
|
||
return (
|
||
<section
|
||
data-testid="rework-slice-opinions"
|
||
aria-label="本切片退回意见"
|
||
className="mt-2 space-y-1.5"
|
||
>
|
||
<strong className="text-xs font-semibold text-rose-700 dark:text-rose-300">
|
||
本切片退回意见 · {list.length} 条(未修改 {red.length})
|
||
</strong>
|
||
<ul className="space-y-1">
|
||
{list.map(({ op, state }) => (
|
||
<li
|
||
key={`${op.round}:${op.id}`}
|
||
data-rework-focus={
|
||
(reworkFocus?.opinionId === op.id && reworkFocus.round === op.round) || undefined
|
||
}
|
||
className={cn(
|
||
"flex flex-wrap items-center gap-2 rounded border px-2 py-1 text-xs",
|
||
state === "red" &&
|
||
"border-rose-400 bg-rose-50 font-semibold text-rose-950 shadow-sm dark:bg-rose-950/40 dark:text-rose-100",
|
||
state === "skipped" &&
|
||
"border-slate-300 bg-slate-50 text-slate-600 dark:border-slate-600 dark:bg-slate-800/50 dark:text-slate-300",
|
||
state === "gray" &&
|
||
"border-slate-200 bg-white/60 text-slate-500 dark:border-slate-700 dark:bg-slate-800/30 dark:text-slate-400",
|
||
state === "old" &&
|
||
"border-slate-200 bg-white/40 text-slate-400 opacity-70 dark:border-slate-700 dark:bg-slate-800/20 dark:text-slate-500",
|
||
)}
|
||
>
|
||
<span
|
||
className={cn(
|
||
"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-bold",
|
||
state === "red" ? "bg-rose-600 text-white" : "bg-slate-400 text-white",
|
||
)}
|
||
>
|
||
{op.scope === "slice"
|
||
? "切片"
|
||
: op.scope === "action"
|
||
? `动作${actionIndexLabel(op.actionId)}`
|
||
: `时间点 ${formatTime(op.atSeconds ?? 0)}`}
|
||
</span>
|
||
<span className="min-w-0 flex-1 break-words">{op.text}</span>
|
||
{op.reattached && (
|
||
<span className="shrink-0 text-[10px] text-slate-400">目标已合并,跟随到现块</span>
|
||
)}
|
||
{state === "old" && (
|
||
<span className="shrink-0 text-[10px] text-slate-400">第 {op.round} 轮历史</span>
|
||
)}
|
||
{op.scope !== "task" && (
|
||
<button
|
||
type="button"
|
||
onClick={() => locateReworkOpinion(op)}
|
||
className="shrink-0 rounded border border-slate-300 px-2 py-0.5 text-[11px] font-medium hover:bg-slate-100 dark:border-slate-600 dark:hover:bg-slate-700"
|
||
>
|
||
定位
|
||
</button>
|
||
)}
|
||
{onReworkSkipToggle && (state === "red" || state === "skipped") ? (
|
||
state === "skipped" ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => toggleReworkSkip(op.id, false)}
|
||
className="shrink-0 rounded border border-slate-400 px-2 py-0.5 text-[11px] font-medium text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-700"
|
||
>
|
||
撤销不改
|
||
</button>
|
||
) : (
|
||
<button
|
||
type="button"
|
||
onClick={() => toggleReworkSkip(op.id, true)}
|
||
className="shrink-0 rounded border border-rose-400 px-2 py-0.5 text-[11px] font-medium text-rose-700 hover:bg-rose-100 dark:text-rose-300 dark:hover:bg-rose-900/40"
|
||
>
|
||
不改了
|
||
</button>
|
||
)
|
||
) : null}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
);
|
||
})()
|
||
: null}
|
||
{phase === "slice" ? (
|
||
<div className="capture-stage-editor capture-slice-details mt-3 space-y-2">
|
||
{sliceBoundaryIssue ? (
|
||
<div
|
||
role="alert"
|
||
className="flex flex-wrap items-center gap-3 text-xs text-amber-700 dark:text-amber-300"
|
||
>
|
||
<span>{sliceBoundaryIssue};原有切片和名称已保留,时间轴仅显示范围内部分。</span>
|
||
{!providedReadOnly && !isQualityReview && onAlignSliceBoundaries && (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={onAlignSliceBoundaries}
|
||
className="rounded border border-amber-500 px-3 py-1.5 font-semibold disabled:opacity-40"
|
||
>
|
||
对齐统一帧边界(保留切片)
|
||
</button>
|
||
)}
|
||
</div>
|
||
) : null}
|
||
<p className="text-xs text-slate-500">
|
||
点击片内“+”新增边界 · 拖动分界手柄微调边界 · 切片名称仅从项目字典选择
|
||
</p>
|
||
{selectedSlice ? (
|
||
<div className="capture-slice-name-editor flex flex-wrap items-center gap-3 rounded-lg border border-orange-200 bg-orange-50/60 p-2.5 dark:border-orange-900/40 dark:bg-orange-950/20">
|
||
<div className="flex items-center gap-2">
|
||
<span className="rounded bg-orange-500/10 px-2 py-0.5 text-xs font-semibold text-orange-600 dark:text-orange-300">
|
||
当前切片 {String(selectedSliceIndex + 1).padStart(3, "0")}
|
||
</span>
|
||
<span className="font-mono text-xs text-slate-600 dark:text-gray-300">
|
||
{formatTime(selectedSlice.start)} ~ {formatTime(selectedSlice.end)}
|
||
<span className="ml-1 text-slate-400">
|
||
({formatTime(selectedSlice.end - selectedSlice.start)})
|
||
</span>
|
||
</span>
|
||
</div>
|
||
<div className="relative flex min-w-0 flex-1 flex-wrap items-center gap-2">
|
||
<label
|
||
htmlFor="selected-slice-name-input"
|
||
className="text-xs font-medium text-slate-600 dark:text-gray-300 shrink-0"
|
||
>
|
||
{selectedDiscarded ? "舍弃原因:" : "切片名称:"}
|
||
</label>
|
||
<div
|
||
id="selected-slice-name-input"
|
||
title={(selectedDiscarded ? selectedSlice.discardReason : selectedSlice.name) || ""}
|
||
className="flex-1 rounded-md border border-slate-300 bg-[color:var(--app-panel)] px-3 py-1.5 text-xs font-semibold text-slate-900 shadow-sm transition placeholder:text-slate-400 focus:border-orange-500 focus:outline-none focus:ring-1 focus:ring-orange-500 dark:border-[#34363b] dark:bg-[#1a1b1e] dark:text-white"
|
||
>
|
||
{(selectedDiscarded ? selectedSlice.discardReason : selectedSlice.name) ||
|
||
"请从项目切片字典选择"}
|
||
</div>
|
||
<div className="capture-slice-dictionary-actions flex flex-wrap items-center gap-2">
|
||
{!selectedDiscarded && !readOnly && !isQualityReview && (
|
||
<SliceNameDictionaryPicker
|
||
inline={focusedLayout}
|
||
portal={adaptiveLayout && phase === "slice" && !focusedLayout}
|
||
triggerRef={sliceDictionaryTriggerRef}
|
||
key={`${taskId}:${selectedSlice.id}`}
|
||
items={sliceDictionary}
|
||
value={selectedSlice.name || ""}
|
||
disabled={saving}
|
||
loading={sliceDictionaryLoading}
|
||
error={userErrorMessage(sliceDictionaryError)}
|
||
onRefresh={onRefreshSliceDictionary}
|
||
onSelect={(name) => onSliceNameChange?.(selectedSlice.id, name)}
|
||
onCloseFocus={focusWorkbench}
|
||
/>
|
||
)}
|
||
{!readOnly && !isQualityReview && onSliceDispositionChange && (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
aria-keyshortcuts="G"
|
||
onClick={() => openDisposition(false)}
|
||
className="inline-flex items-center gap-1.5 rounded-md border border-orange-400 bg-[color:var(--app-panel)] px-3 py-1.5 text-xs font-semibold text-orange-700 disabled:opacity-40 dark:text-orange-300"
|
||
>
|
||
{selectedDiscarded ? "修改舍弃原因" : "舍弃片段"}
|
||
</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
{focusedLayout && error ? (
|
||
<p role="alert" className="capture-slice-error text-xs text-red-600">
|
||
{userErrorMessage(error)}
|
||
</p>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
</>
|
||
)}
|
||
{phase === "slice" && reworkRail}
|
||
</div>
|
||
|
||
{!mediaOnly && showDispositionPanel && (
|
||
<div
|
||
className="mx-5 my-2 rounded-lg border border-slate-200 p-3 text-sm"
|
||
data-testid="slice-disposition-panel"
|
||
>
|
||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||
<span className="font-semibold">{selectedDiscarded ? "已舍弃 · 保留审核证据" : ""}</span>
|
||
{canEditDisposition && selectedDiscarded && (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
className="rounded border px-3 py-1.5 text-sm disabled:opacity-50"
|
||
aria-keyshortcuts="G"
|
||
onClick={() => openDisposition(selectedDiscarded)}
|
||
>
|
||
{selectedDiscarded ? "恢复为保留" : "舍弃片段"}
|
||
</button>
|
||
)}
|
||
</div>
|
||
{selectedDiscarded && (
|
||
<details className="capture-discard-details" open={!focusedLayout}>
|
||
<summary>舍弃原因与审核证据</summary>
|
||
<div>
|
||
<p className="mt-2 whitespace-pre-wrap break-words">
|
||
舍弃原因:{selectedSlice.discardReason}
|
||
{!selectedSlice.discardReasonLabelId && (
|
||
<span className="ml-2 text-xs text-slate-500">手动填写</span>
|
||
)}
|
||
</p>
|
||
<p className="mt-1 text-xs text-slate-500">
|
||
{selectedSlice.discardedAt} · 操作人:{selectedSlice.discardedByUserId}
|
||
;质检/验收仍可播放上方视频并记录问题。
|
||
</p>
|
||
{Boolean(selectedSlice.discardedAnnotations?.length) && (
|
||
<details className="mt-2">
|
||
<summary>查看舍弃前的描述(仅审核证据)</summary>
|
||
{selectedSlice.discardedAnnotations?.map((a) => (
|
||
<p key={a.id}>
|
||
{formatTime(a.start)}–{formatTime(a.end)}:{a.description}
|
||
</p>
|
||
))}
|
||
</details>
|
||
)}
|
||
</div>
|
||
</details>
|
||
)}
|
||
<p className="mt-1 text-xs text-slate-500">
|
||
共 {slices.length} 片 · 保留 {slices.filter((s) => s.deliveryDisposition !== "discard").length} 片 ·
|
||
舍弃 {slices.filter((s) => s.deliveryDisposition === "discard").length} 片
|
||
</p>
|
||
{dispositionOpen && dispositionDraft.sliceId === selectedSlice.id && (
|
||
<div
|
||
ref={dispositionDialogRef}
|
||
role="dialog"
|
||
aria-label={dispositionDraft.discard ? "舍弃片段" : "恢复片段"}
|
||
className="capture-disposition-panel rounded-md border bg-[color:var(--app-panel)] p-3 text-[color:var(--app-text)]"
|
||
onKeyDown={(event) => {
|
||
event.stopPropagation();
|
||
if (event.key === "Escape" && !event.nativeEvent.isComposing) {
|
||
event.preventDefault();
|
||
if (!saving) closeDisposition();
|
||
}
|
||
if ((event.ctrlKey || event.metaKey) && event.key === "Enter") {
|
||
event.preventDefault();
|
||
if (!event.repeat && !event.nativeEvent.isComposing)
|
||
dispositionDialogRef.current
|
||
?.querySelector<HTMLButtonElement>("[data-confirm-disposition]:not(:disabled)")
|
||
?.click();
|
||
}
|
||
}}
|
||
>
|
||
<div className="workspace-dictionary-heading">
|
||
<strong>{dispositionDraft.discard ? "选择舍弃原因" : "恢复为保留"}</strong>
|
||
<button type="button" disabled={saving} onClick={closeDisposition}>
|
||
返回编辑
|
||
</button>
|
||
</div>
|
||
{!dispositionDraft.discard && (
|
||
<p className="my-3 text-sm">恢复后请核对原有描述,再按现有流程提交审核。</p>
|
||
)}
|
||
{dispositionDraft.discard && (
|
||
<DiscardReasonFields
|
||
workspace
|
||
onClose={closeDisposition}
|
||
items={discardReasons}
|
||
allowManual={discardReasonsAllowManual}
|
||
loading={discardReasonsLoading}
|
||
error={userErrorMessage(discardReasonsError)}
|
||
refresh={onRefreshDiscardReasons}
|
||
value={dispositionDraft}
|
||
onChange={(value) => setDispositionDraft((d) => ({ ...d, ...value }))}
|
||
/>
|
||
)}
|
||
{dispositionError && (
|
||
<p role="alert" className="capture-disposition-error mt-2 text-red-600">
|
||
{userErrorMessage(dispositionError)}
|
||
{dispositionError.includes("切片") && dispositionError.includes("名称") && (
|
||
<button type="button" className="mt-2 block underline" onClick={() => closeDisposition()}>
|
||
返回修正切片名称
|
||
</button>
|
||
)}
|
||
</p>
|
||
)}
|
||
<div className="capture-disposition-actions mt-4 flex justify-end gap-3">
|
||
<button type="button" disabled={saving} onClick={() => closeDisposition()}>
|
||
取消
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={
|
||
saving ||
|
||
readOnly ||
|
||
isQualityReview ||
|
||
mediaOnly ||
|
||
(dispositionDraft.discard &&
|
||
(discardReasonsLoading ||
|
||
!!discardReasonsError ||
|
||
(!(
|
||
discardReasonsAllowManual &&
|
||
!discardReasons.length &&
|
||
!!dispositionDraft.reason?.trim()
|
||
) &&
|
||
!discardReasons.some(
|
||
(x) =>
|
||
x.id === dispositionDraft.reasonLabelId &&
|
||
x.version === dispositionDraft.reasonVersion &&
|
||
(!(x.requiresNote || x.name === "其他") || !!dispositionDraft.reasonNote?.trim()),
|
||
))))
|
||
}
|
||
data-confirm-disposition
|
||
className="rounded bg-orange-500 px-3 py-2 text-white disabled:opacity-40"
|
||
onClick={async () => {
|
||
if (
|
||
saving ||
|
||
readOnly ||
|
||
isQualityReview ||
|
||
mediaOnly ||
|
||
dispositionDraft.sliceId !== selectedSlice.id
|
||
)
|
||
return;
|
||
try {
|
||
if (
|
||
await onSliceDispositionChange?.(
|
||
dispositionDraft.sliceId,
|
||
dispositionDraft.discard ? "discard" : "keep",
|
||
{
|
||
reason:
|
||
discardReasonsAllowManual && !discardReasons.length
|
||
? dispositionDraft.reason
|
||
: undefined,
|
||
reasonLabelId:
|
||
discardReasonsAllowManual && !discardReasons.length
|
||
? undefined
|
||
: dispositionDraft.reasonLabelId,
|
||
reasonVersion:
|
||
discardReasonsAllowManual && !discardReasons.length
|
||
? undefined
|
||
: dispositionDraft.reasonVersion,
|
||
reasonNote:
|
||
discardReasonsAllowManual && !discardReasons.length
|
||
? undefined
|
||
: dispositionDraft.reasonNote,
|
||
},
|
||
)
|
||
) {
|
||
closeDisposition();
|
||
}
|
||
} catch (e) {
|
||
setDispositionError((e as Error).message || "保存失败");
|
||
}
|
||
}}
|
||
>
|
||
{saving ? "正在保存…" : dispositionDraft.discard ? "确认舍弃" : "确认恢复"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
{!mediaOnly && phase === "annotate" && !selectedDiscarded ? (
|
||
<div className="capture-annotation-stage px-5 py-4">
|
||
<div className="capture-annotation-heading mb-3 flex flex-wrap items-center justify-between gap-3">
|
||
<div className="flex flex-wrap items-center gap-3">
|
||
<h3 className="text-sm font-semibold text-slate-800 dark:text-gray-100">
|
||
当前切片标注 · {selectedSlice.name || `切片 ${selectedSliceIndex + 1}`}
|
||
</h3>
|
||
<span className="font-mono text-xs text-slate-500">
|
||
({formatTime(selectedSlice.start)} ~ {formatTime(selectedSlice.end)} · 时长{" "}
|
||
{formatTime(selectedSlice.end - selectedSlice.start)})
|
||
</span>
|
||
</div>
|
||
<span className="text-xs flex items-center gap-1.5 text-slate-500">
|
||
<span>{annotationSegments.length} 个动作描述</span>
|
||
<span>·</span>
|
||
<span>
|
||
{continuousActions
|
||
? `${annotationSegments.filter((a) => actionJudgment(a) === "pending").length} 段待标注`
|
||
: annotationGaps.length
|
||
? `${annotationGaps.length} 处留空`
|
||
: "已完整标注"}
|
||
</span>
|
||
</span>
|
||
</div>
|
||
|
||
{!readOnly && !isQualityReview ? (
|
||
<div className="capture-annotation-tools mb-3 flex flex-wrap items-center gap-2">
|
||
{!continuousActions && annotationGaps.length ? (
|
||
<button
|
||
type="button"
|
||
onClick={markUnannotatedInvalid}
|
||
disabled={saving || Boolean(editingAnnotation) || !sliceAligned}
|
||
className="rounded border px-3 py-2 text-sm disabled:opacity-50"
|
||
>
|
||
将本片未标注区间标为无效
|
||
</button>
|
||
) : null}
|
||
{!continuousActions && (
|
||
<button
|
||
type="button"
|
||
onClick={addAnnotation}
|
||
title="新增动作描述(N,填写文本时不触发)"
|
||
aria-keyshortcuts="N"
|
||
disabled={saving}
|
||
className="rounded border border-orange-400 bg-orange-50 px-3 py-2 text-sm font-semibold text-orange-800 disabled:opacity-50 dark:bg-orange-950/30 dark:text-orange-200"
|
||
>
|
||
新增动作描述
|
||
</button>
|
||
)}
|
||
{continuousActions && (
|
||
<>
|
||
<button type="button" onClick={saveProgress} disabled={saving || !onSaveProgress}>
|
||
保存进度
|
||
</button>
|
||
</>
|
||
)}
|
||
<button
|
||
type="button"
|
||
disabled={
|
||
saving ||
|
||
(!continuousActions && Boolean(editingAnnotation)) ||
|
||
!annotationSegments.some(
|
||
(s) => currentTime > s.start + 0.000001 && currentTime < s.end - 0.000001,
|
||
)
|
||
}
|
||
onClick={splitAtPlayhead}
|
||
title="在播放头分割当前动作(C)"
|
||
aria-keyshortcuts="C"
|
||
className="rounded border px-3 py-2 text-sm disabled:opacity-50"
|
||
>
|
||
在播放头分割动作
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
{(!editingAnnotation || isQualityReview) && error ? (
|
||
<p role="alert" className="mb-2 text-xs text-red-600">
|
||
{userErrorMessage(error)}
|
||
</p>
|
||
) : null}
|
||
<div
|
||
ref={annotationTrackRef}
|
||
onPointerDown={(event) => {
|
||
if (
|
||
readOnly ||
|
||
isQualityReview ||
|
||
(event.target as HTMLElement).closest("button,input,textarea,[data-annotation-block]")
|
||
)
|
||
return;
|
||
const point = pointForEvent(
|
||
event,
|
||
event.currentTarget,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
);
|
||
if (isReviewViewing) onReviewNavigate?.();
|
||
seek(snap(point.time));
|
||
}}
|
||
data-testid="slice-annotation-timeline"
|
||
className="relative isolate min-h-40 w-full min-w-0 overflow-hidden select-none rounded-md border border-slate-200 bg-slate-50 dark:border-[#2a2b2f] dark:bg-[#151619]"
|
||
onPointerMove={updateAnnotationBoundaryDrag}
|
||
onPointerUp={(event) => {
|
||
releaseAnnotationBoundaryDrag();
|
||
}}
|
||
onPointerCancel={releaseAnnotationBoundaryDrag}
|
||
onLostPointerCapture={releaseAnnotationBoundaryDrag}
|
||
onPointerLeave={() => {
|
||
releaseAnnotationBoundaryDrag();
|
||
setAnnotationSplitPreview(null);
|
||
setHoveredSegment(null);
|
||
}}
|
||
>
|
||
<input
|
||
type="range"
|
||
aria-label="当前切片播放位置"
|
||
min={lowerAnnotation}
|
||
max={upperAnnotation}
|
||
step="any"
|
||
value={clamp(currentTime, lowerAnnotation, upperAnnotation)}
|
||
{...sliderEvents}
|
||
style={
|
||
{ "--played": timelinePosition(currentTime, lowerAnnotation, upperAnnotation) } as CSSProperties
|
||
}
|
||
className="annotation-time-range relative z-20 w-full accent-orange-500"
|
||
/>
|
||
<div className="absolute inset-x-0 top-7 h-px bg-slate-200 dark:bg-slate-700" />
|
||
<div className="timeline-block-track absolute inset-x-0 top-9 bottom-12">
|
||
{isNewAnnotation && editingAnnotation ? (
|
||
<div
|
||
aria-label="固定起点"
|
||
className="pointer-events-none absolute top-0 bottom-0 z-10 border-l-2 border-orange-500"
|
||
style={{
|
||
left: `${clamp((editingAnnotation.start - descriptionTimelineStart) / (descriptionTimelineEnd - descriptionTimelineStart), 0, 1) * 100}%`,
|
||
}}
|
||
>
|
||
<span className="absolute -top-4 whitespace-nowrap text-[10px] text-orange-600">起点</span>
|
||
</div>
|
||
) : null}
|
||
{visibleDescriptions.map((segment) => {
|
||
const index = annotationForRender.findIndex((item) => item.id === segment.id);
|
||
const segIndex = index;
|
||
const currentSliceLabel = selectedSlice?.name || `切片 ${selectedSliceIndex + 1}`;
|
||
const qaCommentForThis = parsedQAComments.find((c) =>
|
||
c.sliceId
|
||
? c.sliceId === selectedSlice.id && c.segmentId === segment.id
|
||
: c.sliceName === currentSliceLabel &&
|
||
(c.segmentIndex === segIndex ||
|
||
(c.timeRange && c.timeRange.includes(formatTime(segment.start - lowerAnnotation)))),
|
||
);
|
||
const reworkCommentForThis = parsedReworkComments.find((c) =>
|
||
c.sliceId
|
||
? c.sliceId === selectedSlice.id && c.segmentId === segment.id
|
||
: c.sliceName === currentSliceLabel &&
|
||
(c.segmentIndex === segIndex ||
|
||
(c.timeRange && c.timeRange.includes(formatTime(segment.start - lowerAnnotation)))),
|
||
);
|
||
// 返工强调层:有结构化基线时用意见 id 精确挂红,不再依赖打回文本的模糊匹配;
|
||
// 旧格式退回(无基线)保留文本匹配兼容。接收视图(票 09)同一桶红/灰。
|
||
const reworkBucketHere = trackActionBuckets.get(segment.id);
|
||
const reworkRedCount = reworkBucketHere?.red.length || 0;
|
||
const reworkHandledCount = reworkBucketHere
|
||
? reworkBucketHere.gray.length + reworkBucketHere.skipped.length
|
||
: 0;
|
||
const activeComment = isQualityReview
|
||
? qaCommentForThis
|
||
: reworkActive
|
||
? null
|
||
: reworkCommentForThis;
|
||
// 红旗来源:接收视图(票 09)优先基线强调层;质检无基线时保留旧文本匹配。
|
||
const isFlaggedProblem = isQualityReview
|
||
? receiveEmphasisActive
|
||
? reworkRedCount > 0
|
||
: Boolean(qaCommentForThis)
|
||
: reworkActive
|
||
? reworkRedCount > 0
|
||
: Boolean(reworkCommentForThis);
|
||
const isReworkHandled =
|
||
(reworkActive || receiveEmphasisActive) && reworkHandledCount > 0 && reworkRedCount === 0;
|
||
const isInvalidSegment = Boolean(
|
||
segment.isInvalid || segment.description === "无效片段" || segment.label === "无效片段",
|
||
);
|
||
// 工单 02(D2):无效区间在轨道上始终可见。宽度退化(存量零宽/冲突
|
||
// 病态结构残留、亚像素窄段)时 intervalStyle 会给 display:none 或 0 宽,
|
||
// 这里给无效块兜一个最小可见宽度标记——「看不见=消失了」不再发生;
|
||
// 有效块维持 intervalStyle 原语义。
|
||
const rawSegmentStyle = intervalStyle(
|
||
segment.start,
|
||
segment.end,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
);
|
||
const invalidMarkerLeft = (() => {
|
||
const ratio =
|
||
descriptionTimelineEnd > descriptionTimelineStart
|
||
? (segment.start - descriptionTimelineStart) /
|
||
(descriptionTimelineEnd - descriptionTimelineStart)
|
||
: 0;
|
||
return `${Number.isFinite(ratio) ? clamp(ratio, 0, 1) * 100 : 0}%`;
|
||
})();
|
||
const segmentStyle =
|
||
isInvalidSegment && rawSegmentStyle.display === "none"
|
||
? { left: invalidMarkerLeft, width: "0%", minWidth: "2px" }
|
||
: isInvalidSegment
|
||
? { ...rawSegmentStyle, minWidth: "2px" }
|
||
: rawSegmentStyle;
|
||
|
||
return (
|
||
<div
|
||
key={segment.id}
|
||
data-annotation-block
|
||
data-annotation-id={segment.id}
|
||
data-selected={editingAnnotation?.id === segment.id || undefined}
|
||
data-rework-red={reworkRedCount > 0 || undefined}
|
||
data-testid="annotation-description-block"
|
||
className={cn(
|
||
"group absolute top-2 h-16 rounded-md border py-1 pl-2.5 pr-7 text-xs shadow-sm transition-all cursor-pointer",
|
||
isFlaggedProblem
|
||
? "border-rose-500 bg-rose-50/95 text-rose-950 ring-2 ring-rose-400 font-semibold shadow-md dark:bg-rose-950/40 dark:text-rose-100"
|
||
: isInvalidSegment
|
||
? "border-dashed border-slate-300 bg-slate-100/90 text-slate-600 dark:border-slate-700 dark:bg-slate-800/80 dark:text-slate-400"
|
||
: colors[index % colors.length],
|
||
isReworkHandled && "border-slate-300 dark:border-slate-600",
|
||
editingAnnotation?.id === segment.id && "ring-2 ring-orange-500 shadow-md",
|
||
)}
|
||
style={segmentStyle}
|
||
onMouseMove={(event) => {
|
||
if (readOnly || isQualityReview || !annotationTrackRef.current) return;
|
||
const point = pointForEvent(
|
||
event,
|
||
annotationTrackRef.current,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
);
|
||
setAnnotationSplitPreview(
|
||
point.time > segment.start + 0.05 && point.time < segment.end - 0.05
|
||
? { segmentIndex: index, time: point.time }
|
||
: null,
|
||
);
|
||
}}
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
seekAnnotation(segment, "start");
|
||
}}
|
||
onMouseEnter={() => setHoveredSegment({ segment, index })}
|
||
onMouseLeave={() => setHoveredSegment(null)}
|
||
>
|
||
<div className="capture-action-summary flex min-w-0 items-center justify-between gap-1 overflow-hidden whitespace-nowrap pointer-events-none">
|
||
<span className="font-bold text-[11px] opacity-75">#{index + 1}</span>
|
||
<div className="flex items-center gap-1">
|
||
{isFlaggedProblem && (
|
||
<span className="inline-flex items-center gap-0.5 rounded bg-rose-600 px-1 py-0.2 text-[9px] font-bold text-white shadow-sm">
|
||
<AlertCircle className="h-2.5 w-2.5" />
|
||
{reworkActive ? `意见 ${reworkRedCount}` : activeComment?.tag || "问题"}
|
||
</span>
|
||
)}
|
||
{reworkActive && !isFlaggedProblem && reworkHandledCount > 0 && (
|
||
<span className="inline-flex items-center rounded bg-slate-400 px-1 py-0.2 text-[9px] font-bold text-white shadow-sm dark:bg-slate-600">
|
||
已修改待复审 {reworkBucketHere?.gray.length || 0} · 不改{" "}
|
||
{reworkBucketHere?.skipped.length || 0}
|
||
</span>
|
||
)}
|
||
<span className="font-mono text-[10px] text-slate-500">
|
||
{formatTime(segment.end - segment.start)}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div
|
||
className="capture-action-description mt-1 truncate font-medium text-xs pointer-events-none"
|
||
title={segment.description}
|
||
>
|
||
{isInvalidSegment ? (
|
||
<span className="inline-flex items-center gap-1 text-slate-500 dark:text-slate-400 font-semibold">
|
||
<Ban className="h-3 w-3 text-slate-400" />
|
||
无效片段
|
||
</span>
|
||
) : segment.description?.trim() ? (
|
||
segment.description
|
||
) : (
|
||
<span className="text-slate-400 italic">点击填写描述</span>
|
||
)}
|
||
</div>
|
||
<div className="capture-action-time mt-0.5 truncate font-mono text-[9px] text-slate-400 pointer-events-none">
|
||
{formatTime(segment.start - lowerAnnotation)}–{formatTime(segment.end - lowerAnnotation)}
|
||
</div>
|
||
{!readOnly &&
|
||
!isQualityReview &&
|
||
annotationSegments.some((saved) => saved.id === segment.id) ? (
|
||
<button
|
||
type="button"
|
||
aria-label="删除此动作"
|
||
title={continuousActions ? "取消切分,合并后留空" : "删除此动作(保留空白)"}
|
||
disabled={saving || (continuousActions && annotationSegments.length < 2)}
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
if (continuousActions) cancelAnnotationSplit(segment.id);
|
||
else void deleteAnnotationLeavingBlank(segment.id);
|
||
}}
|
||
className="absolute right-1 top-1 rounded p-0.5 text-slate-400 opacity-60 hover:opacity-100 hover:bg-white hover:text-red-600 z-20"
|
||
>
|
||
<Trash2 className="h-3.5 w-3.5" />
|
||
</button>
|
||
) : null}
|
||
{!readOnly &&
|
||
!isQualityReview &&
|
||
index < annotationSegments.length - 1 &&
|
||
Math.abs(segment.end - annotationSegments[index + 1].start) <= 0.000001 ? (
|
||
<button
|
||
type="button"
|
||
aria-label="拖动动作分界"
|
||
onPointerDown={(event) => beginAnnotationBoundaryDrag(event, index)}
|
||
onClick={(e) => e.stopPropagation()}
|
||
className={cn(
|
||
"absolute -right-2 top-2 z-10 grid h-10 w-4 place-items-center rounded-full border bg-white text-slate-500 shadow transition hover:scale-110",
|
||
selectedAnnotationBoundary?.index === index &&
|
||
"border-orange-500 text-orange-600 ring-2 ring-orange-300",
|
||
)}
|
||
>
|
||
<span className="h-4 border-l-2 border-r-2 border-slate-400" />
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
|
||
{/* Split preview line and button */}
|
||
{!readOnly && !isQualityReview && annotationSplitPreview ? (
|
||
<>
|
||
<div
|
||
className="pointer-events-none absolute bottom-5 top-5 z-10 w-px bg-orange-500"
|
||
style={{
|
||
left: timelinePosition(
|
||
annotationSplitPreview.time,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
),
|
||
}}
|
||
/>
|
||
<button
|
||
type="button"
|
||
aria-label="在此拆分动作描述"
|
||
data-testid="annotation-insert-button"
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
insertAnnotationSplit(annotationSplitPreview.segmentIndex, annotationSplitPreview.time);
|
||
}}
|
||
className="absolute top-24 z-20 grid h-6 w-6 -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full bg-orange-500 text-white shadow hover:scale-110 transition"
|
||
style={{
|
||
left: timelinePosition(
|
||
annotationSplitPreview.time,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
),
|
||
}}
|
||
>
|
||
<Plus className="h-4 w-4" />
|
||
</button>
|
||
</>
|
||
) : null}
|
||
|
||
{/* Hover Tooltip - Level 1 user selection */}
|
||
{hoveredSegment &&
|
||
(() => {
|
||
const currentSliceLabel = selectedSlice?.name || `切片 ${selectedSliceIndex + 1}`;
|
||
const qaCommentForThis = parsedQAComments.find(
|
||
(c) =>
|
||
c.sliceName === currentSliceLabel &&
|
||
(c.segmentIndex === hoveredSegment.index ||
|
||
(c.timeRange &&
|
||
c.timeRange.includes(formatTime(hoveredSegment.segment.start - lowerAnnotation)))),
|
||
);
|
||
const reworkCommentForThis = parsedReworkComments.find(
|
||
(c) =>
|
||
c.sliceName === currentSliceLabel &&
|
||
(c.segmentIndex === hoveredSegment.index ||
|
||
(c.timeRange &&
|
||
c.timeRange.includes(formatTime(hoveredSegment.segment.start - lowerAnnotation)))),
|
||
);
|
||
const activeComment = isQualityReview ? qaCommentForThis : reworkCommentForThis;
|
||
|
||
return (
|
||
<div
|
||
className="pointer-events-none absolute z-50 rounded-lg border border-slate-700 bg-slate-900/95 p-3 text-white shadow-2xl backdrop-blur-sm transition-all"
|
||
style={{
|
||
left: timelinePosition(
|
||
(hoveredSegment.segment.start + hoveredSegment.segment.end) / 2,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
),
|
||
top: "2px",
|
||
transform: "translate(-50%, -105%)",
|
||
minWidth: "260px",
|
||
maxWidth: "400px",
|
||
}}
|
||
>
|
||
<div className="flex items-center justify-between gap-2 border-b border-slate-700/60 pb-1.5 text-[11px] font-medium text-slate-300">
|
||
<span className="flex items-center gap-1.5">
|
||
<span className="h-2 w-2 rounded-full bg-orange-400" />
|
||
<span className="font-semibold text-white">动作 #{hoveredSegment.index + 1}</span>
|
||
</span>
|
||
<span className="font-mono text-xs font-semibold text-orange-300">
|
||
{formatTime(hoveredSegment.segment.end - hoveredSegment.segment.start)}
|
||
</span>
|
||
</div>
|
||
<div className="mt-1.5 flex items-center gap-2 font-mono text-[10px] text-slate-400">
|
||
<span>
|
||
片内 {formatTime(hoveredSegment.segment.start - lowerAnnotation)} ~{" "}
|
||
{formatTime(hoveredSegment.segment.end - lowerAnnotation)}
|
||
</span>
|
||
<span>·</span>
|
||
<span>原视频 {formatTime(hoveredSegment.segment.start)}</span>
|
||
</div>
|
||
<div className="mt-2 max-h-40 overflow-y-auto break-words text-xs leading-relaxed text-slate-100">
|
||
{hoveredSegment.segment.isInvalid ||
|
||
hoveredSegment.segment.description === "无效片段" ||
|
||
hoveredSegment.segment.label === "无效片段" ? (
|
||
<span className="inline-flex items-center gap-1.5 font-semibold text-amber-300">
|
||
<Ban className="h-3.5 w-3.5 text-amber-400" />
|
||
当前片段为无效片段(无需动作描述)
|
||
</span>
|
||
) : hoveredSegment.segment.description?.trim() ? (
|
||
hoveredSegment.segment.description
|
||
) : (
|
||
<span className="italic text-slate-400">暂无文字描述(点击色块可直接填写)</span>
|
||
)}
|
||
</div>
|
||
{activeComment && (
|
||
<div className="mt-2 rounded border border-rose-500/40 bg-rose-950/70 p-2 text-rose-200">
|
||
<div className="flex items-center gap-1 font-bold text-[11px] text-rose-300">
|
||
<AlertTriangle className="h-3 w-3 text-rose-400" />
|
||
<span>{isQualityReview ? "已标记审核批注" : "质检打回意见"}</span>
|
||
{activeComment.tag && (
|
||
<span className="rounded bg-rose-800 px-1.5 py-0.2 text-[9px] text-white font-semibold">
|
||
{activeComment.tag}
|
||
</span>
|
||
)}
|
||
</div>
|
||
<div className="mt-1 text-xs leading-relaxed text-rose-100 font-medium">
|
||
{activeComment.comment || "请重点修正此动作片段"}
|
||
</div>
|
||
</div>
|
||
)}
|
||
<div className="mt-2 flex items-center justify-between border-t border-slate-700/40 pt-1 text-[10px] text-slate-400">
|
||
<span>
|
||
💡{" "}
|
||
{readOnly
|
||
? "点击色块可查看具体时间与文本内容"
|
||
: isQualityReview
|
||
? "点击色块可添加/修改审核批注"
|
||
: "点击色块编辑描述"}
|
||
</span>
|
||
<span>{!readOnly && !isQualityReview && "拖动分界手柄按帧微调"}</span>
|
||
</div>
|
||
</div>
|
||
);
|
||
})()}
|
||
|
||
{/* Playhead indicator */}
|
||
<div
|
||
data-testid="annotation-playhead"
|
||
className="pointer-events-none absolute bottom-0 top-5 w-px bg-blue-600 z-30"
|
||
style={{
|
||
left: timelinePosition(currentTime, descriptionTimelineStart, descriptionTimelineEnd),
|
||
}}
|
||
>
|
||
<span
|
||
className={cn(
|
||
"absolute -top-5 rounded bg-slate-900 px-1.5 py-0.5 font-mono text-[10px] text-white shadow whitespace-nowrap",
|
||
(currentTime - descriptionTimelineStart) /
|
||
Math.max(descriptionTimelineEnd - descriptionTimelineStart, 0.001) <
|
||
0.08
|
||
? "left-0"
|
||
: (currentTime - descriptionTimelineStart) /
|
||
Math.max(descriptionTimelineEnd - descriptionTimelineStart, 0.001) >
|
||
0.92
|
||
? "right-0"
|
||
: "-translate-x-1/2",
|
||
)}
|
||
>
|
||
{formatTime(Math.max(0, currentTime - lowerAnnotation))}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
|
||
{editingAnnotation && !(isQualityReview && reviewProblemPanel)
|
||
? (() => {
|
||
const segIndex = annotationSegments.findIndex((s) => s.id === editingAnnotation.id);
|
||
const currentSliceLabel = selectedSlice?.name || `切片 ${selectedSliceIndex + 1}`;
|
||
const qaCommentForThis = parsedQAComments.find((c) =>
|
||
c.sliceId
|
||
? c.sliceId === selectedSlice.id && c.segmentId === editingAnnotation.id
|
||
: c.sliceName === currentSliceLabel &&
|
||
(c.segmentIndex === segIndex ||
|
||
(c.timeRange &&
|
||
c.timeRange.includes(formatTime(editingAnnotation.start - lowerAnnotation)))),
|
||
);
|
||
const reworkCommentForThis = parsedReworkComments.find((c) =>
|
||
c.sliceId
|
||
? c.sliceId === selectedSlice.id && c.segmentId === editingAnnotation.id
|
||
: c.sliceName === currentSliceLabel &&
|
||
(c.segmentIndex === segIndex ||
|
||
(c.timeRange &&
|
||
c.timeRange.includes(formatTime(editingAnnotation.start - lowerAnnotation)))),
|
||
);
|
||
|
||
return (
|
||
<div
|
||
data-testid="annotation-description-editor"
|
||
data-expanded-description={(focusedLayout && expandedDescription) || undefined}
|
||
ref={descriptionEditorRef}
|
||
tabIndex={-1}
|
||
aria-label="动作描述编辑区"
|
||
className="relative mx-auto mt-3 w-full max-w-xl max-h-[max(180px,calc(76dvh-140px))] overflow-auto rounded-md border border-slate-200 bg-[color:var(--app-panel)] p-3.5 shadow-lg outline-none focus-visible:border-orange-500 focus-visible:ring-2 focus-visible:ring-orange-300 dark:border-[#2a2b2f] dark:bg-[#151619]"
|
||
>
|
||
{focusedLayout && showDictionary && editingAnnotation && !readOnly && !isQualityReview ? (
|
||
<WorkspaceDictionaryPanel
|
||
title="选择动作描述"
|
||
searchLabel="搜索描述字典"
|
||
items={labels.map((item) => ({
|
||
id: item.id,
|
||
text: item.description || item.name,
|
||
searchText: `${item.name} ${item.description || ""}`,
|
||
}))}
|
||
status={!labels.length ? <p>暂无字典词条,可直接填写描述。</p> : undefined}
|
||
onSelect={(id) => {
|
||
const item = labels.find((item) => item.id === id);
|
||
if (item) chooseTemplate(item);
|
||
}}
|
||
onClose={closeDescriptionDictionary}
|
||
onDismiss={() => setShowDictionary(false)}
|
||
/>
|
||
) : null}
|
||
{readOnly && !isQualityReview ? (
|
||
<div className="space-y-3">
|
||
<div className="flex items-center justify-between border-b border-slate-200 pb-2 dark:border-slate-700">
|
||
<span className="text-sm font-bold text-slate-800 dark:text-gray-200">
|
||
动作 #{segIndex >= 0 ? segIndex + 1 : 1} 详情
|
||
</span>
|
||
<span className="font-mono text-xs text-slate-500">
|
||
{formatTime(editingAnnotation.start - lowerAnnotation)} ~{" "}
|
||
{formatTime(editingAnnotation.end - lowerAnnotation)} (时长{" "}
|
||
{formatTime(editingAnnotation.end - editingAnnotation.start)})
|
||
</span>
|
||
</div>
|
||
|
||
{reworkCommentForThis && (
|
||
<div className="rounded-lg border border-rose-400 bg-rose-50 p-3 dark:border-rose-900/60 dark:bg-rose-950/30">
|
||
<div className="flex items-center justify-between gap-2">
|
||
<span className="flex items-center gap-1.5 font-bold text-rose-800 dark:text-rose-200 text-xs">
|
||
<AlertTriangle className="h-4 w-4 text-rose-600" />
|
||
质检 / 验收打回意见:
|
||
</span>
|
||
{reworkCommentForThis.tag && (
|
||
<span className="rounded bg-rose-200 px-2 py-0.5 text-[10px] font-bold text-rose-800">
|
||
{reworkCommentForThis.tag}
|
||
</span>
|
||
)}
|
||
</div>
|
||
<p className="mt-1.5 text-xs text-rose-900 dark:text-rose-100 leading-relaxed font-semibold">
|
||
{reworkCommentForThis.comment}
|
||
</p>
|
||
</div>
|
||
)}
|
||
|
||
<div className="space-y-1">
|
||
<div className="text-[11px] font-semibold text-slate-500">标注员填写的动作描述:</div>
|
||
<div className="rounded border border-slate-200 bg-slate-50 p-3 text-xs leading-relaxed text-slate-800 dark:border-[#2a2b2f] dark:bg-[#1a1b1e] dark:text-gray-200 font-medium">
|
||
{editingAnnotation.isInvalid ||
|
||
editingAnnotation.description === "无效片段" ||
|
||
editingAnnotation.label === "无效片段" ? (
|
||
<span className="inline-flex items-center gap-1.5 font-semibold text-amber-700 dark:text-amber-400">
|
||
<Ban className="h-3.5 w-3.5 text-amber-600 dark:text-amber-400" />
|
||
已标记为「无效片段」(无需动作描述)
|
||
</span>
|
||
) : editingAnnotation.description?.trim() ? (
|
||
editingAnnotation.description
|
||
) : (
|
||
<span className="italic text-slate-400">(无文字描述)</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="flex justify-end pt-1">
|
||
<button
|
||
type="button"
|
||
onClick={() => setEditingAnnotation(null)}
|
||
className="rounded border border-slate-300 px-3.5 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-100 dark:border-slate-700 dark:text-gray-300"
|
||
>
|
||
关闭
|
||
</button>
|
||
</div>
|
||
</div>
|
||
) : isQualityReview ? (
|
||
<div className="space-y-3">
|
||
<div className="flex items-center justify-between border-b border-slate-200 pb-2 dark:border-slate-700">
|
||
<span className="text-sm font-bold text-slate-800 dark:text-gray-200 flex items-center gap-1.5">
|
||
<span>动作 #{segIndex >= 0 ? segIndex + 1 : 1} 审核详情</span>
|
||
{qaCommentForThis && (
|
||
<span className="rounded bg-rose-100 px-2 py-0.5 text-[10px] font-semibold text-rose-700 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-300 dark:border-rose-800">
|
||
已标记批注
|
||
</span>
|
||
)}
|
||
</span>
|
||
<span className="font-mono text-xs text-slate-500">
|
||
{formatTime(editingAnnotation.start - lowerAnnotation)} ~{" "}
|
||
{formatTime(editingAnnotation.end - lowerAnnotation)} (时长{" "}
|
||
{formatTime(editingAnnotation.end - editingAnnotation.start)})
|
||
</span>
|
||
</div>
|
||
|
||
{/* Read-only existing text description */}
|
||
<div className="space-y-1">
|
||
<div className="text-[11px] font-semibold text-slate-500">标注员填写的动作描述:</div>
|
||
<div className="rounded border border-slate-200 bg-slate-50 p-2.5 text-xs leading-relaxed text-slate-800 dark:border-[#2a2b2f] dark:bg-[#1a1b1e] dark:text-gray-200 font-medium">
|
||
{editingAnnotation.isInvalid ||
|
||
editingAnnotation.description === "无效片段" ||
|
||
editingAnnotation.label === "无效片段" ? (
|
||
<span className="inline-flex items-center gap-1.5 font-semibold text-amber-700 dark:text-amber-400">
|
||
<Ban className="h-3.5 w-3.5 text-amber-600 dark:text-amber-400" />
|
||
已标记为「无效片段」(无需动作描述)
|
||
</span>
|
||
) : editingAnnotation.description?.trim() ? (
|
||
editingAnnotation.description
|
||
) : (
|
||
<span className="italic text-slate-400">(无文字描述)</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{/* QA inline commenting panel */}
|
||
{!reviewReadOnly || reviewWriteLocked ? (
|
||
<div className="rounded-lg border border-rose-200 bg-rose-50/50 p-3 dark:border-rose-900/40 dark:bg-rose-950/20 space-y-2.5">
|
||
<div className="flex items-center justify-between">
|
||
<label className="text-xs font-bold text-rose-800 dark:text-rose-200 flex items-center gap-1">
|
||
<MessageSquare className="h-3.5 w-3.5 text-rose-600" />
|
||
针对此动作的打回意见与修改要求:
|
||
</label>
|
||
{qaCommentForThis && (
|
||
<span className="text-[10px] text-rose-600 font-semibold">● 已挂载到此片段</span>
|
||
)}
|
||
</div>
|
||
|
||
<textarea
|
||
aria-label="当前动作问题备注"
|
||
disabled={reviewReadOnly}
|
||
rows={3}
|
||
value={qaDraftComment}
|
||
onChange={(e) => setQaDraftComment(e.target.value)}
|
||
placeholder="请输入针对此动作的具体修改指导(例如:放杯子的起始时间提前了约0.5s,需微调对齐;或描述动词不准确)..."
|
||
className="w-full resize-y rounded border border-rose-300 bg-[color:var(--app-panel)] p-2.5 text-xs text-slate-800 outline-none focus:border-rose-500 dark:border-rose-800 dark:bg-[#151619] dark:text-gray-200"
|
||
/>
|
||
|
||
<div className="flex items-center justify-between pt-1">
|
||
{qaCommentForThis ? (
|
||
<button
|
||
type="button"
|
||
disabled={reviewReadOnly}
|
||
onClick={() => {
|
||
deleteSegmentQAComment(
|
||
currentSliceLabel,
|
||
segIndex,
|
||
`${formatTime(editingAnnotation.start - lowerAnnotation)}-${formatTime(editingAnnotation.end - lowerAnnotation)}`,
|
||
);
|
||
setQaDraftComment("");
|
||
}}
|
||
className="inline-flex items-center gap-1 text-xs text-slate-500 hover:text-rose-600"
|
||
>
|
||
<Trash2 className="h-3 w-3" />
|
||
清除此动作批注
|
||
</button>
|
||
) : (
|
||
<div />
|
||
)}
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => setEditingAnnotation(null)}
|
||
className="rounded border border-slate-300 px-2.5 py-1 text-xs text-slate-600 hover:bg-slate-100 dark:border-slate-700 dark:text-gray-300"
|
||
>
|
||
关闭
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={reviewReadOnly}
|
||
onClick={() => {
|
||
saveSegmentQAComment();
|
||
setEditingAnnotation(null);
|
||
}}
|
||
className="rounded bg-rose-600 px-3.5 py-1.5 text-xs font-semibold text-white shadow hover:bg-rose-700 transition"
|
||
>
|
||
{qaCommentForThis ? "更新批注内容" : "✓ 标记此动作并保存批注"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : qaCommentForThis ? (
|
||
<div className="rounded-lg border border-rose-200 bg-rose-50/50 p-3 dark:border-rose-900/40 dark:bg-rose-950/20 space-y-1">
|
||
<div className="text-xs font-bold text-rose-800 dark:text-rose-200 flex items-center gap-1">
|
||
<MessageSquare className="h-3.5 w-3.5 text-rose-600" />
|
||
审核打回意见与批注:
|
||
</div>
|
||
<p className="text-xs text-rose-900 dark:text-rose-100 leading-relaxed font-medium">
|
||
{qaCommentForThis.comment}
|
||
</p>
|
||
<div className="flex justify-end pt-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => setEditingAnnotation(null)}
|
||
className="rounded border border-slate-300 px-2.5 py-1 text-xs text-slate-600 hover:bg-slate-100 dark:border-slate-700 dark:text-gray-300"
|
||
>
|
||
关闭
|
||
</button>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="flex justify-end pt-1">
|
||
<button
|
||
type="button"
|
||
onClick={() => setEditingAnnotation(null)}
|
||
className="rounded border border-slate-300 px-2.5 py-1 text-xs text-slate-600 hover:bg-slate-100 dark:border-slate-700 dark:text-gray-300"
|
||
>
|
||
关闭
|
||
</button>
|
||
</div>
|
||
)}
|
||
</div>
|
||
) : (
|
||
<>
|
||
{/* Annotator rework advice notice */}
|
||
{reworkCommentForThis && (
|
||
<div className="mb-3 rounded-lg border border-rose-400 bg-rose-50 p-3 dark:border-rose-900/60 dark:bg-rose-950/30">
|
||
<div className="flex items-center justify-between gap-2">
|
||
<span className="flex items-center gap-1.5 font-bold text-rose-800 dark:text-rose-200 text-xs">
|
||
<AlertTriangle className="h-4 w-4 text-rose-600" />
|
||
质检 / 验收打回意见(动作 #{segIndex >= 0 ? segIndex + 1 : 1}):
|
||
</span>
|
||
{reworkCommentForThis.tag && (
|
||
<span className="rounded bg-rose-200 px-2 py-0.5 text-[10px] font-bold text-rose-800">
|
||
{reworkCommentForThis.tag}
|
||
</span>
|
||
)}
|
||
</div>
|
||
<p className="mt-1.5 text-xs text-rose-900 dark:text-rose-100 leading-relaxed font-semibold">
|
||
{reworkCommentForThis.comment || "请根据审核意见修改此动作的时间或描述"}
|
||
</p>
|
||
</div>
|
||
)}
|
||
|
||
{(() => {
|
||
const isInvalid = Boolean(
|
||
editingAnnotation.isInvalid ||
|
||
editingAnnotation.description === "无效片段" ||
|
||
editingAnnotation.label === "无效片段",
|
||
);
|
||
|
||
return (
|
||
<>
|
||
<div className="mb-2 flex flex-wrap items-center justify-between gap-2">
|
||
<span className="text-sm font-semibold text-slate-800 dark:text-gray-200">
|
||
编辑动作 #{segIndex >= 0 ? segIndex + 1 : 1} 描述区间
|
||
</span>
|
||
<div className="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
disabled={!canEdit || descriptionSaving}
|
||
onClick={() => {
|
||
if (isInvalid) {
|
||
updateEditingAnnotation({
|
||
isInvalid: false,
|
||
...(continuousActions ? { status: "pending" as const } : {}),
|
||
description: "",
|
||
label: "",
|
||
labelId: "",
|
||
});
|
||
} else {
|
||
void markSelectedInvalid();
|
||
}
|
||
}}
|
||
className={cn(
|
||
"inline-flex items-center gap-1.5 rounded border px-2.5 py-1 text-xs font-medium transition shadow-sm",
|
||
isInvalid
|
||
? "border-amber-400 bg-amber-50 text-amber-800 hover:bg-amber-100 dark:border-amber-700 dark:bg-amber-950/50 dark:text-amber-300"
|
||
: "border-slate-300 bg-white text-slate-700 hover:bg-slate-50 dark:border-slate-600 dark:bg-slate-800 dark:text-gray-300 dark:hover:bg-slate-700",
|
||
)}
|
||
>
|
||
<Ban
|
||
className={cn(
|
||
"h-3.5 w-3.5",
|
||
isInvalid ? "text-amber-600 dark:text-amber-400" : "text-slate-500",
|
||
)}
|
||
/>
|
||
{isInvalid ? "改为动作描述" : "标为无效动作"}
|
||
</button>
|
||
<div className="relative">
|
||
<button
|
||
ref={descriptionDictionaryTriggerRef}
|
||
type="button"
|
||
disabled={isInvalid || saving}
|
||
title="从字典选择(F / D,填写文本时不触发)"
|
||
aria-keyshortcuts="F D"
|
||
onClick={() => setShowDictionary((value) => !value)}
|
||
className="inline-flex items-center gap-1.5 rounded border border-slate-300 px-2 py-1 text-xs text-slate-700 dark:border-slate-600 dark:text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed"
|
||
>
|
||
<BookOpen className="h-3.5 w-3.5" />
|
||
从字典选择
|
||
</button>
|
||
{showDictionary && !isInvalid && !focusedLayout ? (
|
||
<div
|
||
ref={descriptionDictionaryRef}
|
||
role="dialog"
|
||
aria-label="选择动作描述"
|
||
tabIndex={-1}
|
||
onKeyDown={(event) => dictionaryKeyDown(event, closeDescriptionDictionary)}
|
||
onBlur={(event) => {
|
||
if (
|
||
!event.currentTarget.contains(event.relatedTarget as Node) &&
|
||
event.relatedTarget !== descriptionDictionaryTriggerRef.current
|
||
)
|
||
setShowDictionary(false);
|
||
}}
|
||
className="absolute right-0 top-8 z-30 max-h-48 w-56 overflow-auto rounded border border-slate-200 bg-[color:var(--app-panel)] p-1 shadow-xl dark:border-[#2a2b2f] dark:bg-[#1a1b1e]"
|
||
>
|
||
<p className="px-2 py-1 text-[10px] text-slate-500">
|
||
↑ / ↓ 选择 · Enter 填入 · Esc 关闭
|
||
</p>
|
||
{!labels.length && (
|
||
<p className="p-2 text-xs text-slate-500">
|
||
暂无字典词条,可直接填写描述。
|
||
</p>
|
||
)}
|
||
{labels.map((item) => (
|
||
<button
|
||
data-dictionary-option
|
||
key={item.id}
|
||
type="button"
|
||
onClick={() => chooseTemplate(item)}
|
||
className="block w-full rounded px-2 py-2 text-left text-xs text-slate-700 hover:bg-orange-50 dark:text-gray-300 dark:hover:bg-orange-950/40"
|
||
>
|
||
{item.description || item.name}
|
||
</button>
|
||
))}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{isInvalid ? (
|
||
<div className="flex min-h-24 flex-col items-center justify-center rounded border border-dashed border-amber-300 bg-amber-50/60 p-4 text-center dark:border-amber-800/60 dark:bg-amber-950/30">
|
||
<div className="flex items-center gap-1.5 text-sm font-semibold text-amber-800 dark:text-amber-300">
|
||
<Ban className="h-4 w-4 text-amber-600 dark:text-amber-400" />
|
||
当前区间已设为无效片段
|
||
</div>
|
||
<p className="mt-1 text-xs text-amber-700 dark:text-amber-400">
|
||
该区间无需填写动作描述;这是明确的无效标记,与未标注留空不同。
|
||
</p>
|
||
</div>
|
||
) : (
|
||
<textarea
|
||
ref={descriptionInputRef}
|
||
aria-label="动作描述"
|
||
value={editingAnnotation.description || ""}
|
||
onChange={(event) => updateEditingAnnotation({ description: event.target.value })}
|
||
placeholder="直接填写详细动作描述..."
|
||
rows={3}
|
||
className="min-h-24 w-full resize-y rounded border border-slate-300 p-2.5 text-sm text-slate-800 outline-none focus:border-orange-400 dark:border-[#2a2b2f] dark:bg-[#1a1b1e] dark:text-gray-200"
|
||
/>
|
||
)}
|
||
|
||
<div className="capture-description-text-tools mt-1 flex items-center justify-between text-xs text-slate-500">
|
||
{focusedLayout && !isInvalid ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => {
|
||
setExpandedDescription((value) => !value);
|
||
descriptionInputRef.current?.focus({ preventScroll: true });
|
||
}}
|
||
>
|
||
{expandedDescription ? "收起描述编辑" : "展开描述编辑"}
|
||
</button>
|
||
) : null}
|
||
<span className="capture-description-text-hint">
|
||
{isInvalid ? "无效片段自动完成描述确认" : "可从字典填入后修改,也可直接填写"}
|
||
</span>
|
||
<span>
|
||
{isInvalid
|
||
? "无需字数"
|
||
: `已输入 ${editingAnnotation.description?.length || 0} 字`}
|
||
</span>
|
||
</div>
|
||
|
||
<div className="capture-description-boundaries mt-3 grid grid-cols-1 gap-3 text-xs sm:grid-cols-2">
|
||
{(["start", "end"] as const).map((field) => (
|
||
<div key={field} className="min-w-0 space-y-1">
|
||
<label className="block">
|
||
<span className="text-slate-500 dark:text-slate-400">
|
||
片内
|
||
{field === "start"
|
||
? `开始时间${selectingEnd || isNewAnnotation ? "(固定)" : ""}`
|
||
: `结束时间${selectingEnd ? "(跟随播放头)" : ""}`}
|
||
(秒)
|
||
</span>
|
||
<input
|
||
type="number"
|
||
min={0}
|
||
max={upperAnnotation - lowerAnnotation}
|
||
step="0.001"
|
||
aria-label={`动作${field === "start" ? "开始" : "结束"}时间(秒)`}
|
||
disabled={
|
||
saving || (field === "start" && (selectingEnd || isNewAnnotation))
|
||
}
|
||
value={Number((editingAnnotation[field] - lowerAnnotation).toFixed(6))}
|
||
onChange={(event) =>
|
||
editAnnotationBoundary(
|
||
field,
|
||
lowerAnnotation + event.currentTarget.valueAsNumber,
|
||
)
|
||
}
|
||
className="mt-1 w-full rounded border border-[color:var(--app-border)] bg-[color:var(--app-inset)] px-2 py-1.5 text-[color:var(--app-text)]"
|
||
/>
|
||
</label>
|
||
<div className="flex gap-2">
|
||
{([-1, 1] as const).map((direction) => (
|
||
<button
|
||
key={direction}
|
||
type="button"
|
||
disabled={
|
||
saving || (field === "start" && (selectingEnd || isNewAnnotation))
|
||
}
|
||
aria-label={`${field === "start" ? "开始" : "结束"}时间${direction < 0 ? "前移" : "后移"}一帧`}
|
||
onClick={() => {
|
||
if (field === "end" && !continuousActions) {
|
||
if (!selectingEnd && !beginEndSelection()) return;
|
||
step(direction);
|
||
} else
|
||
editAnnotationBoundary(
|
||
field,
|
||
exactFrames
|
||
? stepFrameBoundary(
|
||
frameBoundaries,
|
||
editingAnnotation[field],
|
||
direction,
|
||
)
|
||
: editingAnnotation[field] + direction * frameStep,
|
||
);
|
||
}}
|
||
className="rounded border px-2 py-1 disabled:opacity-50"
|
||
>
|
||
{direction < 0 ? "−1 帧" : "+1 帧"}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
{error ? (
|
||
<p role="alert" className="mt-2 text-xs text-red-600">
|
||
{userErrorMessage(error)}
|
||
</p>
|
||
) : null}
|
||
<div className="capture-description-actions mt-3 flex flex-wrap items-center justify-between gap-2 border-t border-slate-200 pt-3 dark:border-[#2a2b2f]">
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => {
|
||
setEndSelection(null);
|
||
setEditingAnnotation(null);
|
||
setError("");
|
||
pausePlayback();
|
||
focusWorkbench();
|
||
}}
|
||
className="text-xs text-slate-500"
|
||
>
|
||
{isNewAnnotation ? "取消新增" : "取消编辑"}
|
||
</button>
|
||
{!isNewAnnotation ? (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
hidden={continuousActions}
|
||
onClick={() => void deleteAnnotationLeavingBlank(editingAnnotation.id)}
|
||
className="inline-flex items-center gap-1 text-xs text-red-600 hover:text-red-700 disabled:opacity-50"
|
||
>
|
||
<Trash2 className="h-3.5 w-3.5" />
|
||
删除此动作(保留空白)
|
||
</button>
|
||
) : null}
|
||
<button
|
||
type="button"
|
||
disabled={
|
||
saving ||
|
||
(selectingEnd && editingAnnotation.end <= editingAnnotation.start + 0.001)
|
||
}
|
||
hidden={continuousActions}
|
||
onClick={() => (selectingEnd ? confirmEndSelection() : beginEndSelection())}
|
||
title={
|
||
selectingEnd ? "确认结束点(Enter),随后填写描述" : "重新定位当前动作的结束点"
|
||
}
|
||
aria-keyshortcuts={selectingEnd ? "Enter" : undefined}
|
||
className={cn(
|
||
"rounded border border-orange-500 px-3 py-2 text-xs font-semibold disabled:opacity-50",
|
||
selectingEnd ? "bg-orange-500 text-white" : "text-orange-600",
|
||
)}
|
||
>
|
||
{selectingEnd ? "确认结束点" : "调整结束点"}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={saving || selectingEnd}
|
||
onClick={() => void confirmAnnotation()}
|
||
title="保存当前描述(Ctrl / ⌘ + Enter),不提交整个任务"
|
||
aria-keyshortcuts="Control+Enter Meta+Enter"
|
||
className="rounded bg-orange-500 px-4 py-2 text-xs font-semibold text-white shadow hover:bg-orange-600 disabled:opacity-50"
|
||
>
|
||
{isInvalid ? "确认保存(无效片段)" : "确认保存描述"}
|
||
</button>
|
||
</div>
|
||
</>
|
||
);
|
||
})()}
|
||
</>
|
||
)}
|
||
</div>
|
||
);
|
||
})()
|
||
: null}
|
||
{reworkRail}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
)}
|
||
{phase !== "materializing" && !mediaOnly && (
|
||
<footer className="flex flex-wrap items-center justify-between gap-3 border-t border-slate-200 bg-slate-50 px-5 py-3 dark:border-[#202227] dark:bg-[#121316]">
|
||
{!isQualityReview && !readOnly ? (
|
||
<div className="capture-history-controls flex gap-2">
|
||
<button
|
||
type="button"
|
||
disabled={saving || readOnly || sliceEditPanelOpen}
|
||
title={sliceEditPanelOpen ? "面板期间锁定:先 Enter 应用或 Esc 取消" : "撤销(Ctrl / ⌘ + Z)"}
|
||
onClick={() => void onHistoryCommand?.("undo")}
|
||
className="rounded border px-3 py-1 text-xs"
|
||
>
|
||
撤销
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={saving || readOnly || sliceEditPanelOpen}
|
||
title={sliceEditPanelOpen ? "面板期间锁定:先 Enter 应用或 Esc 取消" : "重做(Ctrl / ⌘ + Shift + Z)"}
|
||
onClick={() => void onHistoryCommand?.("redo")}
|
||
className="rounded border px-3 py-1 text-xs"
|
||
>
|
||
重做
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
{isQualityReview && !reviewReadOnly ? (
|
||
<>
|
||
<div className="flex items-center gap-2 text-xs text-slate-500 dark:text-gray-400">
|
||
<span>
|
||
{slices.length} 个切片 · {segments.length} 个动作
|
||
</span>
|
||
{onReleaseTask ? (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={onReleaseTask}
|
||
className="ml-3 inline-flex items-center gap-1 rounded border border-slate-300 px-2 py-1 text-slate-600 hover:bg-slate-100 hover:text-slate-900 dark:border-[#34363b] dark:text-gray-300 dark:hover:bg-[#1a1b1e] dark:hover:text-white"
|
||
>
|
||
<RotateCcw className="h-3 w-3" />
|
||
释放领取
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
<div className="flex items-center gap-3">
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => {
|
||
const { generalComment } = parseSegmentCommentsFromText(reviewComment || "");
|
||
setGeneralRejectReason(generalComment || "");
|
||
if (reviewProblemPanel) onReject?.();
|
||
else setShowRejectModal(true);
|
||
}}
|
||
className="inline-flex items-center gap-1.5 rounded-lg border border-red-500 bg-red-600 px-4 py-2 text-xs font-semibold text-white shadow-sm hover:bg-red-500 disabled:opacity-40"
|
||
>
|
||
<RotateCcw className="h-4 w-4" />
|
||
{reviewMode === "acceptance" ? "验收不通过(打回)" : "审核不通过(打回)"}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={
|
||
saving ||
|
||
Boolean(reviewComment?.trim()) ||
|
||
problemSliceIds.length > 0 ||
|
||
Boolean(qaDraftComment.trim()) ||
|
||
Boolean(sliceProblemDraft?.trim())
|
||
}
|
||
onClick={onApprove}
|
||
className="inline-flex items-center gap-1.5 rounded-lg bg-emerald-600 px-5 py-2 text-xs font-semibold text-white shadow-sm hover:bg-emerald-500 disabled:opacity-40"
|
||
>
|
||
<CheckCircle2 className="h-4 w-4" />
|
||
{reviewMode === "acceptance" ? "验收通过" : "审核通过"}
|
||
</button>
|
||
{!reviewProblemPanel && sliceProblemDraft !== null && (
|
||
<div
|
||
role="dialog"
|
||
aria-label="切片问题备注"
|
||
className="fixed inset-0 z-[150] flex items-center justify-center bg-black/50"
|
||
>
|
||
<div className="w-full max-w-md space-y-3 rounded-xl bg-[color:var(--app-panel)] p-5 text-[color:var(--app-text)]">
|
||
<h3>{selectedSlice.name || "当前切片"} · 问题备注</h3>
|
||
<textarea
|
||
aria-label="切片问题内容"
|
||
className="w-full rounded border p-2"
|
||
value={sliceProblemDraft}
|
||
onChange={(e) => setSliceProblemDraft(e.target.value)}
|
||
/>
|
||
<button type="button" onClick={() => setSliceProblemDraft(null)}>
|
||
取消
|
||
</button>
|
||
<button
|
||
type="button"
|
||
className="ml-4 text-orange-600"
|
||
onClick={() => {
|
||
if (reviewReadOnly) return;
|
||
const parsed = parseSegmentCommentsFromText(reviewComment || "");
|
||
const notes = parsed.segmentComments.filter(
|
||
(c) =>
|
||
!(
|
||
(c.sliceId ? c.sliceId === selectedSlice.id : c.sliceName === selectedSlice.name) &&
|
||
c.segmentIndex === undefined &&
|
||
!c.segmentId
|
||
),
|
||
);
|
||
if (sliceProblemDraft.trim())
|
||
notes.push({
|
||
sliceId: selectedSlice.id,
|
||
segmentId: undefined,
|
||
rawHeader: "",
|
||
sliceName: selectedSlice.name || "切片",
|
||
segmentIndex: undefined,
|
||
timeRange: "",
|
||
tag: "",
|
||
comment: sliceProblemDraft.trim(),
|
||
});
|
||
onReviewCommentChange?.(serializeSegmentCommentsToText(notes, parsed.generalComment));
|
||
const ids = problemSliceIds.filter((id) => id !== selectedSlice.id);
|
||
if (notes.some((c) => c.sliceId === selectedSlice.id || c.sliceName === selectedSlice.name))
|
||
ids.push(selectedSlice.id);
|
||
onProblemSliceIdsChange?.(ids);
|
||
setSliceProblemDraft(null);
|
||
}}
|
||
>
|
||
保存备注
|
||
</button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</>
|
||
) : phase === "slice" ? (
|
||
<>
|
||
<span className="mr-auto text-xs text-amber-700">
|
||
{claimLocked
|
||
? "任务已归您处理;离开前请确认切片,未确认编辑离开后不保留。"
|
||
: "离开或释放任务将清空本次切片调整"}
|
||
</span>
|
||
{onReleaseTask && (
|
||
<button
|
||
type="button"
|
||
disabled={saving || readOnly}
|
||
onClick={onReleaseTask}
|
||
className="inline-flex items-center gap-1.5 rounded border border-[color:var(--app-border)] px-3 py-2 text-sm text-[color:var(--app-text)]"
|
||
>
|
||
<Trash2 className="h-4 w-4 text-orange-600" />
|
||
放弃并释放任务
|
||
</button>
|
||
)}
|
||
<button
|
||
type="button"
|
||
disabled={saving || !canConfirmSlices || readOnly || Boolean(sliceNameIssue)}
|
||
title={sliceNameIssue || "确认全部切片"}
|
||
onClick={() => requestStageConfirmation()}
|
||
className="rounded bg-orange-500 px-4 py-2 text-sm font-semibold text-white disabled:opacity-50"
|
||
>
|
||
确认全部切片
|
||
</button>
|
||
{sliceNameIssue ? (
|
||
<span role="status" className="text-xs text-amber-700">
|
||
{sliceNameIssue}
|
||
</span>
|
||
) : null}
|
||
<span className="text-xs text-slate-500">
|
||
{slices.length} 个切片 ·{" "}
|
||
{!timelineReady ? (
|
||
"等待统一帧范围"
|
||
) : (
|
||
<>
|
||
{sliceBoundaryIssue || "已完整覆盖"} {formatTime(clipStart)}–{formatTime(clipEnd)}
|
||
</>
|
||
)}
|
||
</span>
|
||
</>
|
||
) : readOnly ? (
|
||
<>
|
||
{operationNotice && focusedLayout && (
|
||
<p
|
||
role="status"
|
||
data-testid="workbench-operation-status"
|
||
className="w-full whitespace-normal rounded border border-blue-300 bg-blue-50 px-2 py-2 text-xs text-blue-800 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-200"
|
||
>
|
||
{operationNotice}
|
||
</p>
|
||
)}
|
||
<span className="mr-auto text-xs text-slate-500">{segments.length} 个描述已确认</span>
|
||
<span className="rounded bg-slate-200/80 px-3 py-1.5 text-xs font-medium text-slate-700 dark:bg-slate-800 dark:text-slate-300">
|
||
{isQualityReview ? "质检审核模式(只读查看)" : `${readOnlyStatusLabel}(只读查看)`}
|
||
</span>
|
||
</>
|
||
) : (
|
||
<>
|
||
{/* 票 06(D1 修订版):首标「重新切片」入口恢复——回调仅由首标任务传入
|
||
(resliceEligible),返修任务不渲染;结构微调仍走原地编辑。 */}
|
||
{onRequestReslice ? (
|
||
<>
|
||
<button
|
||
type="button"
|
||
disabled={saving || readOnly}
|
||
onClick={onRequestReslice}
|
||
className="inline-flex items-center gap-1.5 rounded border border-orange-300 px-3 py-2 text-sm text-orange-700"
|
||
>
|
||
<Trash2 className="h-4 w-4" />
|
||
重新切片
|
||
</button>
|
||
<span className="text-xs text-slate-500">重新切片将删除全部已有标注</span>
|
||
</>
|
||
) : null}
|
||
{!error && !canSubmitTask && submissionBlockerReason && !readOnly ? (
|
||
<span className="inline-flex items-center gap-1 text-xs font-medium text-amber-700 dark:text-amber-300 bg-amber-50 dark:bg-amber-950/50 px-2.5 py-1 rounded border border-amber-200 dark:border-amber-800">
|
||
<AlertTriangle className="h-3.5 w-3.5 text-amber-600 shrink-0" />
|
||
<span title={submissionBlockerReason}>
|
||
{submissionBlockerReason.includes("帧边界")
|
||
? "边界需确认,请原地调整切片边界"
|
||
: submissionBlockerReason.includes("待标注") || submissionBlockerReason.includes("所有动作")
|
||
? "还有动作待标注"
|
||
: submissionBlockerReason}
|
||
</span>
|
||
</span>
|
||
) : null}
|
||
<span className="mr-auto text-xs text-slate-500">
|
||
{segments.filter((s) => Boolean(s.description?.trim())).length}/{segments.length} 个描述已确认
|
||
</span>
|
||
<button
|
||
type="button"
|
||
disabled={saving || readOnly || (!canSubmitTask && !outstandingDrafts.length)}
|
||
onClick={() => requestStageConfirmation()}
|
||
title={!canSubmitTask && submissionBlockerReason ? submissionBlockerReason : "完成任务并提交质检"}
|
||
className="rounded bg-orange-500 px-4 py-2 text-sm font-semibold text-white disabled:opacity-50"
|
||
>
|
||
完成任务并提交质检
|
||
</button>
|
||
</>
|
||
)}
|
||
</footer>
|
||
)}
|
||
{showRejectModal && !reviewReadOnly ? (
|
||
<div
|
||
role="dialog"
|
||
aria-modal="true"
|
||
aria-label="审核打回返工"
|
||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4 backdrop-blur-sm"
|
||
>
|
||
<div className="max-h-[calc(100dvh-2rem)] w-full max-w-lg overflow-y-auto rounded-xl border border-[color:var(--app-border)] bg-[color:var(--app-panel)] p-6 text-[color:var(--app-text)] shadow-2xl">
|
||
<div className="flex items-center justify-between pb-3 border-b border-slate-200 dark:border-slate-800">
|
||
<div className="flex items-center gap-2">
|
||
<div className="grid h-8 w-8 place-items-center rounded-full bg-red-100 text-red-600 dark:bg-red-950/60 dark:text-red-400">
|
||
<RotateCcw className="h-4 w-4" />
|
||
</div>
|
||
<h3 className="text-base font-bold text-slate-900 dark:text-white">
|
||
{reviewMode === "acceptance" ? "质检 / 验收打回返工" : "审核不通过 · 打回返工"}
|
||
</h3>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowRejectModal(false)}
|
||
className="text-slate-400 hover:text-slate-600 dark:hover:text-slate-200"
|
||
>
|
||
<X className="h-5 w-5" />
|
||
</button>
|
||
</div>
|
||
|
||
<div className="py-4 space-y-4">
|
||
{parsedQAComments.length > 0 && (
|
||
<div className="rounded-lg border border-amber-200 bg-amber-50/70 p-3 dark:border-amber-900/40 dark:bg-amber-950/20">
|
||
<div className="text-xs font-bold text-amber-800 dark:text-amber-300 mb-1.5 flex items-center gap-1.5">
|
||
<AlertTriangle className="h-3.5 w-3.5 text-amber-600" />
|
||
已在时间轴上标记 {parsedQAComments.length} 处片段批注:
|
||
</div>
|
||
<ul className="space-y-1 text-xs text-amber-900 dark:text-amber-200 list-disc list-inside font-medium max-h-32 overflow-y-auto">
|
||
{parsedQAComments.map((c, idx) => (
|
||
<li key={idx} className="truncate">
|
||
<span className="font-semibold">
|
||
{c.sliceName} {c.segmentIndex !== undefined ? `动作#${c.segmentIndex + 1}` : ""}:
|
||
</span>{" "}
|
||
{c.comment}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</div>
|
||
)}
|
||
|
||
<div>
|
||
<label className="block text-xs font-bold text-slate-700 dark:text-slate-300 mb-1.5">
|
||
{parsedQAComments.length > 0
|
||
? "补充综合修改要求与打回说明(选填):"
|
||
: "打回原因与修改指导(必填):"}
|
||
</label>
|
||
<textarea
|
||
rows={4}
|
||
value={generalRejectReason}
|
||
onChange={(e) => setGeneralRejectReason(e.target.value)}
|
||
placeholder="请详细说明打回原因及需要标注员如何修改(例如:切片分界不准确或动作描述不规范,请重新微调...)"
|
||
className="w-full resize-y rounded-lg border border-[color:var(--app-border)] bg-[color:var(--app-inset)] p-3 text-xs text-[color:var(--app-text)] outline-none focus:border-red-500 focus:ring-1 focus:ring-red-500"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="flex items-center justify-end gap-3 pt-3 border-t border-slate-200 dark:border-slate-800">
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowRejectModal(false)}
|
||
className="rounded-lg border border-slate-300 px-4 py-2 text-xs font-medium text-slate-700 hover:bg-slate-50 dark:border-slate-700 dark:text-gray-300 dark:hover:bg-slate-800"
|
||
>
|
||
取消
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={saving || (parsedQAComments.length === 0 && !generalRejectReason.trim())}
|
||
onClick={() => {
|
||
const combinedComment = serializeSegmentCommentsToText(parsedQAComments, generalRejectReason.trim());
|
||
if (!combinedComment.trim()) return;
|
||
onReviewCommentChange?.(combinedComment);
|
||
if (problemSliceIds.length === 0 && selectedSlice) {
|
||
onProblemSliceIdsChange?.([selectedSlice.id]);
|
||
}
|
||
setShowRejectModal(false);
|
||
setTimeout(() => {
|
||
if (reviewWritableRef.current) onReject?.();
|
||
}, 50);
|
||
}}
|
||
className="rounded-lg bg-red-600 px-5 py-2 text-xs font-bold text-white shadow-sm hover:bg-red-700 disabled:opacity-50"
|
||
>
|
||
确认打回返工
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
{sliceEditPanel && phase === "annotate"
|
||
? (() => {
|
||
const pending = sliceEditPanel.pendingSlices;
|
||
const target = pending.find((slice) => slice.id === sliceEditPanel.sliceId) || pending[0];
|
||
if (!target) return null;
|
||
const targetIndex = pending.findIndex((slice) => slice.id === target.id);
|
||
return (
|
||
<SliceEditPanel
|
||
target={target}
|
||
ordinal={targetIndex + 1}
|
||
total={pending.length}
|
||
focusBoundary={sliceEditPanel.focusBoundary}
|
||
fixed={{ start: targetIndex === 0, end: targetIndex === pending.length - 1 }}
|
||
exactFrames={exactFrames}
|
||
frameIndexOf={(time) => nearestFrameBoundaryIndex(frameBoundaries, time)}
|
||
saving={Boolean(saving)}
|
||
playheadLabel={formatTime(currentTime)}
|
||
error={operationError || error}
|
||
onFocusBoundary={(field) =>
|
||
setSliceEditPanel((panel) =>
|
||
panel && panel.focusBoundary !== field ? { ...panel, focusBoundary: field } : panel,
|
||
)
|
||
}
|
||
onStep={(field, direction, count) => panelNudgeBoundary(field, direction, count)}
|
||
onCoarse={(field, direction) => panelNudgeBoundary(field, direction, 1, true)}
|
||
onSetBoundary={(field, value) => panelSetBoundary(field, value)}
|
||
onSplit={panelSplitAtPlayhead}
|
||
onDiscard={panelDiscardDraftOpen}
|
||
onMerge={panelMergeBoundary}
|
||
onApply={applySliceEditPanel}
|
||
onCancel={() => {
|
||
if (sliceEditDiscardDraft) setSliceEditDiscardDraft(null);
|
||
else cancelSliceEditPanel();
|
||
}}
|
||
dictionary={{
|
||
items: sliceDictionary || [],
|
||
loading: sliceDictionaryLoading,
|
||
error: userErrorMessage(sliceDictionaryError),
|
||
refresh: onRefreshSliceDictionary,
|
||
onSelect: (name) =>
|
||
applySliceEditPanelOp(
|
||
setPendingSliceName(sliceEditPanel.pendingSlices, sliceEditPanel.sliceId, name),
|
||
),
|
||
}}
|
||
discard={{
|
||
draft: sliceEditDiscardDraft,
|
||
reasons: discardReasons,
|
||
allowManual: discardReasonsAllowManual,
|
||
loading: discardReasonsLoading,
|
||
error: userErrorMessage(discardReasonsError),
|
||
refresh: onRefreshDiscardReasons,
|
||
onDraftChange: (draft) => setSliceEditDiscardDraft(draft),
|
||
onConfirm: () => {
|
||
if (!sliceEditDiscardDraft) return;
|
||
applySliceEditPanelOp(
|
||
setPendingSliceDisposition(
|
||
sliceEditPanel.pendingSlices,
|
||
sliceEditPanel.sliceId,
|
||
sliceEditDiscardDraft.discard ? "discard" : "keep",
|
||
{
|
||
reason: sliceEditDiscardDraft.reason,
|
||
reasonLabelId: sliceEditDiscardDraft.reasonLabelId,
|
||
reasonVersion: sliceEditDiscardDraft.reasonVersion,
|
||
reasonNote: sliceEditDiscardDraft.reasonNote,
|
||
},
|
||
),
|
||
{ closeDraft: true },
|
||
);
|
||
},
|
||
onCancel: () => setSliceEditDiscardDraft(null),
|
||
}}
|
||
/>
|
||
);
|
||
})()
|
||
: null}
|
||
{sliceEditConflictList && phase === "annotate" ? (
|
||
<SliceEditConflictList
|
||
entries={sliceEditConflictList.entries}
|
||
saving={saving || quickConflictApplying}
|
||
error={operationError || error}
|
||
beforeSlices={
|
||
sliceEditConflictList.source === "quick"
|
||
? sliceEditQuickConflict?.beforeSlices
|
||
: sliceEditPanel?.snapshot.slices
|
||
}
|
||
afterSlices={
|
||
sliceEditConflictList.source === "quick"
|
||
? sliceEditQuickConflict?.afterSlices
|
||
: sliceEditPanel?.pendingSlices
|
||
}
|
||
decisions={sliceEditConflictList.decisions}
|
||
focus={sliceEditConflictList.focus}
|
||
autoFollows={sliceEditConflictList.autoFollows}
|
||
actionLabel={(actionId) => `动作${actionIndexLabel(actionId)}`}
|
||
onChoose={(entryIndex, position) =>
|
||
setSliceEditConflictList((list) => {
|
||
if (!list) return list;
|
||
const next = applyConflictListChoice(
|
||
list.entries,
|
||
{ focus: entryIndex, decisions: list.decisions },
|
||
position,
|
||
);
|
||
return { ...list, focus: next.focus, decisions: next.decisions };
|
||
})
|
||
}
|
||
onMove={(direction) =>
|
||
setSliceEditConflictList((list) =>
|
||
list ? { ...list, focus: conflictListFocusStep(list.entries.length, list.focus, direction) } : list,
|
||
)
|
||
}
|
||
onApply={() => applySliceEditConflictList(sliceEditConflictList.decisions)}
|
||
onCancel={cancelSliceEditConflictList}
|
||
/>
|
||
) : null}
|
||
</section>
|
||
);
|
||
}
|