16b7802baSBartosz Kaszubowskiimport ReactMarkdown from 'react-markdown';
26b7802baSBartosz Kaszubowski
36b7802baSBartosz Kaszubowskiimport { H2, H2Nested, H3Code, H4 } from '~/components/plugins/Headings';
46b7802baSBartosz Kaszubowskiimport {
56b7802baSBartosz Kaszubowski  ClassDefinitionData,
66b7802baSBartosz Kaszubowski  GeneratedData,
76b7802baSBartosz Kaszubowski  PropData,
86b7802baSBartosz Kaszubowski} from '~/components/plugins/api/APIDataTypes';
96b7802baSBartosz Kaszubowskiimport { APISectionDeprecationNote } from '~/components/plugins/api/APISectionDeprecationNote';
106b7802baSBartosz Kaszubowskiimport { renderMethod } from '~/components/plugins/api/APISectionMethods';
116b7802baSBartosz Kaszubowskiimport {
126b7802baSBartosz Kaszubowski  CommentTextBlock,
136b7802baSBartosz Kaszubowski  getTagData,
146b7802baSBartosz Kaszubowski  getTagNamesList,
156b7802baSBartosz Kaszubowski  mdComponents,
166b7802baSBartosz Kaszubowski  STYLES_APIBOX,
176b7802baSBartosz Kaszubowski  STYLES_NESTED_SECTION_HEADER,
186b7802baSBartosz Kaszubowski  TypeDocKind,
196b7802baSBartosz Kaszubowski} from '~/components/plugins/api/APISectionUtils';
20*12abeb84SBartosz Kaszubowskiimport { CODE } from '~/ui/components/Text';
216b7802baSBartosz Kaszubowski
226b7802baSBartosz Kaszubowskiexport type APISectionNamespacesProps = {
236b7802baSBartosz Kaszubowski  data: GeneratedData[];
246b7802baSBartosz Kaszubowski};
256b7802baSBartosz Kaszubowski
266b7802baSBartosz Kaszubowskiconst isMethod = (child: PropData, allowOverwrites: boolean = false) =>
276b7802baSBartosz Kaszubowski  child.kind &&
286b7802baSBartosz Kaszubowski  [TypeDocKind.Method, TypeDocKind.Function].includes(child.kind) &&
296b7802baSBartosz Kaszubowski  (allowOverwrites || !child.overwrites) &&
306b7802baSBartosz Kaszubowski  !child.name.startsWith('_') &&
316b7802baSBartosz Kaszubowski  !child?.implementationOf;
326b7802baSBartosz Kaszubowski
336b7802baSBartosz Kaszubowskiconst renderNamespace = (namespace: ClassDefinitionData, exposeInSidebar: boolean): JSX.Element => {
346b7802baSBartosz Kaszubowski  const { name, comment, children } = namespace;
356b7802baSBartosz Kaszubowski  const Header = exposeInSidebar ? H2Nested : H4;
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*12abeb84SBartosz Kaszubowski        <CODE>{name}</CODE>
476b7802baSBartosz Kaszubowski      </H3Code>
486b7802baSBartosz Kaszubowski      <CommentTextBlock comment={comment} />
496b7802baSBartosz Kaszubowski      {returnComment && (
506b7802baSBartosz Kaszubowski        <>
516b7802baSBartosz Kaszubowski          <div css={STYLES_NESTED_SECTION_HEADER}>
526b7802baSBartosz Kaszubowski            <H4>Returns</H4>
536b7802baSBartosz Kaszubowski          </div>
546b7802baSBartosz Kaszubowski          <ReactMarkdown components={mdComponents}>{returnComment.text}</ReactMarkdown>
556b7802baSBartosz Kaszubowski        </>
566b7802baSBartosz Kaszubowski      )}
576b7802baSBartosz Kaszubowski      {methods?.length ? (
586b7802baSBartosz Kaszubowski        <>
596b7802baSBartosz Kaszubowski          <div css={STYLES_NESTED_SECTION_HEADER}>
606b7802baSBartosz Kaszubowski            <Header>{name} Methods</Header>
616b7802baSBartosz Kaszubowski          </div>
626b7802baSBartosz Kaszubowski          {methods.map(method => renderMethod(method, { exposeInSidebar }))}
636b7802baSBartosz Kaszubowski        </>
646b7802baSBartosz Kaszubowski      ) : undefined}
656b7802baSBartosz Kaszubowski    </div>
666b7802baSBartosz Kaszubowski  );
676b7802baSBartosz Kaszubowski};
686b7802baSBartosz Kaszubowski
696b7802baSBartosz Kaszubowskiconst APISectionNamespaces = ({ data }: APISectionNamespacesProps) => {
706b7802baSBartosz Kaszubowski  if (data?.length) {
716b7802baSBartosz Kaszubowski    const exposeInSidebar = data.length < 2;
726b7802baSBartosz Kaszubowski    return (
736b7802baSBartosz Kaszubowski      <>
746b7802baSBartosz Kaszubowski        <H2>Namespaces</H2>
756b7802baSBartosz Kaszubowski        {data.map(namespace => renderNamespace(namespace, exposeInSidebar))}
766b7802baSBartosz Kaszubowski      </>
776b7802baSBartosz Kaszubowski    );
786b7802baSBartosz Kaszubowski  }
796b7802baSBartosz Kaszubowski  return null;
806b7802baSBartosz Kaszubowski};
816b7802baSBartosz Kaszubowski
826b7802baSBartosz Kaszubowskiexport default APISectionNamespaces;
83