Skip to content

🎥 Make videos programmatically with React

types

Jonny Burgerf5609796db14
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
index e0bb58723e..e2dcfc9173 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx
@@ -62,12 +62,12 @@ export const SchemaEditor: React.FC<{
return (
<div style={scrollable} className={VERTICAL_SCROLLBAR_CLASSNAME}>
<ZodObjectEditor
- value={value}
+ value={value as Record<string, unknown>}
setValue={setValue}
jsonPath={[]}
schema={schema}
compact={compact}
- defaultValue={defaultProps}
+ defaultValue={defaultProps as Record<string, unknown>}
onSave={
onSave as (
newValue: (
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
index 8b66821c92..7ae62b128e 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
@@ -3,6 +3,7 @@ import type {z} from 'zod';
import {INPUT_BORDER_COLOR_UNHOVERED} from '../../../helpers/colors';
import {useZodIfPossible} from '../../get-zod-if-possible';
import {optionRow} from '../layout';
+import {useLocalState} from './local-state';
import {SchemaFieldsetLabel} from './SchemaLabel';
import type {JSONPath} from './zod-types';
import type {UpdaterFunction} from './ZodSwitch';
@@ -21,12 +22,11 @@ const fieldset: React.CSSProperties = {
borderColor: INPUT_BORDER_COLOR_UNHOVERED,
};
-// TODO: First validate locally
export const ZodObjectEditor: React.FC<{
schema: z.ZodTypeAny;
jsonPath: JSONPath;
- value: unknown;
- defaultValue: unknown;
+ value: Record<string, unknown>;
+ defaultValue: Record<string, unknown>;
setValue: UpdaterFunction<Record<string, unknown>>;
compact: boolean;
onSave: UpdaterFunction<Record<string, unknown>>;
@@ -50,6 +50,12 @@ export const ZodObjectEditor: React.FC<{
throw new Error('expected zod');
}
+ const {localValue, onChange} = useLocalState({
+ schema,
+ setValue,
+ value,
+ });
+
const def = schema._def;
const typeName = def.typeName as z.ZodFirstPartyTypeKind;
@@ -73,7 +79,9 @@ export const ZodObjectEditor: React.FC<{
return {paddingTop};
}, [isRoot, paddingTop]);
- const onRes = useCallback(() => undefined, []);
+ const onRes = useCallback(() => {
+ onChange(() => defaultValue, true);
+ }, [defaultValue, onChange]);
return (
<div style={style}>
@@ -94,11 +102,9 @@ export const ZodObjectEditor: React.FC<{
key={key}
jsonPath={[...jsonPath, key]}
schema={shape[key]}
- value={(value as Record<string, string>)[key]}
+ value={localValue.value[key]}
// In case of null | {a: string, b: string} type, we need to fallback to the default value
- defaultValue={
- ((defaultValue as Record<string, string>) ?? value)[key]
- }
+ defaultValue={(defaultValue ?? value)[key]}
setValue={(val, forceApply) => {
setValue((oldVal) => {
return {
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
index 84c59e51ab..aa3fbb2ab7 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
@@ -65,8 +65,8 @@ export const ZodSwitch: React.FC<{
return (
<ZodObjectEditor
setValue={setValue as UpdaterFunction<Record<string, unknown>>}
- value={value}
- defaultValue={defaultValue}
+ value={value as Record<string, unknown>}
+ defaultValue={defaultValue as Record<string, unknown>}
jsonPath={jsonPath}
schema={schema}
compact={compact}