Skip to content

🎥 Make videos programmatically with React

schema editor

Jonny Burgerd62b01ef2dbb
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
index fa68ca58e2..c91690541b 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
@@ -51,7 +51,11 @@ export const RenderModalData: React.FC<{
</div>
<Spacing y={2} block />
{mode === 'schema' ? (
- <SchemaEditor schema={composition.schema} />
+ <SchemaEditor
+ value={inputProps}
+ setValue={setInputProps}
+ schema={composition.schema}
+ />
) : (
<RenderModalJSONInputPropsEditor
value={inputProps ?? {}}
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
index 1b42027d53..b03d6e6d81 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
@@ -16,7 +16,9 @@ const codeSnippet: React.CSSProperties = {
export const SchemaEditor: React.FC<{
schema: z.ZodTypeAny;
-}> = ({schema}) => {
+ value: unknown;
+ setValue: (value: unknown) => void;
+}> = ({schema, value, setValue}) => {
const def: z.ZodTypeDef = schema._def;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const typeName = (def as any).typeName as z.ZodFirstPartyTypeKind;
@@ -33,7 +35,14 @@ export const SchemaEditor: React.FC<{
}
if (typeName === z.ZodFirstPartyTypeKind.ZodObject) {
- return <ZodObjectEditor jsonPath={[]} schema={schema} />;
+ return (
+ <ZodObjectEditor
+ value={value}
+ setValue={setValue}
+ jsonPath={[]}
+ schema={schema}
+ />
+ );
}
return null;
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.tsx
index 64efdfb291..97866cf7e5 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.tsx
@@ -5,12 +5,21 @@ import {ZodSwitch} from './ZodSwitch';
export const ZodEffectEditor: React.FC<{
schema: z.ZodTypeAny;
jsonPath: JSONPath;
-}> = ({schema, jsonPath}) => {
+ value: unknown;
+ setValue: (value: unknown) => void;
+}> = ({schema, jsonPath, value, setValue}) => {
const def = schema._def;
const typeName = def.typeName as z.ZodFirstPartyTypeKind;
if (typeName !== z.ZodFirstPartyTypeKind.ZodEffects) {
throw new Error('expected effect');
}
- return <ZodSwitch jsonPath={jsonPath} schema={def.schema} />;
+ return (
+ <ZodSwitch
+ value={value}
+ setValue={setValue}
+ jsonPath={jsonPath}
+ schema={def.schema}
+ />
+ );
};
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
index 210ed807f5..6413c68322 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
@@ -31,7 +31,9 @@ const fieldsetLabel: React.CSSProperties = {
export const ZodObjectEditor: React.FC<{
schema: z.ZodTypeAny;
jsonPath: JSONPath;
-}> = ({schema, jsonPath}) => {
+ value: unknown;
+ setValue: (value: unknown) => void;
+}> = ({schema, jsonPath, setValue, value}) => {
const def = schema._def;
const typeName = def.typeName as z.ZodFirstPartyTypeKind;
@@ -63,6 +65,13 @@ export const ZodObjectEditor: React.FC<{
key={key}
jsonPath={[...jsonPath, key]}
schema={shape[key]}
+ value={(value as Record<string, string>)[key]}
+ setValue={(val) => {
+ setValue({
+ ...(value as Record<string, string>),
+ [key]: val,
+ });
+ }}
/>
);
})}
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodStringEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodStringEditor.tsx
index 63a02587c1..c781e1775f 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodStringEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodStringEditor.tsx
@@ -1,4 +1,3 @@
-import {useState} from 'react';
import type {z} from 'remotion';
import {RemotionInput} from '../../NewComposition/RemInput';
import {label, optionRow} from '../layout';
@@ -7,9 +6,9 @@ import type {JSONPath} from './zod-types';
export const ZodStringEditor: React.FC<{
schema: z.ZodTypeAny;
jsonPath: JSONPath;
-}> = ({jsonPath}) => {
- const [value, setValue] = useState('');
-
+ value: string;
+ setValue: (value: string) => void;
+}> = ({jsonPath, value, setValue}) => {
return (
<div style={optionRow}>
<div style={label}>{jsonPath[jsonPath.length - 1]}</div>
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
index 190495cea1..0df14dceb5 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
@@ -7,7 +7,9 @@ import {ZodStringEditor} from './ZodStringEditor';
export const ZodSwitch: React.FC<{
schema: z.ZodTypeAny;
jsonPath: JSONPath;
-}> = ({schema, jsonPath}) => {
+ value: unknown;
+ setValue: (value: unknown) => void;
+}> = ({schema, jsonPath, value, setValue}) => {
const def: z.ZodTypeDef = schema._def;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const typeName = (def as any).typeName as z.ZodFirstPartyTypeKind;
@@ -16,15 +18,36 @@ export const ZodSwitch: React.FC<{
}
if (typeName === z.ZodFirstPartyTypeKind.ZodObject) {
- return <ZodObjectEditor jsonPath={jsonPath} schema={schema} />;
+ return (
+ <ZodObjectEditor
+ setValue={setValue}
+ value={value}
+ jsonPath={jsonPath}
+ schema={schema}
+ />
+ );
}
if (typeName === z.ZodFirstPartyTypeKind.ZodString) {
- return <ZodStringEditor jsonPath={jsonPath} schema={schema} />;
+ return (
+ <ZodStringEditor
+ value={value as string}
+ setValue={setValue as (val: string) => void}
+ jsonPath={jsonPath}
+ schema={schema}
+ />
+ );
}
if (typeName === z.ZodFirstPartyTypeKind.ZodEffects) {
- return <ZodEffectEditor jsonPath={jsonPath} schema={schema} />;
+ return (
+ <ZodEffectEditor
+ value={value}
+ setValue={setValue}
+ jsonPath={jsonPath}
+ schema={schema}
+ />
+ );
}
return <div>unknown</div>;
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index 85c6b563ae..eeb8d857ec 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -191,6 +191,10 @@ export const Index: React.FC = () => {
height={1080}
fps={30}
durationInFrames={180 * 30}
+ defaultProps={{
+ opacity: 1,
+ volume: 0.4,
+ }}
/>
<Composition
id="tiles"
@@ -383,6 +387,10 @@ export const Index: React.FC = () => {
// Change the duration of the video dynamically by passing
// `--props='{"duration": 100}'`
durationInFrames={inputProps?.duration ?? 20}
+ defaultProps={{
+ codec: 'mp4' as const,
+ offthread: false,
+ }}
/>
<Composition
id="nested"
@@ -678,6 +686,13 @@ export const Index: React.FC = () => {
defaultProps={{
vehicle: 'caa',
other: 'hi',
+ abc: {
+ def: {
+ xyz: 'hu',
+ },
+ jkl: 'sting',
+ xyz: 'hi',
+ },
}}
durationInFrames={150}
/>