@apify/docusaurus-plugin-typedoc-api 4.2.4 → 4.2.6

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 (43) hide show
  1. package/assets/styles-8ad572ec.css +44 -0
  2. package/lib/components/ApiItem.js +53 -29
  3. package/lib/components/ApiItem.js.map +1 -1
  4. package/lib/components/ApiItemLayout.js +15 -8
  5. package/lib/components/ApiItemLayout.js.map +1 -1
  6. package/lib/components/ApiOptionsLayout.js +35 -0
  7. package/lib/components/ApiOptionsLayout.js.map +1 -0
  8. package/lib/components/Comment.js +3 -0
  9. package/lib/components/Comment.js.map +1 -1
  10. package/lib/components/Member.js +4 -1
  11. package/lib/components/Member.js.map +1 -1
  12. package/lib/components/MemberSignatureBody.js +57 -16
  13. package/lib/components/MemberSignatureBody.js.map +1 -1
  14. package/lib/components/MemberSignatureTitle.js +11 -1
  15. package/lib/components/MemberSignatureTitle.js.map +1 -1
  16. package/lib/components/Type.js +3 -1
  17. package/lib/components/Type.js.map +1 -1
  18. package/lib/index.js +4 -14
  19. package/lib/index.js.map +1 -1
  20. package/lib/plugin/data.js +38 -1
  21. package/lib/plugin/data.js.map +1 -1
  22. package/package.json +2 -1
  23. package/src/components/ApiItem.tsx +48 -32
  24. package/src/components/ApiItemLayout.tsx +11 -6
  25. package/src/components/ApiOptionsLayout.tsx +22 -0
  26. package/src/components/Comment.tsx +3 -0
  27. package/src/components/Member.tsx +6 -2
  28. package/src/components/MemberSignatureBody.tsx +67 -16
  29. package/src/components/MemberSignatureTitle.tsx +14 -1
  30. package/src/components/Type.tsx +3 -1
  31. package/src/components/styles.css +44 -0
  32. package/src/index.ts +11 -19
  33. package/src/plugin/data.ts +37 -2
  34. package/src/types.ts +5 -1
  35. package/lib/plugin/python-generator/index.js +0 -23
  36. package/lib/plugin/python-generator/index.js.map +0 -1
  37. package/lib/plugin/python-generator/pydoc-markdown.js +0 -72
  38. package/lib/plugin/python-generator/pydoc-markdown.js.map +0 -1
  39. package/lib/plugin/python-generator/transform-docs.js +0 -393
  40. package/lib/plugin/python-generator/transform-docs.js.map +0 -1
  41. package/src/plugin/python-generator/index.ts +0 -18
  42. package/src/plugin/python-generator/pydoc-markdown.ts +0 -70
  43. package/src/plugin/python-generator/transform-docs.ts +0 -417
@@ -6,6 +6,50 @@
6
6
  --tsd-spacing-horizontal: 1rem;
7
7
  }
8
8
 
9
+ .tsd-api-options {
10
+ border-left: 1px solid var(--ifm-toc-border-color);
11
+ font-size: var(--tsd-font-small);
12
+ padding-left: var(--ifm-toc-padding-horizontal);
13
+ }
14
+ .tsd-api-options > div:first-child {
15
+ margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
16
+ }
17
+ .tsd-api-options > label {
18
+ margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
19
+ }
20
+ .tsd-api-options > label > input {
21
+ margin: 0 5px 0 0;
22
+ vertical-align: middle;
23
+ }
24
+ .tsd-api-options > label > span {
25
+ vertical-align: middle;
26
+ }
27
+ .tsd-api-options > div:last-child {
28
+ border-bottom: 1px solid var(--ifm-toc-border-color);
29
+ margin-top: 1rem;
30
+ }
31
+
32
+ .tsd-api-options-mobile {
33
+ font-size: var(--tsd-font-small);
34
+ }
35
+ .tsd-api-options-mobile > div:first-child {
36
+ margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
37
+ }
38
+ .tsd-api-options-mobile > label {
39
+ margin: var(--ifm-toc-padding-vertical) var(--ifm-toc-padding-horizontal);
40
+ }
41
+ .tsd-api-options-mobile > label > input {
42
+ margin: 0 5px 0 0;
43
+ vertical-align: middle;
44
+ }
45
+ .tsd-api-options-mobile > label > span {
46
+ vertical-align: middle;
47
+ }
48
+ .tsd-api-options-mobile > div:last-child {
49
+ border-bottom: 1px solid var(--ifm-toc-border-color);
50
+ margin-top: 1rem;
51
+ }
52
+
9
53
  .tsd-panel {
10
54
  border: 1px solid var(--ifm-card-background-color);
11
55
  border-radius: var(--ifm-global-radius);
package/src/index.ts CHANGED
@@ -13,12 +13,12 @@ import {
13
13
  generateJson,
14
14
  loadPackageJsonAndDocs,
15
15
  } from './plugin/data';
16
- import { generateJsonFromPythonProject } from './plugin/python-generator';
17
16
  import { extractSidebar } from './plugin/sidebar';
18
17
  import { getVersionedDocsDirPath, readVersionsMetadata } from './plugin/version';
19
18
  import type {
20
19
  ApiOptions,
21
20
  DocusaurusPluginTypeDocApiOptions,
21
+ GlobalData,
22
22
  LoadedContent,
23
23
  PackageEntryConfig,
24
24
  PackageReflectionGroup,
@@ -149,19 +149,12 @@ export default function typedocApiPlugin(
149
149
 
150
150
  console.log(`[${prefix}]:`, 'Generating docs...');
151
151
 
152
- if (options.python) {
153
- await generateJsonFromPythonProject({
154
- projectRoot,
155
- outFile: path.join(outDir, 'api-typedoc.json'),
156
- });
157
- } else {
158
- await generateJson(
159
- projectRoot,
160
- entryPoints,
161
- path.join(outDir, 'api-typedoc.json'),
162
- options,
163
- );
164
- }
152
+ await generateJson(
153
+ projectRoot,
154
+ entryPoints,
155
+ path.join(outDir, 'api-typedoc.json'),
156
+ options,
157
+ );
165
158
 
166
159
  console.log(`[${prefix}]:`, 'Persisting packages...');
167
160
 
@@ -207,11 +200,6 @@ export default function typedocApiPlugin(
207
200
  fs.mkdirSync(context.generatedFilesDir, { recursive: true });
208
201
  }
209
202
  fs.copyFileSync(options.pathToCurrentVersionTypedocJSON, outFile);
210
- } else if (options.python) {
211
- await generateJsonFromPythonProject({
212
- projectRoot,
213
- outFile,
214
- });
215
203
  } else {
216
204
  await generateJson(projectRoot, entryPoints, outFile, options);
217
205
  }
@@ -277,6 +265,10 @@ export default function typedocApiPlugin(
277
265
  return;
278
266
  }
279
267
 
268
+ actions.setGlobalData({
269
+ isPython: !!options.python,
270
+ } as GlobalData);
271
+
280
272
  const docs: PropVersionDocs = {};
281
273
 
282
274
  // Create an index of versions for quick lookups.
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import * as TypeDoc from 'typedoc';
4
- import { JSONOutput, ReflectionKind } from 'typedoc';
4
+ import { type InlineTagDisplayPart, type JSONOutput, ReflectionKind } from 'typedoc'
5
5
  import ts from 'typescript';
6
6
  import { normalizeUrl } from '@docusaurus/utils';
7
7
  import type {
@@ -110,7 +110,42 @@ export function createReflectionMap(
110
110
  ): TSDDeclarationReflectionMap {
111
111
  const map: TSDDeclarationReflectionMap = {};
112
112
 
113
+ // eslint-disable-next-line complexity
113
114
  items.forEach((item) => {
115
+ // Add @reference categories to reflection.
116
+ const referenceCategories: Record<string, { title: string; children: number[] }> = {};
117
+ for (const tag of item.comment?.blockTags ?? []) {
118
+ if (tag.tag === '@reference' && tag.content.length >= 2 && tag.content[0].kind === 'text') {
119
+ const categoryName = tag.content[0].text.trim();
120
+ const ref = (tag.content as InlineTagDisplayPart[]).find((t) => t.tag === '@link');
121
+
122
+ if (ref && typeof ref.target === 'number') {
123
+ if (!(categoryName in referenceCategories)) {
124
+ referenceCategories[categoryName] = { title: categoryName, children: [] };
125
+ }
126
+
127
+ if (!referenceCategories[categoryName].children.includes(ref.target)) {
128
+ referenceCategories[categoryName].children.push(ref.target);
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ // Update categories with reference categories.
135
+ if (!item.categories) {
136
+ // eslint-disable-next-line no-param-reassign
137
+ item.categories = [];
138
+ }
139
+ for (const category of Object.values(referenceCategories)) {
140
+ if (category.children.length > 0) {
141
+ const index = item.categories.findIndex((c) => c.title === category.title);
142
+ if (index === -1) {
143
+ item.categories.push(category);
144
+ }
145
+ }
146
+ }
147
+
148
+ // Add item.
114
149
  map[item.id] = item;
115
150
  });
116
151
 
@@ -286,7 +321,7 @@ function modContainsEntryPoint(
286
321
  // They also don't use full paths like "package/src/index.ts" and simply use "index.ts",
287
322
  // so account for those entry points also.
288
323
  if (!relModSourceFile) {
289
- const absEntryPoint = path.normalize(path.join(meta.packageRoot, entry.path));
324
+ const absEntryPoint = path.normalize(path.join(meta.packageRoot ?? '', entry.path ?? ''));
290
325
  const relEntryPointName = path.basename(relEntryPoint);
291
326
  const entryPointInSourceFiles =
292
327
  !!meta.allSourceFiles[absEntryPoint] ||
package/src/types.ts CHANGED
@@ -32,7 +32,7 @@ export interface DocusaurusPluginTypeDocApiOptions
32
32
  typedocOptions?: Partial<TypeDocOptions>;
33
33
 
34
34
  /**
35
- * Switches the processing mode to Python-specific pipeline.
35
+ * Enables the Python-specific rendering patches.
36
36
  */
37
37
  python: boolean;
38
38
 
@@ -45,6 +45,10 @@ export interface DocusaurusPluginTypeDocApiOptions
45
45
  routeBasePath?: string;
46
46
  }
47
47
 
48
+ export interface GlobalData {
49
+ isPython: boolean;
50
+ }
51
+
48
52
  // CONFIG
49
53
 
50
54
  export interface PackageEntryConfig {
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const zx = require('zx');
4
- const pydocMarkdown = require('./pydoc-markdown.js');
5
- const transformDocs = require('./transform-docs.js');
6
- async function generateJsonFromPythonProject({
7
- outFile,
8
- projectRoot
9
- }) {
10
- const pydocJson = await pydocMarkdown.parseWithPydocMarkdown({
11
- projectRoot
12
- });
13
- await zx.spinner('Converting the Python JSON AST to a TypeDoc-compliant file...', async () => {
14
- await transformDocs.pydocToTypedoc({
15
- moduleName: 'python',
16
- // TODO: get from project config files or passed options
17
- outFile,
18
- pydocJson
19
- });
20
- });
21
- }
22
- exports.generateJsonFromPythonProject = generateJsonFromPythonProject;
23
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/plugin/python-generator/index.ts"],"sourcesContent":null,"names":["parseWithPydocMarkdown","spinner","pydocToTypedoc"],"mappings":";;;;;;AAGO,eAAe,6BAA6B,CAAC;AACpD,EAAE,OAAO;AACT,EAAE,WAAW;AACb,CAAC,EAAE;AACH,EAAE,MAAM,SAAS,GAAG,MAAMA,oCAAsB,CAAC;AACjD,IAAI,WAAW;AACf,GAAG,CAAC,CAAC;AACL,EAAE,MAAMC,UAAO,CAAC,+DAA+D,EAAE,YAAY;AAC7F,IAAI,MAAMC,4BAAc,CAAC;AACzB,MAAM,UAAU,EAAE,QAAQ;AAC1B;AACA,MAAM,OAAO;AACb,MAAM,SAAS;AACf,KAAK,CAAC,CAAC;AACP,GAAG,CAAC,CAAC;AACL;;;;"}
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('node:fs');
4
- const path = require('node:path');
5
- const zx = require('zx');
6
- const _interopDefault = e => e && e.__esModule ? e : {
7
- default: e
8
- };
9
- const path__default = /*#__PURE__*/_interopDefault(path);
10
-
11
- /**
12
- * Generates the pydoc-markdown configuration file
13
- * @returns The pydoc-markdown configuration file as a string
14
- */
15
- function getConfigYml({
16
- projectRoot
17
- }) {
18
- return `
19
- loaders:
20
- - type: python
21
- search_path: ["${projectRoot}"]
22
- processors:
23
- - type: filter
24
- skip_empty_modules: true
25
- - type: crossref
26
- renderer:
27
- type: docusaurus
28
- docs_base_path: docs
29
- relative_output_path: reference
30
- relative_sidebar_path: sidebar.json
31
- sidebar_top_level_label: null
32
- `;
33
- }
34
- async function parseWithPydocMarkdown({
35
- projectRoot
36
- }) {
37
- // Check whether the user has Python and pydoc-markdown installed
38
- for (const cmd of ['python', 'pydoc-markdown']) {
39
- try {
40
- // eslint-disable-next-line no-await-in-loop
41
- await zx.spinner(`Checking for ${cmd}...`, () => zx.$`${cmd} --version`);
42
- } catch {
43
- throw new Error(`Please install ${cmd} to use this plugin with Python projects.`);
44
- }
45
- }
46
- ;
47
-
48
- // Generate the JSON file
49
- try {
50
- const configYml = getConfigYml({
51
- projectRoot
52
- });
53
- const configPath = path__default.default.join(__dirname, 'pydoc-markdown.temp.yml');
54
- fs.writeFileSync(configPath, configYml);
55
- let pydoc = null;
56
- await zx.spinner('Parsing the Python project into a JSON AST...', async () => {
57
- pydoc = await zx.$`pydoc-markdown --quiet --dump ${configPath}`;
58
- });
59
- fs.rmSync(configPath);
60
-
61
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
62
- let json = await pydoc.text();
63
- json = json.replaceAll(path__default.default.resolve(projectRoot), 'REPO_ROOT_PLACEHOLDER');
64
- return json;
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- } catch (error) {
67
- // eslint-disable-next-line
68
- throw new Error(`Failed to generate JSON file from Python project:\n\t${error.stderr.split('\n').slice(-2).join('\n')}`);
69
- }
70
- }
71
- exports.parseWithPydocMarkdown = parseWithPydocMarkdown;
72
- //# sourceMappingURL=pydoc-markdown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pydoc-markdown.js","sources":["../../../src/plugin/python-generator/pydoc-markdown.ts"],"sourcesContent":null,"names":["spinner","$","path","writeFileSync","rmSync"],"mappings":";;;;;;;;;;AAIA;AACA;AACA;AACA;AACA,SAAS,YAAY,CAAC;AACtB,EAAE,WAAW;AACb,CAAC,EAAE;AACH,EAAE,OAAO,CAAC;AACV;AACA;AACA,mBAAmB,EAAE,WAAW,CAAC;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,CAAC;AACF,CAAC;AACM,eAAe,sBAAsB,CAAC;AAC7C,EAAE,WAAW;AACb,CAAC,EAAE;AACH;AACA,EAAE,KAAK,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,EAAE;AAClD,IAAI,IAAI;AACR;AACA,MAAM,MAAMA,UAAO,CAAC,CAAC,aAAa,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,MAAMC,IAAC,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACzE,KAAK,CAAC,MAAM;AACZ,MAAM,MAAM,IAAI,KAAK,CAAC,CAAC,eAAe,EAAE,GAAG,CAAC,yCAAyC,CAAC,CAAC,CAAC;AACxF,KAAK;AACL,GAAG;AACH,EAAE,CAAC;AACH;AACA;AACA,EAAE,IAAI;AACN,IAAI,MAAM,SAAS,GAAG,YAAY,CAAC;AACnC,MAAM,WAAW;AACjB,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,UAAU,GAAGC,qBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;AACvE,IAAIC,gBAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACzC,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC;AACrB,IAAI,MAAMH,UAAO,CAAC,+CAA+C,EAAE,YAAY;AAC/E,MAAM,KAAK,GAAG,MAAMC,IAAC,CAAC,8BAA8B,EAAE,UAAU,CAAC,CAAC,CAAC;AACnE,KAAK,CAAC,CAAC;AACP,IAAIG,SAAM,CAAC,UAAU,CAAC,CAAC;AACvB;AACA;AACA,IAAI,IAAI,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;AAClC,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,CAACF,qBAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC,CAAC;AAC/E,IAAI,OAAO,IAAI,CAAC;AAChB;AACA,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB;AACA,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,qDAAqD,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7H,GAAG;AACH;;;;"}