🎥 Make videos programmatically with React
spaghetti napoli
Patric Salvisbergfe6a753408b2
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsxindex 5107b9d237..7ae6f62fe1 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx@@ -10,6 +10,7 @@ import {ZonNonEditableValue} from './ZodNonEditableValue';import {ZodNumberEditor} from './ZodNumberEditor';import {ZodObjectEditor} from './ZodObjectEditor';import {ZodStringEditor} from './ZodStringEditor';+import {ZodUnionEditor} from './ZodUnionEditor';export const ZodSwitch: React.FC<{schema: z.ZodTypeAny;@@ -61,6 +62,7 @@ export const ZodSwitch: React.FC<{}if (typeName === z.ZodFirstPartyTypeKind.ZodString) {+ console.log(typeName, value);return (<ZodStringEditorvalue={value as string}@@ -226,6 +228,23 @@ export const ZodSwitch: React.FC<{);}+ if (typeName === z.ZodFirstPartyTypeKind.ZodUnion) {+ console.log(typeName, value);+ return (+ <ZodUnionEditor+ schema={schema}+ showSaveButton={showSaveButton}+ jsonPath={jsonPath}+ compact={compact}+ value={value}+ defaultValue={defaultValue}+ setValue={setValue}+ onSave={onSave}+ onRemove={onRemove}+ />+ );+ }+return (<ZonNonEditableValuecompact={compact}diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.tsxnew file mode 100644index 0000000000..91011ae7b2--- /dev/null+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.tsx@@ -0,0 +1,119 @@+import {useCallback, useState} from 'react';+import {z} from 'remotion';+import {Checkbox} from '../../Checkbox';+import {narrowOption, optionRow} from '../layout';+import {SchemaLabel} from './SchemaLabel';+import type {JSONPath} from './zod-types';+import {ZodSwitch} from './ZodSwitch';++const fullWidth: React.CSSProperties = {+ width: '100%',+};++export const ZodUnionEditor: React.FC<{+ showSaveButton: boolean;+ jsonPath: JSONPath;+ compact: boolean;+ value: unknown;+ defaultValue: unknown;+ schema: z.ZodTypeAny;+ setValue: React.Dispatch<React.SetStateAction<any>>;+ onSave: (updater: (oldNum: unknown) => unknown) => void;+ onRemove: null | (() => void);+}> = ({+ jsonPath,+ compact,+ schema,+ setValue,+ onSave,+ defaultValue,+ value,+ showSaveButton,+ onRemove,+}) => {+ const {options} = schema._def;+ console.log({value});++ const [isChecked, setIsChecked] = useState<boolean>(false);+ const onValueChange = useCallback(+ (newValue: unknown) => {+ setValue(newValue);+ },+ [setValue]+ );++ const onCheckBoxChange: React.ChangeEventHandler<HTMLInputElement> =+ useCallback(+ (e) => {+ setIsChecked(!isChecked);+ console.log(e.target.checked);+ const val = e.target.checked ? null : '';+ onValueChange(val);+ },+ [isChecked, onValueChange]+ );++ const onChange = useCallback(+ (newValue: unknown) => {+ setValue(newValue);+ },+ [setValue]+ );++ const reset = useCallback(() => {+ onValueChange(defaultValue);+ }, [defaultValue, onValueChange]);++ const save = useCallback(() => {+ onSave(() => value);+ }, [onSave, value]);++ console.log(value);++ if (+ options[0]._def.typeName === z.ZodFirstPartyTypeKind.ZodNull ||+ options[1]._def.typeName === z.ZodFirstPartyTypeKind.ZodNull+ ) {+ return (+ <>+ <div style={compact ? narrowOption : optionRow}>+ <SchemaLabel+ isDefaultValue={value === defaultValue}+ jsonPath={jsonPath}+ onReset={reset}+ onSave={save}+ showSaveButton={showSaveButton}+ compact={compact}+ onRemove={onRemove}+ />+ <div style={fullWidth}>+ <Checkbox+ checked={isChecked}+ onChange={onCheckBoxChange}+ disabled={false}+ />+ </div>+ </div>+ <div style={fullWidth}>+ <ZodSwitch+ value={value}+ setValue={onChange}+ jsonPath={jsonPath}+ schema={+ options[0]._def.typeName === z.ZodFirstPartyTypeKind.ZodNull+ ? options[1]+ : options[0]+ }+ compact={compact}+ defaultValue={defaultValue}+ onSave={onSave}+ showSaveButton={showSaveButton}+ onRemove={onRemove}+ />+ </div>+ </>+ );+ }+};++// console.log(schema._def.options);diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex db9b3a43c3..4ccbbea23f 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -680,10 +680,10 @@ export const Index: React.FC = () => {.refine((v) => ['caa', 'bus', 'truck'].includes(v)),other: z.string(),abc: z.object({- xyz: z.string(),+ union: z.null().or(z.string()),jkl: z.string(),def: z.object({- xyz: z.string(),+ xyz: z.null().or(z.string()),pef: z.string(),}),}),@@ -710,7 +710,7 @@ export const Index: React.FC = () => {defaultProps={{vehicle: 'bus',other: 'hi',- abc: {def: {xyz: 'huthere', pef: 'hu'}, jkl: 'sting', xyz: 'hi'},+ abc: {def: {xyz: 'hell', pef: 'hu'}, jkl: 'sting', union: 'hello'},array: [{a: 'a', b: 'bbbbb'},{a: 'a', b: 'b'},@@ -724,7 +724,7 @@ export const Index: React.FC = () => {num: '179',date: new Date('1999-02-12T20:20:00.000Z'),values: 'a',- supersuperlongvalueabcdefghji: 'hi',+ supersuperlongvalueabcdefghji: 'hia',}}durationInFrames={150}/>