16b7802baSBartosz Kaszubowskiimport ReactMarkdown from 'react-markdown'; 26b7802baSBartosz Kaszubowski 36b7802baSBartosz Kaszubowskiimport { 46b7802baSBartosz Kaszubowski ClassDefinitionData, 56b7802baSBartosz Kaszubowski GeneratedData, 66b7802baSBartosz Kaszubowski PropData, 76b7802baSBartosz Kaszubowski} from '~/components/plugins/api/APIDataTypes'; 86b7802baSBartosz Kaszubowskiimport { APISectionDeprecationNote } from '~/components/plugins/api/APISectionDeprecationNote'; 96b7802baSBartosz Kaszubowskiimport { renderMethod } from '~/components/plugins/api/APISectionMethods'; 106b7802baSBartosz Kaszubowskiimport { 116b7802baSBartosz Kaszubowski CommentTextBlock, 126b7802baSBartosz Kaszubowski getTagData, 136b7802baSBartosz Kaszubowski getTagNamesList, 146b7802baSBartosz Kaszubowski mdComponents, 156b7802baSBartosz Kaszubowski STYLES_APIBOX, 166b7802baSBartosz Kaszubowski TypeDocKind, 17a16a3d18SBartosz Kaszubowski H3Code, 185990cc31SBartosz Kaszubowski getCommentContent, 19be43ea08SBartosz Kaszubowski BoxSectionHeader, 206b7802baSBartosz Kaszubowski} from '~/components/plugins/api/APISectionUtils'; 21*3324c13cSBartosz Kaszubowskiimport { H2, MONOSPACE } from '~/ui/components/Text'; 226b7802baSBartosz Kaszubowski 236b7802baSBartosz Kaszubowskiexport type APISectionNamespacesProps = { 246b7802baSBartosz Kaszubowski data: GeneratedData[]; 256b7802baSBartosz Kaszubowski}; 266b7802baSBartosz Kaszubowski 276b7802baSBartosz Kaszubowskiconst isMethod = (child: PropData, allowOverwrites: boolean = false) => 286b7802baSBartosz Kaszubowski child.kind && 296b7802baSBartosz Kaszubowski [TypeDocKind.Method, TypeDocKind.Function].includes(child.kind) && 306b7802baSBartosz Kaszubowski (allowOverwrites || !child.overwrites) && 316b7802baSBartosz Kaszubowski !child.name.startsWith('_') && 326b7802baSBartosz Kaszubowski !child?.implementationOf; 336b7802baSBartosz Kaszubowski 346b7802baSBartosz Kaszubowskiconst renderNamespace = (namespace: ClassDefinitionData, exposeInSidebar: boolean): JSX.Element => { 356b7802baSBartosz Kaszubowski const { name, comment, children } = namespace; 366b7802baSBartosz Kaszubowski 376b7802baSBartosz Kaszubowski const methods = children 386b7802baSBartosz Kaszubowski ?.filter(child => isMethod(child)) 396b7802baSBartosz Kaszubowski .sort((a: PropData, b: PropData) => a.name.localeCompare(b.name)); 406b7802baSBartosz Kaszubowski const returnComment = getTagData('returns', comment); 416b7802baSBartosz Kaszubowski 426b7802baSBartosz Kaszubowski return ( 436b7802baSBartosz Kaszubowski <div key={`class-definition-${name}`} css={STYLES_APIBOX}> 446b7802baSBartosz Kaszubowski <APISectionDeprecationNote comment={comment} /> 456b7802baSBartosz Kaszubowski <H3Code tags={getTagNamesList(comment)}> 46*3324c13cSBartosz Kaszubowski <MONOSPACE weight="medium">{name}</MONOSPACE> 476b7802baSBartosz Kaszubowski </H3Code> 486b7802baSBartosz Kaszubowski <CommentTextBlock comment={comment} /> 496b7802baSBartosz Kaszubowski {returnComment && ( 506b7802baSBartosz Kaszubowski <> 51be43ea08SBartosz Kaszubowski <BoxSectionHeader text="Returns" /> 525990cc31SBartosz Kaszubowski <ReactMarkdown components={mdComponents}> 535990cc31SBartosz Kaszubowski {getCommentContent(returnComment.content)} 545990cc31SBartosz Kaszubowski </ReactMarkdown> 556b7802baSBartosz Kaszubowski </> 566b7802baSBartosz Kaszubowski )} 576b7802baSBartosz Kaszubowski {methods?.length ? ( 586b7802baSBartosz Kaszubowski <> 59be43ea08SBartosz Kaszubowski <BoxSectionHeader text={`${name} Methods`} exposeInSidebar={exposeInSidebar} /> 606b7802baSBartosz Kaszubowski {methods.map(method => renderMethod(method, { exposeInSidebar }))} 616b7802baSBartosz Kaszubowski </> 626b7802baSBartosz Kaszubowski ) : undefined} 636b7802baSBartosz Kaszubowski </div> 646b7802baSBartosz Kaszubowski ); 656b7802baSBartosz Kaszubowski}; 666b7802baSBartosz Kaszubowski 676b7802baSBartosz Kaszubowskiconst APISectionNamespaces = ({ data }: APISectionNamespacesProps) => { 686b7802baSBartosz Kaszubowski if (data?.length) { 696b7802baSBartosz Kaszubowski const exposeInSidebar = data.length < 2; 706b7802baSBartosz Kaszubowski return ( 716b7802baSBartosz Kaszubowski <> 726b7802baSBartosz Kaszubowski <H2>Namespaces</H2> 736b7802baSBartosz Kaszubowski {data.map(namespace => renderNamespace(namespace, exposeInSidebar))} 746b7802baSBartosz Kaszubowski </> 756b7802baSBartosz Kaszubowski ); 766b7802baSBartosz Kaszubowski } 776b7802baSBartosz Kaszubowski return null; 786b7802baSBartosz Kaszubowski}; 796b7802baSBartosz Kaszubowski 806b7802baSBartosz Kaszubowskiexport default APISectionNamespaces; 81