Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Batch effect prop edits (#9598)

Jonny Burger866c1b3e4dc0
diff --git a/packages/studio-server/src/preview-server/api-routes.ts b/packages/studio-server/src/preview-server/api-routes.ts
index a4ceeab046..46c1b1bfd6 100644
--- a/packages/studio-server/src/preview-server/api-routes.ts
+++ b/packages/studio-server/src/preview-server/api-routes.ts
@@ -35,6 +35,7 @@ import {reorderEffectHandler} from './routes/reorder-effect';
import {reorderSequenceHandler} from './routes/reorder-sequence';
import {handleRestartStudio} from './routes/restart-studio';
import {saveEffectPropsHandler} from './routes/save-effect-props';
+import {saveMultipleEffectPropsHandler} from './routes/save-multiple-effect-props';
import {saveSequencePropsHandler} from './routes/save-sequence-props';
import {splitJsxSequenceHandler} from './routes/split-jsx-sequence';
import {subscribeToDefaultProps} from './routes/subscribe-to-default-props';
@@ -78,6 +79,7 @@ export const allApiRoutes: {
'/api/unsubscribe-from-sequence-props': unsubscribeFromSequenceProps,
'/api/save-sequence-props': saveSequencePropsHandler,
'/api/save-effect-props': saveEffectPropsHandler,
+ '/api/save-multiple-effect-props': saveMultipleEffectPropsHandler,
'/api/add-effect': addEffectHandler,
'/api/reorder-effect': reorderEffectHandler,
'/api/duplicate-effect': duplicateEffectHandler,
diff --git a/packages/studio-server/src/preview-server/routes/save-multiple-effect-props.ts b/packages/studio-server/src/preview-server/routes/save-multiple-effect-props.ts
new file mode 100644
index 0000000000..202e67a82f
--- /dev/null
+++ b/packages/studio-server/src/preview-server/routes/save-multiple-effect-props.ts
@@ -0,0 +1,248 @@
+import {readFileSync} from 'node:fs';
+import {RenderInternals} from '@remotion/renderer';
+import type {
+ SaveMultipleEffectPropsEdit,
+ SaveMultipleEffectPropsRequest,
+ SaveMultipleEffectPropsResponse,
+ SaveMultipleEffectPropsResult,
+} from '@remotion/studio-shared';
+import {getAllSchemaKeys} from '@remotion/studio-shared';
+import {parseAst} from '../../codemods/parse-ast';
+import {
+ type EffectPropUpdate,
+ type UpdateEffectPropsResult,
+ updateEffectProps,
+} from '../../codemods/update-effect-props/update-effect-props';
+import {writeFileAndNotifyFileWatchers} from '../../file-watcher';
+import {resolveFileInsideProject} from '../../helpers/resolve-file-inside-project';
+import {getVideoConfigIdentifierValues} from '../../helpers/video-config-values';
+import type {ApiHandler} from '../api-types';
+import {
+ printUndoHint,
+ pushTransactionToUndoStack,
+ suppressUndoStackInvalidation,
+} from '../undo-stack';
+import {suppressBundlerUpdateForFile} from '../watch-ignore-next-change';
+import {computeEffectPropStatus} from './can-update-effect-props';
+import {findJsxElementAtNodePath} from './can-update-sequence-props';
+import {logEffectUpdate} from './log-updates/log-effect-update';
+import {withSourceFileWriteQueue} from './source-file-write-queue';
+
+type ResolvedEffectPropEdit = {
+ index: number;
+ edit: SaveMultipleEffectPropsEdit;
+ update: EffectPropUpdate;
+ defaultValueString: string | null;
+};
+
+type EffectPropEditGroup = {
+ fileRelativeToRoot: string;
+ edits: ResolvedEffectPropEdit[];
+};
+
+type EffectPropEditResult = UpdateEffectPropsResult & {
+ edit: ResolvedEffectPropEdit;
+ fileRelativeToRoot: string;
+};
+
+const resolveEdit = ({
+ edit,
+ index,
+}: {
+ edit: SaveMultipleEffectPropsEdit;
+ index: number;
+}): ResolvedEffectPropEdit => {
+ const defaultValue =
+ edit.defaultValue === null ? null : JSON.parse(edit.defaultValue);
+ const update =
+ edit.type === 'value'
+ ? {
+ key: edit.key,
+ value: JSON.parse(edit.value),
+ defaultValue,
+ }
+ : {
+ key: edit.key,
+ effectParam: edit.effectParam,
+ defaultValue,
+ };
+
+ return {
+ index,
+ edit,
+ update,
+ defaultValueString:
+ defaultValue === null ? null : JSON.stringify(defaultValue),
+ };
+};
+
+export const saveMultipleEffectPropsHandler: ApiHandler<
+ SaveMultipleEffectPropsRequest,
+ SaveMultipleEffectPropsResponse
+> = ({
+ input: {edits, clientId, undoLabel, redoLabel},
+ remotionRoot,
+ logLevel,
+}) =>
+ withSourceFileWriteQueue(async () => {
+ if (edits.length === 0) {
+ throw new Error('No effect prop edits to save');
+ }
+
+ RenderInternals.Log.trace(
+ {indent: false, logLevel},
+ `[save-multiple-effect-props] Received request with ${edits.length} edit(s)`,
+ );
+
+ const editGroups = new Map<string, EffectPropEditGroup>();
+ for (const [index, edit] of edits.entries()) {
+ const {absolutePath, fileRelativeToRoot} = resolveFileInsideProject({
+ remotionRoot,
+ fileName: edit.fileName,
+ action: 'modify',
+ });
+ const group = editGroups.get(absolutePath) ?? {
+ fileRelativeToRoot,
+ edits: [],
+ };
+ group.edits.push(resolveEdit({edit, index}));
+ editGroups.set(absolutePath, group);
+ }
+
+ const snapshots: Array<{
+ filePath: string;
+ oldContents: string;
+ newContents: string;
+ logLine: number;
+ }> = [];
+ const outputByPath = new Map<string, string>();
+ const resultByIndex = new Map<number, EffectPropEditResult>();
+
+ for (const [absolutePath, group] of editGroups) {
+ const fileContents = readFileSync(absolutePath, 'utf-8');
+ let output = fileContents;
+ let firstLogLine = Number.POSITIVE_INFINITY;
+
+ for (const edit of group.edits) {
+ const result = await updateEffectProps({
+ input: output,
+ sequenceNodePath: edit.edit.sequenceNodePath.nodePath,
+ effectIndex: edit.edit.effectIndex,
+ update: edit.update,
+ schema: edit.edit.schema,
+ });
+ output = result.output;
+ firstLogLine = Math.min(firstLogLine, result.logLine);
+ resultByIndex.set(edit.index, {
+ ...result,
+ edit,
+ fileRelativeToRoot: group.fileRelativeToRoot,
+ });
+ }
+
+ outputByPath.set(absolutePath, output);
+ snapshots.push({
+ filePath: absolutePath,
+ oldContents: fileContents,
+ newContents: output,
+ logLine: Number.isFinite(firstLogLine) ? firstLogLine : 1,
+ });
+ }
+
+ pushTransactionToUndoStack({
+ snapshots,
+ logLevel,
+ remotionRoot,
+ description: {
+ undoMessage: `↩️ ${undoLabel}`,
+ redoMessage: `↪️ ${redoLabel}`,
+ },
+ entryType: 'effect-props',
+ suppressHmrOnFileRestore: true,
+ });
+
+ for (const [absolutePath, output] of outputByPath) {
+ suppressUndoStackInvalidation(absolutePath);
+ suppressBundlerUpdateForFile(absolutePath);
+ writeFileAndNotifyFileWatchers(absolutePath, output, clientId);
+ }
+
+ for (const index of edits.keys()) {
+ const result = resultByIndex.get(index);
+ if (!result) {
+ throw new Error('Could not compute effect prop edit result');
+ }
+
+ logEffectUpdate({
+ fileRelativeToRoot: result.fileRelativeToRoot,
+ line: result.logLine,
+ effectName: result.effectCallee,
+ propKey: result.edit.edit.key,
+ oldValueString: result.oldValueString,
+ newValueString: result.newValueString,
+ defaultValueString: result.edit.defaultValueString,
+ formatted: result.formatted,
+ logLevel,
+ removedProps: result.removedProps,
+ addedProps: [],
+ });
+ }
+
+ printUndoHint(logLevel);
+
+ const statusTargets = [
+ ...new Map(
+ edits.map((edit) => [
+ JSON.stringify([
+ edit.fileName,
+ edit.sequenceNodePath.nodePath,
+ edit.effectIndex,
+ ]),
+ edit,
+ ]),
+ ).values(),
+ ];
+ const results: SaveMultipleEffectPropsResult[] = statusTargets.map(
+ (edit) => {
+ const {absolutePath} = resolveFileInsideProject({
+ remotionRoot,
+ fileName: edit.fileName,
+ action: 'modify',
+ });
+ const output = outputByPath.get(absolutePath);
+ if (!output) {
+ throw new Error('Could not compute effect prop edit status');
+ }
+
+ const ast = parseAst(output);
+ const jsx = findJsxElementAtNodePath(
+ ast,
+ edit.sequenceNodePath.nodePath,
+ );
+ const status = jsx
+ ? computeEffectPropStatus({
+ ast,
+ jsx,
+ effectIndex: edit.effectIndex,
+ keys: getAllSchemaKeys(edit.schema),
+ videoConfigValues: getVideoConfigIdentifierValues({
+ ast,
+ videoConfigValues: edit.sequenceNodePath.videoConfigValues,
+ }),
+ })
+ : {
+ canUpdate: false as const,
+ effectIndex: edit.effectIndex,
+ reason: 'not-found' as const,
+ };
+
+ return {
+ fileName: edit.fileName,
+ sequenceNodePath: edit.sequenceNodePath,
+ status,
+ };
+ },
+ );
+
+ return {results};
+ });
diff --git a/packages/studio-server/src/test/save-multiple-effect-props.test.ts b/packages/studio-server/src/test/save-multiple-effect-props.test.ts
new file mode 100644
index 0000000000..4ea9bc7020
--- /dev/null
+++ b/packages/studio-server/src/test/save-multiple-effect-props.test.ts
@@ -0,0 +1,136 @@
+import {expect, test} from 'bun:test';
+import {mkdtempSync, readFileSync, rmSync, writeFileSync} from 'node:fs';
+import {tmpdir} from 'node:os';
+import {join} from 'node:path';
+import type {InteractivitySchema} from 'remotion';
+import {
+ createFileWatcherRegistry,
+ setFileWatcherRegistry,
+} from '../file-watcher';
+import {setLiveEventsListener} from '../preview-server/live-events';
+import {saveMultipleEffectPropsHandler} from '../preview-server/routes/save-multiple-effect-props';
+import {
+ clearUndoStackForTests,
+ getUndoStack,
+ popRedo,
+ popUndo,
+} from '../preview-server/undo-stack';
+import {lineColumnToNodePath} from './test-utils';
+
+const blurSchema = {
+ radius: {
+ type: 'number',
+ default: 40,
+ description: 'Blur radius',
+ hiddenFromList: false,
+ },
+} satisfies InteractivitySchema;
+
+test('saveMultipleEffectProps batches selected effect resets into one undo entry', async () => {
+ clearUndoStackForTests();
+ const cleanupFileWatcher = setFileWatcherRegistry(
+ createFileWatcherRegistry(),
+ );
+ const cleanupLiveEvents = setLiveEventsListener({
+ addNewClientListener: () => () => undefined,
+ closeConnections: () => Promise.resolve(),
+ router: () => Promise.resolve(),
+ sendEventToClient: () => undefined,
+ sendEventToClientId: () => true,
+ });
+ const dir = mkdtempSync(join(tmpdir(), 'remotion-save-effect-props-'));
+ const fileName = 'Comp.tsx';
+ const filePath = join(dir, fileName);
+ const input = `import {blur} from '@remotion/effects/blur';
+import {Solid} from 'remotion';
+
+export const Comp = () => {
+ return (
+ <>
+ <Solid
+ width={240}
+ height={240}
+ color="#0b84f3"
+ effects={[blur({radius: 20})]}
+ />
+ <Solid
+ width={240}
+ height={240}
+ color="#f30b84"
+ effects={[blur({radius: 30})]}
+ />
+ </>
+ );
+};
+`;
+ const makeNodePath = (line: number) => ({
+ absolutePath: fileName,
+ nodePath: lineColumnToNodePath(input, line),
+ sequenceKeys: [],
+ effectKeys: [['radius']],
+ videoConfigValues: null,
+ });
+
+ try {
+ writeFileSync(filePath, input);
+
+ const response = await saveMultipleEffectPropsHandler({
+ input: {
+ edits: [
+ {
+ type: 'value',
+ fileName,
+ sequenceNodePath: makeNodePath(7),
+ effectIndex: 0,
+ key: 'radius',
+ value: '40',
+ defaultValue: '40',
+ schema: blurSchema,
+ },
+ {
+ type: 'value',
+ fileName,
+ sequenceNodePath: makeNodePath(13),
+ effectIndex: 0,
+ key: 'radius',
+ value: '40',
+ defaultValue: '40',
+ schema: blurSchema,
+ },
+ ],
+ clientId: 'test-client',
+ undoLabel: 'Reset selected effect props',
+ redoLabel: 'Reapply selected effect props',
+ },
+ entryPoint: '',
+ remotionRoot: dir,
+ request: {} as never,
+ response: {} as never,
+ logLevel: 'error',
+ methods: {
+ addJob: () => undefined,
+ cancelJob: () => undefined,
+ removeJob: () => undefined,
+ },
+ publicDir: '',
+ binariesDirectory: null,
+ configFile: null,
+ });
+
+ const output = readFileSync(filePath, 'utf-8');
+ expect(output).not.toContain('radius: 20');
+ expect(output).not.toContain('radius: 30');
+ expect(response.results).toHaveLength(2);
+ expect(getUndoStack()).toHaveLength(1);
+
+ expect(popUndo()).toEqual({success: true});
+ expect(readFileSync(filePath, 'utf-8')).toBe(input);
+ expect(popRedo()).toEqual({success: true});
+ expect(readFileSync(filePath, 'utf-8')).toBe(output);
+ } finally {
+ clearUndoStackForTests();
+ cleanupLiveEvents();
+ cleanupFileWatcher();
+ rmSync(dir, {force: true, recursive: true});
+ }
+});
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index ffbe5ce8c7..755efafdde 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -383,6 +383,28 @@ export type SaveEffectPropsRequest =
export type SaveEffectPropsResponse = CanUpdateEffectPropsResponse;
+type WithoutClientId<T> = T extends unknown ? Omit<T, 'clientId'> : never;
+
+export type SaveMultipleEffectPropsEdit =
+ WithoutClientId<SaveEffectPropsRequest>;
+
+export type SaveMultipleEffectPropsRequest = {
+ edits: SaveMultipleEffectPropsEdit[];
+ clientId: string;
+ undoLabel: string;
+ redoLabel: string;
+};
+
+export type SaveMultipleEffectPropsResult = {
+ fileName: string;
+ sequenceNodePath: SequencePropsSubscriptionKey;
+ status: CanUpdateEffectPropsResponse;
+};
+
+export type SaveMultipleEffectPropsResponse = {
+ results: SaveMultipleEffectPropsResult[];
+};
+
export type AddEffectRequest = {
fileName: string;
sequenceNodePath: SequencePropsSubscriptionKey;
@@ -956,6 +978,10 @@ export type ApiRoutes = {
SaveEffectPropsRequest,
SaveEffectPropsResponse
>;
+ '/api/save-multiple-effect-props': ReqAndRes<
+ SaveMultipleEffectPropsRequest,
+ SaveMultipleEffectPropsResponse
+ >;
'/api/add-effect': ReqAndRes<AddEffectRequest, AddEffectResponse>;
'/api/reorder-effect': ReqAndRes<ReorderEffectRequest, ReorderEffectResponse>;
'/api/duplicate-effect': ReqAndRes<
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index b23210009e..e03bd6f85e 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -83,6 +83,10 @@ export {
RestartStudioResponse,
SaveEffectPropsRequest,
SaveEffectPropsResponse,
+ SaveMultipleEffectPropsEdit,
+ SaveMultipleEffectPropsRequest,
+ SaveMultipleEffectPropsResponse,
+ SaveMultipleEffectPropsResult,
SaveSequencePropEdit,
SaveSequencePropSourceEdit,
SaveSequencePropsRequest,
diff --git a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
index a87652c770..865a784cfc 100644
--- a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
+++ b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
@@ -56,7 +56,7 @@ import {
getKeyframeClipboardDataFromSelections,
getPasteKeyframeTarget,
} from './keyframe-clipboard';
-import {saveEffectProp} from './save-effect-prop';
+import {saveMultipleEffectProps} from './save-effect-prop';
import {
useCurrentTimelineSelectionStateAsRef,
useTimelineSelection,
@@ -100,20 +100,23 @@ export type PasteEffectsTarget =
readonly type: 'unsupported';
};
+type PasteEffectPropEditTarget = {
+ readonly fileName: string;
+ readonly nodePath: SequencePropsSubscriptionKey;
+ readonly effectIndex: number;
+ readonly fieldKey: string;
+ readonly defaultValue: string | null;
+ readonly schema: InteractivitySchema;
+};
+
export type PasteEffectPropTarget =
| {
readonly type: 'valid';
- readonly fileName: string;
- readonly nodePath: SequencePropsSubscriptionKey;
- readonly effectIndex: number;
- readonly fieldKey: string;
- readonly defaultValue: string | null;
- readonly schema: InteractivitySchema;
+ readonly targets: PasteEffectPropEditTarget[];
}
| {
readonly type:
| 'none'
- | 'multiple'
| 'unsupported'
| 'effect-type-mismatch'
| 'prop-mismatch'
@@ -531,32 +534,21 @@ export const getEasingClipboardDataFromSelection = ({
};
};
-export const getPasteEffectPropTarget = ({
- selectedItems,
+const getPasteEffectPropTargetForSelection = ({
+ selection,
payload,
propStatuses,
sequences,
overrideIdsToNodePaths,
}: {
- readonly selectedItems: readonly TimelineSelection[];
+ readonly selection: TimelineSelection;
readonly payload: EffectPropClipboardData;
readonly propStatuses: PropStatuses;
readonly sequences: TSequence[];
readonly overrideIdsToNodePaths: OverrideIdToNodePaths;
-}): PasteEffectPropTarget => {
- if (selectedItems.length === 0) {
- return {type: 'none'};
- }
-
- if (selectedItems.length !== 1) {
- return {type: 'multiple'};
- }
-
- const [selection] = selectedItems;
- if (!selection) {
- return {type: 'none'};
- }
-
+}):
+ | {type: 'valid'; target: PasteEffectPropEditTarget}
+ | Exclude<PasteEffectPropTarget, {type: 'valid'}> => {
if (
selection.type !== 'sequence-effect-prop' &&
selection.type !== 'sequence-effect'
@@ -630,12 +622,60 @@ export const getPasteEffectPropTarget = ({
return {
type: 'valid',
- fileName: selection.nodePathInfo.sequenceSubscriptionKey.absolutePath,
- nodePath: selection.nodePathInfo.sequenceSubscriptionKey,
- effectIndex: target.effectIndex,
- fieldKey: target.fieldKey,
- defaultValue: getDefaultValue(fieldSchema),
- schema: effect.schema,
+ target: {
+ fileName: selection.nodePathInfo.sequenceSubscriptionKey.absolutePath,
+ nodePath: selection.nodePathInfo.sequenceSubscriptionKey,
+ effectIndex: target.effectIndex,
+ fieldKey: target.fieldKey,
+ defaultValue: getDefaultValue(fieldSchema),
+ schema: effect.schema,
+ },
+ };
+};
+
+export const getPasteEffectPropTarget = ({
+ selectedItems,
+ payload,
+ propStatuses,
+ sequences,
+ overrideIdsToNodePaths,
+}: {
+ readonly selectedItems: readonly TimelineSelection[];
+ readonly payload: EffectPropClipboardData;
+ readonly propStatuses: PropStatuses;
+ readonly sequences: TSequence[];
+ readonly overrideIdsToNodePaths: OverrideIdToNodePaths;
+}): PasteEffectPropTarget => {
+ if (selectedItems.length === 0) {
+ return {type: 'none'};
+ }
+
+ const targets: PasteEffectPropEditTarget[] = [];
+ for (const selection of selectedItems) {
+ const result = getPasteEffectPropTargetForSelection({
+ selection,
+ payload,
+ propStatuses,
+ sequences,
+ overrideIdsToNodePaths,
+ });
+ if (result.type !== 'valid') {
+ return result;
+ }
+
+ targets.push(result.target);
+ }
+
+ return {
+ type: 'valid',
+ targets: [
+ ...new Map(
+ targets.map((target) => [
+ `${makeTargetKey(target.nodePath)}:${target.effectIndex}:${target.fieldKey}`,
+ target,
+ ]),
+ ).values(),
+ ],
};
};
@@ -1149,15 +1189,9 @@ export const TimelineClipboardKeybindings: React.FC = () => {
if (effectPropTarget.type !== 'valid') {
switch (effectPropTarget.type) {
- case 'multiple':
- showNotification(
- 'Select one target effect prop or effect to paste onto',
- 3000,
- );
- return;
case 'none':
showNotification(
- 'Select a matching effect prop or effect to paste onto',
+ 'Select matching effect props or effects to paste onto',
3000,
);
return;
@@ -1192,26 +1226,41 @@ export const TimelineClipboardKeybindings: React.FC = () => {
}
}
- return saveEffectProp({
- fileName: effectPropTarget.fileName,
- nodePath: effectPropTarget.nodePath,
- effectIndex: effectPropTarget.effectIndex,
- fieldKey: effectPropTarget.fieldKey,
- ...(effectPropResult.data.param.type === 'static'
- ? {
- type: 'value' as const,
- value: effectPropResult.data.param.value,
- }
- : {
- type: 'effect-param' as const,
- effectParam: effectPropResult.data.param,
- }),
- defaultValue: effectPropTarget.defaultValue,
- schema: effectPropTarget.schema,
+ return saveMultipleEffectProps({
+ changes: effectPropTarget.targets.map((pasteTarget) => ({
+ fileName: pasteTarget.fileName,
+ nodePath: pasteTarget.nodePath,
+ effectIndex: pasteTarget.effectIndex,
+ fieldKey: pasteTarget.fieldKey,
+ ...(effectPropResult.data.param.type === 'static'
+ ? {
+ type: 'value' as const,
+ value: effectPropResult.data.param.value,
+ }
+ : {
+ type: 'effect-param' as const,
+ effectParam: effectPropResult.data.param,
+ }),
+ defaultValue: pasteTarget.defaultValue,
+ schema: pasteTarget.schema,
+ })),
setPropStatuses,
clientId,
+ undoLabel:
+ effectPropTarget.targets.length > 1
+ ? 'Paste effect prop onto selected effects'
+ : 'Paste effect prop',
+ redoLabel:
+ effectPropTarget.targets.length > 1
+ ? 'Reapply effect prop paste onto selected effects'
+ : 'Reapply effect prop paste',
}).then(() => {
- showNotification('Pasted effect prop', 2000);
+ showNotification(
+ effectPropTarget.targets.length > 1
+ ? 'Pasted effect prop onto selected effects'
+ : 'Pasted effect prop',
+ 2000,
+ );
});
}
diff --git a/packages/studio/src/components/Timeline/reset-selected-timeline-props.ts b/packages/studio/src/components/Timeline/reset-selected-timeline-props.ts
index 17be08f3ef..658419e967 100644
--- a/packages/studio/src/components/Timeline/reset-selected-timeline-props.ts
+++ b/packages/studio/src/components/Timeline/reset-selected-timeline-props.ts
@@ -10,7 +10,7 @@ import type {
} from 'remotion';
import {Internals} from 'remotion';
import {findTrackForNodePathInfo} from './find-track-for-node-path-info';
-import {saveEffectProp} from './save-effect-prop';
+import {saveMultipleEffectProps} from './save-effect-prop';
import type {SetPropStatuses} from './save-sequence-prop';
import {saveSequenceProps} from './save-sequence-prop';
import type {TimelineSelection} from './TimelineSelection';
@@ -310,19 +310,29 @@ export const resetSelectedTimelineProps = ({
);
}
- for (const target of effectPropTargets) {
+ if (effectPropTargets.length > 0) {
resetPromises.push(
- saveEffectProp({
- type: 'value',
- fileName: target.fileName,
- nodePath: target.nodePath,
- effectIndex: target.effectIndex,
- fieldKey: target.fieldKey,
- value: target.value,
- defaultValue: target.defaultValue,
- schema: target.schema,
+ saveMultipleEffectProps({
+ changes: effectPropTargets.map((target) => ({
+ type: 'value',
+ fileName: target.fileName,
+ nodePath: target.nodePath,
+ effectIndex: target.effectIndex,
+ fieldKey: target.fieldKey,
+ value: target.value,
+ defaultValue: target.defaultValue,
+ schema: target.schema,
+ })),
setPropStatuses,
clientId,
+ undoLabel:
+ effectPropTargets.length > 1
+ ? 'Reset selected effect props'
+ : 'Reset effect prop',
+ redoLabel:
+ effectPropTargets.length > 1
+ ? 'Reapply selected effect props'
+ : 'Reapply effect prop',
}),
);
}
diff --git a/packages/studio/src/components/Timeline/save-effect-prop.ts b/packages/studio/src/components/Timeline/save-effect-prop.ts
index fbffa4adeb..84e4e6de41 100644
--- a/packages/studio/src/components/Timeline/save-effect-prop.ts
+++ b/packages/studio/src/components/Timeline/save-effect-prop.ts
@@ -1,6 +1,7 @@
import {
optimisticUpdateForEffectPropStatuses,
type EffectClipboardParam,
+ type SaveMultipleEffectPropsEdit,
} from '@remotion/studio-shared';
import type {SequencePropsSubscriptionKey, InteractivitySchema} from 'remotion';
import {callApi} from '../call-api';
@@ -31,6 +32,87 @@ type SaveEffectPropEffectParam = SaveEffectPropBase & {
type SaveEffectPropInput = SaveEffectPropValue | SaveEffectPropEffectParam;
+type WithoutSaveContext<T> = T extends unknown
+ ? Omit<T, 'setPropStatuses' | 'clientId'>
+ : never;
+
+type SaveMultipleEffectPropChange = WithoutSaveContext<SaveEffectPropInput>;
+
+type SaveMultipleEffectPropsOptions = {
+ changes: SaveMultipleEffectPropChange[];
+ setPropStatuses: SetPropStatuses;
+ clientId: string;
+ undoLabel: string;
+ redoLabel: string;
+};
+
+export const saveMultipleEffectProps = ({
+ changes,
+ setPropStatuses,
+ clientId,
+ undoLabel,
+ redoLabel,
+}: SaveMultipleEffectPropsOptions): Promise<void> => {
+ if (changes.length === 0) {
+ return Promise.resolve();
+ }
+
+ for (const change of changes) {
+ if (change.type === 'effect-param') {
+ continue;
+ }
+
+ setPropStatuses(change.nodePath, (prev) =>
+ optimisticUpdateForEffectPropStatuses({
+ previous: prev,
+ effectIndex: change.effectIndex,
+ fieldKey: change.fieldKey,
+ value: change.value,
+ schema: change.schema,
+ }),
+ );
+ }
+
+ return callApi('/api/save-multiple-effect-props', {
+ edits: changes.map(
+ (change): SaveMultipleEffectPropsEdit =>
+ change.type === 'effect-param'
+ ? {
+ type: 'effect-param',
+ fileName: change.fileName,
+ sequenceNodePath: change.nodePath,
+ effectIndex: change.effectIndex,
+ key: change.fieldKey,
+ effectParam: change.effectParam,
+ defaultValue: change.defaultValue,
+ schema: change.schema,
+ }
+ : {
+ type: 'value',
+ fileName: change.fileName,
+ sequenceNodePath: change.nodePath,
+ effectIndex: change.effectIndex,
+ key: change.fieldKey,
+ value: JSON.stringify(change.value),
+ defaultValue: change.defaultValue,
+ schema: change.schema,
+ },
+ ),
+ clientId,
+ undoLabel,
+ redoLabel,
+ }).then((response) => {
+ for (const result of response.results) {
+ setPropStatuses(result.sequenceNodePath, (prev) =>
+ applyEffectResponseToPropStatuses({
+ previous: prev,
+ response: result.status,
+ }),
+ );
+ }
+ });
+};
+
export const saveEffectProp = (input: SaveEffectPropInput): Promise<void> => {
const {
fileName,
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index 6b0da5c097..e08751c5b2 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -1394,12 +1394,125 @@ test('pasting an effect prop targets a matching selected effect', () => {
}),
).toEqual({
type: 'valid',
- fileName: '/project/src/Comp.tsx',
- nodePath,
- effectIndex: 1,
- fieldKey: 'intensity',
- defaultValue: '0',
- schema: effectSchema,
+ targets: [
+ {
+ fileName: '/project/src/Comp.tsx',
+ nodePath,
+ effectIndex: 1,
+ fieldKey: 'intensity',
+ defaultValue: '0',
+ schema: effectSchema,
+ },
+ ],
+ } satisfies PasteEffectPropTarget);
+});
+
+test('pasting an effect prop targets multiple matching selected effects', () => {
+ const firstNodePathInfo = makeNodePathInfo(
+ ['body', 0],
+ ['effects', '0'],
+ true,
+ [['intensity']],
+ );
+ const secondNodePathInfo = makeNodePathInfo(
+ ['body', 1],
+ ['effects', '0', 'intensity'],
+ true,
+ [['intensity']],
+ );
+ const firstNodePath = firstNodePathInfo.sequenceSubscriptionKey;
+ const secondNodePath = secondNodePathInfo.sequenceSubscriptionKey;
+ const effectSchema = {
+ intensity: {type: 'number', default: 0, hiddenFromList: false},
+ } satisfies InteractivitySchema;
+ const effectStatus = {
+ canUpdate: true,
+ callee: 'halftone',
+ importPath: '@remotion/effects/halftone',
+ effectIndex: 0,
+ props: {
+ intensity: {status: 'static', codeValue: 0},
+ },
+ } as const;
+ const propStatuses = {
+ [Internals.makeSequencePropsSubscriptionKey(firstNodePath)]: {
+ canUpdate: true,
+ props: {},
+ effects: [effectStatus],
+ },
+ [Internals.makeSequencePropsSubscriptionKey(secondNodePath)]: {
+ canUpdate: true,
+ props: {},
+ effects: [effectStatus],
+ },
+ } satisfies PropStatuses;
+
+ expect(
+ getPasteEffectPropTarget({
+ selectedItems: [
+ {
+ type: 'sequence-effect',
+ nodePathInfo: firstNodePathInfo,
+ i: 0,
+ },
+ {
+ type: 'sequence-effect-prop',
+ nodePathInfo: secondNodePathInfo,
+ i: 0,
+ key: 'intensity',
+ },
+ ],
+ payload: {
+ type: 'effect-prop',
+ version: 1,
+ remotionClipboard: 'effect-prop',
+ effect: {
+ callee: 'halftone',
+ importPath: '@remotion/effects/halftone',
+ },
+ key: 'intensity',
+ param: {type: 'static', value: 10},
+ },
+ propStatuses,
+ sequences: [
+ makeTimelineSequence({
+ schema: {},
+ effects: [{schema: effectSchema}],
+ id: 'first',
+ overrideId: 'first',
+ }),
+ makeTimelineSequence({
+ schema: {},
+ effects: [{schema: effectSchema}],
+ id: 'second',
+ overrideId: 'second',
+ }),
+ ],
+ overrideIdsToNodePaths: {
+ first: firstNodePath,
+ second: secondNodePath,
+ },
+ }),
+ ).toEqual({
+ type: 'valid',
+ targets: [
+ {
+ fileName: '/project/src/Comp.tsx',
+ nodePath: firstNodePath,
+ effectIndex: 0,
+ fieldKey: 'intensity',
+ defaultValue: '0',
+ schema: effectSchema,
+ },
+ {
+ fileName: '/project/src/Comp.tsx',
+ nodePath: secondNodePath,
+ effectIndex: 0,
+ fieldKey: 'intensity',
+ defaultValue: '0',
+ schema: effectSchema,
+ },
+ ],
} satisfies PasteEffectPropTarget);
});