import React, {useCallback, useMemo} from 'react'; import {Checkmark} from '../../../icons/Checkmark'; import type {ComboboxValue} from '../../NewComposition/ComboBox'; import {Combobox} from '../../NewComposition/ComboBox'; import {useStaticFiles} from '../../use-static-files'; import {Fieldset} from './Fieldset'; import {SchemaLabel} from './SchemaLabel'; import { zodSafeParse, type AnyZodSchema, getUserFacingDescription, } from './zod-schema-type'; import type {JSONPath} from './zod-types'; import {ZodFieldValidation} from './ZodFieldValidation'; import type {UpdaterFunction} from './ZodSwitch'; const container: React.CSSProperties = { width: '100%', }; export const ZodStaticFileEditor: React.FC<{ readonly schema: AnyZodSchema; readonly jsonPath: JSONPath; readonly value: string; readonly setValue: UpdaterFunction; readonly onRemove: null | (() => void); readonly mayPad: boolean; }> = ({schema, jsonPath, setValue, value, onRemove, mayPad}) => { const onChange: UpdaterFunction = useCallback( ( updater: (oldV: string) => string, {shouldSave}: {shouldSave: boolean}, ) => { setValue(updater, {shouldSave}); }, [setValue], ); const zodValidation = useMemo( () => zodSafeParse(schema, value), [schema, value], ); const isRoot = jsonPath.length === 0; const staticFiles = useStaticFiles(); const comboBoxValues = useMemo(() => { return staticFiles.map((option): ComboboxValue => { return { value: option.src, label: option.name, id: option.src, keyHint: null, leftItem: option.src === value ? : null, onClick: (id: string) => { onChange(() => id, {shouldSave: true}); }, quickSwitcherLabel: null, subMenu: null, type: 'item', }; }); }, [onChange, staticFiles, value]); return (
); };