@remotion/studio
Version:
APIs for interacting with the Remotion Studio
57 lines (56 loc) • 3.01 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 get_static_files_1 = require("../../../api/get-static-files");
const Checkmark_1 = require("../../../icons/Checkmark");
const ComboBox_1 = require("../../NewComposition/ComboBox");
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 container = {
width: '100%',
};
const ZodStaticFileEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
if (!z) {
throw new Error('expected zod');
}
const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
schema,
setValue,
unsavedValue: value,
savedValue: defaultValue,
});
const def = schema._def;
const typeName = def.typeName;
if (typeName !== z.ZodFirstPartyTypeKind.ZodString) {
throw new Error('expected enum');
}
const isRoot = jsonPath.length === 0;
const comboBoxValues = (0, react_1.useMemo)(() => {
return (0, get_static_files_1.getStaticFiles)().map((option) => {
return {
value: option.src,
label: option.name,
id: option.src,
keyHint: null,
leftItem: option.src === value ? (0, jsx_runtime_1.jsx)(Checkmark_1.Checkmark, {}) : null,
onClick: (id) => {
setLocalValue(() => id, false, false);
},
quickSwitcherLabel: null,
subMenu: null,
type: 'item',
};
});
}, [setLocalValue, value]);
const save = (0, react_1.useCallback)(() => {
onSave(() => value);
}, [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, onSave: save, showSaveButton: showSaveButton, isDefaultValue: localValue.value === defaultValue, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: (0, jsx_runtime_1.jsx)(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: localValue.value, title: value }) }), (0, jsx_runtime_1.jsx)(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })] }));
};
exports.ZodStaticFileEditor = ZodStaticFileEditor;