1*6b7802baSBartosz Kaszubowskiimport ReactMarkdown from 'react-markdown'; 2*6b7802baSBartosz Kaszubowski 3*6b7802baSBartosz Kaszubowskiimport { InlineCode } from '~/components/base/code'; 4*6b7802baSBartosz Kaszubowskiimport { H2, H2Nested, H3Code, H4 } from '~/components/plugins/Headings'; 5*6b7802baSBartosz Kaszubowskiimport { 6*6b7802baSBartosz Kaszubowski ClassDefinitionData, 7*6b7802baSBartosz Kaszubowski GeneratedData, 8*6b7802baSBartosz Kaszubowski PropData, 9*6b7802baSBartosz Kaszubowski} from '~/components/plugins/api/APIDataTypes'; 10*6b7802baSBartosz Kaszubowskiimport { APISectionDeprecationNote } from '~/components/plugins/api/APISectionDeprecationNote'; 11*6b7802baSBartosz Kaszubowskiimport { renderMethod } from '~/components/plugins/api/APISectionMethods'; 12*6b7802baSBartosz Kaszubowskiimport { 13*6b7802baSBartosz Kaszubowski CommentTextBlock, 14*6b7802baSBartosz Kaszubowski getTagData, 15*6b7802baSBartosz Kaszubowski getTagNamesList, 16*6b7802baSBartosz Kaszubowski mdComponents, 17*6b7802baSBartosz Kaszubowski STYLES_APIBOX, 18*6b7802baSBartosz Kaszubowski STYLES_NESTED_SECTION_HEADER, 19*6b7802baSBartosz Kaszubowski TypeDocKind, 20*6b7802baSBartosz Kaszubowski} from '~/components/plugins/api/APISectionUtils'; 21*6b7802baSBartosz Kaszubowski 22*6b7802baSBartosz Kaszubowskiexport type APISectionNamespacesProps = { 23*6b7802baSBartosz Kaszubowski data: GeneratedData[]; 24*6b7802baSBartosz Kaszubowski}; 25*6b7802baSBartosz Kaszubowski 26*6b7802baSBartosz Kaszubowskiconst isMethod = (child: PropData, allowOverwrites: boolean = false) => 27*6b7802baSBartosz Kaszubowski child.kind && 28*6b7802baSBartosz Kaszubowski [TypeDocKind.Method, TypeDocKind.Function].includes(child.kind) && 29*6b7802baSBartosz Kaszubowski (allowOverwrites || !child.overwrites) && 30*6b7802baSBartosz Kaszubowski !child.name.startsWith('_') && 31*6b7802baSBartosz Kaszubowski !child?.implementationOf; 32*6b7802baSBartosz Kaszubowski 33*6b7802baSBartosz Kaszubowskiconst renderNamespace = (namespace: ClassDefinitionData, exposeInSidebar: boolean): JSX.Element => { 34*6b7802baSBartosz Kaszubowski const { name, comment, children } = namespace; 35*6b7802baSBartosz Kaszubowski const Header = exposeInSidebar ? H2Nested : H4; 36*6b7802baSBartosz Kaszubowski 37*6b7802baSBartosz Kaszubowski const methods = children 38*6b7802baSBartosz Kaszubowski ?.filter(child => isMethod(child)) 39*6b7802baSBartosz Kaszubowski .sort((a: PropData, b: PropData) => a.name.localeCompare(b.name)); 40*6b7802baSBartosz Kaszubowski const returnComment = getTagData('returns', comment); 41*6b7802baSBartosz Kaszubowski 42*6b7802baSBartosz Kaszubowski return ( 43*6b7802baSBartosz Kaszubowski <div key={`class-definition-${name}`} css={STYLES_APIBOX}> 44*6b7802baSBartosz Kaszubowski <APISectionDeprecationNote comment={comment} /> 45*6b7802baSBartosz Kaszubowski <H3Code tags={getTagNamesList(comment)}> 46*6b7802baSBartosz Kaszubowski <InlineCode>{name}</InlineCode> 47*6b7802baSBartosz Kaszubowski </H3Code> 48*6b7802baSBartosz Kaszubowski <CommentTextBlock comment={comment} /> 49*6b7802baSBartosz Kaszubowski {returnComment && ( 50*6b7802baSBartosz Kaszubowski <> 51*6b7802baSBartosz Kaszubowski <div css={STYLES_NESTED_SECTION_HEADER}> 52*6b7802baSBartosz Kaszubowski <H4>Returns</H4> 53*6b7802baSBartosz Kaszubowski </div> 54*6b7802baSBartosz Kaszubowski <ReactMarkdown components={mdComponents}>{returnComment.text}</ReactMarkdown> 55*6b7802baSBartosz Kaszubowski </> 56*6b7802baSBartosz Kaszubowski )} 57*6b7802baSBartosz Kaszubowski {methods?.length ? ( 58*6b7802baSBartosz Kaszubowski <> 59*6b7802baSBartosz Kaszubowski <div css={STYLES_NESTED_SECTION_HEADER}> 60*6b7802baSBartosz Kaszubowski <Header>{name} Methods</Header> 61*6b7802baSBartosz Kaszubowski </div> 62*6b7802baSBartosz Kaszubowski {methods.map(method => renderMethod(method, { exposeInSidebar }))} 63*6b7802baSBartosz Kaszubowski </> 64*6b7802baSBartosz Kaszubowski ) : undefined} 65*6b7802baSBartosz Kaszubowski </div> 66*6b7802baSBartosz Kaszubowski ); 67*6b7802baSBartosz Kaszubowski}; 68*6b7802baSBartosz Kaszubowski 69*6b7802baSBartosz Kaszubowskiconst APISectionNamespaces = ({ data }: APISectionNamespacesProps) => { 70*6b7802baSBartosz Kaszubowski if (data?.length) { 71*6b7802baSBartosz Kaszubowski const exposeInSidebar = data.length < 2; 72*6b7802baSBartosz Kaszubowski return ( 73*6b7802baSBartosz Kaszubowski <> 74*6b7802baSBartosz Kaszubowski <H2>Namespaces</H2> 75*6b7802baSBartosz Kaszubowski {data.map(namespace => renderNamespace(namespace, exposeInSidebar))} 76*6b7802baSBartosz Kaszubowski </> 77*6b7802baSBartosz Kaszubowski ); 78*6b7802baSBartosz Kaszubowski } 79*6b7802baSBartosz Kaszubowski return null; 80*6b7802baSBartosz Kaszubowski}; 81*6b7802baSBartosz Kaszubowski 82*6b7802baSBartosz Kaszubowskiexport default APISectionNamespaces; 83