Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Drag selected clips together to reorder them

Jonny Burger6257970b97cb
diff --git a/packages/browser-studio/src/browser-studio-operations.ts b/packages/browser-studio/src/browser-studio-operations.ts
index 8d977c958c..574a330f0d 100644
--- a/packages/browser-studio/src/browser-studio-operations.ts
+++ b/packages/browser-studio/src/browser-studio-operations.ts
@@ -1868,14 +1868,13 @@ export const createBrowserStudioOperations = ({
});
};
- const reorderSequence: BrowserStudioOperations['reorderSequence'] = async (
- request,
- ) => {
+ const reorderSequence: BrowserStudioOperations['reorderSequence'] = async ({
+ fileName,
+ sourceNodePaths,
+ targetNodePath,
+ position,
+ }) => {
try {
- const {fileName, targetNodePath, position} = request;
- const sourceNodePaths =
- request.sourceNodePaths ??
- (request.sourceNodePath ? [request.sourceNodePath] : []);
const project = getProject();
const absolutePath = findProjectFile({
filePath: fileName,
diff --git a/packages/browser-studio/src/test/browser-studio-operations.test.ts b/packages/browser-studio/src/test/browser-studio-operations.test.ts
index 8ac19b74e3..d65951ba2a 100644
--- a/packages/browser-studio/src/test/browser-studio-operations.test.ts
+++ b/packages/browser-studio/src/test/browser-studio-operations.test.ts
@@ -1656,21 +1656,21 @@ registerRoot(Root);`,
const identicalFailure = await operations.reorderSequence({
fileName: 'src/Composition.tsx',
- sourceNodePath: firstNodePath,
+ sourceNodePaths: [firstNodePath],
targetNodePath: firstNodePath,
position: 'after',
clientId: 'browser-studio',
});
expect(identicalFailure).toMatchObject({
success: false,
- reason: 'Cannot reorder sequence: source and target are identical',
+ reason: 'Cannot reorder sequences relative to a selected sequence',
stack: expect.any(String),
});
expect(getProject().files[fileName]).toBe(initialContents);
const result = await operations.reorderSequence({
fileName: 'src/Composition.tsx',
- sourceNodePath: firstNodePath,
+ sourceNodePaths: [firstNodePath],
targetNodePath: secondNodePath,
position: 'after',
clientId: 'browser-studio',
diff --git a/packages/codemods/src/reorder-sequence.ts b/packages/codemods/src/reorder-sequence.ts
index 547529cbef..280c99495a 100644
--- a/packages/codemods/src/reorder-sequence.ts
+++ b/packages/codemods/src/reorder-sequence.ts
@@ -43,8 +43,7 @@ const getJsxChildrenParent = (
return null;
};
-/* eslint-disable require-await -- Keep the formatter-era Promise API. */
-export const reorderSequences = async ({
+export const reorderSequences = ({
input,
sourceNodePaths,
targetNodePath,
@@ -54,20 +53,13 @@ export const reorderSequences = async ({
sourceNodePaths: readonly SequenceNodePath[];
targetNodePath: SequenceNodePath;
position: ReorderSequencePosition;
- // Kept optional for compatibility with callers from before source edits
- // replaced the full-file formatting pass.
- formatFile?: (input: {
- contents: string;
- prettierConfigOverride: Record<string, unknown> | null;
- }) => Promise<{output: string; formatted: boolean}>;
- prettierConfigOverride?: Record<string, unknown> | null;
-}): Promise<{
+}): {
output: string;
formatted: boolean;
sequenceLabel: string;
logLine: number;
nodePathRemappings: SequenceNodePathRemapping[];
-}> => {
+} => {
if (sourceNodePaths.length === 0) {
throw new Error('Cannot reorder an empty selection');
}
@@ -112,11 +104,7 @@ export const reorderSequences = async ({
}
if (selectedElements.has(targetElement)) {
- throw new Error(
- sourceElements.length === 1
- ? 'Cannot reorder sequence: source and target are identical'
- : 'Cannot reorder sequences relative to a selected sequence',
- );
+ throw new Error('Cannot reorder sequences relative to a selected sequence');
}
const {children} = targetParent;
@@ -187,20 +175,3 @@ export const reorderSequences = async ({
nodePathRemappings,
};
};
-
-export const reorderSequence = (options: {
- input: string;
- sourceNodePath: SequenceNodePath;
- targetNodePath: SequenceNodePath;
- position: ReorderSequencePosition;
- formatFile?: (input: {
- contents: string;
- prettierConfigOverride: Record<string, unknown> | null;
- }) => Promise<{output: string; formatted: boolean}>;
- prettierConfigOverride?: Record<string, unknown> | null;
-}) =>
- reorderSequences({
- ...options,
- sourceNodePaths: [options.sourceNodePath],
- });
-/* eslint-enable require-await */
diff --git a/packages/codemods/src/test/reorder-sequence.test.ts b/packages/codemods/src/test/reorder-sequence.test.ts
index 9179ee038a..0343b303da 100644
--- a/packages/codemods/src/test/reorder-sequence.test.ts
+++ b/packages/codemods/src/test/reorder-sequence.test.ts
@@ -1,6 +1,6 @@
import {expect, test} from 'bun:test';
import {getNodes} from '../get-nodes';
-import {reorderSequence} from '../reorder-sequence';
+import {reorderSequences} from '../reorder-sequence';
import {lineColumnToNodePath} from './node-path-test-utils';
const sequenceContaining = (input: string, search: string) => {
@@ -53,22 +53,16 @@ export const Comp=()=>{
}
`;
-test('reorderSequence moves a sequence forward without formatting the file', async () => {
+test('reorderSequences moves a sequence forward without formatting the file', () => {
const input = buildInput();
- let formatCalls = 0;
- const {output, sequenceLabel, nodePathRemappings} = await reorderSequence({
+ const {output, sequenceLabel, nodePathRemappings} = reorderSequences({
input,
- sourceNodePath: sequenceContaining(input, "name='a'"),
+ sourceNodePaths: [sequenceContaining(input, "name='a'")],
targetNodePath: sequenceContaining(input, "name='c'"),
position: 'after',
- formatFile: () => {
- formatCalls++;
- throw new Error('Prettier must not be called');
- },
});
expect(sequenceLabel).toBe('<Sequence>');
- expect(formatCalls).toBe(0);
expect(output).toBe(`import {Sequence} from 'remotion'
const untouched = {keep:"this spacing"}
@@ -109,11 +103,11 @@ export const Comp=()=>{
]);
});
-test('reorderSequence moves a sequence backward', async () => {
+test('reorderSequences moves a sequence backward', () => {
const input = buildInput();
- const {output, sequenceLabel} = await reorderSequence({
+ const {output, sequenceLabel} = reorderSequences({
input,
- sourceNodePath: sequenceContaining(input, "name='c'"),
+ sourceNodePaths: [sequenceContaining(input, "name='c'")],
targetNodePath: sequenceContaining(input, "name='a'"),
position: 'before',
});
@@ -139,7 +133,7 @@ export const Comp=()=>{
`);
});
-test('reorderSequence preserves CRLF and multiline JSX', async () => {
+test('reorderSequences preserves CRLF and multiline JSX', () => {
const input = [
'export const Comp = () => (',
' <>',
@@ -154,9 +148,9 @@ test('reorderSequence preserves CRLF and multiline JSX', async () => {
'',
].join('\r\n');
- const {output} = await reorderSequence({
+ const {output} = reorderSequences({
input,
- sourceNodePath: sequenceContaining(input, 'name="b"'),
+ sourceNodePaths: [sequenceContaining(input, 'name="b"')],
targetNodePath: sequenceContaining(input, 'name="c"'),
position: 'after',
});
@@ -178,13 +172,13 @@ test('reorderSequence preserves CRLF and multiline JSX', async () => {
);
});
-test('reorderSequence keeps inline siblings parseable', async () => {
+test('reorderSequences keeps inline siblings parseable', () => {
const input =
'export const Comp=()=> <><Sequence name="a"/><Sequence name="b"/></>;\n';
- const {output} = await reorderSequence({
+ const {output} = reorderSequences({
input,
- sourceNodePath: sequenceContaining(input, 'name="a"'),
+ sourceNodePaths: [sequenceContaining(input, 'name="a"')],
targetNodePath: sequenceContaining(input, 'name="b"'),
position: 'after',
});
@@ -194,7 +188,7 @@ test('reorderSequence keeps inline siblings parseable', async () => {
);
});
-test('reorderSequence rejects sequences with different JSX parents', async () => {
+test('reorderSequences rejects sequences with different JSX parents', () => {
const input = `import {Sequence} from 'remotion';
export const Comp = () => {
@@ -209,26 +203,26 @@ export const Comp = () => {
};
`;
- await expect(
- reorderSequence({
+ expect(() =>
+ reorderSequences({
input,
- sourceNodePath: lineColumnToNodePath(input, 7),
+ sourceNodePaths: [lineColumnToNodePath(input, 7)],
targetNodePath: lineColumnToNodePath(input, 9),
position: 'before',
}),
- ).rejects.toThrow(/not JSX siblings/);
+ ).toThrow(/not JSX siblings/);
});
-test('reorderSequence rejects identical source and target sequences', async () => {
+test('reorderSequences rejects identical source and target sequences', () => {
const input = buildInput();
const nodePath = sequenceContaining(input, "name='a'");
- await expect(
- reorderSequence({
+ expect(() =>
+ reorderSequences({
input,
- sourceNodePath: nodePath,
+ sourceNodePaths: [nodePath],
targetNodePath: nodePath,
position: 'after',
}),
- ).rejects.toThrow(/source and target are identical/);
+ ).toThrow(/relative to a selected sequence/);
});
diff --git a/packages/studio-server/src/preview-server/routes/reorder-sequence.ts b/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
index 5a73b9885a..a174035a34 100644
--- a/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
+++ b/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
@@ -24,13 +24,13 @@ import {
export const reorderSequenceHandler: ApiHandler<
ReorderSequenceRequest,
ReorderSequenceResponse
-> = ({input, remotionRoot, logLevel}) => {
+> = ({
+ input: {fileName, sourceNodePaths, targetNodePath, position, clientId},
+ remotionRoot,
+ logLevel,
+}) => {
return withSourceFileWriteQueue(async () => {
try {
- const {fileName, targetNodePath, position, clientId} = input;
- const sourceNodePaths =
- input.sourceNodePaths ??
- (input.sourceNodePath ? [input.sourceNodePath] : []);
RenderInternals.Log.trace(
{indent: false, logLevel},
`[reorder-sequence] Received request for fileName="${fileName}" position=${position}`,
diff --git a/packages/studio-server/src/test/node-path-mutation-routes.test.ts b/packages/studio-server/src/test/node-path-mutation-routes.test.ts
index 88eb32cd03..f9721e7288 100644
--- a/packages/studio-server/src/test/node-path-mutation-routes.test.ts
+++ b/packages/studio-server/src/test/node-path-mutation-routes.test.ts
@@ -144,7 +144,7 @@ test('JSX structure routes broadcast and return node path mutations before writi
clientId: 'initiating-client',
fileName,
position: 'after',
- sourceNodePath: subscriptionKey('name="a"'),
+ sourceNodePaths: [subscriptionKey('name="a"')],
targetNodePath: subscriptionKey('name="c"'),
},
});
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index 3c547b3a9b..a0f02f9ea9 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -694,13 +694,11 @@ export type ReorderSequencePosition = 'before' | 'after';
export type ReorderSequenceRequest = {
fileName: string;
+ sourceNodePaths: SequencePropsSubscriptionKey[];
targetNodePath: SequencePropsSubscriptionKey;
position: ReorderSequencePosition;
clientId: string;
-} & (
- | {sourceNodePaths: SequencePropsSubscriptionKey[]; sourceNodePath?: never}
- | {sourceNodePath: SequencePropsSubscriptionKey; sourceNodePaths?: never}
-);
+};
export type ReorderSequenceResponse =
| {