import React, { ChangeEvent, useEffect, useRef, useState } from 'react'; import { AlignLeft } from 'lucide-react'; import { Button, Modal, ModalBody, ModalFooter, ModalTitle, Styles, SelectBox } from '@vertesia/ui/core'; import { useUITranslation } from '../../../i18n/index.js'; import { TypeNames } from '../type-signature.js'; import { DataEditorProps } from './Editable.js'; import { EditableSchemaProperty } from './EditableSchemaProperty.js'; function makeTypeOptions() { const types: string[] = Object.values(TypeNames) const options = [...types] for (const type of types) { options.push(type + '[]'); } types.sort(); return options; } const TYPE_OPTIONS = makeTypeOptions(); export function PropertyEditor({ value, onChange, onCancel, onSave }: DataEditorProps) { const { t } = useUITranslation(); const [isModalOpen, setModalOpen] = useState(false); if (!value) return null; const onNameChange = (text: string) => { onChange({ ...value, name: text }) } const onTypeChange = (text: string) => { onChange({ ...value, type: text }) } const onDescriptionChange = (text?: string) => { if (text !== undefined && typeof text === 'string') { onChange({ ...value, description: text }, true); } setModalOpen(false); } return (
:
) } export function PropertyNameEditor({ value, onChange, onCancel, onSave }: DataEditorProps) { const ref = useRef(null); useEffect(() => { ref.current?.focus(); }, []) const onKeyUp = (e: React.KeyboardEvent) => { switch (e.key) { case "Enter": onSave?.(); break; case "Escape": onCancel?.(); break; } } const _onChange = (e: ChangeEvent) => { onChange(e.target.value); } return ( ) } function PropertyTypeEditor({ value, onChange, onCancel, onSave }: DataEditorProps) { const onBlur = () => { onSave?.(); } const onKeyDown = (e: React.KeyboardEvent, isOpen: boolean) => { if (!isOpen) { if (e.key === 'Enter') { onSave?.(); } else if (e.key === 'Escape') { onCancel?.(); } } } return ( ) } interface EditDescriptionModalProps { value: string | undefined; isOpen: boolean; onClose: (text?: string) => void; } function EditDescriptionModal({ value, isOpen, onClose }: EditDescriptionModalProps) { const { t } = useUITranslation(); return ( {t('widgets.schema.editDescription')} ) } interface EditDescriptionModalFormProps { value: string | undefined; onSave: (text: string) => void; } function EditDescriptionModalForm({ value, onSave }: EditDescriptionModalFormProps) { const { t } = useUITranslation(); const ref = useRef(null); const [currentValue, setCurrentValue] = useState(value || ''); useEffect(() => { ref.current && ref.current.focus(); }, [ref.current]); return ( <>