Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Toggle selected keyframes together (#8230)

Jonny Burger29cb666cb04d
diff --git a/packages/studio-server/src/preview-server/api-routes.ts b/packages/studio-server/src/preview-server/api-routes.ts
index 756b8f28b3..6908d498f7 100644
--- a/packages/studio-server/src/preview-server/api-routes.ts
+++ b/packages/studio-server/src/preview-server/api-routes.ts
@@ -2,6 +2,7 @@ import type {ApiRoutes} from '@remotion/studio-shared';
import type {ApiHandler} from './api-types';
import {addEffectHandler} from './routes/add-effect';
import {addEffectKeyframeHandler} from './routes/add-effect-keyframe';
+import {addKeyframesHandler} from './routes/add-keyframes';
import {handleAddRender} from './routes/add-render';
import {addSequenceKeyframeHandler} from './routes/add-sequence-keyframe';
import {applyCodemodHandler} from './routes/apply-codemod';
@@ -76,6 +77,7 @@ export const allApiRoutes: {
'/api/move-keyframes': moveKeyframesHandler,
'/api/add-sequence-keyframe': addSequenceKeyframeHandler,
'/api/add-effect-keyframe': addEffectKeyframeHandler,
+ '/api/add-keyframes': addKeyframesHandler,
'/api/update-sequence-keyframe-settings':
updateSequenceKeyframeSettingsHandler,
'/api/update-effect-keyframe-settings': updateEffectKeyframeSettingsHandler,
diff --git a/packages/studio-server/src/preview-server/routes/add-keyframes.ts b/packages/studio-server/src/preview-server/routes/add-keyframes.ts
new file mode 100644
index 0000000000..8b5da873bb
--- /dev/null
+++ b/packages/studio-server/src/preview-server/routes/add-keyframes.ts
@@ -0,0 +1,346 @@
+import {readFileSync} from 'node:fs';
+import type {LogLevel} from '@remotion/renderer';
+import {RenderInternals} from '@remotion/renderer';
+import type {
+ AddEffectKeyframe,
+ AddKeyframesRequest,
+ AddKeyframesResponse,
+ AddSequenceKeyframe,
+} from '@remotion/studio-shared';
+import {
+ updateEffectKeyframes,
+ updateSequenceKeyframes,
+} from '../../codemods/update-keyframes/update-keyframes';
+import {writeFileAndNotifyFileWatchers} from '../../file-watcher';
+import {resolveFileInsideProject} from '../../helpers/resolve-file-inside-project';
+import type {ApiHandler} from '../api-types';
+import {
+ printUndoHint,
+ pushTransactionToUndoStack,
+ suppressUndoStackInvalidation,
+} from '../undo-stack';
+import {suppressBundlerUpdateForFile} from '../watch-ignore-next-change';
+import {logEffectUpdate} from './log-updates/log-effect-update';
+import {logUpdate} from './log-updates/log-update';
+import {withSavePropsLock} from './save-props-mutex';
+
+type ResolvedSequenceKeyframe = AddSequenceKeyframe & {
+ readonly index: number;
+ readonly absolutePath: string;
+ readonly fileRelativeToRoot: string;
+};
+
+type ResolvedEffectKeyframe = AddEffectKeyframe & {
+ readonly index: number;
+ readonly absolutePath: string;
+ readonly fileRelativeToRoot: string;
+};
+
+type FileGroup = {
+ readonly fileRelativeToRoot: string;
+ readonly sequenceKeyframes: ResolvedSequenceKeyframe[];
+ readonly effectKeyframes: ResolvedEffectKeyframe[];
+};
+
+type UndoSnapshot = {
+ readonly filePath: string;
+ readonly oldContents: string;
+ readonly newContents: string;
+ readonly logLine: number;
+};
+
+type SequenceLog = {
+ readonly fileRelativeToRoot: string;
+ readonly line: number;
+ readonly key: string;
+ readonly oldValueString: string;
+ readonly newValueString: string;
+ readonly formatted: boolean;
+};
+
+type EffectLog = {
+ readonly fileRelativeToRoot: string;
+ readonly line: number;
+ readonly effectName: string;
+ readonly propKey: string;
+ readonly oldValueString: string;
+ readonly newValueString: string;
+ readonly formatted: boolean;
+};
+
+const groupBy = <T>(items: T[], getKey: (item: T) => string): T[][] => {
+ const groups = new Map<string, T[]>();
+ for (const item of items) {
+ const key = getKey(item);
+ const group = groups.get(key) ?? [];
+ group.push(item);
+ groups.set(key, group);
+ }
+
+ return [...groups.values()];
+};
+
+const getBatchDescription = ({
+ totalKeyframes,
+ firstKeyframe,
+}: {
+ readonly totalKeyframes: number;
+ readonly firstKeyframe: {readonly key: string; readonly frame: number};
+}) => {
+ if (totalKeyframes === 1) {
+ return {
+ undoMessage: `↩️ ${firstKeyframe.key} keyframe removed at frame ${firstKeyframe.frame}`,
+ redoMessage: `↪️ ${firstKeyframe.key} keyframe added at frame ${firstKeyframe.frame}`,
+ };
+ }
+
+ return {
+ undoMessage: `↩️ ${totalKeyframes} keyframes removed`,
+ redoMessage: `↪️ ${totalKeyframes} keyframes added`,
+ };
+};
+
+export const addKeyframes = async ({
+ sequenceKeyframes,
+ effectKeyframes,
+ clientId,
+ remotionRoot,
+ logLevel,
+}: AddKeyframesRequest & {
+ readonly remotionRoot: string;
+ readonly logLevel: LogLevel;
+}): Promise<void> => {
+ const totalKeyframes = sequenceKeyframes.length + effectKeyframes.length;
+ if (totalKeyframes === 0) {
+ throw new Error('No keyframes were specified for adding');
+ }
+
+ const fileGroups = new Map<string, FileGroup>();
+
+ for (const [index, keyframe] of sequenceKeyframes.entries()) {
+ const {absolutePath, fileRelativeToRoot} = resolveFileInsideProject({
+ remotionRoot,
+ fileName: keyframe.fileName,
+ action: 'modify',
+ });
+ const group = fileGroups.get(absolutePath) ?? {
+ fileRelativeToRoot,
+ sequenceKeyframes: [],
+ effectKeyframes: [],
+ };
+ group.sequenceKeyframes.push({
+ ...keyframe,
+ index,
+ absolutePath,
+ fileRelativeToRoot,
+ });
+ fileGroups.set(absolutePath, group);
+ }
+
+ for (const [index, keyframe] of effectKeyframes.entries()) {
+ const {absolutePath, fileRelativeToRoot} = resolveFileInsideProject({
+ remotionRoot,
+ fileName: keyframe.fileName,
+ action: 'modify',
+ });
+ const group = fileGroups.get(absolutePath) ?? {
+ fileRelativeToRoot,
+ sequenceKeyframes: [],
+ effectKeyframes: [],
+ };
+ group.effectKeyframes.push({
+ ...keyframe,
+ index,
+ absolutePath,
+ fileRelativeToRoot,
+ });
+ fileGroups.set(absolutePath, group);
+ }
+
+ const snapshots: UndoSnapshot[] = [];
+ const sequenceLogs: SequenceLog[] = [];
+ const effectLogs: EffectLog[] = [];
+
+ for (const [absolutePath, group] of fileGroups) {
+ const fileContents = readFileSync(absolutePath, 'utf-8');
+ let output = fileContents;
+ let firstLogLine = Number.POSITIVE_INFINITY;
+
+ for (const keyframeGroup of groupBy(group.sequenceKeyframes, (keyframe) =>
+ JSON.stringify(keyframe.nodePath.nodePath),
+ )) {
+ const [firstSequenceKeyframe] = keyframeGroup;
+ if (!firstSequenceKeyframe) {
+ continue;
+ }
+
+ const result = await updateSequenceKeyframes({
+ input: output,
+ nodePath: firstSequenceKeyframe.nodePath.nodePath,
+ schema: firstSequenceKeyframe.schema,
+ updates: keyframeGroup.map((keyframe) => ({
+ key: keyframe.key,
+ operation: {
+ type: 'add',
+ frame: keyframe.frame,
+ value: JSON.parse(keyframe.value),
+ },
+ })),
+ });
+ output = result.output;
+ firstLogLine = Math.min(firstLogLine, result.logLine);
+
+ for (const [keyframeIndex, keyframe] of keyframeGroup.entries()) {
+ sequenceLogs.push({
+ fileRelativeToRoot: keyframe.fileRelativeToRoot,
+ line: result.logLine,
+ key: keyframe.key,
+ oldValueString: result.oldValueStrings[keyframeIndex],
+ newValueString: result.newValueStrings[keyframeIndex],
+ formatted: result.formatted,
+ });
+ }
+ }
+
+ for (const keyframeGroup of groupBy(
+ group.effectKeyframes,
+ (keyframe) =>
+ `${JSON.stringify(keyframe.sequenceNodePath.nodePath)}:${
+ keyframe.effectIndex
+ }`,
+ )) {
+ const [firstEffectKeyframe] = keyframeGroup;
+ if (!firstEffectKeyframe) {
+ continue;
+ }
+
+ const result = await updateEffectKeyframes({
+ input: output,
+ sequenceNodePath: firstEffectKeyframe.sequenceNodePath.nodePath,
+ effectIndex: firstEffectKeyframe.effectIndex,
+ schema: firstEffectKeyframe.schema,
+ updates: keyframeGroup.map((keyframe) => ({
+ key: keyframe.key,
+ operation: {
+ type: 'add',
+ frame: keyframe.frame,
+ value: JSON.parse(keyframe.value),
+ },
+ })),
+ });
+ output = result.output;
+ firstLogLine = Math.min(firstLogLine, result.logLine);
+
+ for (const [keyframeIndex, keyframe] of keyframeGroup.entries()) {
+ effectLogs.push({
+ fileRelativeToRoot: keyframe.fileRelativeToRoot,
+ line: result.logLine,
+ effectName: result.effectCallee,
+ propKey: keyframe.key,
+ oldValueString: result.oldValueStrings[keyframeIndex],
+ newValueString: result.newValueStrings[keyframeIndex],
+ formatted: result.formatted,
+ });
+ }
+ }
+
+ snapshots.push({
+ filePath: absolutePath,
+ oldContents: fileContents,
+ newContents: output,
+ logLine: Number.isFinite(firstLogLine) ? firstLogLine : 1,
+ });
+ }
+
+ const [firstKeyframe] =
+ sequenceKeyframes.length > 0 ? sequenceKeyframes : effectKeyframes;
+ if (!firstKeyframe) {
+ throw new Error('No keyframes were specified for adding');
+ }
+
+ pushTransactionToUndoStack({
+ snapshots,
+ logLevel,
+ remotionRoot,
+ description: getBatchDescription({totalKeyframes, firstKeyframe}),
+ entryType:
+ sequenceKeyframes.length > 0 && effectKeyframes.length > 0
+ ? // Dead code for now: sequence props and effect props cannot be selected
+ // together yet. Keep the mixed transaction type for the planned UI.
+ 'keyframe-add'
+ : sequenceKeyframes.length > 0
+ ? 'sequence-props'
+ : 'effect-props',
+ suppressHmrOnFileRestore: true,
+ });
+
+ for (const snapshot of snapshots) {
+ suppressUndoStackInvalidation(snapshot.filePath);
+ suppressBundlerUpdateForFile(snapshot.filePath);
+ writeFileAndNotifyFileWatchers(
+ snapshot.filePath,
+ snapshot.newContents,
+ clientId,
+ );
+ }
+
+ for (const log of sequenceLogs) {
+ logUpdate({
+ fileRelativeToRoot: log.fileRelativeToRoot,
+ line: log.line,
+ key: log.key,
+ oldValueString: log.oldValueString,
+ newValueString: log.newValueString,
+ defaultValueString: null,
+ formatted: log.formatted,
+ logLevel,
+ removedProps: [],
+ addedProps: [],
+ });
+ }
+
+ for (const log of effectLogs) {
+ logEffectUpdate({
+ fileRelativeToRoot: log.fileRelativeToRoot,
+ line: log.line,
+ effectName: log.effectName,
+ propKey: log.propKey,
+ oldValueString: log.oldValueString,
+ newValueString: log.newValueString,
+ defaultValueString: null,
+ formatted: log.formatted,
+ logLevel,
+ removedProps: [],
+ addedProps: [],
+ });
+ }
+
+ printUndoHint(logLevel);
+};
+
+export const addKeyframesHandler: ApiHandler<
+ AddKeyframesRequest,
+ AddKeyframesResponse
+> = ({
+ input: {sequenceKeyframes, effectKeyframes, clientId},
+ remotionRoot,
+ logLevel,
+}) =>
+ withSavePropsLock(async () => {
+ RenderInternals.Log.trace(
+ {indent: false, logLevel},
+ `[add-keyframes] Received request to add ${
+ sequenceKeyframes.length + effectKeyframes.length
+ } keyframe(s)`,
+ );
+
+ await addKeyframes({
+ sequenceKeyframes,
+ effectKeyframes,
+ clientId,
+ remotionRoot,
+ logLevel,
+ });
+
+ return {success: true};
+ });
diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.ts
index 1ebb72831d..0702239575 100644
--- a/packages/studio-server/src/preview-server/undo-stack.ts
+++ b/packages/studio-server/src/preview-server/undo-stack.ts
@@ -21,6 +21,9 @@ type UndoEntryType =
| 'default-props'
| 'sequence-props'
| 'effect-props'
+ // Dead code for now: the Studio selection model cannot mix sequence props and
+ // effect props yet, but this will be used once mixed prop selection is enabled.
+ | 'keyframe-add'
| 'keyframe-delete'
| 'add-effect'
| 'delete-effect'
@@ -57,6 +60,7 @@ type UndoEntry = {
| {entryType: 'default-props'}
| {entryType: 'sequence-props'}
| {entryType: 'effect-props'}
+ | {entryType: 'keyframe-add'}
| {entryType: 'keyframe-delete'}
| {entryType: 'add-effect'}
| {entryType: 'delete-effect'}
diff --git a/packages/studio-server/src/test/add-keyframes.test.ts b/packages/studio-server/src/test/add-keyframes.test.ts
new file mode 100644
index 0000000000..4d52268b86
--- /dev/null
+++ b/packages/studio-server/src/test/add-keyframes.test.ts
@@ -0,0 +1,114 @@
+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 {SequenceSchema} from 'remotion';
+import {NoReactInternals} from 'remotion/no-react';
+import {
+ createFileWatcherRegistry,
+ setFileWatcherRegistry,
+} from '../file-watcher';
+import {setLiveEventsListener} from '../preview-server/live-events';
+import {addKeyframes} from '../preview-server/routes/add-keyframes';
+import {
+ clearUndoStackForTests,
+ getUndoStack,
+ popRedo,
+ popUndo,
+} from '../preview-server/undo-stack';
+import {lineColumnToNodePath} from './test-utils';
+
+const input = `import {tint} from '@remotion/effects/tint';
+import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
+
+export const Comp = () => {
+\tconst frame = useCurrentFrame();
+\treturn (
+\t\t<AbsoluteFill
+\t\t\tstyle={{opacity: interpolate(frame, [0, 10], [0, 1])}}
+\t\t\teffects={[tint({amount: interpolate(frame, [0, 20], [0.2, 0.8])})]}
+\t\t/>
+\t);
+};
+`;
+
+const effectSchema = {
+ amount: {
+ type: 'number',
+ default: 0,
+ hiddenFromList: false,
+ },
+} satisfies SequenceSchema;
+
+test('addKeyframes batches sequence and effect adds into one undo entry', async () => {
+ const cleanupFileWatcher = setFileWatcherRegistry(
+ createFileWatcherRegistry(),
+ );
+ const cleanupLiveEvents = setLiveEventsListener({
+ addNewClientListener: () => () => undefined,
+ closeConnections: () => Promise.resolve(),
+ router: () => Promise.resolve(),
+ sendEventToClient: () => undefined,
+ sendEventToClientId: () => undefined,
+ });
+ const dir = mkdtempSync(join(tmpdir(), 'remotion-add-keyframes-'));
+ const fileName = 'Comp.tsx';
+ const filePath = join(dir, fileName);
+ const nodePath = {
+ absolutePath: fileName,
+ nodePath: lineColumnToNodePath(input, 7),
+ sequenceKeys: ['style.opacity'],
+ effectKeys: [['amount']],
+ };
+
+ try {
+ writeFileSync(filePath, input);
+
+ await addKeyframes({
+ sequenceKeyframes: [
+ {
+ fileName,
+ nodePath,
+ key: 'style.opacity',
+ frame: 5,
+ value: JSON.stringify(0.5),
+ schema: NoReactInternals.sequenceSchema,
+ },
+ ],
+ effectKeyframes: [
+ {
+ fileName,
+ sequenceNodePath: nodePath,
+ effectIndex: 0,
+ key: 'amount',
+ frame: 10,
+ value: JSON.stringify(0.4),
+ schema: effectSchema,
+ },
+ ],
+ clientId: 'test-client',
+ remotionRoot: dir,
+ logLevel: 'error',
+ });
+
+ const output = readFileSync(filePath, 'utf-8');
+ expect(output).toContain(
+ 'opacity: interpolate(frame, [0, 5, 10], [0, 0.5, 1])',
+ );
+ expect(output).toContain(
+ 'amount: interpolate(frame, [0, 10, 20], [0.2, 0.4, 0.8])',
+ );
+ 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 8d54c514be..d8bb0514ce 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -436,6 +436,8 @@ export type AddSequenceKeyframeRequest = {
export type AddSequenceKeyframeResponse = SaveSequencePropsResponse;
+export type AddSequenceKeyframe = Omit<AddSequenceKeyframeRequest, 'clientId'>;
+
export type DeleteEffectKeyframe = {
fileName: string;
sequenceNodePath: SequencePropsSubscriptionKey;
@@ -488,6 +490,18 @@ export type AddEffectKeyframeRequest = {
export type AddEffectKeyframeResponse = SaveEffectPropsResponse;
+export type AddEffectKeyframe = Omit<AddEffectKeyframeRequest, 'clientId'>;
+
+export type AddKeyframesRequest = {
+ sequenceKeyframes: AddSequenceKeyframe[];
+ effectKeyframes: AddEffectKeyframe[];
+ clientId: string;
+};
+
+export type AddKeyframesResponse = {
+ success: true;
+};
+
export type KeyframeSettings =
| {
type: 'settings';
@@ -778,6 +792,7 @@ export type ApiRoutes = {
AddEffectKeyframeRequest,
AddEffectKeyframeResponse
>;
+ '/api/add-keyframes': ReqAndRes<AddKeyframesRequest, AddKeyframesResponse>;
'/api/update-sequence-keyframe-settings': ReqAndRes<
UpdateSequenceKeyframeSettingsRequest,
UpdateSequenceKeyframeSettingsResponse
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 99d9e9898d..483854d3f6 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -2,6 +2,8 @@ export {splitAnsi, stripAnsi} from './ansi';
export {
AddEffectKeyframeRequest,
AddEffectKeyframeResponse,
+ AddKeyframesRequest,
+ AddKeyframesResponse,
AddEffectRequest,
AddEffectResponse,
AddRenderRequest,
@@ -92,6 +94,8 @@ export {
UpdateSequenceKeyframeSettingsRequest,
UpdateSequenceKeyframeSettingsResponse,
type KeyframeSettings,
+ type AddEffectKeyframe,
+ type AddSequenceKeyframe,
} from './api-requests';
export {
ASSET_DRAG_MIME_TYPE,
diff --git a/packages/studio/src/components/Timeline/Timeline.tsx b/packages/studio/src/components/Timeline/Timeline.tsx
index ed3557dd1e..b370ece5e0 100644
--- a/packages/studio/src/components/Timeline/Timeline.tsx
+++ b/packages/studio/src/components/Timeline/Timeline.tsx
@@ -24,6 +24,7 @@ import {TimelineDragHandler} from './TimelineDragHandler';
import {TimelineHeightContainer} from './TimelineHeightContainer';
import {TimelineInOutDragHandler} from './TimelineInOutDragHandler';
import {TimelineInOutPointer} from './TimelineInOutPointer';
+import {TimelineKeyframeTracksProvider} from './TimelineKeyframeTracksContext';
import {TimelineList} from './TimelineList';
import {TimelinePinchZoom} from './TimelinePinchZoom';
import {TimelinePlayCursorSyncer} from './TimelinePlayCursorSyncer';
@@ -261,42 +262,44 @@ const TimelineInner: React.FC = () => {
);
})}
<SequencePropsObserver />
- <TimelineSelectAllKeybindings timeline={shown} />
- <TimelineHeightContainer shown={shown} hasBeenCut={hasBeenCut}>
- {isStill ? (
- <TimelineList timeline={shown} />
- ) : (
- <TimelineWidthProvider>
- <TimelinePinchZoom />
- <SplitterContainer
- orientation="vertical"
- defaultFlex={0.2}
- id="names-to-timeline"
- maxFlex={0.5}
- minFlex={0.15}
- >
- <SplitterElement
- type="flexer"
- sticky={<TimelineTimePlaceholders />}
+ <TimelineKeyframeTracksProvider tracks={filtered}>
+ <TimelineSelectAllKeybindings timeline={shown} />
+ <TimelineHeightContainer shown={shown} hasBeenCut={hasBeenCut}>
+ {isStill ? (
+ <TimelineList timeline={shown} />
+ ) : (
+ <TimelineWidthProvider>
+ <TimelinePinchZoom />
+ <SplitterContainer
+ orientation="vertical"
+ defaultFlex={0.2}
+ id="names-to-timeline"
+ maxFlex={0.5}
+ minFlex={0.15}
>
- <TimelineList timeline={shown} />
- </SplitterElement>
- <SplitterHandle onCollapse={noop} allowToCollapse="none" />
- <SplitterElement type="anti-flexer" sticky={null}>
- <TimelineScrollable>
- <TimelineTracks timeline={shown} hasBeenCut={hasBeenCut} />
- <TimelinePlayCursorSyncer />
- <TimelineInOutPointer />
- <TimelineTimeIndicators />
- <TimelineDragHandler />
- <TimelineInOutDragHandler />
- <TimelineSlider />
- </TimelineScrollable>
- </SplitterElement>
- </SplitterContainer>
- </TimelineWidthProvider>
- )}
- </TimelineHeightContainer>
+ <SplitterElement
+ type="flexer"
+ sticky={<TimelineTimePlaceholders />}
+ >
+ <TimelineList timeline={shown} />
+ </SplitterElement>
+ <SplitterHandle onCollapse={noop} allowToCollapse="none" />
+ <SplitterElement type="anti-flexer" sticky={null}>
+ <TimelineScrollable>
+ <TimelineTracks timeline={shown} hasBeenCut={hasBeenCut} />
+ <TimelinePlayCursorSyncer />
+ <TimelineInOutPointer />
+ <TimelineTimeIndicators />
+ <TimelineDragHandler />
+ <TimelineInOutDragHandler />
+ <TimelineSlider />
+ </TimelineScrollable>
+ </SplitterElement>
+ </SplitterContainer>
+ </TimelineWidthProvider>
+ )}
+ </TimelineHeightContainer>
+ </TimelineKeyframeTracksProvider>
</TimelineContextMenuArea>
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
index 63b31f4235..a2d8bbeddc 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
@@ -396,6 +396,7 @@ export const TimelineEffectPropItem: React.FC<{
dragOverrideValue={dragOverrideValue}
schema={field.effectSchema}
effectIndex={field.effectIndex}
+ nodePathInfo={nodePathInfo}
/>
) : null;
diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
index 3e6caba73b..8eb9c818c4 100644
--- a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
+++ b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
@@ -4,19 +4,33 @@ import type {
CanUpdateSequencePropStatus,
CanUpdateSequencePropStatusKeyframed,
DragOverrideValue,
+ GetDragOverrides,
+ GetEffectDragOverrides,
+ PropStatuses,
SequencePropsSubscriptionKey,
SequenceSchema,
} from 'remotion';
import {Internals, useVideoConfig} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import {BLUE, LIGHT_TEXT} from '../../helpers/colors';
+import type {
+ SequenceNodePathInfo,
+ TrackWithHash,
+} from '../../helpers/get-timeline-sequence-sort-key';
+import {
+ buildTimelineTree,
+ type TimelineTreeNode,
+} from '../../helpers/timeline-layout';
+import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';
import {
- callAddEffectKeyframe,
- callAddSequenceKeyframe,
+ callAddKeyframes,
+ type AddEffectKeyframeChange,
+ type AddSequenceKeyframeChange,
} from './call-add-keyframe';
import {
- callDeleteEffectKeyframe,
- callDeleteSequenceKeyframe,
+ callDeleteKeyframes,
+ type DeleteEffectKeyframeChange,
+ type DeleteSequenceKeyframeChange,
} from './call-delete-keyframe';
import {
getNextKeyframeDisplayFrame,
@@ -25,7 +39,14 @@ import {
} from './get-keyframe-navigation';
import {getTimelineKeyframes} from './get-timeline-keyframes';
import {TimelineKeyframeDiamondIcon} from './TimelineKeyframeDiamondIcon';
-import {SELECTION_ENABLED} from './TimelineSelection';
+import {useTimelineKeyframeTracks} from './TimelineKeyframeTracksContext';
+import {
+ getTimelineSelectionFromNodePathInfo,
+ getTimelineSelectionKey,
+ SELECTION_ENABLED,
+ type TimelineSelection,
+ useTimelineSelection,
+} from './TimelineSelection';
const controlsContainerStyle: React.CSSProperties = {
alignItems: 'center',
@@ -65,7 +86,291 @@ const diamondButtonStyle: React.CSSProperties = {
const svgStyle: React.CSSProperties = {display: 'block'};
-const getCurrentKeyframeValue = ({
+type KeyframeControlTarget = {
+ readonly nodePathInfo: SequenceNodePathInfo;
+ readonly fieldKey: string;
+ readonly propStatus: CanUpdateSequencePropStatus;
+ readonly nodePath: SequencePropsSubscriptionKey;
+ readonly fileName: string;
+ readonly keyframeDisplayOffset: number;
+ readonly sourceFrame: number;
+ readonly defaultValue: unknown;
+ readonly dragOverrideValue: DragOverrideValue | undefined;
+ readonly schema: SequenceSchema;
+ readonly effectIndex: number | null;
+};
+
+const isKeyframeControlSelection = (
+ selection: TimelineSelection,
+): selection is TimelineSelection & {
+ readonly type: 'sequence-prop' | 'sequence-effect-prop';
+} => {
+ return (
+ selection.type === 'sequence-prop' ||
+ selection.type === 'sequence-effect-prop'
+ );
+};
+
+export const getSelectedKeyframeControlNodePathInfos = ({
+ clickedNodePathInfo,
+ selectedItems,
+}: {
+ readonly clickedNodePathInfo: SequenceNodePathInfo;
+ readonly selectedItems: readonly TimelineSelection[];
+}): readonly SequenceNodePathInfo[] => {
+ const clickedSelection =
+ getTimelineSelectionFromNodePathInfo(clickedNodePathInfo);
+ if (
+ clickedSelection === null ||
+ !isKeyframeControlSelection(clickedSelection)
+ ) {
+ return [clickedNodePathInfo];
+ }
+
+ const clickedSelectionKey = getTimelineSelectionKey(clickedSelection);
+ const selectedKeyframeControls = selectedItems.filter(
+ isKeyframeControlSelection,
+ );
+ const clickedIsSelected = selectedKeyframeControls.some(
+ (selection) => getTimelineSelectionKey(selection) === clickedSelectionKey,
+ );
+
+ if (!clickedIsSelected || selectedKeyframeControls.length <= 1) {
+ return [clickedNodePathInfo];
+ }
+
+ return selectedKeyframeControls.map((selection) => selection.nodePathInfo);
+};
+
+const findFieldNode = (
+ nodes: readonly TimelineTreeNode[],
+ nodePathInfoKey: string,
+): (TimelineTreeNode & {readonly kind: 'field'}) | null => {
+ for (const node of nodes) {
+ if (timelineNodePathInfoToKey(node.nodePathInfo) === nodePathInfoKey) {
+ return node.kind === 'field' ? node : null;
+ }
+
+ if (node.kind === 'group') {
+ const child = findFieldNode(node.children, nodePathInfoKey);
+ if (child !== null) {
+ return child;
+ }
+ }
+ }
+
+ return null;
+};
+
+const findTrackForNodePathInfo = ({
+ tracks,
+ nodePathInfo,
+}: {
+ readonly tracks: readonly TrackWithHash[];
+ readonly nodePathInfo: SequenceNodePathInfo;
+}): TrackWithHash | null => {
+ return (
+ tracks.find((track) => {
+ if (track.nodePathInfo === null) {
+ return false;
+ }
+
+ return (
+ timelineNodePathInfoToKey({
+ ...track.nodePathInfo,
+ auxiliaryKeys: [],
+ }) ===
+ timelineNodePathInfoToKey({
+ ...nodePathInfo,
+ auxiliaryKeys: [],
+ })
+ );
+ }) ?? null
+ );
+};
+
+const resolveKeyframeControlTarget = ({
+ nodePathInfo,
+ tracks,
+ propStatuses,
+ getDragOverrides,
+ getEffectDragOverrides,
+ timelinePosition,
+}: {
+ readonly nodePathInfo: SequenceNodePathInfo;
+ readonly tracks: readonly TrackWithHash[];
+ readonly propStatuses: PropStatuses;
+ readonly getDragOverrides: GetDragOverrides;
+ readonly getEffectDragOverrides: GetEffectDragOverrides;
+ readonly timelinePosition: number;
+}): KeyframeControlTarget | null => {
+ const track = findTrackForNodePathInfo({tracks, nodePathInfo});
+ if (
+ track === null ||
+ track.nodePathInfo === null ||
+ !track.sequence.controls
+ ) {
+ return null;
+ }
+
+ const tree = buildTimelineTree({
+ sequence: track.sequence,
+ nodePathInfo: track.nodePathInfo,
+ getDragOverrides,
+ getEffectDragOverrides,
+ propStatuses,
+ });
+ const fieldNode = findFieldNode(
+ tree,
+ timelineNodePathInfoToKey(nodePathInfo),
+ );
+ if (fieldNode === null || fieldNode.field === null) {
+ return null;
+ }
+
+ const nodePath = nodePathInfo.sequenceSubscriptionKey;
+ if (fieldNode.field.kind === 'sequence-field') {
+ const sequencePropStatuses = Internals.getPropStatusesCtx(
+ propStatuses,
+ nodePath,
+ );
+ const sequenceSelectedPropStatus =
+ sequencePropStatuses?.[fieldNode.field.key] ?? null;
+ if (sequenceSelectedPropStatus === null) {
+ return null;
+ }
+
+ return {
+ nodePathInfo,
+ fieldKey: fieldNode.field.key,
+ propStatus: sequenceSelectedPropStatus,
+ nodePath,
+ fileName: nodePath.absolutePath,
+ keyframeDisplayOffset: track.keyframeDisplayOffset,
+ sourceFrame: timelinePosition - track.keyframeDisplayOffset,
+ defaultValue: fieldNode.field.fieldSchema.default,
+ dragOverrideValue: (getDragOverrides(nodePath) ?? {})[
+ fieldNode.field.key
+ ],
+ schema: track.sequence.controls.schema,
+ effectIndex: null,
+ };
+ }
+
+ const effectStatus = Internals.getEffectPropStatusesCtx({
+ propStatuses,
+ nodePath,
+ effectIndex: fieldNode.field.effectIndex,
+ });
+ const effectSelectedPropStatus =
+ effectStatus.type === 'can-update-effect'
+ ? (effectStatus.props?.[fieldNode.field.key] ?? null)
+ : null;
+ if (effectSelectedPropStatus === null) {
+ return null;
+ }
+
+ return {
+ nodePathInfo,
+ fieldKey: fieldNode.field.key,
+ propStatus: effectSelectedPropStatus,
+ nodePath,
+ fileName: nodePath.absolutePath,
+ keyframeDisplayOffset: track.keyframeDisplayOffset,
+ sourceFrame: timelinePosition - track.keyframeDisplayOffset,
+ defaultValue: fieldNode.field.fieldSchema.default,
+ dragOverrideValue: getEffectDragOverrides(
+ nodePath,
+ fieldNode.field.effectIndex,
+ )[fieldNode.field.key],
+ schema: fieldNode.field.effectSchema,
+ effectIndex: fieldNode.field.effectIndex,
+ };
+};
+
+const hasTargetKeyframeAtCurrentFrame = (target: KeyframeControlTarget) => {
+ if (!isKeyframedStatus(target.propStatus)) {
+ return false;
+ }
+
+ return hasKeyframeAtSourceFrame(
+ target.propStatus.keyframes,
+ target.sourceFrame,
+ );
+};
+
+const getAddChange = (
+ target: KeyframeControlTarget,
+): AddSequenceKeyframeChange | AddEffectKeyframeChange | null => {
+ if (
+ target.propStatus.status === 'computed' ||
+ !isSchemaFieldKeyframable({schema: target.schema, key: target.fieldKey}) ||
+ hasTargetKeyframeAtCurrentFrame(target)
+ ) {
+ return null;
+ }
+
+ const value = getCurrentKeyframeValue({
+ propStatus: target.propStatus,
+ jsxFrame: target.sourceFrame,
+ defaultValue: target.defaultValue,
+ dragOverrideValue: target.dragOverrideValue,
+ });
+ if (value === null) {
+ return null;
+ }
+
+ const change = {
+ fileName: target.fileName,
+ nodePath: target.nodePath,
+ fieldKey: target.fieldKey,
+ sourceFrame: target.sourceFrame,
+ value,
+ schema: target.schema,
+ };
+
+ if (target.effectIndex === null) {
+ return change;
+ }
+
+ return {
+ ...change,
+ effectIndex: target.effectIndex,
+ };
+};
+
+const getDeleteChange = (
+ target: KeyframeControlTarget,
+): DeleteSequenceKeyframeChange | DeleteEffectKeyframeChange | null => {
+ if (!hasTargetKeyframeAtCurrentFrame(target)) {
+ return null;
+ }
+
+ const change = {
+ fileName: target.fileName,
+ nodePath: target.nodePath,
+ fieldKey: target.fieldKey,
+ sourceFrame: target.sourceFrame,
+ schema: target.schema,
+ };
+
+ if (target.effectIndex === null) {
+ return change;
+ }
+
+ return {
+ ...change,
+ effectIndex: target.effectIndex,
+ };
+};
+
+const hasEffectIndex = <T extends object>(
+ change: T,
+): change is T & {readonly effectIndex: number} => {
+ return 'effectIndex' in change;
+};
+
+function getCurrentKeyframeValue({
propStatus,
jsxFrame,
defaultValue,
@@ -75,7 +380,7 @@ const getCurrentKeyframeValue = ({
jsxFrame: number;
defaultValue: unknown;
dragOverrideValue: DragOverrideValue | undefined;
-}): unknown | null => {
+}): unknown | null {
if (isKeyframedStatus(propStatus)) {
return Internals.getEffectiveVisualModeValue({
propStatus,
@@ -97,7 +402,7 @@ const getCurrentKeyframeValue = ({
}
return null;
-};
+}
export const shouldShowTimelineKeyframeControls = ({
propStatus,
@@ -133,6 +438,7 @@ export const TimelineKeyframeControls: React.FC<{
readonly dragOverrideValue: DragOverrideValue | undefined;
readonly schema: SequenceSchema;
readonly effectIndex: number | null;
+ readonly nodePathInfo: SequenceNodePathInfo;
}> = ({
fieldKey,
propStatus,
@@ -143,12 +449,19 @@ export const TimelineKeyframeControls: React.FC<{
dragOverrideValue,
schema,
effectIndex,
+ nodePathInfo,
}) => {
const videoConfig = useVideoConfig();
const timelinePosition = Internals.Timeline.useTimelinePosition();
const setFrame = Internals.useTimelineSetFrame();
const {setPropStatuses} = useContext(Internals.VisualModeSettersContext);
+ const {propStatuses} = useContext(Internals.VisualModePropStatusesContext);
+ const {getDragOverrides, getEffectDragOverrides} = useContext(
+ Internals.VisualModeDragOverridesContext,
+ );
const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const {selectedItems} = useTimelineSelection();
+ const tracks = useTimelineKeyframeTracks();
const clientId =
previewServerState.type === 'connected'
@@ -172,17 +485,6 @@ export const TimelineKeyframeControls: React.FC<{
);
}, [jsxFrame, propStatus]);
- const currentKeyframeValue = useMemo(
- () =>
- getCurrentKeyframeValue({
- propStatus,
- jsxFrame,
- defaultValue,
- dragOverrideValue,
- }),
- [defaultValue, dragOverrideValue, jsxFrame, propStatus],
- );
-
const previousDisplayFrame = useMemo(
() =>
getPreviousKeyframeDisplayFrame(
@@ -211,6 +513,76 @@ export const TimelineKeyframeControls: React.FC<{
propStatus.status !== 'computed' &&
(hasKeyframeAtCurrentFrame || canAddKeyframe);
+ const selectedNodePathInfos = useMemo(
+ () =>
+ getSelectedKeyframeControlNodePathInfos({
+ clickedNodePathInfo: nodePathInfo,
+ selectedItems,
+ }),
+ [nodePathInfo, selectedItems],
+ );
+
+ const clickedTarget = useMemo(
+ (): KeyframeControlTarget => ({
+ nodePathInfo,
+ fieldKey,
+ propStatus,
+ nodePath,
+ fileName,
+ keyframeDisplayOffset,
+ sourceFrame: jsxFrame,
+ defaultValue,
+ dragOverrideValue,
+ schema,
+ effectIndex,
+ }),
+ [
+ defaultValue,
+ dragOverrideValue,
+ effectIndex,
+ fieldKey,
+ fileName,
+ jsxFrame,
+ keyframeDisplayOffset,
+ nodePath,
+ nodePathInfo,
+ propStatus,
+ schema,
+ ],
+ );
+
+ const keyframeToggleTargets = useMemo((): KeyframeControlTarget[] => {
+ const clickedNodePathInfoKey = timelineNodePathInfoToKey(nodePathInfo);
+ return selectedNodePathInfos.flatMap((selectedNodePathInfo) => {
+ if (
+ timelineNodePathInfoToKey(selectedNodePathInfo) ===
+ clickedNodePathInfoKey
+ ) {
+ return [clickedTarget];
+ }
+
+ const target = resolveKeyframeControlTarget({
+ nodePathInfo: selectedNodePathInfo,
+ tracks,
+ propStatuses,
+ getDragOverrides,
+ getEffectDragOverrides,
+ timelinePosition,
+ });
+
+ return target === null ? [] : [target];
+ });
+ }, [
+ clickedTarget,
+ getDragOverrides,
+ getEffectDragOverrides,
+ nodePathInfo,
+ propStatuses,
+ selectedNodePathInfos,
+ timelinePosition,
+ tracks,
+ ]);
+
const seekToDisplayFrame = useCallback(
(frame: number) => {
setFrame((current) => {
@@ -249,60 +621,42 @@ export const TimelineKeyframeControls: React.FC<{
return;
}
- if (hasKeyframeAtCurrentFrame && isKeyframedStatus(propStatus)) {
- if (effectIndex === null) {
- await callDeleteSequenceKeyframe({
- fileName,
- nodePath,
- fieldKey,
- sourceFrame: jsxFrame,
- schema,
- setPropStatuses,
- clientId,
- });
- return;
- }
-
- await callDeleteEffectKeyframe({
- fileName,
- nodePath,
- effectIndex,
- fieldKey,
- sourceFrame: jsxFrame,
- schema,
+ if (hasKeyframeAtCurrentFrame) {
+ const deleteChanges = keyframeToggleTargets.flatMap((target) => {
+ const change = getDeleteChange(target);
+ return change === null ? [] : [change];
+ });
+ await callDeleteKeyframes({
+ sequenceKeyframes: deleteChanges.filter(
+ (change): change is DeleteSequenceKeyframeChange =>
+ !hasEffectIndex(change),
+ ),
+ effectKeyframes: deleteChanges.filter(
+ (change): change is DeleteEffectKeyframeChange =>
+ hasEffectIndex(change),
+ ),
setPropStatuses,
clientId,
});
return;
}
- const value = currentKeyframeValue;
- if (value === null) {
- return;
- }
-
- if (effectIndex === null) {
- await callAddSequenceKeyframe({
- fileName,
- nodePath,
- fieldKey,
- sourceFrame: jsxFrame,
- value,
- schema,
- setPropStatuses,
- clientId,
- });
+ const addChanges = keyframeToggleTargets.flatMap((target) => {
+ const change = getAddChange(target);
+ return change === null ? [] : [change];
+ });
+ if (addChanges.length === 0) {
return;
}
- await callAddEffectKeyframe({
- fileName,
- nodePath,
- effectIndex,
- fieldKey,
- sourceFrame: jsxFrame,
- value,
- schema,
+ await callAddKeyframes({
+ sequenceKeyframes: addChanges.filter(
+ (change): change is AddSequenceKeyframeChange =>
+ !hasEffectIndex(change),
+ ),
+ effectKeyframes: addChanges.filter(
+ (change): change is AddEffectKeyframeChange => hasEffectIndex(change),
+ ),
setPropStatuses,
clientId,
});
@@ -310,15 +664,8 @@ export const TimelineKeyframeControls: React.FC<{
[
canToggleKeyframe,
clientId,
- effectIndex,
- fieldKey,
- fileName,
hasKeyframeAtCurrentFrame,
- currentKeyframeValue,
- jsxFrame,
- nodePath,
- propStatus,
- schema,
+ keyframeToggleTargets,
setPropStatuses,
],
);
diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeTracksContext.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeTracksContext.tsx
new file mode 100644
index 0000000000..aeb17a76e3
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineKeyframeTracksContext.tsx
@@ -0,0 +1,24 @@
+import React, {createContext, useContext} from 'react';
+import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
+
+const TimelineKeyframeTracksContext = createContext<readonly TrackWithHash[]>(
+ [],
+);
+
+// Keyframe diamonds need track metadata to resolve other selected rows. The
+// selection state only stores identities, and a mounted-row registry would miss
+// collapsed or otherwise unmounted rows.
+export const TimelineKeyframeTracksProvider: React.FC<{
+ readonly tracks: readonly TrackWithHash[];
+ readonly children: React.ReactNode;
+}> = ({tracks, children}) => {
+ return (
+ <TimelineKeyframeTracksContext.Provider value={tracks}>
+ {children}
+ </TimelineKeyframeTracksContext.Provider>
+ );
+};
+
+export const useTimelineKeyframeTracks = () => {
+ return useContext(TimelineKeyframeTracksContext);
+};
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index db5e0de359..d7fd8099ee 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -333,7 +333,7 @@ export const getTimelineSelectionFromNodePathInfo = (
return null;
};
-const getTimelineSelectionKey = (item: TimelineSelection): string => {
+export const getTimelineSelectionKey = (item: TimelineSelection): string => {
const sequenceKey = getTimelineSequenceSelectionKey(item.nodePathInfo);
switch (item.type) {
case 'sequence':
diff --git a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
index 06b706d79d..5ca5244f15 100644
--- a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
@@ -258,6 +258,7 @@ export const TimelineSequencePropItem: React.FC<{
dragOverrideValue={dragOverrideValue}
schema={schema}
effectIndex={null}
+ nodePathInfo={nodePathInfo}
/>
) : null;
diff --git a/packages/studio/src/components/Timeline/call-add-keyframe.ts b/packages/studio/src/components/Timeline/call-add-keyframe.ts
index 1236d99591..d505a6d51c 100644
--- a/packages/studio/src/components/Timeline/call-add-keyframe.ts
+++ b/packages/studio/src/components/Timeline/call-add-keyframe.ts
@@ -8,6 +8,33 @@ import {applyEffectResponseToPropStatuses} from './apply-effect-response-to-prop
import {enqueueSavePropChange} from './save-prop-queue';
import type {SetPropStatuses} from './save-sequence-prop';
+export type AddSequenceKeyframeChange = {
+ fileName: string;
+ nodePath: SequencePropsSubscriptionKey;
+ fieldKey: string;
+ sourceFrame: number;
+ value: unknown;
+ schema: SequenceSchema;
+};
+
+export type AddEffectKeyframeChange = AddSequenceKeyframeChange & {
+ effectIndex: number;
+};
+
+const groupByNodePath = <T extends {nodePath: SequencePropsSubscriptionKey}>(
+ keyframes: T[],
+): T[][] => {
+ const groups = new Map<string, T[]>();
+ for (const keyframe of keyframes) {
+ const key = JSON.stringify(keyframe.nodePath);
+ const group = groups.get(key) ?? [];
+ group.push(keyframe);
+ groups.set(key, group);
+ }
+
+ return [...groups.values()];
+};
+
export const callAddSequenceKeyframe = ({
fileName,
nodePath,
@@ -52,6 +79,86 @@ export const callAddSequenceKeyframe = ({
});
};
+export const callAddKeyframes = ({
+ sequenceKeyframes,
+ effectKeyframes,
+ setPropStatuses,
+ clientId,
+}: {
+ sequenceKeyframes: AddSequenceKeyframeChange[];
+ effectKeyframes: AddEffectKeyframeChange[];
+ setPropStatuses: SetPropStatuses;
+ clientId: string;
+}): Promise<void> => {
+ if (sequenceKeyframes.length === 0 && effectKeyframes.length === 0) {
+ return Promise.resolve();
+ }
+
+ for (const keyframes of groupByNodePath(sequenceKeyframes)) {
+ const [firstKeyframe] = keyframes;
+ if (!firstKeyframe) {
+ continue;
+ }
+
+ setPropStatuses(firstKeyframe.nodePath, (prev) =>
+ keyframes.reduce(
+ (current, keyframe) =>
+ optimisticAddSequenceKeyframe({
+ previous: current,
+ fieldKey: keyframe.fieldKey,
+ frame: keyframe.sourceFrame,
+ value: keyframe.value,
+ schema: keyframe.schema,
+ }),
+ prev,
+ ),
+ );
+ }
+
+ for (const keyframes of groupByNodePath(effectKeyframes)) {
+ const [firstKeyframe] = keyframes;
+ if (!firstKeyframe) {
+ continue;
+ }
+
+ setPropStatuses(firstKeyframe.nodePath, (prev) =>
+ keyframes.reduce(
+ (current, keyframe) =>
+ optimisticAddEffectKeyframe({
+ previous: current,
+ effectIndex: keyframe.effectIndex,
+ fieldKey: keyframe.fieldKey,
+ frame: keyframe.sourceFrame,
+ value: keyframe.value,
+ schema: keyframe.schema,
+ }),
+ prev,
+ ),
+ );
+ }
+
+ return callApi('/api/add-keyframes', {
+ sequenceKeyframes: sequenceKeyframes.map((keyframe) => ({
+ fileName: keyframe.fileName,
+ nodePath: keyframe.nodePath,
+ key: keyframe.fieldKey,
+ frame: keyframe.sourceFrame,
+ value: JSON.stringify(keyframe.value),
+ schema: keyframe.schema,
+ })),
+ effectKeyframes: effectKeyframes.map((keyframe) => ({
+ fileName: keyframe.fileName,
+ sequenceNodePath: keyframe.nodePath,
+ effectIndex: keyframe.effectIndex,
+ key: keyframe.fieldKey,
+ frame: keyframe.sourceFrame,
+ value: JSON.stringify(keyframe.value),
+ schema: keyframe.schema,
+ })),
+ clientId,
+ }).then(() => undefined);
+};
+
export const callAddEffectKeyframe = ({
fileName,
nodePath,
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index f5e29d0051..dd0394c9de 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -37,6 +37,7 @@ import {
type PasteEffectPropTarget,
type PasteEffectsTarget,
} from '../components/Timeline/TimelineClipboardKeybindings';
+import {getSelectedKeyframeControlNodePathInfos} from '../components/Timeline/TimelineKeyframeControls';
import {
ENABLE_OUTLINES,
getSelectableTimelineSequenceSelections,
@@ -202,6 +203,35 @@ test('Timeline selection should stay disabled until released publicly', () => {
expect(SELECTION_ENABLED).toBe(false);
});
+test('keyframe diamond target resolution uses all selected prop rows when clicked row is selected', () => {
+ const opacity = makeNodePathInfo(['body', 0], ['controls', 'style.opacity']);
+ const rotate = makeNodePathInfo(['body', 0], ['controls', 'style.rotate']);
+
+ expect(
+ getSelectedKeyframeControlNodePathInfos({
+ clickedNodePathInfo: opacity,
+ selectedItems: [
+ {type: 'sequence-prop', nodePathInfo: opacity, key: 'style.opacity'},
+ {type: 'sequence-prop', nodePathInfo: rotate, key: 'style.rotate'},
+ ],
+ }),
+ ).toEqual([opacity, rotate]);
+});
+
+test('keyframe diamond target resolution falls back to clicked row when it is not selected', () => {
+ const opacity = makeNodePathInfo(['body', 0], ['controls', 'style.opacity']);
+ const rotate = makeNodePathInfo(['body', 0], ['controls', 'style.rotate']);
+
+ expect(
+ getSelectedKeyframeControlNodePathInfos({
+ clickedNodePathInfo: opacity,
+ selectedItems: [
+ {type: 'sequence-prop', nodePathInfo: rotate, key: 'style.rotate'},
+ ],
+ }),
+ ).toEqual([opacity]);
+});
+
test('pasting effects is blocked for sequences that do not support effects', () => {
const unsupportedSequenceNodePathInfo = makeNodePathInfo(
['body', 0],