Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

Merge remote-tracking branch 'origin/main' into feat/settings-extensions

webadderall16c6204af287
diff --cc src/components/video-editor/timeline/TimelineEditor.tsx
index 7d61a190,3336ce96..e1438824
--- a/src/components/video-editor/timeline/TimelineEditor.tsx
+++ b/src/components/video-editor/timeline/TimelineEditor.tsx
@@@ -63,13 -62,48 +64,50 @@@ import { type AudioPeaksData, useAudioP
import { buildInteractionZoomSuggestions } from "./zoomSuggestionUtils";
const ZOOM_ROW_ID = "row-zoom";
+const TRIM_ROW_ID = "row-trim";
const CLIP_ROW_ID = "row-clip";
const ANNOTATION_ROW_ID = "row-annotation";
+const SPEED_ROW_ID = "row-speed";
const AUDIO_ROW_ID = "row-audio";
+ const ANNOTATION_ROW_PREFIX = `${ANNOTATION_ROW_ID}-`;
+ const AUDIO_ROW_PREFIX = "row-audio-";
const FALLBACK_RANGE_MS = 1000;
const TARGET_MARKER_COUNT = 12;
+
+ function getAnnotationTrackRowId(trackIndex: number) {
+ return `${ANNOTATION_ROW_ID}-${Math.max(0, Math.floor(trackIndex))}`;
+ }
+
+ function isAnnotationTrackRowId(rowId: string) {
+ return rowId === ANNOTATION_ROW_ID || rowId.startsWith(ANNOTATION_ROW_PREFIX);
+ }
+
+ function getAnnotationTrackIndex(rowId: string) {
+ if (rowId === ANNOTATION_ROW_ID) {
+ return 0;
+ }
+
+ const parsed = Number.parseInt(rowId.slice(ANNOTATION_ROW_PREFIX.length), 10);
+ return Number.isFinite(parsed) ? Math.max(0, parsed) : 0;
+ }
+
+ function getAudioTrackRowId(trackIndex: number) {
+ return `${AUDIO_ROW_PREFIX}${Math.max(0, Math.floor(trackIndex))}`;
+ }
+
+ function isAudioTrackRowId(rowId: string) {
+ return rowId === AUDIO_ROW_ID || rowId.startsWith(AUDIO_ROW_PREFIX);
+ }
+
+ function getAudioTrackIndex(rowId: string) {
+ if (rowId === AUDIO_ROW_ID) {
+ return 0;
+ }
+
+ const parsed = Number.parseInt(rowId.slice(AUDIO_ROW_PREFIX.length), 10);
+ return Number.isFinite(parsed) ? Math.max(0, parsed) : 0;
+ }
+
interface TimelineEditorProps {
videoDuration: number;
currentTime: number;
@@@ -591,12 -785,29 +630,32 @@@ function Timeline(
);
const zoomItems = items.filter((item) => item.rowId === ZOOM_ROW_ID);
+ const trimItems = items.filter((item) => item.rowId === TRIM_ROW_ID);
+
const clipItems = items.filter((item) => item.rowId === CLIP_ROW_ID);
- const annotationItems = items.filter((item) => item.rowId === ANNOTATION_ROW_ID);
+ const annotationItems = items.filter((item) => isAnnotationTrackRowId(item.rowId));
+ const speedItems = items.filter((item) => item.rowId === SPEED_ROW_ID);
- const audioItems = items.filter((item) => item.rowId === AUDIO_ROW_ID);
+ const audioItems = items.filter((item) => isAudioTrackRowId(item.rowId));
+ const audioRowIds = useMemo(
+ () =>
+ Array.from(
+ new Set(
+ audioItems.map((item) => getAudioTrackRowId(getAudioTrackIndex(item.rowId))),
+ ),
+ ).sort((left, right) => getAudioTrackIndex(left) - getAudioTrackIndex(right)),
+ [audioItems],
+ );
+ const annotationRowIds = useMemo(
+ () =>
+ Array.from(
+ new Set(
+ annotationItems.map((item) =>
+ getAnnotationTrackRowId(getAnnotationTrackIndex(item.rowId)),
+ ),
+ ),
+ ).sort((left, right) => getAnnotationTrackIndex(left) - getAnnotationTrackIndex(right)),
+ [annotationItems],
+ );
return (
<div
@@@ -631,101 -856,93 +690,125 @@@
{item.label}
</Item>
))}
- </Track>
-
- {!hiddenTrackIds?.has(ZOOM_ROW_ID) && (
- <Track
- id={ZOOM_ROW_ID}
- isEmpty={zoomItems.length === 0}
- hint="Press Z to add zoom"
- trackStyle={{ background: "transparent" }}
- >
- {zoomItems.map((item) => (
- <Item
- id={item.id}
- key={item.id}
- rowId={item.rowId}
- span={item.span}
- isSelected={selectAllBlocksActive || item.id === selectedZoomId}
- onSelect={() => onSelectZoom?.(item.id)}
- zoomDepth={item.zoomDepth}
- zoomMode={item.zoomMode}
- variant="zoom"
- >
- {item.label}
- </Item>
- ))}
- </Track>
- )}
+ </Row>
- {!hiddenTrackIds?.has(ANNOTATION_ROW_ID) &&
- annotationRowIds.map((rowId) => {
- const rowItems = annotationItems.filter(
- (item) =>
- getAnnotationTrackRowId(getAnnotationTrackIndex(item.rowId)) ===
- rowId,
- );
-
- return (
- <Track key={rowId} id={rowId} isEmpty={false}>
- {rowItems.map((item) => (
- <Item
- id={item.id}
- key={item.id}
- rowId={item.rowId}
- span={item.span}
- isSelected={
- selectAllBlocksActive ||
- item.id === selectedAnnotationId
- }
- onSelect={() => onSelectAnnotation?.(item.id)}
- variant="annotation"
- >
- {item.label}
- </Item>
- ))}
- </Track>
- );
- })}
-
- {!hiddenTrackIds?.has(AUDIO_ROW_ID) &&
- audioRowIds.map((rowId) => {
- const rowItems = audioItems.filter(
- (item) => getAudioTrackRowId(getAudioTrackIndex(item.rowId)) === rowId,
- );
- return (
- <Track
- key={rowId}
- id={rowId}
- isEmpty={false}
- trackStyle={{ background: "rgba(255,255,255,0.054)" }}
- >
- {rowItems.map((item) => (
- <Item
- id={item.id}
- key={item.id}
- rowId={item.rowId}
- span={item.span}
- isSelected={
- selectAllBlocksActive || item.id === selectedAudioId
- }
- onSelect={() => onSelectAudio?.(item.id)}
- variant="audio"
- >
- {item.label}
- </Item>
- ))}
- </Track>
- );
- })}
+ <Row id={TRIM_ROW_ID} isEmpty={trimItems.length === 0} hint="Press T to add trim">
+ {trimItems.map((item) => (
+ <Item
+ id={item.id}
+ key={item.id}
+ rowId={item.rowId}
+ span={item.span}
+ isSelected={selectAllBlocksActive || item.id === _selectedTrimId}
+ onSelect={() => onSelectTrim?.(item.id)}
+ variant="trim"
+ >
+ {item.label}
+ </Item>
+ ))}
+ </Row>
+
+ <Row id={ZOOM_ROW_ID} isEmpty={zoomItems.length === 0} hint="Press Z to add zoom">
+ {zoomItems.map((item) => (
+ <Item
+ id={item.id}
+ key={item.id}
+ rowId={item.rowId}
+ span={item.span}
+ isSelected={selectAllBlocksActive || item.id === selectedZoomId}
+ onSelect={() => onSelectZoom?.(item.id)}
+ zoomDepth={item.zoomDepth}
++ zoomMode={item.zoomMode}
+ variant="zoom"
+ >
+ {item.label}
+ </Item>
+ ))}
+ </Row>
+
+ <Row
+ id={SPEED_ROW_ID}
+ isEmpty={speedItems.length === 0}
+ hint="Press S to add speed"
+ >
+ {speedItems.map((item) => (
+ <Item
+ id={item.id}
+ key={item.id}
+ rowId={item.rowId}
+ span={item.span}
+ isSelected={selectAllBlocksActive || item.id === _selectedSpeedId}
+ onSelect={() => onSelectSpeed?.(item.id)}
+ speedValue={item.speedValue}
+ variant="speed"
+ >
+ {item.label}
+ </Item>
+ ))}
+ </Row>
+
- <Row
- id={ANNOTATION_ROW_ID}
- isEmpty={annotationItems.length === 0}
- hint="Press A to add annotation"
- >
- {annotationItems.map((item) => (
- <Item
- id={item.id}
- key={item.id}
- rowId={item.rowId}
- span={item.span}
- isSelected={selectAllBlocksActive || item.id === selectedAnnotationId}
- onSelect={() => onSelectAnnotation?.(item.id)}
- variant="annotation"
++ {annotationRowIds.map((rowId, index) => {
++ const rowItems = annotationItems.filter(
++ (item) =>
++ getAnnotationTrackRowId(getAnnotationTrackIndex(item.rowId)) === rowId,
++ );
++
++ return (
++ <Row
++ key={rowId}
++ id={rowId}
++ isEmpty={rowItems.length === 0}
++ hint={index === 0 ? "Press A to add annotation" : undefined}
+ >
- {item.label}
- </Item>
- ))}
- </Row>
-
- <Row
- id={AUDIO_ROW_ID}
- isEmpty={audioItems.length === 0}
- hint="Click music icon to add audio"
- >
- {audioItems.map((item) => (
- <Item
- id={item.id}
- key={item.id}
- rowId={item.rowId}
- span={item.span}
- isSelected={selectAllBlocksActive || item.id === selectedAudioId}
- onSelect={() => onSelectAudio?.(item.id)}
- variant="audio"
++ {rowItems.map((item) => (
++ <Item
++ id={item.id}
++ key={item.id}
++ rowId={item.rowId}
++ span={item.span}
++ isSelected={
++ selectAllBlocksActive || item.id === selectedAnnotationId
++ }
++ onSelect={() => onSelectAnnotation?.(item.id)}
++ variant="annotation"
++ >
++ {item.label}
++ </Item>
++ ))}
++ </Row>
++ );
++ })}
++
++ {audioRowIds.map((rowId, index) => {
++ const rowItems = audioItems.filter(
++ (item) => getAudioTrackRowId(getAudioTrackIndex(item.rowId)) === rowId,
++ );
++
++ return (
++ <Row
++ key={rowId}
++ id={rowId}
++ isEmpty={rowItems.length === 0}
++ hint={index === 0 ? "Click music icon to add audio" : undefined}
+ >
- {item.label}
- </Item>
- ))}
- </Row>
++ {rowItems.map((item) => (
++ <Item
++ id={item.id}
++ key={item.id}
++ rowId={item.rowId}
++ span={item.span}
++ isSelected={
++ selectAllBlocksActive || item.id === selectedAudioId
++ }
++ onSelect={() => onSelectAudio?.(item.id)}
++ variant="audio"
++ >
++ {item.label}
++ </Item>
++ ))}
++ </Row>
++ );
++ })}
</div>
</div>
);
@@@ -1737,10 -1970,10 +1821,10 @@@ const TimelineEditor = forwardRef<Timel
id: r.id,
start: r.startMs,
end: r.endMs,
- rowId: AUDIO_ROW_ID,
+ rowId: getAudioTrackRowId(r.trackIndex ?? 0),
}));
- return [...zooms, ...clips, ...audios];
- }, [zoomRegions, clipRegions, audioRegions]);
+ return [...zooms, ...trims, ...clips, ...speeds, ...audios];
+ }, [zoomRegions, trimRegions, clipRegions, speedRegions, audioRegions]);
const handleItemSpanChange = useCallback(
(id: string, span: Span) => {