UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

35 lines (34 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZodStringEditor = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const react_2 = require("react"); const get_zod_if_possible_1 = require("../../get-zod-if-possible"); const RemInput_1 = require("../../NewComposition/RemInput"); const Fieldset_1 = require("./Fieldset"); const SchemaLabel_1 = require("./SchemaLabel"); const zod_schema_type_1 = require("./zod-schema-type"); const ZodFieldValidation_1 = require("./ZodFieldValidation"); const fullWidth = { width: '100%', }; const ZodStringEditor = ({ jsonPath, value, setValue, schema, onRemove, mayPad }) => { const z = (0, get_zod_if_possible_1.useZodIfPossible)(); if (!z) { throw new Error('expected zod'); } const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]); const onChange = (0, react_2.useCallback)((e) => { setValue(() => e.target.value, { shouldSave: false }); }, [setValue]); const onBlur = (0, react_2.useCallback)(() => { setValue(() => value, { shouldSave: true }); }, [setValue, value]); return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [ jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [ jsx_runtime_1.jsx(RemInput_1.RemotionInput, { value: value, status: zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, onBlur: onBlur, rightAlign: false, name: jsonPath.join('.') }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation }) ] }) ] })); }; exports.ZodStringEditor = ZodStringEditor;