@apify/docusaurus-plugin-typedoc-api 3.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +27 -5
  2. package/lib/components/AnchorLink.js +15 -10
  3. package/lib/components/AnchorLink.js.map +1 -1
  4. package/lib/components/ApiChangelog.js +9 -11
  5. package/lib/components/ApiChangelog.js.map +1 -1
  6. package/lib/components/ApiDataContext.js +2 -2
  7. package/lib/components/ApiIndex.js +55 -37
  8. package/lib/components/ApiIndex.js.map +1 -1
  9. package/lib/components/ApiItem.js +33 -29
  10. package/lib/components/ApiItem.js.map +1 -1
  11. package/lib/components/ApiItemLayout.js +49 -27
  12. package/lib/components/ApiItemLayout.js.map +1 -1
  13. package/lib/components/ApiPage.js +18 -10
  14. package/lib/components/ApiPage.js.map +1 -1
  15. package/lib/components/Breadcrumb.js +27 -14
  16. package/lib/components/Breadcrumb.js.map +1 -1
  17. package/lib/components/Comment.js +24 -18
  18. package/lib/components/Comment.js.map +1 -1
  19. package/lib/components/CommentBadges.js +8 -11
  20. package/lib/components/CommentBadges.js.map +1 -1
  21. package/lib/components/DefaultValue.js +20 -20
  22. package/lib/components/DefaultValue.js.map +1 -1
  23. package/lib/components/Flags.js +9 -11
  24. package/lib/components/Flags.js.map +1 -1
  25. package/lib/components/Footer.js +11 -12
  26. package/lib/components/Footer.js.map +1 -1
  27. package/lib/components/Hierarchy.js +15 -16
  28. package/lib/components/Hierarchy.js.map +1 -1
  29. package/lib/components/Icon.js +2 -6
  30. package/lib/components/Icon.js.map +1 -1
  31. package/lib/components/Index.js +84 -62
  32. package/lib/components/Index.js.map +1 -1
  33. package/lib/components/Markdown.js +80 -66
  34. package/lib/components/Markdown.js.map +1 -1
  35. package/lib/components/Member.js +28 -28
  36. package/lib/components/Member.js.map +1 -1
  37. package/lib/components/MemberDeclaration.js +51 -42
  38. package/lib/components/MemberDeclaration.js.map +1 -1
  39. package/lib/components/MemberGetterSetter.js +50 -40
  40. package/lib/components/MemberGetterSetter.js.map +1 -1
  41. package/lib/components/MemberReference.js +27 -16
  42. package/lib/components/MemberReference.js.map +1 -1
  43. package/lib/components/MemberSignatureBody.js +57 -45
  44. package/lib/components/MemberSignatureBody.js.map +1 -1
  45. package/lib/components/MemberSignatureTitle.js +48 -27
  46. package/lib/components/MemberSignatureTitle.js.map +1 -1
  47. package/lib/components/MemberSignatures.js +46 -38
  48. package/lib/components/MemberSignatures.js.map +1 -1
  49. package/lib/components/MemberSources.js +18 -15
  50. package/lib/components/MemberSources.js.map +1 -1
  51. package/lib/components/Members.js +32 -31
  52. package/lib/components/Members.js.map +1 -1
  53. package/lib/components/MembersGroup.js +24 -22
  54. package/lib/components/MembersGroup.js.map +1 -1
  55. package/lib/components/Parameter.js +139 -109
  56. package/lib/components/Parameter.js.map +1 -1
  57. package/lib/components/Reflection.js +113 -90
  58. package/lib/components/Reflection.js.map +1 -1
  59. package/lib/components/SourceLink.js +12 -13
  60. package/lib/components/SourceLink.js.map +1 -1
  61. package/lib/components/Type.js +320 -206
  62. package/lib/components/Type.js.map +1 -1
  63. package/lib/components/TypeAndParent.js +11 -10
  64. package/lib/components/TypeAndParent.js.map +1 -1
  65. package/lib/components/TypeParameters.js +23 -20
  66. package/lib/components/TypeParameters.js.map +1 -1
  67. package/lib/components/TypeParametersGeneric.js +17 -16
  68. package/lib/components/TypeParametersGeneric.js.map +1 -1
  69. package/lib/components/VersionBanner.js +21 -9
  70. package/lib/components/VersionBanner.js.map +1 -1
  71. package/lib/hooks/useBreadcrumbs.js +2 -2
  72. package/lib/hooks/useGitRefName.js +2 -2
  73. package/lib/hooks/useMinimalLayout.js +2 -2
  74. package/lib/hooks/useReflection.js +10 -6
  75. package/lib/hooks/useReflection.js.map +1 -1
  76. package/lib/hooks/useReflectionMap.js +2 -2
  77. package/lib/index.js +62 -25
  78. package/lib/index.js.map +1 -1
  79. package/lib/plugin/data.js +61 -18
  80. package/lib/plugin/data.js.map +1 -1
  81. package/lib/plugin/version.js +5 -4
  82. package/lib/plugin/version.js.map +1 -1
  83. package/lib/utils/helpers.js +8 -0
  84. package/lib/utils/helpers.js.map +1 -0
  85. package/lib/utils/hierarchy.js +6 -3
  86. package/lib/utils/hierarchy.js.map +1 -1
  87. package/lib/utils/icons.js +2 -5
  88. package/lib/utils/icons.js.map +1 -1
  89. package/lib/utils/markdown.js +5 -7
  90. package/lib/utils/markdown.js.map +1 -1
  91. package/package.json +17 -14
  92. package/src/components/AnchorLink.tsx +6 -3
  93. package/src/components/ApiChangelog.tsx +0 -1
  94. package/src/components/ApiDataContext.ts +2 -2
  95. package/src/components/ApiIndex.tsx +1 -1
  96. package/src/components/ApiItem.tsx +18 -20
  97. package/src/components/ApiItemLayout.tsx +1 -2
  98. package/src/components/ApiPage.tsx +18 -13
  99. package/src/components/Breadcrumb.tsx +2 -3
  100. package/src/components/Comment.tsx +3 -4
  101. package/src/components/CommentBadges.tsx +0 -1
  102. package/src/components/DefaultValue.tsx +0 -1
  103. package/src/components/Flags.tsx +1 -1
  104. package/src/components/Footer.tsx +0 -2
  105. package/src/components/Hierarchy.tsx +0 -1
  106. package/src/components/Icon.tsx +2 -3
  107. package/src/components/Index.tsx +14 -19
  108. package/src/components/Markdown.tsx +54 -25
  109. package/src/components/Member.tsx +7 -6
  110. package/src/components/MemberDeclaration.tsx +7 -7
  111. package/src/components/MemberGetterSetter.tsx +6 -6
  112. package/src/components/MemberReference.tsx +4 -4
  113. package/src/components/MemberSignatureBody.tsx +5 -5
  114. package/src/components/MemberSignatureTitle.tsx +11 -9
  115. package/src/components/MemberSignatures.tsx +5 -5
  116. package/src/components/MemberSources.tsx +3 -5
  117. package/src/components/Members.tsx +3 -4
  118. package/src/components/MembersGroup.tsx +1 -2
  119. package/src/components/Parameter.tsx +7 -12
  120. package/src/components/README.md +1 -1
  121. package/src/components/Reflection.tsx +7 -10
  122. package/src/components/SourceLink.tsx +0 -2
  123. package/src/components/Type.tsx +34 -22
  124. package/src/components/TypeAndParent.tsx +0 -1
  125. package/src/components/TypeParameters.tsx +0 -1
  126. package/src/components/TypeParametersGeneric.tsx +3 -3
  127. package/src/components/VersionBanner.tsx +1 -1
  128. package/src/hooks/useReflection.ts +11 -4
  129. package/src/hooks/useReflectionMap.ts +2 -2
  130. package/src/index.ts +92 -39
  131. package/src/plugin/data.ts +123 -54
  132. package/src/plugin/sidebar.ts +4 -3
  133. package/src/types.ts +24 -33
  134. package/src/utils/helpers.ts +4 -0
  135. package/src/utils/hierarchy.ts +11 -7
  136. package/src/utils/icons.ts +2 -3
  137. package/src/utils/markdown.ts +10 -7
  138. package/src/utils/visibility.ts +4 -4
@@ -1,10 +1,10 @@
1
- import React, { useMemo } from 'react';
2
- import type { JSONOutput } from 'typedoc';
1
+ import { useMemo } from 'react';
3
2
  import { PageMetadata } from '@docusaurus/theme-common';
4
3
  import type { Props as DocItemProps } from '@theme/DocItem';
5
- import { useReflection } from '../hooks/useReflection';
4
+ import { useReflection, useRequiredReflection } from '../hooks/useReflection';
6
5
  import { useReflectionMap } from '../hooks/useReflectionMap';
7
- import type { DeclarationReflectionMap, TOCItem } from '../types';
6
+ import type { TOCItem, TSDDeclarationReflection, TSDDeclarationReflectionMap } from '../types';
7
+ import { escapeMdx } from '../utils/helpers';
8
8
  import { getKindIconHtml } from '../utils/icons';
9
9
  import ApiItemLayout from './ApiItemLayout';
10
10
  import { displayPartsToMarkdown } from './Comment';
@@ -12,29 +12,27 @@ import { Flags } from './Flags';
12
12
  import { Reflection } from './Reflection';
13
13
  import { TypeParametersGeneric } from './TypeParametersGeneric';
14
14
 
15
- function extractTOC(
16
- item: JSONOutput.DeclarationReflection,
17
- map: DeclarationReflectionMap,
18
- ): TOCItem[] {
15
+ function extractTOC(item: TSDDeclarationReflection, map: TSDDeclarationReflectionMap): TOCItem[] {
19
16
  const toc: TOCItem[] = [];
20
17
  const mapped = new Set<string>();
21
18
 
22
19
  item.groups?.forEach((group) => {
23
20
  group.children?.forEach((childId) => {
24
- const child = map[childId]!;
21
+ const child = map[childId];
25
22
 
26
23
  if (mapped.has(child.name)) {
27
24
  return;
28
25
  }
29
26
 
30
- const iconHtml = getKindIconHtml(child.kind, child.name);
31
-
32
27
  if (!child.permalink || child.permalink.includes('#')) {
28
+ const iconHtml = getKindIconHtml(child.kind, child.name);
29
+ const value = escapeMdx(child.name) ?? '';
30
+
33
31
  toc.push({
34
32
  // @ts-expect-error Not typed upstream
35
33
  children: [],
36
34
  id: child.name,
37
- value: iconHtml ? `${iconHtml} ${child.name}` : child.name,
35
+ value: iconHtml ? `${iconHtml} ${value}` : value,
38
36
  level: 1,
39
37
  });
40
38
 
@@ -51,7 +49,7 @@ export interface ApiItemProps extends Pick<DocItemProps, 'route'> {
51
49
  }
52
50
 
53
51
  export default function ApiItem({ readme: Readme, route }: ApiItemProps) {
54
- const item = useReflection((route as unknown as { id: number }).id)!;
52
+ const item = useRequiredReflection((route as unknown as { id: number }).id);
55
53
  const reflections = useReflectionMap();
56
54
  const toc = useMemo(() => extractTOC(item, reflections), [item, reflections]);
57
55
 
@@ -63,14 +61,14 @@ export default function ApiItem({ readme: Readme, route }: ApiItemProps) {
63
61
  next: nextItem
64
62
  ? {
65
63
  permalink: nextItem.permalink,
66
- title: nextItem.name,
67
- }
64
+ title: escapeMdx(nextItem.name) ?? '',
65
+ }
68
66
  : undefined,
69
67
  previous: prevItem
70
68
  ? {
71
69
  permalink: prevItem.permalink,
72
- title: prevItem.name,
73
- }
70
+ title: escapeMdx(prevItem.name) ?? '',
71
+ }
74
72
  : undefined,
75
73
  }),
76
74
  [nextItem, prevItem],
@@ -83,15 +81,15 @@ export default function ApiItem({ readme: Readme, route }: ApiItemProps) {
83
81
  <span className="tsd-header-flags">
84
82
  <Flags flags={item.flags} />
85
83
  </span>
86
- {item.name} <TypeParametersGeneric params={item.typeParameters} />
84
+ {escapeMdx(item.name)} <TypeParametersGeneric params={item.typeParameters} />
87
85
  </>
88
86
  }
89
87
  module={(item as unknown as { module: string }).module}
90
88
  name={item.name}
91
89
  pageMetadata={
92
90
  <PageMetadata
93
- description={item.comment?.summary ? displayPartsToMarkdown(item.comment.summary) : ''}
94
- title={`${item.name} | API`}
91
+ description={item?.comment?.summary ? displayPartsToMarkdown(item.comment.summary) : ''}
92
+ title={`${item?.name ? `${item.name} | ` : ''}API`}
95
93
  />
96
94
  }
97
95
  pagingMetadata={pagingMetadata}
@@ -2,7 +2,6 @@
2
2
  // we had to duplicate it. Keep this file in sync as much as possible!
3
3
  // https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx
4
4
 
5
- import React from 'react';
6
5
  import type { PropNavigation } from '@docusaurus/plugin-content-docs';
7
6
  import { ThemeClassNames, useWindowSize } from '@docusaurus/theme-common';
8
7
  import DocBreadcrumbs from '@theme/DocBreadcrumbs';
@@ -23,7 +22,7 @@ export interface ApiItemLayoutProps extends Pick<DocItemProps, 'route'> {
23
22
  toc: readonly TOCItem[];
24
23
  pageMetadata?: React.ReactNode;
25
24
  pagingMetadata?: PropNavigation;
26
- name: string;
25
+ name?: string;
27
26
  module?: string;
28
27
  }
29
28
 
@@ -2,20 +2,25 @@
2
2
 
3
3
  import '@vscode/codicons/dist/codicon.css';
4
4
  import './styles.css';
5
- import React, { useMemo } from 'react';
6
- import type { JSONOutput } from 'typedoc';
7
- import DocPage, { type Props as DocPageProps } from '@theme/DocPage';
8
- import type { ApiOptions, DeclarationReflectionMap, PackageReflectionGroup } from '../types';
5
+ import { useMemo } from 'react';
6
+ import DocRoot, { type Props as DocRootProps } from '@theme/DocRoot';
7
+ import type {
8
+ ApiOptions,
9
+ PackageReflectionGroup,
10
+ TSDDeclarationReflection,
11
+ TSDDeclarationReflectionMap,
12
+ TSDReflection,
13
+ } from '../types';
9
14
  import { ApiDataContext } from './ApiDataContext';
10
15
 
11
- function isObject(value: unknown): value is JSONOutput.Reflection {
16
+ function isObject(value: unknown): value is TSDReflection {
12
17
  return typeof value === 'object' && value !== null && !Array.isArray(value);
13
18
  }
14
19
 
15
20
  function deepMapReflections(
16
- data: JSONOutput.Reflection,
17
- map: DeclarationReflectionMap,
18
- parent?: JSONOutput.Reflection,
21
+ data: TSDReflection,
22
+ map: TSDDeclarationReflectionMap,
23
+ parent?: TSDReflection,
19
24
  ) {
20
25
  Object.entries(data).forEach(([key, value]) => {
21
26
  if (key === 'id') {
@@ -23,7 +28,7 @@ function deepMapReflections(
23
28
 
24
29
  // Dont overwrite with reference nodes
25
30
  if (!hasType || (hasType && (data as unknown as { type: string }).type !== 'reference')) {
26
- map[Number(value)] = data;
31
+ map[Number(value)] = data as TSDDeclarationReflection;
27
32
 
28
33
  if (parent) {
29
34
  data.parentId = parent.id;
@@ -43,8 +48,8 @@ function deepMapReflections(
43
48
  return map;
44
49
  }
45
50
 
46
- function mapPackagesToReflection(packages: PackageReflectionGroup[]): DeclarationReflectionMap {
47
- const map: DeclarationReflectionMap = {};
51
+ function mapPackagesToReflection(packages: PackageReflectionGroup[]): TSDDeclarationReflectionMap {
52
+ const map: TSDDeclarationReflectionMap = {};
48
53
 
49
54
  packages.forEach((pkg) => {
50
55
  pkg.entryPoints.forEach((entry) => {
@@ -55,7 +60,7 @@ function mapPackagesToReflection(packages: PackageReflectionGroup[]): Declaratio
55
60
  return map;
56
61
  }
57
62
 
58
- export interface ApiPageProps extends DocPageProps {
63
+ export interface ApiPageProps extends DocRootProps {
59
64
  options: ApiOptions;
60
65
  packages: PackageReflectionGroup[];
61
66
  }
@@ -69,7 +74,7 @@ function ApiPage({ options, packages, ...props }: ApiPageProps) {
69
74
  return (
70
75
  <ApiDataContext.Provider value={value}>
71
76
  <div className="apiPage">
72
- <DocPage {...props} />
77
+ <DocRoot {...props} />
73
78
  </div>
74
79
  </ApiDataContext.Provider>
75
80
  );
@@ -1,12 +1,11 @@
1
1
  // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/breadcrumb.hbs
2
2
 
3
- import React from 'react';
4
- import type { JSONOutput } from 'typedoc';
5
3
  import Link from '@docusaurus/Link';
6
4
  import { useReflection } from '../hooks/useReflection';
5
+ import type { TSDReflection } from '../types';
7
6
 
8
7
  export interface BreadcrumbProps {
9
- reflection: JSONOutput.Reflection;
8
+ reflection: TSDReflection;
10
9
  root?: boolean;
11
10
  }
12
11
 
@@ -1,6 +1,5 @@
1
1
  // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/comment.hbs
2
-
3
- import React from 'react';
2
+ import { Fragment } from 'react';
4
3
  import type { JSONOutput } from 'typedoc';
5
4
  import { Markdown } from './Markdown';
6
5
 
@@ -58,14 +57,14 @@ export function Comment({ comment, root, hideTags = [] }: CommentProps) {
58
57
  {blockTags.length > 0 && (
59
58
  <dl className="tsd-comment-tags">
60
59
  {blockTags.map((tag) => (
61
- <React.Fragment key={tag.tag}>
60
+ <Fragment key={tag.tag}>
62
61
  <dt>
63
62
  <strong>{tag.tag}</strong>
64
63
  </dt>
65
64
  <dd>
66
65
  <Markdown content={displayPartsToMarkdown(tag.content)} />
67
66
  </dd>
68
- </React.Fragment>
67
+ </Fragment>
69
68
  ))}
70
69
  </dl>
71
70
  )}
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { JSONOutput } from 'typedoc';
3
2
 
4
3
  function getModifierClassName(tag: string) {
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable react-perf/jsx-no-new-object-as-prop */
2
2
 
3
- import React from 'react';
4
3
  import type { JSONOutput } from 'typedoc';
5
4
  import { displayPartsToMarkdown } from './Comment';
6
5
  import { Type } from './Type';
@@ -1,5 +1,5 @@
1
1
  // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/comment.hbs
2
- import React from 'react';
2
+
3
3
  import type { JSONOutput } from 'typedoc';
4
4
 
5
5
  function removePrefix(value: string) {
@@ -1,5 +1,3 @@
1
- import React from 'react';
2
-
3
1
  export function Footer() {
4
2
  return (
5
3
  <footer className="tsd-footer">
@@ -1,6 +1,5 @@
1
1
  // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/hierarchy.hbs
2
2
 
3
- import React from 'react';
4
3
  import type { HierarchyNode } from '../utils/hierarchy';
5
4
  import { Type } from './Type';
6
5
 
@@ -1,9 +1,8 @@
1
- import React from 'react';
2
- import type { JSONOutput } from 'typedoc';
1
+ import type { TSDDeclarationReflection, TSDSignatureReflection } from '../types';
3
2
  import { getKindIcon, getKindIconColor } from '../utils/icons';
4
3
 
5
4
  export interface IconProps {
6
- reflection: JSONOutput.DeclarationReflection;
5
+ reflection: TSDDeclarationReflection | TSDSignatureReflection;
7
6
  }
8
7
 
9
8
  export function Icon({ reflection }: IconProps) {
@@ -1,7 +1,8 @@
1
- import React from 'react';
2
- import type { JSONOutput } from 'typedoc';
1
+ import { Fragment } from 'react';
3
2
  import Link from '@docusaurus/Link';
4
- import { useReflection } from '../hooks/useReflection';
3
+ import { useRequiredReflection } from '../hooks/useReflection';
4
+ import type { TSDDeclarationReflection } from '../types';
5
+ import { escapeMdx } from '../utils/helpers';
5
6
  import { AnchorLink } from './AnchorLink';
6
7
  import { Icon } from './Icon';
7
8
 
@@ -10,20 +11,20 @@ export interface IndexChildProps {
10
11
  }
11
12
 
12
13
  function IndexChild({ id }: IndexChildProps) {
13
- const reflection = useReflection(id)!;
14
+ const reflection = useRequiredReflection(id);
14
15
 
15
16
  return (
16
17
  <li>
17
18
  <Link className="tsd-kind-icon" to={reflection.permalink ?? `#${reflection.name}`}>
18
19
  <Icon reflection={reflection} />
19
- {reflection.name ?? <em>{reflection.kindString}</em>}
20
+ {escapeMdx(reflection.name)}
20
21
  </Link>
21
22
  </li>
22
23
  );
23
24
  }
24
25
 
25
26
  export interface IndexProps {
26
- reflection: JSONOutput.DeclarationReflection;
27
+ reflection: TSDDeclarationReflection;
27
28
  }
28
29
 
29
30
  export function Index({ reflection }: IndexProps) {
@@ -39,14 +40,12 @@ export function Index({ reflection }: IndexProps) {
39
40
  {reflection.categories.map((category) => (
40
41
  <section key={category.title} className="tsd-index-section">
41
42
  <h3 className="tsd-panel-header">
42
- {category.title === 'CATEGORY' ? 'Other' : category.title}
43
+ {category.title === '__CATEGORY__' ? 'Other' : category.title}
43
44
  </h3>
44
45
 
45
46
  <div className="tsd-panel-content">
46
47
  <ul className="tsd-index-list">
47
- {category.children?.map((child) => (
48
- <IndexChild key={child} id={child} />
49
- ))}
48
+ {category.children?.map((child) => <IndexChild key={child} id={child} />)}
50
49
  </ul>
51
50
  </div>
52
51
  </section>
@@ -70,19 +69,17 @@ export function Index({ reflection }: IndexProps) {
70
69
  <section key={group.title} className="tsd-index-section">
71
70
  {group.categories && group.categories.length > 0 ? (
72
71
  group.categories.map((category) => (
73
- <React.Fragment key={category.title}>
72
+ <Fragment key={category.title}>
74
73
  <h3 className="tsd-panel-header">
75
- {category.title === 'CATEGORY' ? group.title : category.title}
74
+ {category.title === '__CATEGORY__' ? group.title : category.title}
76
75
  </h3>
77
76
 
78
77
  <div className="tsd-panel-content">
79
78
  <ul className="tsd-index-list">
80
- {category.children?.map((child) => (
81
- <IndexChild key={child} id={child} />
82
- ))}
79
+ {category.children?.map((child) => <IndexChild key={child} id={child} />)}
83
80
  </ul>
84
81
  </div>
85
- </React.Fragment>
82
+ </Fragment>
86
83
  ))
87
84
  ) : (
88
85
  <>
@@ -90,9 +87,7 @@ export function Index({ reflection }: IndexProps) {
90
87
 
91
88
  <div className="tsd-panel-content">
92
89
  <ul className="tsd-index-list">
93
- {group.children?.map((child) => (
94
- <IndexChild key={child} id={child} />
95
- ))}
90
+ {group.children?.map((child) => <IndexChild key={child} id={child} />)}
96
91
  </ul>
97
92
  </div>
98
93
  </>
@@ -1,9 +1,11 @@
1
- /* eslint-disable unicorn/no-unsafe-regex */
2
1
  /* eslint-disable react/no-array-index-key */
3
2
 
4
- import React, { useState } from 'react';
5
- import { marked } from 'marked';
3
+ import { Fragment, useState } from 'react';
4
+ import { marked, type Tokens } from 'marked';
5
+ import { markedSmartypants } from 'marked-smartypants';
6
+ import { useDocsData } from '@docusaurus/plugin-content-docs/client';
6
7
  import { useDocsVersion } from '@docusaurus/theme-common/internal';
8
+ import CodeBlock from '@theme/CodeBlock';
7
9
  import MDX from '@theme/MDXComponents';
8
10
  import { useReflectionMap } from '../hooks/useReflectionMap';
9
11
  import { replaceLinkTokens } from '../utils/markdown';
@@ -14,30 +16,48 @@ interface Admonition {
14
16
  title?: string;
15
17
  keyword?: string;
16
18
  text: string;
17
- tokens: marked.Token[];
19
+ tokens: Token[];
18
20
  }
19
21
 
20
- type TokensList = (Admonition | marked.Token)[];
21
-
22
- marked.setOptions({
23
- gfm: true,
24
- headerIds: false,
25
- mangle: false,
26
- smartLists: true,
27
- smartypants: true,
28
- });
22
+ type Token =
23
+ | Admonition
24
+ | Tokens.Blockquote
25
+ | Tokens.Br
26
+ | Tokens.Code
27
+ | Tokens.Codespan
28
+ | Tokens.Def
29
+ | Tokens.Del
30
+ | Tokens.Em
31
+ | Tokens.Escape
32
+ | Tokens.Heading
33
+ | Tokens.Hr
34
+ | Tokens.HTML
35
+ | Tokens.Image
36
+ | Tokens.Link
37
+ | Tokens.List
38
+ | Tokens.ListItem
39
+ | Tokens.Paragraph
40
+ | Tokens.Space
41
+ | Tokens.Strong
42
+ | Tokens.Table
43
+ | Tokens.Tag
44
+ | Tokens.Text;
45
+ type TokensList = Token[];
29
46
 
30
47
  const ADMONITION_START = /^:{3}([a-z]+)? *(.*)\n/;
31
48
  const ADMONITION_END = '\n:::';
32
49
 
50
+ marked.setOptions({
51
+ gfm: true,
52
+ });
53
+ marked.use(markedSmartypants());
33
54
  marked.use({
34
55
  extensions: [
35
56
  {
36
57
  name: 'admonition',
37
58
  level: 'block',
38
59
  start(src) {
39
- // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
40
- return src.match(ADMONITION_START)?.index!;
60
+ return src.match(ADMONITION_START)?.index;
41
61
  },
42
62
  tokenizer(src, tokens) {
43
63
  const match = ADMONITION_START.exec(src);
@@ -100,9 +120,12 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
100
120
  switch (token.type) {
101
121
  case 'code':
102
122
  elements.push(
103
- <MDX.pre key={counter} className={token.lang && `language-${token.lang}`}>
123
+ /* <MDX.pre key={counter} className={token.lang && `language-${token.lang}`}>
124
+ {token.text}
125
+ </MDX.pre>, */
126
+ <CodeBlock key={counter} language={token.lang}>
104
127
  {token.text}
105
- </MDX.pre>,
128
+ </CodeBlock>,
106
129
  );
107
130
  break;
108
131
 
@@ -119,12 +142,12 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
119
142
  }
120
143
 
121
144
  case 'image':
122
- elements.push(<MDX.img key={counter} alt={token.title} src={token.href} />);
145
+ elements.push(<MDX.img key={counter} alt={token.title ?? ''} src={token.href} />);
123
146
  break;
124
147
 
125
148
  case 'link':
126
149
  elements.push(
127
- <MDX.a key={counter} href={token.href} title={token.title}>
150
+ <MDX.a key={counter} href={token.href} title={token.title ?? ''}>
128
151
  {convertAstToElements(children) ?? token.text}
129
152
  </MDX.a>,
130
153
  );
@@ -163,7 +186,7 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
163
186
  <thead>
164
187
  <tr>
165
188
  {token.header.map((h, i) => (
166
- <th key={i} align={token.align[i]!}>
189
+ <th key={i} align={token.align[i] ?? 'left'}>
167
190
  {convertAstToElements(h.tokens as TokensList)}
168
191
  </th>
169
192
  ))}
@@ -173,7 +196,7 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
173
196
  {token.rows.map((cells, i) => (
174
197
  <tr key={i}>
175
198
  {cells.map((c, i2) => (
176
- <td key={i2} align={token.align[i]!}>
199
+ <td key={i2} align={token.align[i] ?? 'left'}>
177
200
  {convertAstToElements(c.tokens as TokensList)}
178
201
  </td>
179
202
  ))}
@@ -189,7 +212,7 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
189
212
  children.length === 0 ? (
190
213
  token.text
191
214
  ) : (
192
- <React.Fragment key={counter}>{convertAstToElements(children)}</React.Fragment>
215
+ <Fragment key={counter}>{convertAstToElements(children)}</Fragment>
193
216
  ),
194
217
  );
195
218
  break;
@@ -203,7 +226,9 @@ function convertAstToElements(ast: TokensList): React.ReactNode[] | undefined {
203
226
  break;
204
227
 
205
228
  default: {
206
- const Comp = TOKEN_TO_TAG[token.type] || token.type;
229
+ const Comp = (TOKEN_TO_TAG[token.type] || token.type) as unknown as React.ComponentType<{
230
+ children: React.ReactNode;
231
+ }>;
207
232
  const innerText = 'text' in token ? token.text : '';
208
233
 
209
234
  elements.push(<Comp key={counter}>{convertAstToElements(children) ?? innerText}</Comp>);
@@ -229,8 +254,12 @@ export interface MarkdownProps {
229
254
  export function Markdown({ content }: MarkdownProps) {
230
255
  const reflections = useReflectionMap();
231
256
  const version = useDocsVersion();
232
- const [ast] = useState<TokensList>(() =>
233
- marked.lexer(replaceLinkTokens(content, reflections, version)),
257
+ const docsData = useDocsData(version.pluginId);
258
+ const [ast] = useState<TokensList>(
259
+ () =>
260
+ marked.lexer(
261
+ replaceLinkTokens(content, reflections, version, docsData.path),
262
+ ) as unknown as TokensList,
234
263
  );
235
264
 
236
265
  if (!content) {
@@ -1,9 +1,10 @@
1
1
  // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/members.hbs
2
2
 
3
- import React from 'react';
3
+ import { Fragment } from 'react';
4
4
  import type { JSONOutput } from 'typedoc';
5
- import { useReflection } from '../hooks/useReflection';
5
+ import { useRequiredReflection } from '../hooks/useReflection';
6
6
  import { useReflectionMap } from '../hooks/useReflectionMap';
7
+ import { escapeMdx } from '../utils/helpers';
7
8
  import { hasOwnDocument } from '../utils/visibility';
8
9
  import { AnchorLink } from './AnchorLink';
9
10
  import { CommentBadges, isCommentWithModifiers } from './CommentBadges';
@@ -20,7 +21,7 @@ export interface MemberProps {
20
21
 
21
22
  export function Member({ id }: MemberProps) {
22
23
  const reflections = useReflectionMap();
23
- const reflection = useReflection(id)!;
24
+ const reflection = useRequiredReflection(id);
24
25
  const { comment } = reflection;
25
26
  let content: React.ReactNode = null;
26
27
 
@@ -46,18 +47,18 @@ export function Member({ id }: MemberProps) {
46
47
  <AnchorLink id={reflection.name} />
47
48
  <SourceLink sources={reflection.sources} />
48
49
  <Flags flags={reflection.flags} />
49
- {reflection.name}
50
+ {escapeMdx(reflection.name)}
50
51
  {isCommentWithModifiers(comment) && <CommentBadges comment={comment} />}
51
52
  </h3>
52
53
 
53
54
  {content}
54
55
 
55
56
  {reflection.groups?.map((group) => (
56
- <React.Fragment key={group.title}>
57
+ <Fragment key={group.title}>
57
58
  {group.children?.map((child) =>
58
59
  hasOwnDocument(child, reflections) ? null : <Member key={child} id={child} />,
59
60
  )}
60
- </React.Fragment>
61
+ </Fragment>
61
62
  ))}
62
63
  </section>
63
64
  );
@@ -1,14 +1,14 @@
1
1
  // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/member.declaration.hbs
2
2
 
3
- import React from 'react';
4
3
  import { useMinimalLayout } from '../hooks/useMinimalLayout';
5
- import { useReflection } from '../hooks/useReflection';
4
+ import { useRequiredReflection } from '../hooks/useReflection';
5
+ import { escapeMdx } from '../utils/helpers';
6
6
  import { Comment, hasComment } from './Comment';
7
7
  import { DefaultValue } from './DefaultValue';
8
8
  import { Icon } from './Icon';
9
9
  import { MemberSources } from './MemberSources';
10
10
  import { Parameter } from './Parameter';
11
- import { Type } from './Type';
11
+ import { extractDeclarationFromType, Type } from './Type';
12
12
  import { TypeParameters } from './TypeParameters';
13
13
  import { TypeParametersGeneric } from './TypeParametersGeneric';
14
14
 
@@ -17,17 +17,17 @@ export interface MemberDeclarationProps {
17
17
  }
18
18
 
19
19
  export function MemberDeclaration({ id }: MemberDeclarationProps) {
20
- const reflection = useReflection(id)!;
20
+ const reflection = useRequiredReflection(id);
21
21
  const minimal = useMinimalLayout();
22
22
  const showTypes = reflection.typeParameters && reflection.typeParameters.length > 0;
23
- const showDeclaration = !minimal && reflection.type?.declaration;
23
+ const showDeclaration = !minimal && extractDeclarationFromType(reflection.type);
24
24
 
25
25
  return (
26
26
  <>
27
27
  <div className="tsd-panel-content">
28
28
  <div className="tsd-signature tsd-kind-icon">
29
29
  <Icon reflection={reflection} />
30
- {reflection.name}
30
+ {escapeMdx(reflection.name)}
31
31
  <TypeParametersGeneric params={reflection.typeParameters} />
32
32
  <span className="tsd-signature-symbol">{reflection.flags?.isOptional && '?'}: </span>{' '}
33
33
  <Type type={reflection.type} />
@@ -58,7 +58,7 @@ export function MemberDeclaration({ id }: MemberDeclarationProps) {
58
58
  {showDeclaration && (
59
59
  <div className="tsd-type-declaration">
60
60
  <h4>Type declaration</h4>
61
- <Parameter param={reflection.type?.declaration} />
61
+ <Parameter param={extractDeclarationFromType(reflection.type)} />
62
62
  </div>
63
63
  )}
64
64
  </div>
@@ -1,16 +1,16 @@
1
1
  // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/member.getterSetter.hbs
2
2
 
3
- import React from 'react';
4
- import type { JSONOutput } from 'typedoc';
5
3
  import { useMinimalLayout } from '../hooks/useMinimalLayout';
4
+ import type { TSDDeclarationReflection } from '../types';
5
+ import { escapeMdx } from '../utils/helpers';
6
6
  import { Icon } from './Icon';
7
7
  import { hasSigBody, MemberSignatureBody } from './MemberSignatureBody';
8
8
  import { MemberSignatureTitle } from './MemberSignatureTitle';
9
9
 
10
10
  export interface MemberGetterSetterProps {
11
11
  inPanel?: boolean;
12
- getter?: JSONOutput.DeclarationReflection['getSignature'];
13
- setter?: JSONOutput.DeclarationReflection['setSignature'];
12
+ getter?: TSDDeclarationReflection['getSignature'];
13
+ setter?: TSDDeclarationReflection['setSignature'];
14
14
  }
15
15
 
16
16
  // eslint-disable-next-line complexity
@@ -30,7 +30,7 @@ export function MemberGetterSetter({ inPanel, getter, setter }: MemberGetterSett
30
30
  <li className="tsd-signature tsd-kind-icon">
31
31
  <Icon reflection={getter} />
32
32
  <span className="tsd-signature-symbol">get </span>
33
- {getter.name}
33
+ {escapeMdx(getter.name)}
34
34
  <MemberSignatureTitle hideName sig={getter} />
35
35
  </li>
36
36
  )}
@@ -39,7 +39,7 @@ export function MemberGetterSetter({ inPanel, getter, setter }: MemberGetterSett
39
39
  <li className="tsd-signature tsd-kind-icon">
40
40
  <Icon reflection={setter} />
41
41
  <span className="tsd-signature-symbol">set </span>
42
- {setter.name}
42
+ {escapeMdx(setter.name)}
43
43
  <MemberSignatureTitle hideName sig={setter} />
44
44
  </li>
45
45
  )}