UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

34 lines (33 loc) 1.84 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 = ({ def, onChange, jsonPath, index, value, defaultValue, onSave: onSaveObject, showSaveButton, saving, saveDisabledByParent, 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)], false, true); }, [index, onChange]); 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.type, value: value, setValue: setValue, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: mayRemove ? onRemove : null, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }) })); }; exports.ZodArrayItemEditor = ZodArrayItemEditor;