Skip to content

🎥 Make videos programmatically with React

this is actually good

Jonny Burger5dc0e47af1af
diff --git a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
index d17ba35889..edc66a533a 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
@@ -230,6 +230,7 @@ export const TimelineEffectFieldRow: React.FC<{
onSelect={selection.onSelect}
showSelectedBackground
containsSelection={false}
+ outerHeight={null}
>
<TimelineFieldLabel
rowDepth={rowDepth}
diff --git a/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx
index ced77a7a93..bbc8c7205c 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx
@@ -187,7 +187,7 @@ export const TimelineEffectGroupRow: React.FC<{
const hoverEffect = labelHovered && documentationLink !== null;
return {
...rowLabel,
- ...getTimelineSelectedLabelStyle(selection.selected),
+ ...getTimelineSelectedLabelStyle(selection.selected, true),
alignSelf: 'stretch',
alignItems: 'center',
color: selection.selected ? TIMELINE_SELECTED_LABEL_TEXT : rowLabel.color,
@@ -237,6 +237,7 @@ export const TimelineEffectGroupRow: React.FC<{
onSelect={selection.onSelect}
showSelectedBackground
containsSelection={false}
+ outerHeight={null}
>
<span
onPointerEnter={() => setLabelHovered(true)}
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
index 3543fcdbcc..63ff231bf3 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
@@ -55,7 +55,7 @@ export const TimelineExpandedRow: React.FC<{
const labelStyle = React.useMemo(
(): React.CSSProperties => ({
...rowLabel,
- ...getTimelineSelectedLabelStyle(selection.selected),
+ ...getTimelineSelectedLabelStyle(selection.selected, true),
alignSelf: 'stretch',
alignItems: 'center',
color: selection.selected ? TIMELINE_SELECTED_LABEL_TEXT : rowLabel.color,
@@ -106,6 +106,7 @@ export const TimelineExpandedRow: React.FC<{
onSelect={selection.onSelect}
showSelectedBackground
containsSelection={false}
+ outerHeight={null}
>
<span style={labelStyle}>{node.label}</span>
</TimelineRowChrome>
@@ -156,6 +157,7 @@ export const TimelineExpandedRow: React.FC<{
onSelect={selection.onSelect}
showSelectedBackground
containsSelection={false}
+ outerHeight={null}
>
<span style={labelStyle}>{node.label}</span>
</TimelineRowChrome>
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx b/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx
index dc56781bec..4a49485cf4 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx
@@ -193,6 +193,7 @@ const TimelineExpandedTrackKeyframesInner: React.FC<{
aria-label={`Select keyframe at frame ${keyframe.frame}`}
onPointerDown={(e) => {
if (e.button === 0) {
+ e.stopPropagation();
selectItem(selectionItem);
}
}}
diff --git a/packages/studio/src/components/Timeline/TimelineFieldLabel.tsx b/packages/studio/src/components/Timeline/TimelineFieldLabel.tsx
index f6055df98c..aaab031969 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldLabel.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldLabel.tsx
@@ -1,8 +1,8 @@
import React, {useMemo} from 'react';
import {getTimelineFieldLabelRowStyle} from './timeline-field-row-layout';
import {
+ getTimelineColor,
getTimelineSelectedLabelStyle,
- TIMELINE_SELECTED_LABEL_TEXT,
} from './TimelineSelection';
const fieldNameBase: React.CSSProperties = {
@@ -24,7 +24,7 @@ export const TimelineFieldLabel: React.FC<{
const labelRowStyle = useMemo(
(): React.CSSProperties => ({
...getTimelineFieldLabelRowStyle(rowDepth),
- ...getTimelineSelectedLabelStyle(selected),
+ ...getTimelineSelectedLabelStyle(selected, true),
alignSelf: 'stretch',
}),
[rowDepth, selected],
@@ -33,7 +33,7 @@ export const TimelineFieldLabel: React.FC<{
const fieldNameStyle = useMemo(
(): React.CSSProperties => ({
...fieldNameBase,
- color: selected ? TIMELINE_SELECTED_LABEL_TEXT : fieldNameBase.color,
+ color: getTimelineColor(selected, true),
}),
[selected],
);
diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
index cd31eb4c6a..acf1d1699e 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
@@ -183,6 +183,7 @@ export const TimelineFieldRow: React.FC<{
onSelect={selection.onSelect}
showSelectedBackground
containsSelection={false}
+ outerHeight={null}
>
<TimelineFieldLabel
rowDepth={rowDepth}
diff --git a/packages/studio/src/components/Timeline/TimelineItemName.tsx b/packages/studio/src/components/Timeline/TimelineItemName.tsx
index 7c05373e65..833dc4277e 100644
--- a/packages/studio/src/components/Timeline/TimelineItemName.tsx
+++ b/packages/studio/src/components/Timeline/TimelineItemName.tsx
@@ -42,7 +42,7 @@ export const TimelineItemName: React.FC<{
return {
alignItems: 'center',
alignSelf: 'stretch',
- ...getTimelineSelectedLabelStyle(selected),
+ ...getTimelineSelectedLabelStyle(selected, false),
display: 'inline-flex',
fontSize: 12,
whiteSpace: 'nowrap',
diff --git a/packages/studio/src/components/Timeline/TimelineLayerEye.tsx b/packages/studio/src/components/Timeline/TimelineLayerEye.tsx
index 03b0918b38..5daea93399 100644
--- a/packages/studio/src/components/Timeline/TimelineLayerEye.tsx
+++ b/packages/studio/src/components/Timeline/TimelineLayerEye.tsx
@@ -84,6 +84,7 @@ export const TimelineLayerEye: React.FC<{
return;
}
+ e.stopPropagation();
layerPointedDown = hidden ? 'enable' : 'disable';
onInvoked(layerPointedDown);
window.addEventListener(
diff --git a/packages/studio/src/components/Timeline/TimelineList.tsx b/packages/studio/src/components/Timeline/TimelineList.tsx
index a8da37d8af..2d5c6e09e3 100644
--- a/packages/studio/src/components/Timeline/TimelineList.tsx
+++ b/packages/studio/src/components/Timeline/TimelineList.tsx
@@ -1,8 +1,9 @@
import {PlayerInternals} from '@remotion/player';
-import React, {useRef} from 'react';
+import React, {useCallback, useRef} from 'react';
import {BACKGROUND} from '../../helpers/colors';
import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
import {TimelineListItem} from './TimelineListItem';
+import {useTimelineSelection} from './TimelineSelection';
import {TimelineTimePadding} from './TimelineTimeIndicators';
const container: React.CSSProperties = {
@@ -21,8 +22,24 @@ export const TimelineList: React.FC<{
const isCompact = size ? size.width < 250 : false;
+ const {clearSelection} = useTimelineSelection();
+
+ // Selection-triggering click handlers in children call e.stopPropagation(),
+ // so any pointerdown that bubbles up here is by definition on empty space
+ // and should clear the current selection.
+ const onPointerDown = useCallback(
+ (e: React.PointerEvent<HTMLDivElement>) => {
+ if (e.button !== 0) {
+ return;
+ }
+
+ clearSelection();
+ },
+ [clearSelection],
+ );
+
return (
- <div ref={ref} style={container}>
+ <div ref={ref} style={container} onPointerDown={onPointerDown}>
<TimelineTimePadding />
{timeline.map((track) => {
return (
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 7a66deb509..a60c934130 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -2,7 +2,6 @@ import React, {useCallback, useContext, useMemo} from 'react';
import type {TSequence} from 'remotion';
import {Internals} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
-import {TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
import {
getTimelineLayerHeight,
@@ -275,23 +274,9 @@ export const TimelineListItem: React.FC<{
],
);
- const outer: React.CSSProperties = useMemo(() => {
- return {
- height:
- getTimelineLayerHeight(sequence.type) + TIMELINE_ITEM_BORDER_BOTTOM,
- borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,
- display: 'flex',
- flexDirection: 'column',
- };
- }, [sequence.type]);
-
- const onSelectPointerDown = useCallback(
- (e: React.PointerEvent<HTMLDivElement>) => {
- if (e.button === 0) {
- onSelect();
- }
- },
- [onSelect],
+ const outerHeight = useMemo(
+ () => getTimelineLayerHeight(sequence.type) + TIMELINE_ITEM_BORDER_BOTTOM,
+ [sequence.type],
);
const inner: React.CSSProperties = useMemo(() => {
@@ -325,57 +310,52 @@ export const TimelineListItem: React.FC<{
codeHiddenStatus.canUpdate;
const trackRow = (
- <div
- style={outer}
- onPointerDown={selectable ? onSelectPointerDown : undefined}
- onContextMenu={selectable ? onSelect : undefined}
- >
- <TimelineRowChrome
- depth={nestedDepth}
- eye={
- canToggleVisibility ? (
- <TimelineLayerEye
- type={sequence.type === 'audio' ? 'speaker' : 'eye'}
- hidden={isItemHidden}
- onInvoked={onToggleVisibility}
- />
- ) : (
- <TimelineLayerEyeSpacer />
- )
- }
- arrow={
- hasExpandableContent ? (
- <TimelineExpandArrowButton
- isExpanded={isExpanded}
- onClick={onToggleExpand}
- label="track properties"
- disabled={!previewConnected || nodePathInfo === null}
- />
- ) : (
- <TimelineExpandArrowSpacer />
- )
- }
- style={inner}
- selected={selected}
- selectable={false}
- onSelect={onSelect}
- showSelectedBackground
- containsSelection={containsSelection}
- >
- <div style={labelContainerStyle}>
- <TimelineItemName
- sequence={sequence}
- selected={selected}
- containsSelection={containsSelection}
+ <TimelineRowChrome
+ depth={nestedDepth}
+ eye={
+ canToggleVisibility ? (
+ <TimelineLayerEye
+ type={sequence.type === 'audio' ? 'speaker' : 'eye'}
+ hidden={isItemHidden}
+ onInvoked={onToggleVisibility}
/>
- {mediaSrc ? <TimelineMediaInfo src={mediaSrc} /> : null}
- <TimelineItemStack
- isCompact={isCompact}
- originalLocation={originalLocation}
+ ) : (
+ <TimelineLayerEyeSpacer />
+ )
+ }
+ arrow={
+ hasExpandableContent ? (
+ <TimelineExpandArrowButton
+ isExpanded={isExpanded}
+ onClick={onToggleExpand}
+ label="track properties"
+ disabled={!previewConnected || nodePathInfo === null}
/>
- </div>
- </TimelineRowChrome>
- </div>
+ ) : (
+ <TimelineExpandArrowSpacer />
+ )
+ }
+ style={inner}
+ selected={selected}
+ selectable={selectable}
+ onSelect={onSelect}
+ showSelectedBackground
+ containsSelection={containsSelection}
+ outerHeight={outerHeight}
+ >
+ <div style={labelContainerStyle}>
+ <TimelineItemName
+ sequence={sequence}
+ selected={selected}
+ containsSelection={containsSelection}
+ />
+ {mediaSrc ? <TimelineMediaInfo src={mediaSrc} /> : null}
+ <TimelineItemStack
+ isCompact={isCompact}
+ originalLocation={originalLocation}
+ />
+ </div>
+ </TimelineRowChrome>
);
return (
diff --git a/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx b/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
index 47196251fb..ec501f5e87 100644
--- a/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
+++ b/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
@@ -94,6 +94,8 @@ const useAssetLink = (src: string) => {
overflow: 'hidden',
whiteSpace: 'pre',
textOverflow: 'ellipsis',
+ userSelect: 'none',
+ WebkitUserSelect: 'none',
}),
[linkInfo, hovered],
);
diff --git a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
index a29b9db00e..c9c0eb4cdc 100644
--- a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
+++ b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
@@ -1,4 +1,5 @@
import React, {useCallback, useMemo} from 'react';
+import {TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';
import {Padder} from './Padder';
import {
TIMELINE_ROW_BASE_PADDING,
@@ -30,6 +31,10 @@ export const TimelineRowChrome: React.FC<{
readonly onSelect: () => void;
readonly showSelectedBackground: boolean;
readonly containsSelection: boolean;
+ // When set, the chrome is wrapped in an outer container of this height with a
+ // 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;
}> = ({
depth,
eye,
@@ -41,42 +46,88 @@ export const TimelineRowChrome: React.FC<{
onSelect,
showSelectedBackground,
containsSelection,
+ outerHeight,
}) => {
- const rowStyle = useMemo(
- (): React.CSSProperties => ({
- ...rowBase,
- ...style,
- backgroundColor:
- showSelectedBackground && (selected || containsSelection)
- ? TIMELINE_SELECTED_BACKGROUND
- : undefined,
- }),
- [selected, containsSelection, showSelectedBackground, style],
- );
-
const indentWidth = getTimelineRowIndentWidth(depth);
const onPointerDown = useCallback(
(e: React.PointerEvent<HTMLDivElement>) => {
if (e.button === 0) {
+ e.stopPropagation();
onSelect();
}
},
[onSelect],
);
- return (
- <div
- style={rowStyle}
- onPointerDown={selectable ? onPointerDown : undefined}
- onContextMenu={selectable ? onSelect : undefined}
- >
+ const onContextMenu = useCallback(
+ (e: React.MouseEvent<HTMLDivElement>) => {
+ e.stopPropagation();
+ onSelect();
+ },
+ [onSelect],
+ );
+
+ const highlightBackground =
+ showSelectedBackground && (selected || containsSelection)
+ ? TIMELINE_SELECTED_BACKGROUND
+ : undefined;
+
+ const innerRowStyle = useMemo(
+ (): React.CSSProperties => ({
+ ...rowBase,
+ ...style,
+ backgroundColor:
+ outerHeight === undefined ? highlightBackground : undefined,
+ }),
+ [style, outerHeight, highlightBackground],
+ );
+
+ const outerStyle = useMemo((): React.CSSProperties | undefined => {
+ if (outerHeight === null) {
+ return undefined;
+ }
+
+ return {
+ height: outerHeight,
+ borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,
+ display: 'flex',
+ flexDirection: 'column',
+ justifyContent: 'center',
+ backgroundColor: highlightBackground,
+ };
+ }, [outerHeight, highlightBackground]);
+
+ const chrome = (
+ <>
<div style={chromeColumnStyle}>
{eye}
{indentWidth > 0 ? <Padder depth={depth} /> : null}
{arrow}
</div>
{children}
+ </>
+ );
+
+ if (outerStyle) {
+ return (
+ <div
+ style={outerStyle}
+ onPointerDown={selectable ? onPointerDown : undefined}
+ onContextMenu={selectable ? onContextMenu : undefined}
+ >
+ <div style={innerRowStyle}>{chrome}</div>
+ </div>
+ );
+ }
+
+ return (
+ <div
+ onPointerDown={selectable ? onPointerDown : undefined}
+ onContextMenu={selectable ? onContextMenu : undefined}
+ style={innerRowStyle}
+ >
+ {chrome}
</div>
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index f1d721a567..d6a51fa38e 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -20,14 +20,27 @@ export const TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING = 2;
export const getTimelineSelectedLabelStyle = (
selected: boolean,
+ subcategory: boolean,
): CSSProperties => {
return {
paddingLeft: TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING,
paddingRight: TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING,
- ...(selected ? {backgroundColor: TIMELINE_SELECTED_LABEL_BACKGROUND} : {}),
+ ...(selected
+ ? {
+ backgroundColor: subcategory
+ ? 'rgba(255, 255, 255, 0.1)'
+ : TIMELINE_SELECTED_LABEL_BACKGROUND,
+ }
+ : {}),
};
};
+export const getTimelineColor = (selected: boolean, subcategory: boolean) => {
+ return selected && !subcategory
+ ? TIMELINE_SELECTED_LABEL_TEXT
+ : 'rgba(255, 255, 255, 0.8)';
+};
+
export const getTimelineSelectedTrackHighlightStyle = (): CSSProperties => ({
backgroundColor: TIMELINE_SELECTED_BACKGROUND,
bottom: 0,
@@ -56,6 +69,7 @@ type TimelineSelectionContextValue = {
readonly isSelected: (item: TimelineSelection) => boolean;
readonly selectItem: (item: TimelineSelection) => void;
readonly containsSelection: (nodePathInfo: SequenceNodePathInfo) => boolean;
+ readonly clearSelection: () => void;
};
const TimelineSelectionContext = createContext<TimelineSelectionContextValue>({
@@ -63,6 +77,7 @@ const TimelineSelectionContext = createContext<TimelineSelectionContextValue>({
isSelected: () => false,
selectItem: () => undefined,
containsSelection: () => false,
+ clearSelection: () => undefined,
});
const getTimelineSelectionKey = (item: TimelineSelection): string => {
@@ -113,6 +128,10 @@ export const TimelineSelectionProvider: React.FC<{
[canSelect],
);
+ const clearSelection = useCallback(() => {
+ setSelectedItem(null);
+ }, []);
+
const containsSelection = useCallback(
(nodePathInfo: SequenceNodePathInfo) => {
if (selectedItem === null) {
@@ -156,8 +175,9 @@ export const TimelineSelectionProvider: React.FC<{
isSelected,
selectItem,
containsSelection,
+ clearSelection,
}),
- [canSelect, isSelected, selectItem, containsSelection],
+ [canSelect, isSelected, selectItem, containsSelection, clearSelection],
);
return (