Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/studio`: Add drag reordering for Series clips and tracks

Jonny Burger312ace9a6aef
diff --git a/packages/example/src/TrackPrototype.tsx b/packages/example/src/TrackPrototype.tsx
index 18416c6469..124c62d94c 100644
--- a/packages/example/src/TrackPrototype.tsx
+++ b/packages/example/src/TrackPrototype.tsx
@@ -10,42 +10,6 @@ import {
useVideoConfig,
} from 'remotion';
-const DemoCard: React.FC<{
- readonly title: string;
- readonly description: string;
- readonly children: React.ReactNode;
-}> = ({title, description, children}) => {
- return (
- <div>
- <div style={{fontSize: 21, fontWeight: 600, marginBottom: 5}}>
- {title}
- </div>
- <div
- style={{
- fontSize: 15,
- lineHeight: '19px',
- minHeight: 38,
- color: '#a7b0c0',
- marginBottom: 12,
- }}
- >
- {description}
- </div>
- <div
- style={{
- position: 'relative',
- height: 128,
- overflow: 'hidden',
- borderRadius: 12,
- backgroundColor: '#202936',
- }}
- >
- {children}
- </div>
- </div>
- );
-};
-
const Scene: React.FC<{
readonly color: string;
readonly children: React.ReactNode;
@@ -90,8 +54,6 @@ const Flash: React.FC = () => {
};
export const TrackPrototype: React.FC = () => {
- const frame = useCurrentFrame();
-
return (
<div
style={{
@@ -100,203 +62,137 @@ export const TrackPrototype: React.FC = () => {
backgroundColor: '#101720',
color: 'white',
fontFamily: 'Arial, sans-serif',
- padding: 40,
}}
>
- <div style={{display: 'flex', justifyContent: 'space-between'}}>
- <div style={{fontSize: 36, fontWeight: 700}}>Track prototype</div>
- <div
- style={{
- fontSize: 22,
- color: '#a7b0c0',
- fontVariantNumeric: 'tabular-nums',
- }}
- >
- Frame {frame} / 239
- </div>
- </div>
- <div style={{fontSize: 18, color: '#a7b0c0', marginTop: 8}}>
- One scene row per Track. Overlapping overlays add auxiliary rows.
- </div>
- <div
- style={{
- display: 'grid',
- gridTemplateColumns: '1fr 1fr 1fr',
- gap: '32px 24px',
- marginTop: 30,
- }}
- >
- <DemoCard
- title="Series"
- description="Automatically one row: 80 + 54 + 80 = 214 frames."
- >
- <Series name="Series">
- <Series.Sequence name="Series A" durationInFrames={80}>
- <Scene color="#3268a8">A</Scene>
- </Series.Sequence>
- <Series.Sequence name="Series B" durationInFrames={54}>
- <Scene color="#6a4daf">B</Scene>
- </Series.Sequence>
- <Series.Sequence name="Series C" durationInFrames={80}>
- <Scene color="#a34777">C</Scene>
- </Series.Sequence>
- </Series>
- </DemoCard>
- <DemoCard
- title="TransitionSeries"
- description="90-frame clips with 15-frame fades: 240 frames total."
- >
- <TransitionSeries name="Transitions">
- <TransitionSeries.Sequence name="Fade A" durationInFrames={90}>
- <Scene color="#327e79">A</Scene>
- </TransitionSeries.Sequence>
- <TransitionSeries.Transition
- presentation={fade()}
- timing={linearTiming({durationInFrames: 15})}
- />
- <TransitionSeries.Sequence name="Fade B" durationInFrames={90}>
- <Scene color="#967130">B</Scene>
- </TransitionSeries.Sequence>
- <TransitionSeries.Transition
- presentation={fade()}
- timing={linearTiming({durationInFrames: 15})}
- />
- <TransitionSeries.Sequence name="Fade C" durationInFrames={90}>
- <Scene color="#a34a43">C</Scene>
- </TransitionSeries.Sequence>
- </TransitionSeries>
- </DemoCard>
- <DemoCard
- title="Overlays sharing a row"
- description="Frames 68–91 and 168–191 share one auxiliary row."
- >
- <TransitionSeries name="Nonoverlapping overlays">
- <TransitionSeries.Sequence name="Overlay A" durationInFrames={80}>
- <Scene color="#436582">A</Scene>
- </TransitionSeries.Sequence>
- <TransitionSeries.Overlay durationInFrames={24}>
- <Flash />
- </TransitionSeries.Overlay>
- <TransitionSeries.Sequence name="Overlay B" durationInFrames={80}>
- <Scene color="#774e90">B</Scene>
- </TransitionSeries.Sequence>
- <TransitionSeries.Overlay durationInFrames={24} offset={20}>
- <Flash />
- </TransitionSeries.Overlay>
- <TransitionSeries.Sequence name="Overlay C" durationInFrames={80}>
- <Scene color="#8f5f48">C</Scene>
- </TransitionSeries.Sequence>
- </TransitionSeries>
- </DemoCard>
- <DemoCard
- title="Overlapping overlays"
- description="Both effects appear on frames 80–119: three timeline rows."
- >
- <TransitionSeries name="Overlapping overlays">
- <TransitionSeries.Sequence name="Scene A" durationInFrames={80}>
- <Scene color="#355c6e">A</Scene>
- </TransitionSeries.Sequence>
- <TransitionSeries.Overlay durationInFrames={80}>
- <div
- style={{
- position: 'absolute',
- top: 12,
- left: 12,
- padding: '8px 12px',
- borderRadius: 6,
- backgroundColor: '#7de1c0',
- color: '#102e24',
- fontSize: 18,
- fontWeight: 600,
- }}
- >
- Overlay 1 Β· 40–119
- </div>
- </TransitionSeries.Overlay>
- <TransitionSeries.Sequence
- name="Short scene B"
- durationInFrames={40}
- >
- <Scene color="#44566e">B</Scene>
- </TransitionSeries.Sequence>
- <TransitionSeries.Overlay durationInFrames={80}>
- <div
- style={{
- position: 'absolute',
- bottom: 12,
- right: 12,
- padding: '8px 12px',
- borderRadius: 6,
- backgroundColor: '#f1c27a',
- color: '#392710',
- fontSize: 18,
- fontWeight: 600,
- }}
- >
- Overlay 2 Β· 80–159
- </div>
- </TransitionSeries.Overlay>
- <TransitionSeries.Sequence name="Scene C" durationInFrames={120}>
- <Scene color="#6b526e">C</Scene>
- </TransitionSeries.Sequence>
- </TransitionSeries>
- </DemoCard>
- <DemoCard
- title="Negative offsets"
- description="20-frame overlaps stay on the scene row; later clips cover earlier clips."
- >
- <Series name="Overlapping clips">
- <Series.Sequence name="Overlap A" durationInFrames={100}>
- <Scene color="#517345">A</Scene>
- </Series.Sequence>
- <Series.Sequence
- name="Overlap B"
- durationInFrames={100}
- offset={-20}
- >
- <Scene color="#92742d">B</Scene>
- </Series.Sequence>
- <Series.Sequence
- name="Overlap C"
- durationInFrames={80}
- offset={-20}
- >
- <Scene color="#a15437">C</Scene>
- </Series.Sequence>
- </Series>
- </DemoCard>
- <DemoCard
- title="Caption tokens"
- description="All eight clips stay registered while one word is visible."
- >
- <Track name="Caption tokens">
- <Sequence name="Every" durationInFrames={30}>
- <Scene color="#27354a">Every</Scene>
- </Sequence>
- <Sequence name="caption" from={30} durationInFrames={30}>
- <Scene color="#27354a">caption</Scene>
- </Sequence>
- <Sequence name="token" from={60} durationInFrames={30}>
- <Scene color="#27354a">token</Scene>
- </Sequence>
- <Sequence name="stays" from={90} durationInFrames={30}>
- <Scene color="#27354a">stays</Scene>
- </Sequence>
- <Sequence name="visible" from={120} durationInFrames={30}>
- <Scene color="#27354a">visible</Scene>
- </Sequence>
- <Sequence name="in" from={150} durationInFrames={30}>
- <Scene color="#27354a">in</Scene>
- </Sequence>
- <Sequence name="one" from={180} durationInFrames={30}>
- <Scene color="#27354a">one</Scene>
- </Sequence>
- <Sequence name="track" from={210} durationInFrames={30}>
- <Scene color="#27354a">track</Scene>
- </Sequence>
- </Track>
- </DemoCard>
- </div>
+ <Series name="Series">
+ <Series.Sequence name="Series A" durationInFrames={80}>
+ <Scene color="#3268a8">A</Scene>
+ </Series.Sequence>
+ <Series.Sequence name="Series C" durationInFrames={80}>
+ <Scene color="#a34777">C</Scene>
+ </Series.Sequence>
+ <Series.Sequence name="Series B" durationInFrames={54}>
+ <Scene color="#6a4daf">B</Scene>
+ </Series.Sequence>
+ </Series>
+ <TransitionSeries name="Transitions">
+ <TransitionSeries.Sequence name="Fade A" durationInFrames={90}>
+ <Scene color="#327e79">A</Scene>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={fade()}
+ timing={linearTiming({durationInFrames: 15})}
+ />
+ <TransitionSeries.Sequence name="Fade B" durationInFrames={90}>
+ <Scene color="#967130">B</Scene>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={fade()}
+ timing={linearTiming({durationInFrames: 15})}
+ />
+ <TransitionSeries.Sequence name="Fade C" durationInFrames={90}>
+ <Scene color="#a34a43">C</Scene>
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ <TransitionSeries name="Nonoverlapping overlays">
+ <TransitionSeries.Sequence name="Overlay A" durationInFrames={80}>
+ <Scene color="#436582">A</Scene>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Overlay durationInFrames={24}>
+ <Flash />
+ </TransitionSeries.Overlay>
+ <TransitionSeries.Sequence name="Overlay B" durationInFrames={80}>
+ <Scene color="#774e90">B</Scene>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Overlay durationInFrames={24} offset={20}>
+ <Flash />
+ </TransitionSeries.Overlay>
+ <TransitionSeries.Sequence name="Overlay C" durationInFrames={80}>
+ <Scene color="#8f5f48">C</Scene>
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ <TransitionSeries name="Overlapping overlays">
+ <TransitionSeries.Sequence name="Scene A" durationInFrames={80}>
+ <Scene color="#355c6e">A</Scene>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Overlay durationInFrames={80}>
+ <div
+ style={{
+ position: 'absolute',
+ top: 12,
+ left: 12,
+ padding: '8px 12px',
+ borderRadius: 6,
+ backgroundColor: '#7de1c0',
+ color: '#102e24',
+ fontSize: 18,
+ fontWeight: 600,
+ }}
+ >
+ Overlay 1 Β· 40–119
+ </div>
+ </TransitionSeries.Overlay>
+ <TransitionSeries.Sequence name="Short scene B" durationInFrames={40}>
+ <Scene color="#44566e">B</Scene>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Overlay durationInFrames={80}>
+ <div
+ style={{
+ position: 'absolute',
+ bottom: 12,
+ right: 12,
+ padding: '8px 12px',
+ borderRadius: 6,
+ backgroundColor: '#f1c27a',
+ color: '#392710',
+ fontSize: 18,
+ fontWeight: 600,
+ }}
+ >
+ Overlay 2 Β· 80–159
+ </div>
+ </TransitionSeries.Overlay>
+ <TransitionSeries.Sequence name="Scene C" durationInFrames={120}>
+ <Scene color="#6b526e">C</Scene>
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ <Series name="Overlapping clips">
+ <Series.Sequence name="Overlap A" durationInFrames={100}>
+ <Scene color="#517345">A</Scene>
+ </Series.Sequence>
+ <Series.Sequence name="Overlap B" durationInFrames={100} offset={-20}>
+ <Scene color="#92742d">B</Scene>
+ </Series.Sequence>
+ <Series.Sequence name="Overlap C" durationInFrames={80} offset={-20}>
+ <Scene color="#a15437">C</Scene>
+ </Series.Sequence>
+ </Series>
+ <Track name="Caption tokens">
+ <Sequence name="Every" durationInFrames={30}>
+ <Scene color="#27354a">Every</Scene>
+ </Sequence>
+ <Sequence name="caption" from={30} durationInFrames={30}>
+ <Scene color="#27354a">caption</Scene>
+ </Sequence>
+ <Sequence name="token" from={60} durationInFrames={30}>
+ <Scene color="#27354a">token</Scene>
+ </Sequence>
+ <Sequence name="stays" from={90} durationInFrames={30}>
+ <Scene color="#27354a">stays</Scene>
+ </Sequence>
+ <Sequence name="visible" from={120} durationInFrames={30}>
+ <Scene color="#27354a">visible</Scene>
+ </Sequence>
+ <Sequence name="in" from={150} durationInFrames={30}>
+ <Scene color="#27354a">in</Scene>
+ </Sequence>
+ <Sequence name="one" from={180} durationInFrames={30}>
+ <Scene color="#27354a">one</Scene>
+ </Sequence>
+ <Sequence name="track" from={210} durationInFrames={30}>
+ <Scene color="#27354a">track</Scene>
+ </Sequence>
+ </Track>
</div>
);
};
diff --git a/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx b/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx
index 96c89a17f8..165c0eb14e 100644
--- a/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx
+++ b/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx
@@ -236,6 +236,7 @@ export const MultiSequenceField: React.FC<{
showSelectedBackground={false}
containsSelection={false}
outerHeight={null}
+ showBottomBorder={false}
>
<TimelineFieldRowContent field={field} rowDepth={0} selected={false}>
{content}
diff --git a/packages/studio/src/components/Timeline/TimelineEffectItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
index 223997c1a4..7c24d0afe5 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
@@ -545,6 +545,7 @@ export const TimelineEffectItem: React.FC<{
showSelectedBackground
containsSelection={containsSelection}
outerHeight={null}
+ showBottomBorder={false}
>
<div style={labelContainerStyle}>
<span role="group" aria-label={label} style={labelStyle}>
diff --git a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
index b65706f763..ae14f4e2f2 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
@@ -684,6 +684,7 @@ export const TimelineEffectPropItem: React.FC<{
showSelectedBackground
containsSelection={containsSelection}
outerHeight={null}
+ showBottomBorder={false}
>
<TimelineFieldRowContent
field={field}
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
index 3387d289d0..081df123a3 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
@@ -128,6 +128,7 @@ const TimelineExpandedRowInner: React.FC<TimelineExpandedRowProps> = ({
showSelectedBackground
containsSelection={containsSelection}
outerHeight={null}
+ showBottomBorder={false}
>
<span style={labelStyle}>{node.label}</span>
</TimelineRowChrome>
@@ -188,6 +189,7 @@ const TimelineExpandedRowInner: React.FC<TimelineExpandedRowProps> = ({
showSelectedBackground
containsSelection={false}
outerHeight={null}
+ showBottomBorder={false}
>
<span style={labelStyle}>{node.label}</span>
</TimelineRowChrome>
diff --git a/packages/studio/src/components/Timeline/TimelineList.tsx b/packages/studio/src/components/Timeline/TimelineList.tsx
index 03016b89d0..01217cb932 100644
--- a/packages/studio/src/components/Timeline/TimelineList.tsx
+++ b/packages/studio/src/components/Timeline/TimelineList.tsx
@@ -1,11 +1,5 @@
import React from 'react';
-import {
- BACKGROUND,
- LIGHT_TEXT,
- TIMELINE_TRACK_SEPARATOR,
- WHITE_ALPHA_20,
-} from '../../helpers/colors';
-import {getTimelineRowLeftChromeWidth} from './timeline-row-layout';
+import {BACKGROUND, TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';
import {TIMELINE_PACKED_AUXILIARY_ROW_HEIGHT} from './timeline-track-groups';
import {TimelineSequenceItem} from './TimelineSequenceItem';
import {
@@ -29,6 +23,7 @@ const TimelineListTrack: React.FC<{
return (
<>
<TimelineSequenceItem
+ showBottomBorder={row.auxiliaryRows.length === 0}
afterDropLineOffset={afterDropLineOffset}
siblingIndex={siblingIndex}
connectedCompositions={
@@ -51,42 +46,13 @@ const TimelineListTrack: React.FC<{
/>
{row.auxiliaryRows.length > 0 ? (
<div
+ aria-hidden="true"
style={{
height:
row.auxiliaryRows.length * TIMELINE_PACKED_AUXILIARY_ROW_HEIGHT,
borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,
- paddingLeft: getTimelineRowLeftChromeWidth(track.depth) + 8,
- paddingRight: 8,
- position: 'relative',
- userSelect: 'none',
- WebkitUserSelect: 'none',
}}
- >
- <div
- aria-hidden="true"
- style={{
- position: 'absolute',
- top: 0,
- left: getTimelineRowLeftChromeWidth(track.depth) - 2,
- width: 6,
- height: TIMELINE_PACKED_AUXILIARY_ROW_HEIGHT / 2,
- borderLeft: `1px solid ${WHITE_ALPHA_20}`,
- borderBottom: `1px solid ${WHITE_ALPHA_20}`,
- }}
- />
- <div
- style={{
- color: LIGHT_TEXT,
- fontSize: 11,
- lineHeight: `${TIMELINE_PACKED_AUXILIARY_ROW_HEIGHT}px`,
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- whiteSpace: 'nowrap',
- }}
- >
- Overlays
- </div>
- </div>
+ />
) : null}
</>
);
diff --git a/packages/studio/src/components/Timeline/TimelinePackedTrack.tsx b/packages/studio/src/components/Timeline/TimelinePackedTrack.tsx
index 69a07d7faf..7da9aad8d5 100644
--- a/packages/studio/src/components/Timeline/TimelinePackedTrack.tsx
+++ b/packages/studio/src/components/Timeline/TimelinePackedTrack.tsx
@@ -7,6 +7,7 @@ import {
TIMELINE_PACKED_TRACK_HEIGHT,
} from './timeline-track-groups';
import {TimelineSequence} from './TimelineSequence';
+import {useSeriesReorder} from './use-series-reorder';
const noConnectedCompositions = [] as const;
const primaryRowHeight =
@@ -17,6 +18,8 @@ export const TimelinePackedTrack: React.FC<{
readonly items: readonly TimelineTrackWithDisplayGroup[];
readonly auxiliaryRows: readonly (readonly TimelineTrackWithDisplayGroup[])[];
}> = ({track, items, auxiliaryRows}) => {
+ const {dropIndicatorLeft, onClickCapture, onPointerDownCapture} =
+ useSeriesReorder(items);
const labelStartFrames = useMemo(() => {
const starts = new Map<string, number>();
let precedingTransition: TimelineTrackWithDisplayGroup['sequence'] | null =
@@ -68,6 +71,8 @@ export const TimelinePackedTrack: React.FC<{
return (
<div
data-timeline-track={track.sequence.displayName}
+ onClickCapture={onClickCapture}
+ onPointerDownCapture={onPointerDownCapture}
style={{
position: 'relative',
height:
@@ -96,6 +101,7 @@ export const TimelinePackedTrack: React.FC<{
row.items.map((item) => (
<div
key={item.sequence.id}
+ data-timeline-track-item-id={item.sequence.id}
style={{
position: 'absolute',
top: row.top,
@@ -122,6 +128,23 @@ export const TimelinePackedTrack: React.FC<{
</div>
)),
)}
+ {dropIndicatorLeft === null ? null : (
+ <div
+ aria-hidden="true"
+ data-series-reorder-indicator
+ style={{
+ position: 'absolute',
+ left: dropIndicatorLeft - 6.5,
+ top: 0,
+ height: TIMELINE_PACKED_TRACK_HEIGHT,
+ width: 13,
+ background:
+ 'linear-gradient(to right, #00E50000, #00E500 6px, #00E500 7px, #00E50000)',
+ pointerEvents: 'none',
+ zIndex: 2,
+ }}
+ />
+ )}
</div>
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
index c55a4ea605..36de2e73a8 100644
--- a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
+++ b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
@@ -78,6 +78,7 @@ export const TimelineRowChrome: React.FC<{
// bottom track separator. The background highlight and click target span the
// outer (used by sequence rows whose layer is taller than the chrome row).
readonly outerHeight: number | null;
+ readonly showBottomBorder: boolean;
readonly onDragLeave?: (e: React.DragEvent<HTMLDivElement>) => void;
readonly onDragOver?: (e: React.DragEvent<HTMLDivElement>) => void;
readonly onDrop?: (e: React.DragEvent<HTMLDivElement>) => void;
@@ -98,6 +99,7 @@ export const TimelineRowChrome: React.FC<{
containsSelection,
hovered = false,
outerHeight,
+ showBottomBorder,
onDragLeave,
onDragOver,
onDrop,
@@ -220,13 +222,13 @@ export const TimelineRowChrome: React.FC<{
return {
height: outerHeight,
- borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,
+ borderBottom: `1px solid ${showBottomBorder ? TIMELINE_TRACK_SEPARATOR : 'transparent'}`,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
backgroundColor: highlightBackground,
};
- }, [outerHeight, highlightBackground]);
+ }, [outerHeight, highlightBackground, showBottomBorder]);
const chrome = (
<>
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index 7340741baa..a28dda9b40 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -348,6 +348,7 @@ const getSequencePointerDropTargetAtPoint = ({
const SEQUENCE_REORDER_POINTER_THRESHOLD = 3;
const TimelineSequenceItemInner: React.FC<{
+ readonly showBottomBorder: boolean;
readonly afterDropLineOffset: number;
readonly sequence: TSequence;
readonly connectedCompositions: readonly _InternalTypes['AnyComposition'][];
@@ -360,6 +361,7 @@ const TimelineSequenceItemInner: React.FC<{
readonly numberOfHiddenDuplicates: number;
readonly showProvisionalVisibilityToggle: boolean;
}> = ({
+ showBottomBorder,
afterDropLineOffset,
connectedCompositions,
nestedDepth,
@@ -477,11 +479,10 @@ const TimelineSequenceItemInner: React.FC<{
);
const parentId = sequence.parent ?? null;
const canReorderSequence =
- !isPackedTrack &&
previewInteractive &&
Boolean(nodePath && nodePathKey && validatedLocation?.source) &&
nodePathInfo?.numberOfSequencesWithThisNodePath === 1;
- const canHandleSequenceDrag = previewInteractive && !isPackedTrack;
+ const canHandleSequenceDrag = previewInteractive;
const confirm = useConfirmationDialog();
const deleteDisabled = useMemo(
@@ -775,7 +776,6 @@ const TimelineSequenceItemInner: React.FC<{
sourceRows.some(
(row, index) =>
!row ||
- row.track.sequence.timelineTrack?.role === 'track' ||
row.track.sequence.parent !== parentId ||
selectedNodePathInfos[index].numberOfSequencesWithThisNodePath !==
1 ||
@@ -1678,6 +1678,7 @@ const TimelineSequenceItemInner: React.FC<{
containsSelection={containsSelection}
hovered={hovered}
outerHeight={outerHeight}
+ showBottomBorder={showBottomBorder}
onDragLeave={canDropEffect ? onEffectDragLeave : undefined}
onDragOver={canDropEffect ? onEffectDragOver : undefined}
onDrop={canDropEffect ? onEffectDrop : undefined}
diff --git a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
index d6c46d7778..ca02b54296 100644
--- a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
@@ -855,6 +855,7 @@ export const TimelineSequencePropItem: React.FC<{
showSelectedBackground
containsSelection={containsSelection}
outerHeight={null}
+ showBottomBorder={false}
>
{hidePathValue ? (
<TimelineFieldLabel
diff --git a/packages/studio/src/components/Timeline/timeline-track-groups.ts b/packages/studio/src/components/Timeline/timeline-track-groups.ts
index 776f786c75..4de034be11 100644
--- a/packages/studio/src/components/Timeline/timeline-track-groups.ts
+++ b/packages/studio/src/components/Timeline/timeline-track-groups.ts
@@ -2,7 +2,7 @@ import type {TSequence} from 'remotion';
import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';
import type {TimelineTrackWithDisplayGroup} from './timeline-display-groups';
-export const TIMELINE_PACKED_TRACK_HEIGHT = 54;
+export const TIMELINE_PACKED_TRACK_HEIGHT = 28;
export const TIMELINE_PACKED_AUXILIARY_ROW_HEIGHT = 24;
export type TimelineDisplayRow = {
diff --git a/packages/studio/src/components/Timeline/use-series-reorder.ts b/packages/studio/src/components/Timeline/use-series-reorder.ts
new file mode 100644
index 0000000000..51b21cd037
--- /dev/null
+++ b/packages/studio/src/components/Timeline/use-series-reorder.ts
@@ -0,0 +1,343 @@
+import {getCanvasSequenceReorderSelection} from '@remotion/sdk';
+import type {ReorderSequencePosition} from '@remotion/studio-shared';
+import {useCallback, useContext, useEffect, useRef, useState} from 'react';
+import {Internals} from 'remotion';
+import {StudioServerConnectionCtx} from '../../helpers/client-id';
+import {isStudioInteractivityEnabled} from '../../helpers/interactivity-enabled';
+import {
+ isPointerSessionRelease,
+ startDeferredCapturedPointerSession,
+} from '../../helpers/pointer-session';
+import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
+import {showNotification} from '../Notifications/NotificationCenter';
+import {reorderSequence} from '../reorder-sequence-api';
+import type {TimelineTrackWithDisplayGroup} from './timeline-display-groups';
+import {scrollableRef} from './timeline-refs';
+import {
+ SCROLL_INCREMENT,
+ startTimelineEdgeAutoScroll,
+} from './timeline-scroll-logic';
+import {
+ isTimelineSelectionModifierEvent,
+ useTimelineSelection,
+} from './TimelineSelection';
+import {TimelineWidthContext} from './TimelineWidthProvider';
+
+const SERIES_REORDER_SEAM_SNAP_DISTANCE = 12;
+
+export const useSeriesReorder = (
+ items: readonly TimelineTrackWithDisplayGroup[],
+) => {
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const timelineWidth = useContext(TimelineWidthContext);
+ const video = Internals.useVideo();
+ const {selectedItems} = useTimelineSelection();
+ const [dropIndicatorLeft, setDropIndicatorLeft] = useState<number | null>(
+ null,
+ );
+ const stopPointerSession = useRef<(() => void) | null>(null);
+ const suppressNextClick = useRef(false);
+
+ useEffect(() => {
+ return () => stopPointerSession.current?.();
+ }, []);
+
+ const onPointerDownCapture = useCallback(
+ (e: React.PointerEvent<HTMLDivElement>) => {
+ if (
+ e.button !== 0 ||
+ !e.isPrimary ||
+ isTimelineSelectionModifierEvent(e) ||
+ !isStudioInteractivityEnabled() ||
+ previewServerState.type !== 'connected' ||
+ timelineWidth === null ||
+ video === null ||
+ !(e.target instanceof Element) ||
+ e.target.closest('button, input, textarea, select, [role="separator"]')
+ ) {
+ return;
+ }
+
+ const clipElement = e.target.closest<HTMLDivElement>(
+ '[data-track-item="clip"]',
+ );
+ const itemId = clipElement?.closest<HTMLElement>(
+ '[data-timeline-track-item-id]',
+ )?.dataset.timelineTrackItemId;
+ const draggedItem = items.find((item) => item.sequence.id === itemId);
+ if (
+ !clipElement ||
+ !draggedItem?.nodePathInfo ||
+ draggedItem.sequence.controls?.componentIdentity !==
+ 'dev.remotion.remotion.Series.Sequence'
+ ) {
+ return;
+ }
+
+ const siblings = items.filter(
+ (item) =>
+ item.sequence.parent === draggedItem.sequence.parent &&
+ item.sequence.controls?.componentIdentity ===
+ 'dev.remotion.remotion.Series.Sequence',
+ );
+ const sourceInfos = getCanvasSequenceReorderSelection({
+ draggedItem: {type: 'sequence', nodePathInfo: draggedItem.nodePathInfo},
+ selectedItems,
+ });
+ const sourceKeys = sourceInfos.map((info) =>
+ Internals.makeSequencePropsSubscriptionKey(
+ info.sequenceSubscriptionKey,
+ ),
+ );
+ const sourceIndexes = sourceKeys.map((key) =>
+ siblings.findIndex(
+ (item) =>
+ item.nodePathInfo !== null &&
+ Internals.makeSequencePropsSubscriptionKey(
+ item.nodePathInfo.sequenceSubscriptionKey,
+ ) === key,
+ ),
+ );
+ const fileName =
+ draggedItem.nodePathInfo.sequenceSubscriptionKey.absolutePath;
+ const frameIncrement =
+ (timelineWidth - TIMELINE_PADDING * 2) / video.durationInFrames;
+ if (
+ !Number.isFinite(frameIncrement) ||
+ frameIncrement <= 0 ||
+ sourceIndexes.some((index) => index === -1) ||
+ sourceInfos.some(
+ (info) =>
+ info.numberOfSequencesWithThisNodePath !== 1 ||
+ info.sequenceSubscriptionKey.absolutePath !== fileName,
+ )
+ ) {
+ return;
+ }
+
+ stopPointerSession.current?.();
+ const trackElement = e.currentTarget;
+ const sourceRect = clipElement.getBoundingClientRect();
+ const startX = e.clientX;
+ const startY = e.clientY;
+ let clientX = startX;
+ let clientY = startY;
+ let didDrag = false;
+ let preview: HTMLDivElement | null = null;
+ let previousUserSelect = '';
+ let previousWebkitUserSelect = '';
+ let dropTarget: {
+ item: TimelineTrackWithDisplayGroup | null;
+ position: ReorderSequencePosition;
+ changesOrder: boolean;
+ } | null = null;
+ const candidates = siblings.flatMap((item, index) =>
+ sourceIndexes.includes(index) ? [] : [{item, index}],
+ );
+ const sources = siblings.filter((_, index) =>
+ sourceIndexes.includes(index),
+ );
+
+ const updateDropTarget = () => {
+ dropTarget = null;
+ const rect = trackElement.getBoundingClientRect();
+ if (clientY < rect.top || clientY > rect.top + sourceRect.height) {
+ setDropIndicatorLeft(null);
+ return;
+ }
+
+ const pointerLeft = clientX - rect.left;
+ let seamIndex: number | null = null;
+ let seamLeft: number | null = null;
+ let closestDistance = SERIES_REORDER_SEAM_SNAP_DISTANCE;
+ // Include the outer edges as well as seams between siblings. Keep selected
+ // clips in this search so their original placement remains reachable.
+ for (let index = 0; index <= siblings.length; index++) {
+ const lastSequence = siblings[siblings.length - 1].sequence;
+ const left =
+ (index === siblings.length
+ ? lastSequence.from + lastSequence.duration
+ : siblings[index].sequence.from) * frameIncrement;
+ const distance = Math.abs(pointerLeft - left);
+ if (distance <= closestDistance) {
+ seamIndex = index;
+ seamLeft = left;
+ closestDistance = distance;
+ }
+ }
+
+ if (seamIndex === null) {
+ setDropIndicatorLeft(null);
+ return;
+ }
+
+ // Once a seam has been reached, the glow supplies the feedback for
+ // the rest of the gesture, even if the pointer leaves the seam.
+ preview?.remove();
+ preview = null;
+ const insertionIndex =
+ seamIndex - sourceIndexes.filter((index) => index < seamIndex).length;
+ const reordered = candidates.map(({item}) => item);
+ reordered.splice(insertionIndex, 0, ...sources);
+ // Series only permits an unlimited duration on its final clip.
+ if (
+ reordered
+ .slice(0, -1)
+ .some(
+ (item) =>
+ item.sequence.controls?.runtimeValues.getSnapshot()
+ .durationInFrames === Infinity,
+ )
+ ) {
+ setDropIndicatorLeft(null);
+ return;
+ }
+
+ const changesOrder = reordered.some(
+ (item, index) => item !== siblings[index],
+ );
+ const next = candidates[insertionIndex];
+ const candidate = next ?? candidates.at(-1);
+ if (
+ changesOrder &&
+ (!candidate ||
+ candidate.item.nodePathInfo?.numberOfSequencesWithThisNodePath !==
+ 1 ||
+ candidate.item.nodePathInfo.sequenceSubscriptionKey.absolutePath !==
+ fileName)
+ ) {
+ setDropIndicatorLeft(null);
+ return;
+ }
+
+ dropTarget = {
+ item: candidate?.item ?? null,
+ position: next ? 'before' : 'after',
+ changesOrder,
+ };
+ setDropIndicatorLeft(seamLeft);
+ };
+
+ const autoScroll = startTimelineEdgeAutoScroll({
+ includeHorizontal: true,
+ includeVertical: false,
+ verticalTopOffset: 0,
+ onTick: ({x}) => {
+ if (x === null || !scrollableRef.current) {
+ return;
+ }
+
+ scrollableRef.current.scrollLeft +=
+ x === 'left' ? -SCROLL_INCREMENT : SCROLL_INCREMENT;
+ updateDropTarget();
+ },
+ });
+ stopPointerSession.current = startDeferredCapturedPointerSession({
+ // The row stays mounted when horizontal scrolling crops the source clip.
+ captureTarget: trackElement,
+ event: e.nativeEvent,
+ onMove: (event, capturePointer) => {
+ clientX = event.clientX;
+ clientY = event.clientY;
+ if (!didDrag && Math.hypot(clientX - startX, clientY - startY) < 3) {
+ return;
+ }
+
+ if (!didDrag) {
+ didDrag = true;
+ capturePointer();
+ previousUserSelect = document.body.style.userSelect;
+ previousWebkitUserSelect = document.body.style.webkitUserSelect;
+ document.body.style.userSelect = 'none';
+ document.body.style.webkitUserSelect = 'none';
+ preview = clipElement.cloneNode(true) as HTMLDivElement;
+ preview.setAttribute('aria-hidden', 'true');
+ preview.setAttribute('data-series-reorder-preview', 'true');
+ Object.assign(preview.style, {
+ position: 'fixed',
+ left: `${sourceRect.left}px`,
+ top: `${sourceRect.top}px`,
+ marginLeft: '0',
+ width: `${sourceRect.width}px`,
+ height: `${sourceRect.height}px`,
+ opacity: '0.8',
+ pointerEvents: 'none',
+ zIndex: '2147483647',
+ });
+ // Edge handles on the clone must not intercept drop gestures.
+ for (const child of preview.querySelectorAll<HTMLElement>('*')) {
+ child.style.pointerEvents = 'none';
+ }
+
+ document.body.appendChild(preview);
+ }
+
+ event.preventDefault();
+ if (preview) {
+ preview.style.transform = `translateX(${clientX - startX}px)`;
+ }
+
+ updateDropTarget();
+ autoScroll.update({clientX, clientY});
+ },
+ onEnd: (reason, event) => {
+ const released = isPointerSessionRelease(reason, event);
+ if (released && didDrag) {
+ clientX = event.clientX;
+ clientY = event.clientY;
+ updateDropTarget();
+ }
+
+ autoScroll.stop();
+ preview?.remove();
+ setDropIndicatorLeft(null);
+ stopPointerSession.current = null;
+ if (!didDrag) {
+ return;
+ }
+
+ document.body.style.userSelect = previousUserSelect;
+ document.body.style.webkitUserSelect = previousWebkitUserSelect;
+ suppressNextClick.current = true;
+ setTimeout(() => {
+ suppressNextClick.current = false;
+ }, 0);
+ if (
+ !released ||
+ !dropTarget?.changesOrder ||
+ !dropTarget.item?.nodePathInfo
+ ) {
+ return;
+ }
+
+ reorderSequence({
+ fileName,
+ sourceNodePaths: sourceInfos.map(
+ (info) => info.sequenceSubscriptionKey,
+ ),
+ targetNodePath:
+ dropTarget.item.nodePathInfo.sequenceSubscriptionKey,
+ position: dropTarget.position,
+ clientId: previewServerState.clientId,
+ })
+ .then((result) => {
+ if (!result.success) {
+ showNotification(result.reason, 4000);
+ }
+ })
+ .catch((err) => showNotification((err as Error).message, 4000));
+ },
+ });
+ },
+ [items, previewServerState, selectedItems, timelineWidth, video],
+ );
+ const onClickCapture = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
+ if (suppressNextClick.current) {
+ e.preventDefault();
+ e.stopPropagation();
+ suppressNextClick.current = false;
+ }
+ }, []);
+
+ return {dropIndicatorLeft, onClickCapture, onPointerDownCapture};
+};