Skip to content

🎥 Make videos programmatically with React

get schema label

Jonny Burger97fe85709c2d
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsx
index c0a4bbd1ec..a3a8f371ac 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsx
@@ -3,6 +3,7 @@ import {LIGHT_TEXT} from '../../../helpers/colors';
import {Flex, Spacing} from '../../layout';
import {InlineRemoveButton} from '../InlineRemoveButton';
import {label} from '../layout';
+import {getSchemaLabel} from './get-schema-label';
import {SchemaResetButton} from './SchemaResetButton';
import {SchemaSaveButton} from './SchemaSaveButton';
import type {JSONPath} from './zod-types';
@@ -29,6 +30,12 @@ const wideStyles: React.CSSProperties = {
alignItems: 'center',
};
+const labelStyle: React.CSSProperties = {
+ fontFamily: 'monospace',
+ fontSize: 14,
+ color: LIGHT_TEXT,
+};
+
export const SchemaLabel: React.FC<{
jsonPath: JSONPath;
isDefaultValue: boolean;
@@ -48,7 +55,8 @@ export const SchemaLabel: React.FC<{
}) => {
return (
<div style={compact ? compactStyles : wideStyles}>
- {jsonPath[jsonPath.length - 1]} {compact ? <Flex /> : <Spacing x={1} />}
+ <span style={labelStyle}>{getSchemaLabel(jsonPath)}</span>
+ {compact ? <Flex /> : <Spacing x={1} />}
{isDefaultValue ? null : <SchemaResetButton onClick={onReset} />}
{isDefaultValue ? null : showSaveButton ? (
<SchemaSaveButton onClick={onSave} />
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx
index d143545a45..9167b63812 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx
@@ -6,7 +6,9 @@ import {
} from '../../../helpers/colors';
import {Spacing} from '../../layout';
import {ValidationMessage} from '../../NewComposition/ValidationMessage';
+import {InlineRemoveButton} from '../InlineRemoveButton';
import {fieldsetLabel, optionRow} from '../layout';
+import {getSchemaLabel} from './get-schema-label';
import type {JSONPath} from './zod-types';
import {ZodArrayItemEditor} from './ZodArrayItemEditor';
@@ -34,6 +36,7 @@ export const ZodArrayEditor: React.FC<{
onSave: (updater: (oldState: unknown[]) => unknown[]) => void;
compact: boolean;
showSaveButton: boolean;
+ onRemove: null | (() => void);
}> = ({
schema,
jsonPath,
@@ -43,6 +46,7 @@ export const ZodArrayEditor: React.FC<{
value,
onSave,
showSaveButton,
+ onRemove,
}) => {
const [localValue, setLocalValue] = useState<LocalState>(() => {
return {
@@ -106,14 +110,22 @@ export const ZodArrayEditor: React.FC<{
<Element style={fieldset}>
{isRoot ? null : (
<legend style={fieldsetLabel}>
- {jsonPath[jsonPath.length - 1]}
- <Spacing x={1} />
+ {getSchemaLabel(jsonPath)}
+ {onRemove ? (
+ <>
+ <Spacing x={1} /> <InlineRemoveButton onClick={onRemove} />
+ </>
+ ) : null}
+
{!localValue.zodValidation.success && (
- <ValidationMessage
- align="flex-end"
- message={localValue.zodValidation.error.format()._errors[0]}
- type="error"
- />
+ <>
+ <Spacing x={1} />
+ <ValidationMessage
+ align="flex-end"
+ message={localValue.zodValidation.error.format()._errors[0]}
+ type="error"
+ />
+ </>
)}
</legend>
)}
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
index 82e91df56a..17413dda6c 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
@@ -4,6 +4,7 @@ import {INPUT_BORDER_COLOR_UNHOVERED} from '../../../helpers/colors';
import {Spacing} from '../../layout';
import {InlineRemoveButton} from '../InlineRemoveButton';
import {fieldsetLabel, optionRow} from '../layout';
+import {getSchemaLabel} from './get-schema-label';
import type {JSONPath} from './zod-types';
import {ZodSwitch} from './ZodSwitch';
@@ -73,7 +74,7 @@ export const ZodObjectEditor: React.FC<{
<Element style={fieldset}>
{isRoot ? null : (
<legend style={fieldsetLabel}>
- {jsonPath[jsonPath.length - 1]}
+ {getSchemaLabel(jsonPath)}
{onRemove ? (
<>
<Spacing x={1} /> <InlineRemoveButton onClick={onRemove} />
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
index 62ba42a87a..4a68f4436d 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
@@ -101,6 +101,7 @@ export const ZodSwitch: React.FC<{
defaultValue={defaultValue as unknown[]}
onSave={onSave as (newValue: (oldVal: unknown[]) => unknown[]) => void}
showSaveButton={showSaveButton}
+ onRemove={onRemove}
/>
);
}
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/get-schema-label.ts b/packages/cli/src/editor/components/RenderModal/SchemaEditor/get-schema-label.ts
new file mode 100644
index 0000000000..02ad02b795
--- /dev/null
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/get-schema-label.ts
@@ -0,0 +1,17 @@
+import type {JSONPath} from './zod-types';
+
+export const getSchemaLabel = (jsonPath: JSONPath): string => {
+ const lastKey = jsonPath[jsonPath.length - 1];
+ if (typeof lastKey === 'number') {
+ const secondLastKey = jsonPath[jsonPath.length - 2];
+ if (typeof secondLastKey === 'undefined') {
+ return `[${lastKey}]`;
+ }
+
+ return `${getSchemaLabel(
+ jsonPath.slice(0, jsonPath.length - 1)
+ )}[${lastKey}]`;
+ }
+
+ return lastKey;
+};
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index d7ec36125c..a9b36866ab 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -695,7 +695,7 @@ export const Index: React.FC = () => {
})
)
.min(2),
- array2: z.array(z.string()),
+ array2: z.array(z.array(z.string())),
mynum: z.number(),
})}
defaultProps={{
@@ -706,7 +706,7 @@ export const Index: React.FC = () => {
{a: 'a', b: 'bbbbb'},
{a: 'a', b: 'b'},
],
- array2: ['bbbbbb', 'bbbbbb'],
+ array2: [['bbbbbb'], ['bbbbbb']],
mynum: 179,
}}
durationInFrames={150}