UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

32 lines (31 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZodEffectEditor = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const get_zod_if_possible_1 = require("../../get-zod-if-possible"); const Fieldset_1 = require("./Fieldset"); const ZodFieldValidation_1 = require("./ZodFieldValidation"); const ZodSwitch_1 = require("./ZodSwitch"); const local_state_1 = require("./local-state"); const fullWidth = { width: '100%', }; const ZodEffectEditor = ({ schema, jsonPath, value, setValue: updateValue, defaultValue, onSave, onRemove, showSaveButton, saving, mayPad, }) => { const z = (0, get_zod_if_possible_1.useZodIfPossible)(); if (!z) { throw new Error('expected zod'); } const { localValue, onChange } = (0, local_state_1.useLocalState)({ unsavedValue: value, schema, setValue: updateValue, savedValue: defaultValue, }); const def = schema._def; const typeName = def.typeName; if (typeName !== z.ZodFirstPartyTypeKind.ZodEffects) { throw new Error('expected effect'); } return ((0, jsx_runtime_1.jsxs)(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [(0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { value: value, setValue: onChange, jsonPath: jsonPath, schema: def.schema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: !localValue.zodValidation.success, mayPad: false }) }), (0, jsx_runtime_1.jsx)(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })] })); }; exports.ZodEffectEditor = ZodEffectEditor;