import { APICallSignature, APIConstructSignature, APIIndexSignature, APIInterface, APIMethodSignature, APIPropertySignature, SanityArrayItem, } from '@sanity/tsdoc' import {Card, Code} from '@sanity/ui' import {useMemo} from 'react' import {_compileInterfaceDefinition} from '../../app/lib/_compile' import {CommentExampleBlocks, CommentRemarks} from '../../comment' import {H, useTextSize} from '../../lib/ui' import {Members} from '../members' import {_getMembers} from '../members/helpers' function useMembers(data: APIInterface) { return useMemo(() => { const members = _getMembers(data) as APIInterface['members'] const ret: { callSignatures: SanityArrayItem[] constructSignatures: SanityArrayItem[] indexSignatures: SanityArrayItem[] methodSignatures: SanityArrayItem[] propertySignatures: SanityArrayItem[] } = { callSignatures: [], constructSignatures: [], indexSignatures: [], methodSignatures: [], propertySignatures: [], } for (const m of members) { if (m._type === 'api.callSignature') { ret.callSignatures.push(m) } else if (m._type === 'api.constructSignature') { ret.constructSignatures.push(m) } else if (m._type === 'api.indexSignature') { ret.indexSignatures.push(m) } else if (m._type === 'api.methodSignature') { ret.methodSignatures.push(m) } else if (m._type === 'api.propertySignature') { ret.propertySignatures.push(m) } else { // eslint-disable-next-line console.log('WARN: unknown member type:', (m as any)._type) } } return ret }, [data]) } export function InterfaceContent(props: {data: APIInterface}): React.ReactNode { const {data} = props const {comment} = data const { callSignatures, constructSignatures, indexSignatures, methodSignatures, propertySignatures, } = useMembers(data) return ( <> Signature {_compileInterfaceDefinition(data)} {constructSignatures.length > 0 && ( <> Construct signatures )} {callSignatures.length > 0 && ( <> Call signatures )} {indexSignatures.length > 0 && ( <> Index signatures )} {methodSignatures.length > 0 && ( <> Call signatures )} {propertySignatures.length > 0 && ( <> Properties )} {comment && } {comment && } ) }