forked from longtao.wu/droboticflow
- thin marker strip atop the review slice timeline: orange dots at capture-seconds positions; near-neighbours (<0.8% track width) cluster into a count badge; single marker click seeks via reviewController, cluster click expands a popover listing each opinion (time + text) - parent slices are never painted red (markers live on their own strip, visually distinct from the playhead) - data flows through the new reviewTimestampOpinions prop mapped from reviewDraft.timestampProblems (same source as G-jump and locate) - browser-verified on the replica stack: two nearby opinions (0.09s/ 0.14s) cluster into one '2 条' marker, expansion lists both; frontend regressions identical to baseline (14), tsc clean
4969 lines
234 KiB
TypeScript
4969 lines
234 KiB
TypeScript
import { userErrorMessage } from "../lib/user-error-message.js";
|
||
import { reviewShortcut, reviewShortcutHelp } from "../lib/review-shortcuts.js";
|
||
import type { ReviewViewingProps, ReviewViewingController, ReviewPosition, ReviewNavigation } from "./review-viewing";
|
||
import { ReviewVideoCaption, ReviewCaptionDetails, type ReviewCaption } from "./ReviewCaptions";
|
||
import { reviewCaptionAtTime } from "../lib/review-captions.js";
|
||
import { DiscardReasonFields, type DiscardReasonChoice } from "./DiscardReasonFields";
|
||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||
import { cancelActionPartition, lastActionFrame, moveActionBoundary } from "../lib/action-frame-boundary.js";
|
||
import { actionJudgment } from "../lib/continuous-actions.js";
|
||
import { adjacentAnnotation } from "../lib/annotation-list-navigation.js";
|
||
import { WorkspaceDictionaryPanel } from "./WorkspaceDictionaryPanel";
|
||
import { SliceNameDictionaryPicker } from "./SliceNameDictionaryPicker";
|
||
import type { CSSProperties, 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 { AnnotationLabelRecord, AnnotationSegment, SemanticLabelDefinition, SliceSegment } from "../types";
|
||
import {
|
||
CAPTURE_PLAYBACK_RATES,
|
||
capturePlaybackBounds,
|
||
sliceDictionaryNameIssue,
|
||
annotationEventOverlaps,
|
||
annotationConfirmationInterval,
|
||
annotationSegmentsForSlice,
|
||
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 { cn } from "../lib/utils";
|
||
import { intervalStyle } from "../lib/timeline-viewport.js";
|
||
import {
|
||
annotationShortcut,
|
||
annotationShortcutHelpForContext,
|
||
dictionaryKeyDown,
|
||
stageConfirmationShortcut,
|
||
} from "../lib/annotation-shortcuts.js";
|
||
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;
|
||
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;
|
||
slices: SliceSegment[];
|
||
segments: AnnotationSegment[];
|
||
labels?: SemanticLabelDefinition[];
|
||
discardReasons?: AnnotationLabelRecord[];
|
||
discardReasonsLoading?: boolean;
|
||
discardReasonsAllowManual?: boolean;
|
||
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;
|
||
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;
|
||
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;
|
||
onDeleteSlice?: (sliceIndex: number) => void;
|
||
onMergeSliceBoundary?: (sliceId: string, direction: "shrink" | "expand") => void;
|
||
onConfirmSlices?: () => void;
|
||
canConfirmSlices?: boolean;
|
||
onConfirmAnnotations?: (
|
||
segments: AnnotationSegment[],
|
||
sliceId: string,
|
||
before?: AnnotationEditState,
|
||
) => Promise<boolean> | boolean | void;
|
||
problemSliceIds?: string[];
|
||
onProblemSliceIdsChange?: (ids: string[]) => void;
|
||
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 = (seconds: number) => {
|
||
// Convert once: subtracting integer seconds can turn 4.1 into a displayed
|
||
// 04.099 through floating-point cancellation. Preserve millisecond truncation.
|
||
const totalMilliseconds = Math.floor(Math.max(0, seconds) * 1000 + 1e-7);
|
||
const minutes = Math.floor(totalMilliseconds / 60000);
|
||
const wholeSeconds = Math.floor(totalMilliseconds / 1000) % 60;
|
||
const milliseconds = totalMilliseconds % 1000;
|
||
return `${String(minutes).padStart(2, "0")}:${String(wholeSeconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
|
||
};
|
||
|
||
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,
|
||
slices,
|
||
segments,
|
||
labels = [],
|
||
discardReasons = [],
|
||
discardReasonsLoading = false,
|
||
discardReasonsAllowManual = false,
|
||
discardReasonsError = "",
|
||
onRefreshDiscardReasons,
|
||
sliceDictionary = [],
|
||
sliceDictionaryLoading = false,
|
||
sliceDictionaryError = "",
|
||
onRefreshSliceDictionary,
|
||
statuses,
|
||
phase,
|
||
adaptiveLayout = false,
|
||
focusedLayout = false,
|
||
viewportSuspended = false,
|
||
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,
|
||
onReviewProblemNavigate,
|
||
onReviewTimestampJump,
|
||
reviewTimestampOpinions,
|
||
onReviewProblemEdit,
|
||
onReviewProblemDelete,
|
||
onReviewEscape,
|
||
reviewProblemPanel,
|
||
reviewComment = "",
|
||
onReviewCommentChange,
|
||
onApprove,
|
||
onReject,
|
||
reworkNotice,
|
||
onChange,
|
||
onPlayheadChange,
|
||
onDraftsChange,
|
||
onSliceNameChange,
|
||
onSliceDispositionChange,
|
||
onSliceBoundaryChange,
|
||
onSliceBoundaryEditStart,
|
||
onSliceBoundaryEditEnd,
|
||
onAnnotationEdit,
|
||
onAnnotationDraftEdit,
|
||
onHistoryCommand,
|
||
historyReveal,
|
||
onSplitSlice,
|
||
onDeleteSlice,
|
||
onMergeSliceBoundary,
|
||
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";
|
||
const readOnly = providedReadOnly || !timelineReady || (isQualityReview && reviewWriteLocked);
|
||
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 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 [playbackRate, setPlaybackRate] = useState(1);
|
||
const [showLeft, setShowLeft] = useState(initialCameraVisibility?.left ?? true);
|
||
const [showRight, setShowRight] = useState(initialCameraVisibility?.right ?? Boolean(rightVideoSource));
|
||
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);
|
||
const [splitPreview, setSplitPreview] = useState<SplitPreview>(null);
|
||
const [editingAnnotation, setEditingAnnotation] = useState<AnnotationSegment | null>(null);
|
||
const [parkedEditors, setParkedEditors] = useState<Record<string, SliceEditor>>({});
|
||
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]);
|
||
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) && (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]);
|
||
|
||
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 captionViewKey = `${source}:${rightSource}:${effectiveShowLeft}:${effectiveShowRight}:${focusedLayout}:${inspectionCamera}`;
|
||
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 sliceTimelineStart = clipStart;
|
||
const sliceTimelineEnd = 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 (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 (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 : time - clipStart),
|
||
[clipStart, sourceIsFullVideo],
|
||
);
|
||
const toRightMedia = useCallback(
|
||
(time: number) =>
|
||
sourceIsFullVideo && unifiedBoundaries
|
||
? mapCameraBoundaryTime(frameBoundaries, rightMediaBoundaries, time)
|
||
: toMedia(time),
|
||
[sourceIsFullVideo, unifiedBoundaries, frameBoundaries, rightMediaBoundaries, toMedia],
|
||
);
|
||
|
||
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 : clipStart + time),
|
||
fromRight: (time) =>
|
||
sourceIsFullVideo && unifiedBoundaries
|
||
? mapCameraBoundaryTime(rightMediaBoundaries, frameBoundaries, time)
|
||
: 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) => {
|
||
if (saving || !timelineReady || phase === "materializing") 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]);
|
||
|
||
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) => {
|
||
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);
|
||
};
|
||
|
||
const beginSliceBoundaryDrag = (event: ReactPointerEvent<HTMLButtonElement>, index: number) => {
|
||
if (readOnly || saving || phase !== "slice" || !sliceTrackRef.current) 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 (!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;
|
||
onSliceBoundaryEditEnd?.();
|
||
transport.finishScrub();
|
||
focusWorkbench();
|
||
};
|
||
|
||
const insertSlice = (index: number, time: number) => {
|
||
if (readOnly || isQualityReview || saving || phase !== "slice") 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 = 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 (
|
||
!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 (!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("旧切片边界未对齐统一帧边界,请确认重新切片后再标注;不会自动移动已有描述。");
|
||
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 (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 (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();
|
||
};
|
||
|
||
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, isReviewViewing ? "start" : "end");
|
||
};
|
||
|
||
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,
|
||
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,
|
||
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) => {
|
||
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" && onDeleteSlice && slices.length > 1 && target && neighbor);
|
||
};
|
||
const deleteSliceAtIndex = (index: number) => {
|
||
if (!canDeleteSliceAtIndex(index)) 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) => {
|
||
if (saving || readOnly || isQualityReview || mediaOnly || phase !== "slice" || !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 (viewportSuspended || saving || showDictionary || stageConfirmation) stopBoundaryHold();
|
||
}, [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") onSliceBoundaryEditEnd?.();
|
||
else if (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;
|
||
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 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-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;
|
||
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]")),
|
||
},
|
||
);
|
||
if (!command) return;
|
||
event.preventDefault();
|
||
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-problem" || command === "next-problem")
|
||
onReviewProblemNavigate?.(command === "previous-problem" ? -1 : 1);
|
||
else if (command === "jump-timestamp-problem") onReviewTimestampJump?.();
|
||
else if (command === "edit-problem") onReviewProblemEdit?.();
|
||
else if (command === "delete-problem") onReviewProblemDelete?.();
|
||
}
|
||
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,
|
||
},
|
||
);
|
||
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 (canEdit) {
|
||
if (action === "adjust-boundary") startBoundaryHold(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();
|
||
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();
|
||
}
|
||
}
|
||
}}
|
||
>
|
||
{continuousActions && phase === "annotate" && !selectedDiscarded && (
|
||
<aside className="capture-action-list" aria-label="当前切片动作列表">
|
||
<strong>动作 · {annotationForRender.length}</strong>
|
||
<div ref={actionListRef} role="listbox" aria-label="动作区间" className="capture-action-list-scroll">
|
||
{annotationForRender.map((action, index) => (
|
||
<button
|
||
key={action.id}
|
||
type="button"
|
||
role="option"
|
||
aria-selected={editingAnnotation?.id === action.id}
|
||
onClick={() => seekAnnotation(action, "end")}
|
||
>
|
||
<span className={action.status === "needs-check" ? "font-semibold text-amber-600 dark:text-amber-400" : undefined}>
|
||
#{index + 1} ·{" "}
|
||
{action.status === "needs-check"
|
||
? "待核对(边界拆分)"
|
||
: 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 (slice) selectSlice(slice);
|
||
}}
|
||
>
|
||
{slice?.name || draft.sliceId} · {draft.selectingEnd ? "尚未确认结束点" : "描述尚未保存"}
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
) : (
|
||
<div className="mt-3 space-y-2 text-sm">
|
||
<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>
|
||
{(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>
|
||
<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 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">
|
||
{readOnlyStatusLabel}(只读查看)
|
||
</span>
|
||
</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">
|
||
质检审核模式{readOnly ? "(只读查看)" : ""}
|
||
</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 && (
|
||
<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>
|
||
)}
|
||
<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)]">
|
||
{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)}
|
||
>
|
||
{!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>
|
||
)}
|
||
{reviewCaption && (
|
||
<>
|
||
<ReviewVideoCaption
|
||
videoRef={leftVideoRef}
|
||
surfaceRef={videoSurfaceRef}
|
||
caption={reviewCaption}
|
||
viewKey={captionViewKey}
|
||
camera="left"
|
||
/>
|
||
{rightSource && (
|
||
<ReviewVideoCaption
|
||
videoRef={rightVideoRef}
|
||
surfaceRef={videoSurfaceRef}
|
||
caption={reviewCaption}
|
||
viewKey={captionViewKey}
|
||
camera="right"
|
||
/>
|
||
)}
|
||
</>
|
||
)}
|
||
{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}
|
||
</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 && (
|
||
<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="Capture 播放位置"
|
||
min={clipStart}
|
||
max={clipEnd}
|
||
step="any"
|
||
value={currentTime}
|
||
{...sliderEvents}
|
||
style={{ "--played": 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={reviewWriteLocked}
|
||
onClick={() => {
|
||
if (reviewProblemPanel) {
|
||
onReviewProblem?.({ ...reviewPosition, actionId: null });
|
||
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}
|
||
<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) => `${o.atSeconds.toFixed(2)}s ${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"
|
||
>
|
||
{o.atSeconds.toFixed(2)}s {o.text}
|
||
</button>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
));
|
||
})()}
|
||
</div>
|
||
)}
|
||
<div className="timeline-block-track capture-slice-blocks absolute inset-x-0 top-4 h-16">
|
||
{visibleSlices.map((slice) => {
|
||
const index = slices.findIndex((item) => item.id === slice.id);
|
||
const style = intervalStyle(slice.start, slice.end, sliceTimelineStart, sliceTimelineEnd);
|
||
const selected = slice.id === selectedSlice.id;
|
||
return (
|
||
<div
|
||
key={slice.id}
|
||
data-slice-id={slice.id}
|
||
data-selected={selected || 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],
|
||
selected && "ring-2 ring-orange-400 ring-offset-1",
|
||
phase === "annotate" && "cursor-pointer",
|
||
)}
|
||
onMouseMove={(event) => {
|
||
if (phase !== "slice" || readOnly || !sliceTrackRef.current) 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)}
|
||
>
|
||
<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>
|
||
<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" && !readOnly ? (
|
||
<button
|
||
type="button"
|
||
aria-label="删除切片"
|
||
disabled={!canDeleteSliceAtIndex(index)}
|
||
title="取消切分,合并后重新定义"
|
||
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" && index < slices.length - 1 ? (
|
||
<button
|
||
type="button"
|
||
aria-label="拖动切片边界"
|
||
disabled={readOnly || saving}
|
||
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" && 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}
|
||
<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>
|
||
{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">
|
||
({(selectedSlice.end - selectedSlice.start).toFixed(2)}s)
|
||
</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}
|
||
</>
|
||
)}
|
||
</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)} · 时长{" "}
|
||
{(selectedSlice.end - selectedSlice.start).toFixed(2)}s)
|
||
</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)))),
|
||
);
|
||
const activeComment = isQualityReview ? qaCommentForThis : reworkCommentForThis;
|
||
const isFlaggedProblem = Boolean(activeComment);
|
||
const isInvalidSegment = Boolean(
|
||
segment.isInvalid || segment.description === "无效片段" || segment.label === "无效片段",
|
||
);
|
||
|
||
return (
|
||
<div
|
||
key={segment.id}
|
||
data-annotation-block
|
||
data-annotation-id={segment.id}
|
||
data-selected={editingAnnotation?.id === segment.id || 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],
|
||
editingAnnotation?.id === segment.id && "ring-2 ring-orange-500 shadow-md",
|
||
)}
|
||
style={intervalStyle(
|
||
segment.start,
|
||
segment.end,
|
||
descriptionTimelineStart,
|
||
descriptionTimelineEnd,
|
||
)}
|
||
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();
|
||
if (continuousActions || isReviewViewing)
|
||
seekAnnotation(segment, isReviewViewing ? "start" : "end");
|
||
else {
|
||
selectDescription(segment);
|
||
focusWorkbench();
|
||
}
|
||
}}
|
||
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" />
|
||
{activeComment?.tag || "问题"}
|
||
</span>
|
||
)}
|
||
<span className="font-mono text-[10px] text-slate-500">
|
||
{(segment.end - segment.start).toFixed(2)}s
|
||
</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">
|
||
{(hoveredSegment.segment.end - hoveredSegment.segment.start).toFixed(2)}s
|
||
</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)} (时长{" "}
|
||
{(editingAnnotation.end - editingAnnotation.start).toFixed(2)}s)
|
||
</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)} (时长{" "}
|
||
{(editingAnnotation.end - editingAnnotation.start).toFixed(2)}s)
|
||
</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 */}
|
||
{!readOnly || 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={reviewWriteLocked}
|
||
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={reviewWriteLocked}
|
||
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={reviewWriteLocked}
|
||
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}
|
||
</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}
|
||
onClick={() => void onHistoryCommand?.("undo")}
|
||
className="rounded border px-3 py-1 text-xs"
|
||
title="撤销(Ctrl / ⌘ + Z)"
|
||
>
|
||
撤销
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={saving || readOnly}
|
||
onClick={() => void onHistoryCommand?.("redo")}
|
||
className="rounded border px-3 py-1 text-xs"
|
||
title="重做(Ctrl / ⌘ + Shift + Z)"
|
||
>
|
||
重做
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
{isQualityReview && !readOnly ? (
|
||
<>
|
||
<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={() => {
|
||
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 ? (
|
||
<>
|
||
<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>
|
||
</>
|
||
) : (
|
||
<>
|
||
<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="mr-auto text-xs text-slate-500">重新切片将删除全部已有标注</span>
|
||
|
||
{!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="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 ? (
|
||
<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(() => 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}
|
||
</section>
|
||
);
|
||
}
|