Skip to content

🎥 Make videos programmatically with React

cool

Jonny Burgerf1e0900fb9fb
diff --git a/packages/studio/src/components/Timeline/TimelineItemStack.tsx b/packages/studio/src/components/Timeline/TimelineItemStack.tsx
index 59aa725a73..34a6b45ee0 100644
--- a/packages/studio/src/components/Timeline/TimelineItemStack.tsx
+++ b/packages/studio/src/components/Timeline/TimelineItemStack.tsx
@@ -8,6 +8,7 @@ import {openOriginalPositionInEditor} from '../../helpers/open-in-editor';
import {Spacing} from '../layout';
import {showNotification} from '../Notifications/NotificationCenter';
import {Spinner} from '../Spinner';
+import {SELECTION_ENABLED} from './TimelineSelection';
import {getOriginalSourceAttribution} from './TimelineStack/source-attribution';
export const TimelineItemStack: React.FC<{
@@ -44,7 +45,8 @@ export const TimelineItemStack: React.FC<{
const canOpenInGitHub = Boolean(
window.remotion_gitSource && originalLocation,
);
- const hoverable = !isCompact && (canOpenInEditor || canOpenInGitHub);
+ const hoverable =
+ !SELECTION_ENABLED && !isCompact && (canOpenInEditor || canOpenInGitHub);
const onClick = useCallback(() => {
if (!originalLocation) {
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 9049afe341..56de6dfb7a 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -1,8 +1,10 @@
import React, {useCallback, useContext, useMemo} from 'react';
import type {TSequence} from 'remotion';
import {Internals} from 'remotion';
+import {NoReactInternals} from 'remotion/no-react';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
+import {openOriginalPositionInEditor} from '../../helpers/open-in-editor';
import {
getTimelineLayerHeight,
TIMELINE_ITEM_BORDER_BOTTOM,
@@ -24,7 +26,11 @@ import {
import {TimelineExpandedSection} from './TimelineExpandedSection';
import {TimelineItemStack} from './TimelineItemStack';
import {TimelineLayerEye, TimelineLayerEyeSpacer} from './TimelineLayerEye';
-import {TimelineMediaInfo} from './TimelineMediaInfo';
+import {
+ TimelineMediaInfo,
+ getTimelineAssetLinkInfo,
+ openTimelineAssetLink,
+} from './TimelineMediaInfo';
import {TimelineRowChrome} from './TimelineRowChrome';
import {
useTimelineRowContainsSelection,
@@ -55,6 +61,7 @@ export const TimelineListItem: React.FC<{
const {toggleTrack} = useContext(ExpandedTracksSetterContext);
const {codeValues} = useContext(Internals.VisualModeCodeValuesContext);
const {setCodeValues} = useContext(Internals.VisualModeSettersContext);
+ const {setCanvasContent} = useContext(Internals.CompositionSetters);
const {onSelect, selectable, selected} =
useTimelineRowSelection(nodePathInfo);
const containsSelection = useTimelineRowContainsSelection(nodePathInfo);
@@ -148,14 +155,94 @@ export const TimelineListItem: React.FC<{
}
}, [nodePath, validatedLocation?.source, nodePathInfo]);
+ const showInEditorDisabled =
+ !window.remotion_editorName || !previewConnected || !originalLocation;
+
+ const mediaSrc =
+ sequence.type === 'audio' ||
+ sequence.type === 'video' ||
+ sequence.type === 'image'
+ ? sequence.src
+ : null;
+
+ const assetLinkInfo = useMemo(
+ () => (mediaSrc ? getTimelineAssetLinkInfo(mediaSrc) : null),
+ [mediaSrc],
+ );
+
const contextMenuValues = useMemo((): ComboboxValue[] => {
if (!previewConnected) {
return [];
}
+ const editorName = window.remotion_editorName;
+ const documentationLink = sequence.documentationLink;
+
return [
+ editorName
+ ? {
+ type: 'item' as const,
+ id: 'show-in-editor',
+ keyHint: null,
+ label: `Show in ${editorName}`,
+ leftItem: null,
+ disabled: showInEditorDisabled,
+ onClick: async () => {
+ if (showInEditorDisabled || !originalLocation) {
+ return;
+ }
+
+ try {
+ await openOriginalPositionInEditor(originalLocation);
+ } catch (err) {
+ showNotification((err as Error).message, 2000);
+ }
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ value: 'show-in-editor',
+ }
+ : null,
+ documentationLink
+ ? {
+ type: 'item' as const,
+ id: 'open-component-docs',
+ keyHint: null,
+ label: 'Open component docs',
+ leftItem: null,
+ disabled: false,
+ onClick: () => {
+ window.open(documentationLink, '_blank', 'noopener,noreferrer');
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ value: 'open-component-docs',
+ }
+ : null,
+ assetLinkInfo
+ ? {
+ type: 'item' as const,
+ id: 'show-asset',
+ keyHint: null,
+ label: 'Show asset',
+ leftItem: null,
+ disabled: false,
+ onClick: () => {
+ openTimelineAssetLink(assetLinkInfo, setCanvasContent);
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ value: 'show-asset',
+ }
+ : null,
+ documentationLink
+ ? {
+ type: 'divider' as const,
+ id: 'open-component-docs-divider',
+ }
+ : null,
{
- type: 'item',
+ type: 'item' as const,
id: 'duplicate-sequence',
keyHint: null,
label: 'Duplicate',
@@ -173,7 +260,7 @@ export const TimelineListItem: React.FC<{
value: 'duplicate-sequence',
},
{
- type: 'item',
+ type: 'item' as const,
id: 'delete-sequence',
keyHint: null,
label: 'Delete',
@@ -190,13 +277,18 @@ export const TimelineListItem: React.FC<{
subMenu: null,
value: 'delete-sequence',
},
- ];
+ ].filter(NoReactInternals.truthy);
}, [
+ assetLinkInfo,
deleteDisabled,
duplicateDisabled,
onDeleteSequenceFromSource,
onDuplicateSequenceFromSource,
+ originalLocation,
previewConnected,
+ sequence.documentationLink,
+ setCanvasContent,
+ showInEditorDisabled,
]);
const isExpanded =
@@ -290,13 +382,6 @@ export const TimelineListItem: React.FC<{
};
}, []);
- const mediaSrc =
- sequence.type === 'audio' ||
- sequence.type === 'video' ||
- sequence.type === 'image'
- ? sequence.src
- : null;
-
const hasExpandableContent =
Boolean(sequence.controls) || sequence.effects.length > 0;
diff --git a/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx b/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
index ec501f5e87..777df1ca18 100644
--- a/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
+++ b/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
@@ -2,6 +2,7 @@ import React, {useCallback, useMemo, useState} from 'react';
import {Internals} from 'remotion';
import {LIGHT_TEXT, VERY_LIGHT_TEXT} from '../../helpers/colors';
import {pushUrl} from '../../helpers/url-state';
+import {SELECTION_ENABLED} from './TimelineSelection';
const lineStyle: React.CSSProperties = {
whiteSpace: 'nowrap',
@@ -26,7 +27,9 @@ type LinkInfo =
}
| null;
-const getLinkInfo = (src: string): LinkInfo => {
+export type TimelineAssetLinkInfo = Exclude<LinkInfo, null>;
+
+export const getTimelineAssetLinkInfo = (src: string): LinkInfo => {
const staticBase =
typeof window === 'undefined' ? null : window.remotion_staticBase;
@@ -55,11 +58,27 @@ const getLinkInfo = (src: string): LinkInfo => {
return null;
};
+export const openTimelineAssetLink = (
+ linkInfo: TimelineAssetLinkInfo,
+ setCanvasContent: React.ContextType<
+ typeof Internals.CompositionSetters
+ >['setCanvasContent'],
+) => {
+ if (linkInfo.kind === 'local') {
+ setCanvasContent({type: 'asset', asset: linkInfo.assetPath});
+ pushUrl(`/assets/${linkInfo.assetPath}`);
+ return;
+ }
+
+ window.open(linkInfo.href, '_blank', 'noopener,noreferrer');
+};
+
const useAssetLink = (src: string) => {
const {setCanvasContent} = React.useContext(Internals.CompositionSetters);
const [hovered, setHovered] = useState(false);
- const linkInfo = useMemo(() => getLinkInfo(src), [src]);
+ const linkInfo = useMemo(() => getTimelineAssetLinkInfo(src), [src]);
+ const interactive = !SELECTION_ENABLED && linkInfo !== null;
const onClick = useCallback(
(e: React.MouseEvent) => {
@@ -70,13 +89,7 @@ const useAssetLink = (src: string) => {
e.preventDefault();
e.stopPropagation();
- if (linkInfo.kind === 'local') {
- setCanvasContent({type: 'asset', asset: linkInfo.assetPath});
- pushUrl(`/assets/${linkInfo.assetPath}`);
- return;
- }
-
- window.open(linkInfo.href, '_blank', 'noopener,noreferrer');
+ openTimelineAssetLink(linkInfo, setCanvasContent);
},
[linkInfo, setCanvasContent],
);
@@ -87,8 +100,8 @@ const useAssetLink = (src: string) => {
const fileNameStyle: React.CSSProperties = useMemo(
() => ({
...lineStyle,
- color: linkInfo && hovered ? LIGHT_TEXT : VERY_LIGHT_TEXT,
- cursor: linkInfo ? 'pointer' : undefined,
+ color: interactive && hovered ? LIGHT_TEXT : VERY_LIGHT_TEXT,
+ cursor: interactive ? 'pointer' : undefined,
textDecoration: 'none',
display: 'inline-block',
overflow: 'hidden',
@@ -97,28 +110,40 @@ const useAssetLink = (src: string) => {
userSelect: 'none',
WebkitUserSelect: 'none',
}),
- [linkInfo, hovered],
+ [interactive, hovered],
);
- return {linkInfo, onClick, onPointerEnter, onPointerLeave, fileNameStyle};
+ return {
+ linkInfo,
+ interactive,
+ onClick,
+ onPointerEnter,
+ onPointerLeave,
+ fileNameStyle,
+ };
};
export const TimelineMediaInfo: React.FC<{
readonly src: string;
}> = ({src}) => {
- // Images aren't supported by mediabunny, so don't even try.
const fileName = useMemo(() => Internals.getAssetDisplayName(src), [src]);
- const {linkInfo, onClick, onPointerEnter, onPointerLeave, fileNameStyle} =
- useAssetLink(src);
+ const {
+ linkInfo,
+ interactive,
+ onClick,
+ onPointerEnter,
+ onPointerLeave,
+ fileNameStyle,
+ } = useAssetLink(src);
return (
<div
style={fileNameStyle}
title={linkInfo ? linkInfo.title : fileName}
- onClick={linkInfo ? onClick : undefined}
- onPointerEnter={linkInfo ? onPointerEnter : undefined}
- onPointerLeave={linkInfo ? onPointerLeave : undefined}
+ onClick={interactive ? onClick : undefined}
+ onPointerEnter={interactive ? onPointerEnter : undefined}
+ onPointerLeave={interactive ? onPointerLeave : undefined}
>
{fileName}
</div>
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceName.tsx b/packages/studio/src/components/Timeline/TimelineSequenceName.tsx
index 45a696dca6..6d4ece7c21 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceName.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceName.tsx
@@ -3,6 +3,7 @@ import type {TSequence} from 'remotion';
import {
getTimelineColor,
getTimelineSelectedLabelStyle,
+ SELECTION_ENABLED,
TIMELINE_SELECTED_LABEL_BACKGROUND,
} from './TimelineSelection';
@@ -23,7 +24,7 @@ export const TimelineSequenceName: React.FC<{
}> = ({sequence, selected, containsSelection}) => {
const [hovered, setHovered] = useState(false);
const {documentationLink} = sequence;
- const hoverable = documentationLink !== null;
+ const hoverable = !SELECTION_ENABLED && documentationLink !== null;
const onClick = useCallback(() => {
if (documentationLink === null) {