import { useId, useMemo, useState } from 'react'; import apiFetch from '@wordpress/api-fetch'; import { ExternalLinkIcon, PlusIcon, Trash2Icon } from 'lucide-react'; import { Button } from '../../components/ui/button'; import { Callout } from '../../components/ui/callout'; import { Input } from '../../components/ui/input'; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from '../../components/ui/select'; import { Textarea } from '../../components/ui/textarea'; import { FieldHeader } from '../components/fields'; import { DETAIL_TYPES, FROM_POST_TYPES, isRequired, missingRequired, parseEntries, SCHEMA_TYPES, serializeEntries, type SchemaEntry, type SchemaField, } from './types'; const GROUPS = ['Content', 'Business', 'Media', 'Other'] as const; const TYPE_ITEMS = Object.entries(SCHEMA_TYPES).map(([value, type]) => ({ value, label: type.label, })); /** The label shown for a value like "https://schema.org/EventScheduled" or "FULL_TIME". */ const optionLabel = (option: string): string => option .replace(/^https?:\/\/schema\.org\//, '') .replace(/([a-z])([A-Z])/g, '$1 $2') .replace(/_/g, ' ') .toLowerCase() .replace(/^./, first => first.toUpperCase()); const Field = ({ field, value, onChange, }: { field: SchemaField; value: string; onChange: (value: string) => void; }): JSX.Element => { const id = useId(); const input = (): JSX.Element => { switch (field.type) { case 'textarea': return (