@remotion/studio
Version:
APIs for interacting with the Remotion Studio
29 lines (28 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodEffectEditor = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const Fieldset_1 = require("./Fieldset");
const zod_schema_type_1 = require("./zod-schema-type");
const zod_schema_type_2 = require("./zod-schema-type");
const ZodFieldValidation_1 = require("./ZodFieldValidation");
const ZodSwitch_1 = require("./ZodSwitch");
const fullWidth = {
width: '100%',
};
const ZodEffectEditor = ({ schema, jsonPath, value, setValue: updateValue, onRemove, mayPad }) => {
const typeName = (0, zod_schema_type_2.getZodSchemaType)(schema);
if (typeName !== 'effects') {
throw new Error('expected effect');
}
const onChange = (0, react_1.useCallback)((updater, { shouldSave }) => {
updateValue(updater, { shouldSave });
}, [updateValue]);
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
const innerSchema = (0, zod_schema_type_2.getEffectsInner)(schema);
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { value: value, setValue: onChange, jsonPath: jsonPath, schema: innerSchema, onRemove: onRemove, mayPad: false }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
] }));
};
exports.ZodEffectEditor = ZodEffectEditor;