Skip to content

🎥 Make videos programmatically with React

@remotion/studio: Block pasting effects onto unsupported sequences

Jonny Burger0c9fbf9e91e7
diff --git a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
index 0fb49d1508..d121729291 100644
--- a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
+++ b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
@@ -7,6 +7,7 @@ import type React from 'react';
import {useContext, useEffect} from 'react';
import {Internals, type SequencePropsSubscriptionKey} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
import {useKeybinding} from '../../helpers/use-keybinding';
import {callApi} from '../call-api';
import {showNotification} from '../Notifications/NotificationCenter';
@@ -28,20 +29,73 @@ const makeTargetKey = (nodePath: SequencePropsSubscriptionKey): string => {
});
};
-const getTargetSequenceNodePath = (
+export type PasteEffectsTarget =
+ | {
+ readonly type: 'valid';
+ readonly nodePathInfo: SequenceNodePathInfo;
+ }
+ | {
+ readonly type: 'none';
+ }
+ | {
+ readonly type: 'multiple';
+ }
+ | {
+ readonly type: 'unsupported';
+ };
+
+const getTargetSequenceNodePathInfo = (
selection: TimelineSelection,
-): SequencePropsSubscriptionKey | null => {
+): SequenceNodePathInfo | null => {
if (
selection.type === 'sequence' ||
selection.type === 'sequence-effect' ||
selection.type === 'sequence-all-effects'
) {
- return selection.nodePathInfo.sequenceSubscriptionKey;
+ return selection.nodePathInfo;
}
return null;
};
+export const getPasteEffectsTarget = (
+ selectedItems: readonly TimelineSelection[],
+): PasteEffectsTarget => {
+ const targetNodePathInfos = selectedItems
+ .map(getTargetSequenceNodePathInfo)
+ .filter(
+ (targetNodePathInfo): targetNodePathInfo is SequenceNodePathInfo =>
+ targetNodePathInfo !== null,
+ );
+ const uniqueTargetKeys = new Set(
+ targetNodePathInfos.map((targetNodePathInfo) =>
+ makeTargetKey(targetNodePathInfo.sequenceSubscriptionKey),
+ ),
+ );
+
+ if (uniqueTargetKeys.size === 0) {
+ return {type: 'none'};
+ }
+
+ if (uniqueTargetKeys.size !== 1) {
+ return {type: 'multiple'};
+ }
+
+ const [nodePathInfo] = targetNodePathInfos;
+ if (!nodePathInfo) {
+ return {type: 'none'};
+ }
+
+ if (!nodePathInfo.supportsEffects) {
+ return {type: 'unsupported'};
+ }
+
+ return {
+ type: 'valid',
+ nodePathInfo,
+ };
+};
+
type CopyableEffectStatus = {
readonly canUpdate: true;
readonly callee: string;
@@ -237,17 +291,8 @@ export const TimelineClipboardKeybindings: React.FC = () => {
e.preventDefault();
- const targetNodePaths = selectedItems
- .map(getTargetSequenceNodePath)
- .filter(
- (nodePath): nodePath is SequencePropsSubscriptionKey =>
- nodePath !== null,
- );
- const uniqueTargetKeys = new Set(
- targetNodePaths.map(makeTargetKey),
- );
-
- if (uniqueTargetKeys.size !== 1) {
+ const target = getPasteEffectsTarget(selectedItems);
+ if (target.type === 'multiple') {
showNotification(
'Select one target sequence to paste effects',
3000,
@@ -255,12 +300,18 @@ export const TimelineClipboardKeybindings: React.FC = () => {
return;
}
- const [targetSequenceNodePath] = targetNodePaths;
- if (!targetSequenceNodePath) {
+ if (target.type === 'none') {
showNotification('Select a sequence to paste effects onto', 3000);
return;
}
+ if (target.type === 'unsupported') {
+ showNotification('This sequence does not support effects', 3000);
+ return;
+ }
+
+ const {sequenceSubscriptionKey: targetSequenceNodePath} =
+ target.nodePathInfo;
return callApi('/api/paste-effects', {
targetFileName: targetSequenceNodePath.absolutePath,
targetSequenceNodePath,
diff --git a/packages/studio/src/helpers/calculate-timeline.ts b/packages/studio/src/helpers/calculate-timeline.ts
index 73c4011979..5aa235412e 100644
--- a/packages/studio/src/helpers/calculate-timeline.ts
+++ b/packages/studio/src/helpers/calculate-timeline.ts
@@ -108,6 +108,7 @@ export const calculateTimeline = ({
auxiliaryKeys: [],
index: 0,
numberOfSequencesWithThisNodePath: 0,
+ supportsEffects: sequence.controls?.supportsEffects === true,
}
: null,
});
@@ -162,6 +163,7 @@ export const calculateTimeline = ({
auxiliaryKeys: track.nodePathInfo.auxiliaryKeys,
index,
numberOfSequencesWithThisNodePath: 0,
+ supportsEffects: track.nodePathInfo.supportsEffects,
},
};
})
@@ -182,6 +184,7 @@ export const calculateTimeline = ({
index: track.nodePathInfo.index,
numberOfSequencesWithThisNodePath:
nodePathIndexCounters.get(key) ?? 0,
+ supportsEffects: track.nodePathInfo.supportsEffects,
},
};
});
diff --git a/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts b/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts
index c688883bb0..0ed2716a39 100644
--- a/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts
+++ b/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts
@@ -5,6 +5,7 @@ export type SequenceNodePathInfo = {
auxiliaryKeys: string[];
index: number;
numberOfSequencesWithThisNodePath: number;
+ supportsEffects: boolean;
};
type Track = {
diff --git a/packages/studio/src/helpers/timeline-layout.ts b/packages/studio/src/helpers/timeline-layout.ts
index deff472fff..53af42251e 100644
--- a/packages/studio/src/helpers/timeline-layout.ts
+++ b/packages/studio/src/helpers/timeline-layout.ts
@@ -83,7 +83,8 @@ export const buildTimelineTree = ({
codeValues: CodeValues;
}): TimelineTreeNode[] => {
const roots: TimelineTreeNode[] = [];
- const {sequenceSubscriptionKey, index, auxiliaryKeys} = nodePathInfo;
+ const {sequenceSubscriptionKey, index, auxiliaryKeys, supportsEffects} =
+ nodePathInfo;
const controlFields = getFieldsToShow({
schema: sequence.controls!.schema,
@@ -103,6 +104,7 @@ export const buildTimelineTree = ({
auxiliaryKeys: [...auxiliaryKeys, 'controls', f.key],
index,
numberOfSequencesWithThisNodePath: 0,
+ supportsEffects,
},
label: f.description ?? f.key,
field: f,
@@ -118,6 +120,7 @@ export const buildTimelineTree = ({
auxiliaryKeys: [...auxiliaryKeys, 'effects'],
index,
numberOfSequencesWithThisNodePath: 0,
+ supportsEffects,
},
label: 'Effects',
effectInfo: null,
@@ -136,6 +139,7 @@ export const buildTimelineTree = ({
auxiliaryKeys: [...auxiliaryKeys, 'effects', i.toString()],
index,
numberOfSequencesWithThisNodePath: 0,
+ supportsEffects,
},
label: effect.label,
effectInfo: {
@@ -156,6 +160,7 @@ export const buildTimelineTree = ({
],
index,
numberOfSequencesWithThisNodePath: 0,
+ supportsEffects,
},
label: f.description ?? f.key,
field: f,
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index 6670a55ebe..0d1973aa00 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -18,6 +18,10 @@ import {
import {deleteSelectedTimelineItems} from '../components/Timeline/delete-selected-timeline-item';
import {isDuplicatableSequenceRowSelection} from '../components/Timeline/duplicate-selected-timeline-item';
import {getTimelinePropResetTargets} from '../components/Timeline/reset-selected-timeline-props';
+import {
+ getPasteEffectsTarget,
+ type PasteEffectsTarget,
+} from '../components/Timeline/TimelineClipboardKeybindings';
import {
ENABLE_OUTLINES,
getSelectableTimelineSequenceSelections,
@@ -40,11 +44,13 @@ const makeKey = (nodePath: SequenceNodePath): SequencePropsSubscriptionKey => ({
const makeNodePathInfo = (
nodePath: SequenceNodePath,
auxiliaryKeys: string[],
+ supportsEffects = true,
): SequenceNodePathInfo => ({
sequenceSubscriptionKey: makeKey(nodePath),
auxiliaryKeys,
index: 0,
numberOfSequencesWithThisNodePath: 1,
+ supportsEffects,
});
const makeTimelineSequence = ({
@@ -73,6 +79,7 @@ const makeTimelineSequence = ({
schema,
currentRuntimeValueDotNotation: {},
overrideId: 'override',
+ supportsEffects: true,
},
refForOutline: null,
effects,
@@ -82,6 +89,31 @@ test('Timeline selection should stay disabled until released publicly', () => {
expect(SELECTION_ENABLED).toBe(false);
});
+test('pasting effects is blocked for sequences that do not support effects', () => {
+ const unsupportedSequenceNodePathInfo = makeNodePathInfo(
+ ['body', 0],
+ [],
+ false,
+ );
+ const supportedSequenceNodePathInfo = makeNodePathInfo(['body', 1], [], true);
+
+ expect(
+ getPasteEffectsTarget([
+ {type: 'sequence', nodePathInfo: unsupportedSequenceNodePathInfo},
+ ]),
+ ).toEqual({
+ type: 'unsupported',
+ } satisfies PasteEffectsTarget);
+ expect(
+ getPasteEffectsTarget([
+ {type: 'sequence', nodePathInfo: supportedSequenceNodePathInfo},
+ ]),
+ ).toEqual({
+ type: 'valid',
+ nodePathInfo: supportedSequenceNodePathInfo,
+ } satisfies PasteEffectsTarget);
+});
+
test('Timeline top drag should not be enabled', () => {
expect(TIMELINE_TOP_DRAG).toBe(false);
});