@remotion/studio
Version:
APIs for interacting with the Remotion Studio
45 lines (44 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodStaticFileEditor = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const Checkmark_1 = require("../../../icons/Checkmark");
const ComboBox_1 = require("../../NewComposition/ComboBox");
const use_static_files_1 = require("../../use-static-files");
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 container = {
width: '100%',
};
const ZodStaticFileEditor = ({ schema, jsonPath, setValue, value, onRemove, mayPad }) => {
const onChange = (0, react_1.useCallback)((updater, { shouldSave }) => {
setValue(updater, { shouldSave });
}, [setValue]);
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
const isRoot = jsonPath.length === 0;
const staticFiles = (0, use_static_files_1.useStaticFiles)();
const comboBoxValues = (0, react_1.useMemo)(() => {
return staticFiles.map((option) => {
return {
value: option.src,
label: option.name,
id: option.src,
keyHint: null,
leftItem: option.src === value ? jsx_runtime_1.jsx(Checkmark_1.Checkmark, {}) : null,
onClick: (id) => {
onChange(() => id, { shouldSave: true });
},
quickSwitcherLabel: null,
subMenu: null,
type: 'item',
};
});
}, [onChange, staticFiles, 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.jsx("div", { style: isRoot ? undefined : container, children: jsx_runtime_1.jsx(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: value, title: value }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
] }));
};
exports.ZodStaticFileEditor = ZodStaticFileEditor;