🎥 Make videos programmatically with React
nice progress
Jonny Burger079fd1df1b18
diff --git a/packages/studio-server/src/codemods/apply-visual-control.ts b/packages/studio-server/src/codemods/apply-visual-control.tsindex 11c27dd2b1..b431740910 100644--- a/packages/studio-server/src/codemods/apply-visual-control.ts+++ b/packages/studio-server/src/codemods/apply-visual-control.ts@@ -1,4 +1,8 @@-import type {File} from '@babel/types';+import type {+ AssignmentExpression,+ ExpressionStatement,+ File,+} from '@babel/types';import type {ApplyVisualControlCodemod} from '@remotion/studio-shared';import type {namedTypes} from 'ast-types';import {visit} from 'ast-types';@@ -55,8 +59,14 @@ export const applyVisualControl = ({continue;}- node.arguments[1] = parseAst(change.newValueSerialized).program- .body[0] as unknown as ExpressionKind;+ const parsed = (+ (+ parseAst('a = ' + change.newValueSerialized).program+ .body[0] as unknown as ExpressionStatement+ ).expression as AssignmentExpression+ ).right as ExpressionKind;++ node.arguments[1] = parsed;changesMade.push({description: `Applied visual control ${change.id}`,diff --git a/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts b/packages/studio-server/src/preview-server/routes/apply-visual-control-change.tsindex 738599def6..670118b1ab 100644--- a/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts+++ b/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts@@ -12,42 +12,34 @@ export const applyVisualControlHandler: ApiHandler<ApplyVisualControlRequest,ApplyVisualControlResponse> = ({input: {fileName, changes}, remotionRoot}) => {- try {- const absolutePath = path.resolve(remotionRoot, fileName);- const fileRelativeToRoot = path.relative(remotionRoot, absolutePath);- if (fileRelativeToRoot.startsWith('..')) {- throw new Error(- 'Cannot apply visual control change to a file outside the project',- );- }+ const absolutePath = path.resolve(remotionRoot, fileName);+ const fileRelativeToRoot = path.relative(remotionRoot, absolutePath);+ if (fileRelativeToRoot.startsWith('..')) {+ throw new Error(+ 'Cannot apply visual control change to a file outside the project',+ );+ }- const fileContents = readFileSync(absolutePath, 'utf-8');- const ast = parseAst(fileContents);+ const fileContents = readFileSync(absolutePath, 'utf-8');+ const ast = parseAst(fileContents);- const {newAst, changesMade} = applyCodemod({- file: ast,- codeMod: {- type: 'apply-visual-control',- changes,- },- });+ const {newAst, changesMade} = applyCodemod({+ file: ast,+ codeMod: {+ type: 'apply-visual-control',+ changes,+ },+ });- if (changesMade.length === 0) {- throw new Error('No changes were made to the file');- }+ if (changesMade.length === 0) {+ throw new Error('No changes were made to the file');+ }- const output = serializeAst(newAst);+ const output = serializeAst(newAst);- writeFileSync(absolutePath, output);+ writeFileSync(absolutePath, output);- return Promise.resolve({- success: true,- });- } catch (err) {- return Promise.resolve({- success: false,- reason: (err as Error).message,- stack: (err as Error).stack as string,- });- }+ return Promise.resolve({+ success: true,+ });};diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex 15fad58a75..6c78002850 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -135,7 +135,7 @@ export type ApplyVisualControlRequest = {};export type ApplyVisualControlResponse = {- success: boolean;+ success: true;};export type UpdateDefaultPropsResponse =diff --git a/packages/studio/src/components/VisualControls/VisualControlHandle.tsx b/packages/studio/src/components/VisualControls/VisualControlHandle.tsxindex 1bcfeb5076..2d1600723e 100644--- a/packages/studio/src/components/VisualControls/VisualControlHandle.tsx+++ b/packages/studio/src/components/VisualControls/VisualControlHandle.tsx@@ -8,6 +8,7 @@ import {type VisualControlValue,} from '../../visual-controls/VisualControls';import {getVisualControlEditedValue} from '../../visual-controls/get-current-edited-value';+import {showNotification} from '../Notifications/NotificationCenter';import type {UpdaterFunction} from '../RenderModal/SchemaEditor/ZodSwitch';import {ZodSwitch} from '../RenderModal/SchemaEditor/ZodSwitch';import {useLocalState} from '../RenderModal/SchemaEditor/local-state';@@ -45,6 +46,7 @@ export const VisualControlHandle: React.FC<{const onSave: UpdaterFunction<unknown> = useCallback((updater) => {const val = updater(value.valueInCode);+window.remotion_ignoreFastRefreshUpdate = fastRefreshes + 1;applyVisualControlChange({fileName: 'src/VisualControls/index.tsx',@@ -54,6 +56,8 @@ export const VisualControlHandle: React.FC<{newValueSerialized: JSON.stringify(val),},],+ }).catch((e) => {+ showNotification(`Could not save visual control: ${e.message}`, 3000);});},[fastRefreshes, keyName, value.valueInCode],