Skip to content

🎥 Make videos programmatically with React

nesting

Jonny Burger34983d18ad50
diff --git a/packages/cli/src/editor/components/CompositionSelector.tsx b/packages/cli/src/editor/components/CompositionSelector.tsx
index 546eb3bf73..804b90a5ed 100644
--- a/packages/cli/src/editor/components/CompositionSelector.tsx
+++ b/packages/cli/src/editor/components/CompositionSelector.tsx
@@ -24,13 +24,13 @@ const Item = styled.a<{
color: ${(props) => (props.selected ? 'black' : 'white')};
padding-left: 8px;
padding-right: 8px;
- padding-top: 4px;
- padding-bottom: 4px;
+ padding-top: 6px;
+ padding-bottom: 6px;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
display: block;
+ border-radius: 2px;
text-decoration: none;
- border-radius: 6px;
cursor: default;
`;
diff --git a/packages/cli/src/editor/components/Timeline/Timeline.tsx b/packages/cli/src/editor/components/Timeline/Timeline.tsx
index 3bcabe45f7..f87126e083 100644
--- a/packages/cli/src/editor/components/Timeline/Timeline.tsx
+++ b/packages/cli/src/editor/components/Timeline/Timeline.tsx
@@ -57,12 +57,8 @@ export const Timeline: React.FC = () => {
<SplitterElement type="anti-flexer">
<TimelineDragHandler>
{timeline.map((track) => (
- <div key={track.trackId} style={inner}>
- {track.sequences.map((s) => {
- return (
- <TimelineSequence key={s.id} fps={videoConfig.fps} s={s} />
- );
- })}
+ <div key={track.sequence.id} style={inner}>
+ <TimelineSequence fps={videoConfig.fps} s={track.sequence} />
</div>
))}
</TimelineDragHandler>
diff --git a/packages/cli/src/editor/components/Timeline/TimelineList.tsx b/packages/cli/src/editor/components/Timeline/TimelineList.tsx
index 0a5b98130f..285831bd88 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineList.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineList.tsx
@@ -13,12 +13,16 @@ export const TimelineList: React.FC<{
}> = ({timeline}) => {
return (
<div style={container}>
- {timeline.map((track) => {
+ {timeline.map((track, i) => {
+ const beforeDepth = i === 0 ? 0 : timeline[i - 1].depth;
return (
- <div key={track.trackId}>
- {track.sequences.map((s) => {
- return <TimelineListItem key={s.id} sequence={s} />;
- })}
+ <div key={track.sequence.id}>
+ <TimelineListItem
+ key={track.sequence.id}
+ nestedDepth={track.depth}
+ sequence={track.sequence}
+ beforeDepth={beforeDepth}
+ />
</div>
);
})}
diff --git a/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx b/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx
index c5f6e330d5..fe8b8ad65e 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineListItem.tsx
@@ -5,7 +5,9 @@ import {
TIMELINE_PADDING,
} from '../../helpers/timeline-layout';
-const BORDER_BOTTOM_LEFT_RADIUS = 7;
+const HOOK_WIDTH = 7;
+const BORDER_BOTTOM_LEFT_RADIUS = 2;
+const SPACING = 5;
const outer: React.CSSProperties = {
height: TIMELINE_LAYER_HEIGHT,
@@ -20,44 +22,60 @@ const outer: React.CSSProperties = {
const hookContainer: React.CSSProperties = {
height: TIMELINE_LAYER_HEIGHT,
- width: 10,
+ width: HOOK_WIDTH,
position: 'relative',
};
const hook: React.CSSProperties = {
- borderLeft: '1px solid white',
- borderBottom: '1px solid white',
+ borderLeft: '1px solid #555',
+ borderBottom: '1px solid #555',
borderBottomLeftRadius: BORDER_BOTTOM_LEFT_RADIUS,
- height: TIMELINE_LAYER_HEIGHT + BORDER_BOTTOM_LEFT_RADIUS / 2 + 2,
- width: 10,
+ width: HOOK_WIDTH,
position: 'absolute',
bottom: TIMELINE_LAYER_HEIGHT / 2 - 1,
};
const space: React.CSSProperties = {
- width: 5,
+ width: SPACING,
+};
+const smallSpace: React.CSSProperties = {
+ width: SPACING * 0.5,
};
export const TimelineListItem: React.FC<{
sequence: TSequence;
-}> = ({sequence}) => {
- const leftOffset = sequence.parent ? 7 : 0;
+ nestedDepth: number;
+ beforeDepth: number;
+}> = ({nestedDepth, sequence, beforeDepth}) => {
+ const leftOffset = HOOK_WIDTH + SPACING * 1.5;
+ const hookStyle = useMemo(() => {
+ return {
+ ...hook,
+ height:
+ TIMELINE_LAYER_HEIGHT +
+ BORDER_BOTTOM_LEFT_RADIUS / 2 -
+ (beforeDepth === nestedDepth ? 2 : 12),
+ };
+ }, [beforeDepth, nestedDepth]);
const padder = useMemo((): React.CSSProperties => {
return {
- width: leftOffset,
+ width: leftOffset * (nestedDepth - 1),
};
- }, [leftOffset]);
+ }, [leftOffset, nestedDepth]);
return (
<div style={outer}>
<div style={padder} />
{sequence.parent ? (
- <div style={hookContainer}>
- <div style={hook} />
- </div>
+ <>
+ <div style={smallSpace} />
+ <div style={hookContainer}>
+ <div style={hookStyle} />
+ </div>
+ <div style={space} />
+ </>
) : null}
- <div style={space} />
{sequence.displayName}
</div>
);
diff --git a/packages/cli/src/editor/helpers/calculate-timeline.ts b/packages/cli/src/editor/helpers/calculate-timeline.ts
index 1749ae0c62..7f49f6747f 100644
--- a/packages/cli/src/editor/helpers/calculate-timeline.ts
+++ b/packages/cli/src/editor/helpers/calculate-timeline.ts
@@ -1,4 +1,5 @@
import {TSequence} from 'remotion';
+import {getTimelineNestedLevel} from './get-timeline-nestedness';
import {getTimelineSequenceHash} from './get-timeline-sequence-hash';
export type SequenceWithOverlap = {
@@ -7,8 +8,8 @@ export type SequenceWithOverlap = {
};
export type Track = {
- trackId: string;
- sequences: TSequence[];
+ sequence: TSequence;
+ depth: number;
};
export const calculateTimeline = ({
@@ -23,19 +24,17 @@ export const calculateTimeline = ({
if (sequences.length === 0) {
return [
{
- sequences: [
- {
- displayName: '',
- duration: sequenceDuration,
- from: 0,
- id: 'seq',
- parent: null,
- type: 'sequence',
- isThumbnail: false,
- rootId: 'hi',
- },
- ],
- trackId: '0',
+ sequence: {
+ displayName: '',
+ duration: sequenceDuration,
+ from: 0,
+ id: 'seq',
+ parent: null,
+ type: 'sequence',
+ isThumbnail: false,
+ rootId: 'hi',
+ },
+ depth: 0,
},
];
}
@@ -48,6 +47,7 @@ export const calculateTimeline = ({
hashesUsedInRoot[sequence.rootId] = [];
}
const baseHash = getTimelineSequenceHash(sequence, sequences);
+ const depth = getTimelineNestedLevel(sequence, sequences, 0);
const actualHash =
baseHash +
hashesUsedInRoot[sequence.rootId].filter((h) => h === baseHash).length;
@@ -59,13 +59,7 @@ export const calculateTimeline = ({
hashesUsedInRoot[sequence.rootId].push(baseHash);
hashesUsed.push(actualHash);
- if (!tracks[i]) {
- tracks[i] = {
- sequences: [],
- trackId: String(i),
- };
- }
- tracks[i].sequences.push(sequence);
+ tracks.push({sequence, depth});
}
return tracks;
};
diff --git a/packages/cli/src/editor/helpers/get-timeline-nestedness.ts b/packages/cli/src/editor/helpers/get-timeline-nestedness.ts
new file mode 100644
index 0000000000..c3ac7947e6
--- /dev/null
+++ b/packages/cli/src/editor/helpers/get-timeline-nestedness.ts
@@ -0,0 +1,16 @@
+import {TSequence} from 'remotion';
+
+export const getTimelineNestedLevel = (
+ sequence: TSequence,
+ allSequences: TSequence[],
+ depth: number
+): number => {
+ if (!sequence.parent) {
+ return depth;
+ }
+ const parentSequence = allSequences.find((s) => s.id === sequence.parent);
+ if (!parentSequence) {
+ throw new Error('has parentId but no parent');
+ }
+ return getTimelineNestedLevel(parentSequence, allSequences, depth + 1);
+};
diff --git a/packages/core/src/get-timeline-clip-name.ts b/packages/core/src/get-timeline-clip-name.ts
index 56a2b4f615..b594afc496 100644
--- a/packages/core/src/get-timeline-clip-name.ts
+++ b/packages/core/src/get-timeline-clip-name.ts
@@ -1,19 +1,18 @@
import {Children, isValidElement} from 'react';
-export const getTimelineClipName = (
- children: React.ReactNode,
- i = 0
-): string => {
+export const getTimelineClipName = (children: React.ReactNode): string => {
const tree = Children.map(children, (ch) => {
- if (!isValidElement(ch)) return '';
+ if (!isValidElement(ch)) return null;
// Must be name, not ID
const name = typeof ch.type !== 'string' && ch.type.name;
- const root = name ? ' '.repeat(i) + name : null;
+ if (name) {
+ return name;
+ }
if (ch.props.children) {
- const chName = getTimelineClipName(ch.props.children, i + 1);
- return [root, chName].filter(Boolean).join('\n');
+ const chName = getTimelineClipName(ch.props.children);
+ return chName;
}
- return root;
- });
- return tree ? tree.filter(Boolean).join('\n') : '';
+ return null;
+ })?.filter(Boolean);
+ return tree?.length ? tree[0] : '';
};
diff --git a/packages/example/src/AudioTestingMute/index.tsx b/packages/example/src/AudioTestingMute/index.tsx
index 2fcf7bf1c4..28b3b6ecb9 100644
--- a/packages/example/src/AudioTestingMute/index.tsx
+++ b/packages/example/src/AudioTestingMute/index.tsx
@@ -38,6 +38,8 @@ const AudioTestingMute: React.FC = () => {
<Sequence from={20} durationInFrames={100}>
<Sequence from={20} durationInFrames={100}>
<Audio src={music} muted={getMuteState('music')} />
+ <Audio src={music} muted={getMuteState('music')} />
+ <Audio src={music} muted={getMuteState('music')} />
</Sequence>
</Sequence>
</div>