import { Chip } from '@heroui/chip' import { Tooltip } from '@heroui/tooltip' import { motion } from 'motion/react' import React, { useState } from 'react' import toast from 'react-hot-toast' import { TbSquareRoundedChevronRightFilled } from 'react-icons/tb' import type { LiteralValue, ParsedSchema } from '@/utils/zod' interface DisplayStructProps { schema: ParsedSchema | ParsedSchema[] } const SchemaType = ({ type, value }: { type: string value?: LiteralValue }) => { let name = type switch (type) { case 'union': name = '联合类型' break case 'value': name = '固定值' break } let chipColor: 'primary' | 'success' | 'primary' | 'warning' | 'secondary' = 'primary' switch (type) { case 'enum': chipColor = 'warning' break case 'union': chipColor = 'secondary' break case 'array': chipColor = 'primary' break case 'object': chipColor = 'success' break } return ( {name} {type === 'value' && ( {value} )} ) } const SchemaLabel: React.FC<{ schema: ParsedSchema }> = ({ schema }) => ( <> {Array.isArray(schema.type) ? ( schema.type.map((type) => ( )) ) : ( )} {schema.optional && ( 可选 )} {schema.description && ( {schema.description} )} ) const SchemaContainer: React.FC<{ schema: ParsedSchema children: React.ReactNode }> = ({ schema, children }) => { const [expanded, setExpanded] = useState(false) const toggleExpand = () => setExpanded(!expanded) return (
{ e.stopPropagation() navigator.clipboard.writeText(schema.name || '') toast.success('已复制') }} > {schema.name}
{children}
) } const RenderSchema: React.FC<{ schema: ParsedSchema }> = ({ schema }) => { if (schema.type === 'object') { return ( {schema.children && schema.children.length > 0 ? ( schema.children.map((child, i) => ( )) ) : (
{`{}`}
)}
) } if (schema.type === 'array' || schema.type === 'union') { return ( {schema.children?.map((child, i) => ( ))} ) } if (schema.type === 'enum' && Array.isArray(schema.enum)) { return (
{schema.enum?.map((value, i) => ( {value?.toString()} ))}
) } return (
{ e.stopPropagation() navigator.clipboard.writeText(schema.name || '') toast.success('已复制') }} > {schema.name}
) } const DisplayStruct: React.FC = ({ schema }) => { return (
{Array.isArray(schema) ? ( schema.map((s, i) => ) ) : ( )}
) } export default DisplayStruct