🎥 Make videos programmatically with React
implement zod array
Jonny Burger7924db5ecf23
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsxnew file mode 100644index 0000000000..c10976c527--- /dev/null+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx@@ -0,0 +1,84 @@+import React from 'react';+import {z} from 'remotion';+import {+ INPUT_BORDER_COLOR_UNHOVERED,+ LIGHT_TEXT,+} from '../../../helpers/colors';+import {optionRow} from '../layout';+import type {JSONPath} from './zod-types';+import {ZodSwitch} from './ZodSwitch';++const container: React.CSSProperties = {+ width: '100%',+};++const fullWidth: React.CSSProperties = {+ width: '100%',+};++const fieldset: React.CSSProperties = {+ borderRadius: 4,+ borderColor: INPUT_BORDER_COLOR_UNHOVERED,+};++const fieldsetLabel: React.CSSProperties = {+ color: LIGHT_TEXT,+ fontSize: 14,+ paddingLeft: 10,+ paddingRight: 10,+};++export const ZodArrayEditor: React.FC<{+ schema: z.ZodTypeAny;+ jsonPath: JSONPath;+ value: unknown[];+ setValue: (value: unknown[]) => void;+}> = ({schema, jsonPath, setValue, value}) => {+ const def = schema._def;++ const typeName = def.typeName as z.ZodFirstPartyTypeKind;+ if (typeName !== z.ZodFirstPartyTypeKind.ZodArray) {+ throw new Error('expected object');+ }++ console.log(def);++ const isRoot = jsonPath.length === 0;+ const Element = isRoot ? 'div' : 'fieldset';++ const {paddingLeft, paddingTop} = optionRow;++ return (+ <div style={isRoot ? undefined : {paddingLeft, paddingTop}}>+ <div style={fullWidth}>+ <Element style={fieldset}>+ {isRoot ? null : (+ <legend style={fieldsetLabel}>+ {jsonPath[jsonPath.length - 1]}+ </legend>+ )}+ <div style={isRoot ? undefined : container}>+ {value.map((child, i) => {+ return (+ <ZodSwitch+ // eslint-disable-next-line react/no-array-index-key+ key={i}+ jsonPath={[...jsonPath, i]}+ schema={def.type}+ value={child}+ setValue={(val) => {+ setValue([+ ...value.slice(0, i),+ val,+ ...value.slice(i + 1),+ ]);+ }}+ />+ );+ })}+ </div>+ </Element>+ </div>+ </div>+ );+};diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsxindex 0df14dceb5..234338b0ae 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx@@ -1,5 +1,6 @@import {z} from 'remotion';import type {JSONPath} from './zod-types';+import {ZodArrayEditor} from './ZodArrayEditor';import {ZodEffectEditor} from './ZodEffectEditor';import {ZodObjectEditor} from './ZodObjectEditor';import {ZodStringEditor} from './ZodStringEditor';@@ -39,6 +40,17 @@ export const ZodSwitch: React.FC<{);}+ if (typeName === z.ZodFirstPartyTypeKind.ZodArray) {+ return (+ <ZodArrayEditor+ setValue={setValue}+ value={value as unknown[]}+ jsonPath={jsonPath}+ schema={schema}+ />+ );+ }+if (typeName === z.ZodFirstPartyTypeKind.ZodEffects) {return (<ZodEffectEditordiff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex 27c85ff04a..5cbe4d54b8 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -683,6 +683,7 @@ export const Index: React.FC = () => {pef: z.string(),}),}),+ array: z.array(z.string()),})}defaultProps={{vehicle: 'caa',@@ -695,6 +696,7 @@ export const Index: React.FC = () => {jkl: 'sting',xyz: 'hi',},+ array: ['hi', 'hi', 'hi'],}}durationInFrames={150}/>