Skip to content

🎥 Make videos programmatically with React

setup

Jonny Burger6c20593a4378
diff --git a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
index f3809c47e9..afc3eea630 100644
--- a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
@@ -272,6 +272,43 @@ const getNestedPropStatus = (
return {canUpdate: true, codeValue: extractStaticValue(propValue)};
};
+export const computeSequencePropsStatusFromContent = (
+ fileContents: string,
+ nodePath: SequenceNodePath,
+ keys: string[],
+): CanUpdateSequencePropsResponse => {
+ const ast = parseAst(fileContents);
+
+ const jsxElement = findJsxElementAtNodePath(ast, nodePath);
+
+ if (!jsxElement) {
+ throw new Error('Could not find a JSX element at the specified location');
+ }
+
+ const allProps = getPropsStatus(jsxElement);
+ const filteredProps: Record<string, CanUpdatePropStatus> = {};
+ for (const key of keys) {
+ const dotIndex = key.indexOf('.');
+ if (dotIndex !== -1) {
+ filteredProps[key] = getNestedPropStatus(
+ jsxElement,
+ key.slice(0, dotIndex),
+ key.slice(dotIndex + 1),
+ );
+ } else if (key in allProps) {
+ filteredProps[key] = allProps[key];
+ } else {
+ filteredProps[key] = {canUpdate: true, codeValue: undefined};
+ }
+ }
+
+ return {
+ canUpdate: true as const,
+ props: filteredProps,
+ nodePath,
+ };
+};
+
export const computeSequencePropsStatus = ({
fileName,
nodePath,
@@ -291,36 +328,7 @@ export const computeSequencePropsStatus = ({
}
const fileContents = readFileSync(absolutePath, 'utf-8');
- const ast = parseAst(fileContents);
-
- const jsxElement = findJsxElementAtNodePath(ast, nodePath);
-
- if (!jsxElement) {
- throw new Error('Could not find a JSX element at the specified location');
- }
-
- const allProps = getPropsStatus(jsxElement);
- const filteredProps: Record<string, CanUpdatePropStatus> = {};
- for (const key of keys) {
- const dotIndex = key.indexOf('.');
- if (dotIndex !== -1) {
- filteredProps[key] = getNestedPropStatus(
- jsxElement,
- key.slice(0, dotIndex),
- key.slice(dotIndex + 1),
- );
- } else if (key in allProps) {
- filteredProps[key] = allProps[key];
- } else {
- filteredProps[key] = {canUpdate: true, codeValue: undefined};
- }
- }
-
- return {
- canUpdate: true as const,
- props: filteredProps,
- nodePath,
- };
+ return computeSequencePropsStatusFromContent(fileContents, nodePath, keys);
} catch (err) {
return {
canUpdate: false as const,
diff --git a/packages/studio-server/src/test/unsupported-translate.test.ts b/packages/studio-server/src/test/unsupported-translate.test.ts
new file mode 100644
index 0000000000..f7f6d19777
--- /dev/null
+++ b/packages/studio-server/src/test/unsupported-translate.test.ts
@@ -0,0 +1,36 @@
+import assert from 'assert';
+import {expect, test} from 'bun:test';
+import {computeSequencePropsStatusFromContent} from '../preview-server/routes/can-update-sequence-props';
+import {lineColumnToNodePath} from './test-utils';
+
+const componentInput = `import {Video} from '@remotion/media';
+
+const src = 'https://remotion.media/video.mp4';
+
+export const Component = () => {
+ return (
+ <Video
+ src={src}
+ style={{
+ translate: '0px 202px',
+ scale: 2.47,
+ }}
+ playbackRate={2.19}
+ />
+ );
+};
+
+`;
+
+test('Should be able to update translate if it is pixels', () => {
+ const result = computeSequencePropsStatusFromContent(
+ componentInput,
+ lineColumnToNodePath(componentInput, 7),
+ ['style.scale', 'style.translate'],
+ );
+
+ assert(result.canUpdate);
+ expect(result.props['style.translate'].canUpdate).toBe(true);
+ assert(result.props['style.translate'].canUpdate);
+ expect(result.props['style.translate'].codeValue).toBe('0px 202px');
+});