UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

31 lines (30 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZodTupleItemEditor = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const get_zod_if_possible_1 = require("../../get-zod-if-possible"); const ZodSwitch_1 = require("./ZodSwitch"); const ZodTupleItemEditor = ({ def, onChange, jsonPath, index, value, defaultValue, onSave: onSaveObject, showSaveButton, saving, saveDisabledByParent, mayPad, }) => { const z = (0, get_zod_if_possible_1.useZodIfPossible)(); if (!z) { throw new Error('expected zod'); } const setValue = (0, react_1.useCallback)((val) => { onChange((oldV) => [ ...oldV.slice(0, index), typeof val === 'function' ? val(oldV[index]) : val, ...oldV.slice(index + 1), ], false, false); }, [index, onChange]); const newJsonPath = (0, react_1.useMemo)(() => [...jsonPath, index], [index, jsonPath]); const onSave = (0, react_1.useCallback)((updater) => { onSaveObject((oldV) => [ ...oldV.slice(0, index), updater(oldV[index]), ...oldV.slice(index + 1), ], false, false); }, [index, onSaveObject]); return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { jsonPath: newJsonPath, schema: def.items[index], value: value, setValue: setValue, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: null, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }) })); }; exports.ZodTupleItemEditor = ZodTupleItemEditor;