Skip to content

🎥 Make videos programmatically with React

better handling if no props are specified

Jonny Burger11e88772c82b
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx
index 02b1b4d085..60ecaaa81d 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx
@@ -88,6 +88,8 @@ export const RenderModalJSONInputPropsEditor: React.FC<{
[setValue]
);
+ // TODO: Don't show save button if no changes have been made
+ // TODO: Indicate saving progress
return (
<>
<RemTextarea
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
index 3acfd74fca..433b19fd6b 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
@@ -1,5 +1,6 @@
-import React from 'react';
+import React, {useCallback} from 'react';
import {z} from 'remotion';
+import {Button} from '../../../../preview-server/error-overlay/remotion-overlay/Button';
import {LIGHT_TEXT} from '../../../helpers/colors';
import {Spacing} from '../../layout';
import {ZodErrorMessages} from './ZodErrorMessages';
@@ -9,11 +10,12 @@ const errorExplanation: React.CSSProperties = {
fontSize: 14,
color: LIGHT_TEXT,
fontFamily: 'sans-serif',
+ lineHeight: 1.5,
};
const codeSnippet: React.CSSProperties = {
fontSize: 14,
- color: LIGHT_TEXT,
+ color: 'var(--blue)',
fontFamily: 'monospace',
};
@@ -40,6 +42,10 @@ export const SchemaEditor: React.FC<{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const typeName = (def as any).typeName as z.ZodFirstPartyTypeKind;
+ const reset = useCallback(() => {
+ setValue(defaultProps);
+ }, [defaultProps, setValue]);
+
if (typeName === z.ZodFirstPartyTypeKind.ZodAny) {
return (
<div style={errorExplanation}>
@@ -52,7 +58,46 @@ export const SchemaEditor: React.FC<{
}
if (!zodValidationResult.success) {
- // TODO: Distinguish between default props not valid and JSON input not valid
+ if (defaultProps === undefined) {
+ return (
+ <div>
+ <div style={errorExplanation}>
+ The schema can not be edited because the{' '}
+ <code style={codeSnippet}>defaultProps</code> prop in the{' '}
+ <code style={codeSnippet}>{'<Composition>'}</code> does not exist.
+ </div>
+ <Spacing y={1} />
+ <div style={errorExplanation}>
+ Fix the schema by adding a{' '}
+ <code style={codeSnippet}>defaultProps</code> prop to your
+ composition.
+ </div>
+ </div>
+ );
+ }
+
+ const defaultPropsValid = schema.safeParse(defaultProps);
+
+ if (!defaultPropsValid.success) {
+ return (
+ <div>
+ <div style={errorExplanation}>
+ The schema can not be edited because the{' '}
+ <code style={codeSnippet}>defaultProps</code> prop in the{' '}
+ <code style={codeSnippet}>{'<Composition>'}</code> is not valid:
+ </div>
+ <Spacing y={1} block />
+ <ZodErrorMessages zodValidationResult={zodValidationResult} />
+ <Spacing y={1} block />
+ <div style={errorExplanation}>
+ Fix the schema by changing the{' '}
+ <code style={codeSnippet}>defaultProps</code> prop in your
+ composition so it does not give a type error.
+ </div>
+ </div>
+ );
+ }
+
return (
<div>
<div style={errorExplanation}>
@@ -64,6 +109,13 @@ export const SchemaEditor: React.FC<{
<div style={errorExplanation}>
Fix the schema using the JSON editor.
</div>
+ <Spacing y={1} block />
+ <div style={errorExplanation}>
+ Alternatively, reset the data to the <code>defaultProps</code> that
+ you have defined.
+ </div>
+ <Spacing y={1} block />
+ <Button onClick={reset}>Reset props</Button>
</div>
);
}
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodErrorMessages.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodErrorMessages.tsx
index 9001682b8a..ea3ce2c2e7 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodErrorMessages.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodErrorMessages.tsx
@@ -25,7 +25,11 @@ export const ZodErrorMessages: React.FC<{
{zodValidationResult.error.errors.map((error) => {
return (
<div key={error.path.join('.')} style={label}>
- - <code style={code}>{error.path.join('.')}</code>: {error.message}
+ -{' '}
+ <code style={code}>
+ {error.path.length === 0 ? 'Root' : error.path.join('.')}
+ </code>
+ : {error.message}
</div>
);
})}
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index 054209905e..f6f21ffe57 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -740,6 +740,17 @@ export const Index: React.FC = () => {
schema={schemaTestSchema}
defaultProps={{title: 'fsdfsdfsdfsdf', delay: 5.2}}
/>
+ {/**
+ // @ts-expect-error */}
+ <Composition
+ id="impossible-to-save"
+ component={SchemaTest}
+ width={1200}
+ height={630}
+ fps={30}
+ durationInFrames={150}
+ schema={schemaTestSchema}
+ />
</Folder>
</>
);