UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

24 lines (23 loc) 1.18 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 = ({ tupleItems, onChange, jsonPath, index, value, mayPad }) => { const z = (0, get_zod_if_possible_1.useZodIfPossible)(); if (!z) { throw new Error('expected zod'); } const setValue = (0, react_1.useCallback)((val, { shouldSave }) => { onChange((oldV) => [ ...oldV.slice(0, index), typeof val === 'function' ? val(oldV[index]) : val, ...oldV.slice(index + 1), ], { shouldSave }); }, [index, onChange]); const newJsonPath = (0, react_1.useMemo)(() => [...jsonPath, index], [index, jsonPath]); return (jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { jsonPath: newJsonPath, schema: tupleItems[index], value: value, setValue: setValue, onRemove: null, mayPad: mayPad }) })); }; exports.ZodTupleItemEditor = ZodTupleItemEditor;