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, 12*a16a3d18SBartosz Kaszubowski getAPISectionHeader, 136b7802baSBartosz Kaszubowski getTagData, 146b7802baSBartosz Kaszubowski getTagNamesList, 156b7802baSBartosz Kaszubowski mdComponents, 166b7802baSBartosz Kaszubowski STYLES_APIBOX, 176b7802baSBartosz Kaszubowski STYLES_NESTED_SECTION_HEADER, 186b7802baSBartosz Kaszubowski TypeDocKind, 19*a16a3d18SBartosz Kaszubowski H3Code, 206b7802baSBartosz Kaszubowski} from '~/components/plugins/api/APISectionUtils'; 21*a16a3d18SBartosz Kaszubowskiimport { H2, H4, CODE } 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; 36*a16a3d18SBartosz Kaszubowski const Header = getAPISectionHeader(exposeInSidebar); 376b7802baSBartosz Kaszubowski 386b7802baSBartosz Kaszubowski const methods = children 396b7802baSBartosz Kaszubowski ?.filter(child => isMethod(child)) 406b7802baSBartosz Kaszubowski .sort((a: PropData, b: PropData) => a.name.localeCompare(b.name)); 416b7802baSBartosz Kaszubowski const returnComment = getTagData('returns', comment); 426b7802baSBartosz Kaszubowski 436b7802baSBartosz Kaszubowski return ( 446b7802baSBartosz Kaszubowski <div key={`class-definition-${name}`} css={STYLES_APIBOX}> 456b7802baSBartosz Kaszubowski <APISectionDeprecationNote comment={comment} /> 466b7802baSBartosz Kaszubowski <H3Code tags={getTagNamesList(comment)}> 4712abeb84SBartosz Kaszubowski <CODE>{name}</CODE> 486b7802baSBartosz Kaszubowski </H3Code> 496b7802baSBartosz Kaszubowski <CommentTextBlock comment={comment} /> 506b7802baSBartosz Kaszubowski {returnComment && ( 516b7802baSBartosz Kaszubowski <> 526b7802baSBartosz Kaszubowski <div css={STYLES_NESTED_SECTION_HEADER}> 536b7802baSBartosz Kaszubowski <H4>Returns</H4> 546b7802baSBartosz Kaszubowski </div> 556b7802baSBartosz Kaszubowski <ReactMarkdown components={mdComponents}>{returnComment.text}</ReactMarkdown> 566b7802baSBartosz Kaszubowski </> 576b7802baSBartosz Kaszubowski )} 586b7802baSBartosz Kaszubowski {methods?.length ? ( 596b7802baSBartosz Kaszubowski <> 606b7802baSBartosz Kaszubowski <div css={STYLES_NESTED_SECTION_HEADER}> 616b7802baSBartosz Kaszubowski <Header>{name} Methods</Header> 626b7802baSBartosz Kaszubowski </div> 636b7802baSBartosz Kaszubowski {methods.map(method => renderMethod(method, { exposeInSidebar }))} 646b7802baSBartosz Kaszubowski </> 656b7802baSBartosz Kaszubowski ) : undefined} 666b7802baSBartosz Kaszubowski </div> 676b7802baSBartosz Kaszubowski ); 686b7802baSBartosz Kaszubowski}; 696b7802baSBartosz Kaszubowski 706b7802baSBartosz Kaszubowskiconst APISectionNamespaces = ({ data }: APISectionNamespacesProps) => { 716b7802baSBartosz Kaszubowski if (data?.length) { 726b7802baSBartosz Kaszubowski const exposeInSidebar = data.length < 2; 736b7802baSBartosz Kaszubowski return ( 746b7802baSBartosz Kaszubowski <> 756b7802baSBartosz Kaszubowski <H2>Namespaces</H2> 766b7802baSBartosz Kaszubowski {data.map(namespace => renderNamespace(namespace, exposeInSidebar))} 776b7802baSBartosz Kaszubowski </> 786b7802baSBartosz Kaszubowski ); 796b7802baSBartosz Kaszubowski } 806b7802baSBartosz Kaszubowski return null; 816b7802baSBartosz Kaszubowski}; 826b7802baSBartosz Kaszubowski 836b7802baSBartosz Kaszubowskiexport default APISectionNamespaces; 84