@remotion/studio
Version:
APIs for interacting with the Remotion Studio
43 lines (42 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodTextareaEditor = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const RemTextarea_1 = require("../../NewComposition/RemTextarea");
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
const Fieldset_1 = require("./Fieldset");
const SchemaLabel_1 = require("./SchemaLabel");
const ZodFieldValidation_1 = require("./ZodFieldValidation");
const local_state_1 = require("./local-state");
const fullWidth = {
width: '100%',
};
const textareaStyle = {
resize: 'vertical',
minHeight: 100,
};
const ZodTextareaEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, onSave, onRemove, saving, saveDisabledByParent, mayPad, }) => {
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
if (!z) {
throw new Error('expected zod');
}
const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
if (!zodTypes) {
throw new Error('expected zod textarea');
}
const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
schema,
setValue,
unsavedValue: value,
savedValue: defaultValue,
});
const onChange = (0, react_1.useCallback)((e) => {
setLocalValue(() => e.target.value, false, false);
}, [setLocalValue]);
const save = (0, react_1.useCallback)(() => {
onSave(() => value, false, false);
}, [onSave, value]);
return ((0, jsx_runtime_1.jsxs)(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(RemTextarea_1.RemTextarea, { onChange: onChange, value: localValue.value, status: localValue.zodValidation ? 'ok' : 'error', placeholder: jsonPath.join('.'), name: jsonPath.join('.'), style: textareaStyle }), (0, jsx_runtime_1.jsx)(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })] })] }));
};
exports.ZodTextareaEditor = ZodTextareaEditor;