UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

29 lines (28 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZodArrayItemEditor = 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 ZodArrayItemEditor = ({ elementSchema, onChange, jsonPath, index, value, mayPad, mayRemove }) => { const z = (0, get_zod_if_possible_1.useZodIfPossible)(); if (!z) { throw new Error('expected zod'); } const onRemove = (0, react_1.useCallback)(() => { onChange((oldV) => [...oldV.slice(0, index), ...oldV.slice(index + 1)], { shouldSave: true, }); }, [index, onChange]); 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: elementSchema, value: value, setValue: setValue, onRemove: mayRemove ? onRemove : null, mayPad: mayPad }) })); }; exports.ZodArrayItemEditor = ZodArrayItemEditor;