@depup/nextra 4.6.1-depup.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.
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/changes.json +110 -0
- package/dist/client/components/banner/close-banner-button.d.ts +8 -0
- package/dist/client/components/banner/close-banner-button.js +45 -0
- package/dist/client/components/banner/index.client.d.ts +5 -0
- package/dist/client/components/banner/index.client.js +46 -0
- package/dist/client/components/banner/index.d.ts +51 -0
- package/dist/client/components/banner/index.js +93 -0
- package/dist/client/components/bleed.d.ts +63 -0
- package/dist/client/components/bleed.js +54 -0
- package/dist/client/components/button.d.ts +9 -0
- package/dist/client/components/button.js +55 -0
- package/dist/client/components/callout.d.ts +136 -0
- package/dist/client/components/callout.js +99 -0
- package/dist/client/components/cards.d.ts +104 -0
- package/dist/client/components/cards.js +132 -0
- package/dist/client/components/collapse.d.ts +12 -0
- package/dist/client/components/collapse.js +143 -0
- package/dist/client/components/file-tree/file.d.ts +9 -0
- package/dist/client/components/file-tree/file.js +43 -0
- package/dist/client/components/file-tree/folder.d.ts +12 -0
- package/dist/client/components/file-tree/folder.js +94 -0
- package/dist/client/components/file-tree/index.d.ts +57 -0
- package/dist/client/components/file-tree/index.js +12 -0
- package/dist/client/components/file-tree/tree.d.ts +5 -0
- package/dist/client/components/file-tree/tree.js +41 -0
- package/dist/client/components/head.d.ts +139 -0
- package/dist/client/components/head.js +202 -0
- package/dist/client/components/image-zoom.d.ts +6 -0
- package/dist/client/components/image-zoom.js +79 -0
- package/dist/client/components/index.d.ts +56 -0
- package/dist/client/components/index.js +42 -0
- package/dist/client/components/playground.d.ts +90 -0
- package/dist/client/components/playground.js +103 -0
- package/dist/client/components/popup/index.client.d.ts +7 -0
- package/dist/client/components/popup/index.client.js +83 -0
- package/dist/client/components/popup/index.d.ts +12 -0
- package/dist/client/components/popup/index.js +11 -0
- package/dist/client/components/search.d.ts +88 -0
- package/dist/client/components/search.js +426 -0
- package/dist/client/components/select.d.ts +19 -0
- package/dist/client/components/select.js +109 -0
- package/dist/client/components/skip-nav/index.client.d.ts +5 -0
- package/dist/client/components/skip-nav/index.client.js +45 -0
- package/dist/client/components/skip-nav/index.d.ts +6 -0
- package/dist/client/components/skip-nav/index.js +24 -0
- package/dist/client/components/steps.d.ts +64 -0
- package/dist/client/components/steps.js +74 -0
- package/dist/client/components/tabs/index.client.d.ts +21 -0
- package/dist/client/components/tabs/index.client.js +243 -0
- package/dist/client/components/tabs/index.d.ts +53 -0
- package/dist/client/components/tabs/index.js +9 -0
- package/dist/client/evaluate.d.ts +30 -0
- package/dist/client/evaluate.js +17 -0
- package/dist/client/hocs/index.d.ts +4 -0
- package/dist/client/hocs/index.js +6 -0
- package/dist/client/hocs/with-github-alert.d.ts +11 -0
- package/dist/client/hocs/with-github-alert.js +30 -0
- package/dist/client/hocs/with-icons.d.ts +6 -0
- package/dist/client/hocs/with-icons.js +76 -0
- package/dist/client/hooks/index.d.ts +4 -0
- package/dist/client/hooks/index.js +10 -0
- package/dist/client/hooks/use-copy.d.ts +9 -0
- package/dist/client/hooks/use-copy.js +77 -0
- package/dist/client/hooks/use-fs-route.d.ts +3 -0
- package/dist/client/hooks/use-fs-route.js +20 -0
- package/dist/client/hooks/use-hash.d.ts +3 -0
- package/dist/client/hooks/use-hash.js +20 -0
- package/dist/client/hooks/use-mounted.d.ts +3 -0
- package/dist/client/hooks/use-mounted.js +13 -0
- package/dist/client/icons/arrow-right.d.ts +5 -0
- package/dist/client/icons/arrow-right.js +24 -0
- package/dist/client/icons/chatgpt.d.ts +2 -0
- package/dist/client/icons/chatgpt.js +24 -0
- package/dist/client/icons/check.d.ts +2 -0
- package/dist/client/icons/check.js +24 -0
- package/dist/client/icons/claude.d.ts +2 -0
- package/dist/client/icons/claude.js +81 -0
- package/dist/client/icons/copy.d.ts +2 -0
- package/dist/client/icons/copy.js +31 -0
- package/dist/client/icons/cpp.d.ts +2 -0
- package/dist/client/icons/cpp.js +24 -0
- package/dist/client/icons/cross-circled.d.ts +2 -0
- package/dist/client/icons/cross-circled.js +24 -0
- package/dist/client/icons/csharp.d.ts +2 -0
- package/dist/client/icons/csharp.js +24 -0
- package/dist/client/icons/css.d.ts +2 -0
- package/dist/client/icons/css.js +24 -0
- package/dist/client/icons/discord.d.ts +2 -0
- package/dist/client/icons/discord.js +24 -0
- package/dist/client/icons/expand.d.ts +2 -0
- package/dist/client/icons/expand.js +31 -0
- package/dist/client/icons/file.d.ts +2 -0
- package/dist/client/icons/file.js +24 -0
- package/dist/client/icons/folder-open.d.ts +2 -0
- package/dist/client/icons/folder-open.js +24 -0
- package/dist/client/icons/folder.d.ts +2 -0
- package/dist/client/icons/folder.js +24 -0
- package/dist/client/icons/github-caution.d.ts +2 -0
- package/dist/client/icons/github-caution.js +24 -0
- package/dist/client/icons/github-important.d.ts +2 -0
- package/dist/client/icons/github-important.js +24 -0
- package/dist/client/icons/github-note.d.ts +2 -0
- package/dist/client/icons/github-note.js +24 -0
- package/dist/client/icons/github-tip.d.ts +2 -0
- package/dist/client/icons/github-tip.js +24 -0
- package/dist/client/icons/github-warning.d.ts +2 -0
- package/dist/client/icons/github-warning.js +24 -0
- package/dist/client/icons/github.d.ts +2 -0
- package/dist/client/icons/github.js +24 -0
- package/dist/client/icons/globe.d.ts +2 -0
- package/dist/client/icons/globe.js +24 -0
- package/dist/client/icons/go.d.ts +2 -0
- package/dist/client/icons/go.js +46 -0
- package/dist/client/icons/graphql.d.ts +2 -0
- package/dist/client/icons/graphql.js +56 -0
- package/dist/client/icons/index.d.ts +2 -0
- package/dist/client/icons/index.js +92 -0
- package/dist/client/icons/javascript.d.ts +2 -0
- package/dist/client/icons/javascript.js +24 -0
- package/dist/client/icons/json.d.ts +2 -0
- package/dist/client/icons/json.js +41 -0
- package/dist/client/icons/link-arrow.d.ts +2 -0
- package/dist/client/icons/link-arrow.js +31 -0
- package/dist/client/icons/link.d.ts +2 -0
- package/dist/client/icons/link.js +24 -0
- package/dist/client/icons/markdown.d.ts +2 -0
- package/dist/client/icons/markdown.js +24 -0
- package/dist/client/icons/mdx.d.ts +2 -0
- package/dist/client/icons/mdx.js +24 -0
- package/dist/client/icons/menu.d.ts +2 -0
- package/dist/client/icons/menu.js +36 -0
- package/dist/client/icons/moon.d.ts +2 -0
- package/dist/client/icons/moon.js +24 -0
- package/dist/client/icons/move.d.ts +2 -0
- package/dist/client/icons/move.js +24 -0
- package/dist/client/icons/python.d.ts +2 -0
- package/dist/client/icons/python.js +31 -0
- package/dist/client/icons/react.d.ts +2 -0
- package/dist/client/icons/react.js +38 -0
- package/dist/client/icons/rust.d.ts +2 -0
- package/dist/client/icons/rust.js +31 -0
- package/dist/client/icons/spinner.d.ts +2 -0
- package/dist/client/icons/spinner.js +31 -0
- package/dist/client/icons/sun.d.ts +2 -0
- package/dist/client/icons/sun.js +24 -0
- package/dist/client/icons/svelte.d.ts +2 -0
- package/dist/client/icons/svelte.js +31 -0
- package/dist/client/icons/terminal.d.ts +2 -0
- package/dist/client/icons/terminal.js +24 -0
- package/dist/client/icons/terraform.d.ts +2 -0
- package/dist/client/icons/terraform.js +24 -0
- package/dist/client/icons/typescript.d.ts +2 -0
- package/dist/client/icons/typescript.js +24 -0
- package/dist/client/icons/word-wrap.d.ts +2 -0
- package/dist/client/icons/word-wrap.js +24 -0
- package/dist/client/icons/x.d.ts +2 -0
- package/dist/client/icons/x.js +24 -0
- package/dist/client/mdx-components/anchor.d.ts +10 -0
- package/dist/client/mdx-components/anchor.js +109 -0
- package/dist/client/mdx-components/code.d.ts +7 -0
- package/dist/client/mdx-components/code.js +52 -0
- package/dist/client/mdx-components/details.d.ts +5 -0
- package/dist/client/mdx-components/details.js +166 -0
- package/dist/client/mdx-components/image.d.ts +28 -0
- package/dist/client/mdx-components/image.js +39 -0
- package/dist/client/mdx-components/index.d.ts +11 -0
- package/dist/client/mdx-components/index.js +16 -0
- package/dist/client/mdx-components/pre/copy-to-clipboard.d.ts +5 -0
- package/dist/client/mdx-components/pre/copy-to-clipboard.js +49 -0
- package/dist/client/mdx-components/pre/index.d.ts +16 -0
- package/dist/client/mdx-components/pre/index.js +156 -0
- package/dist/client/mdx-components/pre/toggle-word-wrap-button.d.ts +7 -0
- package/dist/client/mdx-components/pre/toggle-word-wrap-button.js +31 -0
- package/dist/client/mdx-components/summary.d.ts +5 -0
- package/dist/client/mdx-components/summary.js +80 -0
- package/dist/client/mdx-components/table.d.ts +57 -0
- package/dist/client/mdx-components/table.js +95 -0
- package/dist/client/mdx-components.d.ts +89 -0
- package/dist/client/mdx-components.js +15 -0
- package/dist/client/mdx-remote.d.ts +62 -0
- package/dist/client/mdx-remote.js +36 -0
- package/dist/client/normalize-pages.d.ts +84 -0
- package/dist/client/normalize-pages.js +232 -0
- package/dist/client/package.json +1 -0
- package/dist/client/pages.d.ts +131 -0
- package/dist/client/pages.js +39 -0
- package/dist/client/remove-links.d.ts +6 -0
- package/dist/client/remove-links.js +35 -0
- package/dist/client/setup-page.d.ts +18 -0
- package/dist/client/setup-page.js +14 -0
- package/dist/server/compile-metadata.d.ts +12 -0
- package/dist/server/compile-metadata.js +39 -0
- package/dist/server/compile.d.ts +39 -0
- package/dist/server/compile.js +158 -0
- package/dist/server/constants.d.ts +15 -0
- package/dist/server/constants.js +22 -0
- package/dist/server/fetch-filepaths-from-github.d.ts +10 -0
- package/dist/server/fetch-filepaths-from-github.js +36 -0
- package/dist/server/index.d.ts +39 -0
- package/dist/server/index.js +203 -0
- package/dist/server/loader.d.ts +18 -0
- package/dist/server/loader.js +155 -0
- package/dist/server/locales.d.ts +22 -0
- package/dist/server/locales.js +38 -0
- package/dist/server/page-map/find-meta-and-page-file-paths.d.ts +8 -0
- package/dist/server/page-map/find-meta-and-page-file-paths.js +32 -0
- package/dist/server/page-map/get.d.ts +50 -0
- package/dist/server/page-map/get.js +28 -0
- package/dist/server/page-map/index-page.d.ts +21 -0
- package/dist/server/page-map/index-page.js +57 -0
- package/dist/server/page-map/index.d.ts +26 -0
- package/dist/server/page-map/index.js +24 -0
- package/dist/server/page-map/merge-meta-with-page-map.d.ts +17 -0
- package/dist/server/page-map/merge-meta-with-page-map.js +74 -0
- package/dist/server/page-map/normalize.d.ts +17 -0
- package/dist/server/page-map/normalize.js +122 -0
- package/dist/server/page-map/placeholder.d.ts +2 -0
- package/dist/server/page-map/placeholder.js +0 -0
- package/dist/server/page-map/to-ast.d.ts +18 -0
- package/dist/server/page-map/to-ast.js +47 -0
- package/dist/server/page-map/to-js.d.ts +21 -0
- package/dist/server/page-map/to-js.js +72 -0
- package/dist/server/page-map/to-page-map.d.ts +26 -0
- package/dist/server/page-map/to-page-map.js +101 -0
- package/dist/server/recma-plugins/index.d.ts +3 -0
- package/dist/server/recma-plugins/index.js +4 -0
- package/dist/server/recma-plugins/recma-rewrite.d.ts +11 -0
- package/dist/server/recma-plugins/recma-rewrite.js +98 -0
- package/dist/server/rehype-plugins/index.d.ts +18 -0
- package/dist/server/rehype-plugins/index.js +16 -0
- package/dist/server/rehype-plugins/rehype-better-react-mathjax.d.ts +24 -0
- package/dist/server/rehype-plugins/rehype-better-react-mathjax.js +96 -0
- package/dist/server/rehype-plugins/rehype-extract-toc-content.d.ts +6 -0
- package/dist/server/rehype-plugins/rehype-extract-toc-content.js +119 -0
- package/dist/server/rehype-plugins/rehype-twoslash-popup.d.ts +6 -0
- package/dist/server/rehype-plugins/rehype-twoslash-popup.js +50 -0
- package/dist/server/rehype-plugins/rehype.d.ts +21 -0
- package/dist/server/rehype-plugins/rehype.js +84 -0
- package/dist/server/remark-plugins/index.d.ts +15 -0
- package/dist/server/remark-plugins/index.js +26 -0
- package/dist/server/remark-plugins/remark-assign-frontmatter.d.ts +10 -0
- package/dist/server/remark-plugins/remark-assign-frontmatter.js +24 -0
- package/dist/server/remark-plugins/remark-custom-heading-id.d.ts +9 -0
- package/dist/server/remark-plugins/remark-custom-heading-id.js +18 -0
- package/dist/server/remark-plugins/remark-export-only-metadata.d.ts +6 -0
- package/dist/server/remark-plugins/remark-export-only-metadata.js +18 -0
- package/dist/server/remark-plugins/remark-export-source-code.d.ts +6 -0
- package/dist/server/remark-plugins/remark-export-source-code.js +35 -0
- package/dist/server/remark-plugins/remark-headings.d.ts +12 -0
- package/dist/server/remark-plugins/remark-headings.js +133 -0
- package/dist/server/remark-plugins/remark-link-rewrite.d.ts +11 -0
- package/dist/server/remark-plugins/remark-link-rewrite.js +12 -0
- package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.d.ts +10 -0
- package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.js +10 -0
- package/dist/server/remark-plugins/remark-mdx-frontmatter.d.ts +6 -0
- package/dist/server/remark-plugins/remark-mdx-frontmatter.js +37 -0
- package/dist/server/remark-plugins/remark-mdx-title.d.ts +10 -0
- package/dist/server/remark-plugins/remark-mdx-title.js +53 -0
- package/dist/server/remark-plugins/remark-remove-imports.d.ts +6 -0
- package/dist/server/remark-plugins/remark-remove-imports.js +12 -0
- package/dist/server/remark-plugins/remark-static-image.d.ts +6 -0
- package/dist/server/remark-plugins/remark-static-image.js +107 -0
- package/dist/server/schemas.d.ts +352 -0
- package/dist/server/schemas.js +240 -0
- package/dist/server/tsdoc/base.d.ts +38 -0
- package/dist/server/tsdoc/base.js +284 -0
- package/dist/server/tsdoc/index.d.ts +6 -0
- package/dist/server/tsdoc/index.js +10 -0
- package/dist/server/tsdoc/tsdoc.d.ts +102 -0
- package/dist/server/tsdoc/tsdoc.js +262 -0
- package/dist/server/tsdoc/types.d.ts +64 -0
- package/dist/server/tsdoc/types.js +0 -0
- package/dist/server/tsdoc/zod-to-ts.d.ts +5 -0
- package/dist/server/tsdoc/zod-to-ts.js +107 -0
- package/dist/server/twoslash.d.ts +6 -0
- package/dist/server/twoslash.js +60 -0
- package/dist/server/utils.d.ts +12 -0
- package/dist/server/utils.js +45 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.generated.d.ts +203 -0
- package/dist/types.generated.js +0 -0
- package/dist/types.js +0 -0
- package/loader.cjs +24 -0
- package/package.json +265 -0
- package/styles/cards.css +24 -0
- package/styles/code-block.css +266 -0
- package/styles/default.css +55 -0
- package/styles/react-medium-image-zoom.css +101 -0
- package/styles/scrollbar.css +14 -0
- package/styles/steps.css +22 -0
- package/styles/subheading-anchor.css +25 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import slash from "slash";
|
|
3
|
+
import { Project, SyntaxKind, ts } from "ts-morph";
|
|
4
|
+
import { CWD } from "../constants.js";
|
|
5
|
+
import { logger } from "../utils.js";
|
|
6
|
+
const project = new Project({
|
|
7
|
+
tsConfigFilePath: "./tsconfig.json",
|
|
8
|
+
skipAddingFilesFromTsConfig: true,
|
|
9
|
+
compilerOptions: {
|
|
10
|
+
// Do not show `undefined` value in type for optional value
|
|
11
|
+
exactOptionalPropertyTypes: true,
|
|
12
|
+
// Show `null` value in type if exist
|
|
13
|
+
strictNullChecks: true
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const DEFAULT_FILENAME = "$.ts";
|
|
17
|
+
let compilerObject;
|
|
18
|
+
function generateDefinition({
|
|
19
|
+
code,
|
|
20
|
+
exportName = "default",
|
|
21
|
+
flattened = false
|
|
22
|
+
}) {
|
|
23
|
+
compilerObject ??= project.getTypeChecker().compilerObject;
|
|
24
|
+
const sourceFile = project.createSourceFile(DEFAULT_FILENAME, code, {
|
|
25
|
+
overwrite: true
|
|
26
|
+
});
|
|
27
|
+
const output = [];
|
|
28
|
+
for (const [key, declaration2] of sourceFile.getExportedDeclarations()) {
|
|
29
|
+
if (key === exportName) output.push(...declaration2);
|
|
30
|
+
}
|
|
31
|
+
const declaration = output[0];
|
|
32
|
+
if (!declaration) {
|
|
33
|
+
throw new Error(`Can't find "${exportName}" declaration`);
|
|
34
|
+
}
|
|
35
|
+
const declarationFilePath = declaration.getSourceFile().getFilePath();
|
|
36
|
+
const filePath = slash(path.relative(CWD, declarationFilePath));
|
|
37
|
+
const symbol = declaration.getSymbolOrThrow();
|
|
38
|
+
const { comment, tags } = getCommentAndTags(declaration);
|
|
39
|
+
const description = ts.displayPartsToString(comment);
|
|
40
|
+
tags.returns &&= replaceJsDocLinks(tags.returns);
|
|
41
|
+
const definition = {
|
|
42
|
+
// Skip adding `filePath` to snapshots on test env, since we have tests on Mac and on Windows, they fail
|
|
43
|
+
...// process.env.NODE_ENV !== 'test' &&
|
|
44
|
+
filePath !== DEFAULT_FILENAME && { filePath },
|
|
45
|
+
name: symbol.getName(),
|
|
46
|
+
...description && { description },
|
|
47
|
+
...Object.keys(tags).length && { tags }
|
|
48
|
+
};
|
|
49
|
+
const declarationType = declaration.getType();
|
|
50
|
+
const callSignatures = declarationType.getCallSignatures();
|
|
51
|
+
const isFunction = callSignatures.length > 0;
|
|
52
|
+
if (!isFunction) {
|
|
53
|
+
const entries = declarationType.getProperties().flatMap(
|
|
54
|
+
(prop) => getDocEntry({
|
|
55
|
+
symbol: prop,
|
|
56
|
+
declaration,
|
|
57
|
+
flattened
|
|
58
|
+
})
|
|
59
|
+
).filter((entry) => !entry.tags || !("internal" in entry.tags));
|
|
60
|
+
if (!entries.length) {
|
|
61
|
+
const typeName = declarationType.getText();
|
|
62
|
+
if (typeName === "any") {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Your type is resolved as "any", it seems like you have an issue in "generateDefinition.code" argument.'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
throw new Error(
|
|
68
|
+
`No properties found, check if your type "${typeName}" exist.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
...definition,
|
|
73
|
+
entries
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
...definition,
|
|
78
|
+
signatures: callSignatures.map((signature) => {
|
|
79
|
+
const params = signature.getParameters();
|
|
80
|
+
const typeParams = params.flatMap(
|
|
81
|
+
(param) => getDocEntry({
|
|
82
|
+
symbol: param,
|
|
83
|
+
declaration,
|
|
84
|
+
flattened
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
const returnType = signature.getDeclaration().getSignature().getReturnType();
|
|
88
|
+
let flattenedReturnType = flattened && shouldFlattenType(returnType) ? returnType.getProperties().flatMap(
|
|
89
|
+
(childProp) => getDocEntry({
|
|
90
|
+
symbol: childProp,
|
|
91
|
+
declaration,
|
|
92
|
+
flattened
|
|
93
|
+
})
|
|
94
|
+
) : [];
|
|
95
|
+
if (!flattenedReturnType.length) {
|
|
96
|
+
flattenedReturnType = {
|
|
97
|
+
type: getFormattedText(returnType)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
params: typeParams,
|
|
102
|
+
returns: flattenedReturnType
|
|
103
|
+
};
|
|
104
|
+
})
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function getCommentAndTags(declaration) {
|
|
108
|
+
const symbol = declaration.getSymbolOrThrow();
|
|
109
|
+
const comment = symbol.compilerSymbol.getDocumentationComment(compilerObject);
|
|
110
|
+
if (!comment.length) {
|
|
111
|
+
const aliasSymbol = declaration.getType().getAliasSymbol();
|
|
112
|
+
if (aliasSymbol) {
|
|
113
|
+
return {
|
|
114
|
+
comment: aliasSymbol.compilerSymbol.getDocumentationComment(compilerObject),
|
|
115
|
+
tags: getTags(aliasSymbol)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
comment,
|
|
121
|
+
tags: getTags(symbol)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function getDocEntry({
|
|
125
|
+
symbol,
|
|
126
|
+
declaration,
|
|
127
|
+
flattened,
|
|
128
|
+
prefix = ""
|
|
129
|
+
}) {
|
|
130
|
+
const originalSubType = project.getTypeChecker().getTypeOfSymbolAtLocation(symbol, declaration);
|
|
131
|
+
const valueDeclaration = symbol.getValueDeclaration();
|
|
132
|
+
const isFunctionParameter = valueDeclaration && valueDeclaration.getKind() === SyntaxKind.Parameter;
|
|
133
|
+
const subType = isFunctionParameter ? originalSubType.getNonNullableType() : originalSubType;
|
|
134
|
+
if (flattened && shouldFlattenType(subType)) {
|
|
135
|
+
return subType.getProperties().flatMap((childProp) => {
|
|
136
|
+
const childPrefix = isFunctionParameter ? symbol.getName().replace(/^_+/, "") : symbol.getName();
|
|
137
|
+
const newPrefix = typeof +childPrefix === "number" && !Number.isNaN(+childPrefix) ? `[${childPrefix}]` + (originalSubType.isNullable() ? "?" : "") : childPrefix;
|
|
138
|
+
return getDocEntry({
|
|
139
|
+
symbol: childProp,
|
|
140
|
+
declaration,
|
|
141
|
+
flattened,
|
|
142
|
+
prefix: prexify(prefix, newPrefix)
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const tags = getTags(symbol);
|
|
147
|
+
const name = symbol.getName();
|
|
148
|
+
const typeDescription = replaceJsDocLinks(
|
|
149
|
+
ts.displayPartsToString(
|
|
150
|
+
symbol.compilerSymbol.getDocumentationComment(compilerObject)
|
|
151
|
+
)
|
|
152
|
+
).replace(/^- /, "");
|
|
153
|
+
const isOptional = isFunctionParameter ? (
|
|
154
|
+
// @ts-expect-error -- fixme
|
|
155
|
+
valueDeclaration.isOptional()
|
|
156
|
+
) : symbol.isOptional();
|
|
157
|
+
const typeName = getTypeName({
|
|
158
|
+
tags,
|
|
159
|
+
symbol,
|
|
160
|
+
subType,
|
|
161
|
+
valueDeclaration
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
name: prexify(prefix, name),
|
|
165
|
+
type: typeName,
|
|
166
|
+
...typeDescription && { description: typeDescription },
|
|
167
|
+
...Object.keys(tags).length && { tags },
|
|
168
|
+
...isOptional && { optional: isOptional }
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function printType(paramType) {
|
|
172
|
+
const inlineParamAlias = paramType.getNonNullableType().getAliasSymbol();
|
|
173
|
+
const paramTags = inlineParamAlias && getTags(inlineParamAlias);
|
|
174
|
+
const hasLine = paramTags && "inline" in paramTags;
|
|
175
|
+
if (!hasLine) {
|
|
176
|
+
return getFormattedText(paramType);
|
|
177
|
+
}
|
|
178
|
+
const typeText = inlineParamAlias.getDeclaredType().getText(
|
|
179
|
+
void 0,
|
|
180
|
+
ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.InTypeAlias
|
|
181
|
+
// | ts.TypeFormatFlags.WriteArrayAsGenericType
|
|
182
|
+
// | ts.TypeFormatFlags.UseFullyQualifiedType
|
|
183
|
+
);
|
|
184
|
+
return typeText;
|
|
185
|
+
}
|
|
186
|
+
function getTypeName({
|
|
187
|
+
tags,
|
|
188
|
+
symbol,
|
|
189
|
+
subType,
|
|
190
|
+
valueDeclaration
|
|
191
|
+
}) {
|
|
192
|
+
const aliasSymbol = subType.getAliasSymbol();
|
|
193
|
+
const subTypeTags = aliasSymbol ? getTags(aliasSymbol) : {};
|
|
194
|
+
const typeName = (tags.remarks || subTypeTags.remarks)?.match(
|
|
195
|
+
/^`(?<name>.+)`/
|
|
196
|
+
)?.groups.name;
|
|
197
|
+
if (typeName) {
|
|
198
|
+
return typeName;
|
|
199
|
+
}
|
|
200
|
+
const declarationNode = symbol.getDeclarations().find(
|
|
201
|
+
(d) => ts.isPropertySignature(d.compilerNode) || ts.isParameter(d.compilerNode)
|
|
202
|
+
);
|
|
203
|
+
const typeNode = declarationNode?.asKind(SyntaxKind.PropertySignature) ?? declarationNode?.asKind(SyntaxKind.Parameter);
|
|
204
|
+
const t = typeNode?.getTypeNode()?.getText();
|
|
205
|
+
const useTypeNode = t && (t.startsWith("Partial<") || ["React.ReactNode", "React.ReactElement"].includes(t));
|
|
206
|
+
if (useTypeNode) {
|
|
207
|
+
return t;
|
|
208
|
+
}
|
|
209
|
+
const isInline = "inline" in tags || "inline" in subTypeTags;
|
|
210
|
+
if (!isInline) {
|
|
211
|
+
const typeOf = valueDeclaration?.getType() ?? symbol.getDeclaredType();
|
|
212
|
+
return typeOf.isUnknown() ? "unknown" : getFormattedText(subType);
|
|
213
|
+
}
|
|
214
|
+
const [signature] = subType.getCallSignatures();
|
|
215
|
+
const isFunction = !!signature;
|
|
216
|
+
if (isFunction) {
|
|
217
|
+
const params = signature.getParameters().map((param) => {
|
|
218
|
+
const paramDecl = param.getDeclarations()[0];
|
|
219
|
+
const paramType = project.getTypeChecker().getTypeOfSymbolAtLocation(param, paramDecl);
|
|
220
|
+
const paramTypeStr = printType(paramType);
|
|
221
|
+
const optional = paramDecl.asKindOrThrow(SyntaxKind.Parameter).isOptional();
|
|
222
|
+
return `${param.getName()}${optional ? "?" : ""}: ${paramTypeStr}`;
|
|
223
|
+
});
|
|
224
|
+
return `(${params.join(", ")}) => ${getFormattedText(signature.getReturnType())}`;
|
|
225
|
+
}
|
|
226
|
+
const [aliasDecl] = aliasSymbol.getDeclarations();
|
|
227
|
+
if (!aliasDecl) {
|
|
228
|
+
throw new Error("Can't find alias declaration for type.");
|
|
229
|
+
}
|
|
230
|
+
const inlineNode = aliasDecl.asKindOrThrow(SyntaxKind.TypeAliasDeclaration).getTypeNodeOrThrow();
|
|
231
|
+
return inlineNode.getText();
|
|
232
|
+
}
|
|
233
|
+
function prexify(prefix, name) {
|
|
234
|
+
return prefix ? [prefix, name].join(".") : name;
|
|
235
|
+
}
|
|
236
|
+
function shouldFlattenType(t) {
|
|
237
|
+
if (!t.isObject() || t.isArray() || t.isTuple() || // Is not function
|
|
238
|
+
t.getCallSignatures().length > 0 || // Is not `unknown`
|
|
239
|
+
t.getText() === "{}" || // Is not an empty object
|
|
240
|
+
!t.getProperties().length) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const baseName = t.getSymbolOrThrow().getName();
|
|
245
|
+
if (IGNORED_TYPES.has(baseName)) return false;
|
|
246
|
+
return t.isInterface() || baseName === "__type" || baseName === "__object";
|
|
247
|
+
} catch {
|
|
248
|
+
logger.error(`Symbol "${t.getText()}" isn't found.`);
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const IGNORED_TYPES = /* @__PURE__ */ new Set([
|
|
253
|
+
"Date",
|
|
254
|
+
"RegExp",
|
|
255
|
+
"ReactElement",
|
|
256
|
+
"Element",
|
|
257
|
+
"CSSProperties"
|
|
258
|
+
]);
|
|
259
|
+
function getTags(prop) {
|
|
260
|
+
const tags = /* @__PURE__ */ Object.create(null);
|
|
261
|
+
for (const tag of prop.getJsDocTags()) {
|
|
262
|
+
const tagName = tag.getName();
|
|
263
|
+
const tagValue = ts.displayPartsToString(tag.getText());
|
|
264
|
+
if (tagName in tags) {
|
|
265
|
+
tags[tagName] += `
|
|
266
|
+
${tagValue}`;
|
|
267
|
+
} else {
|
|
268
|
+
tags[tagName] = tagValue;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return tags;
|
|
272
|
+
}
|
|
273
|
+
function getFormattedText(t) {
|
|
274
|
+
return t.getText(
|
|
275
|
+
void 0,
|
|
276
|
+
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
function replaceJsDocLinks(md) {
|
|
280
|
+
return md.replaceAll(/{@link (?<link>[^}]*)}/g, "$1");
|
|
281
|
+
}
|
|
282
|
+
export {
|
|
283
|
+
generateDefinition
|
|
284
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { TSDoc } from './tsdoc.js';
|
|
2
|
+
export { generateDefinition } from './base.js';
|
|
3
|
+
export { generateTsFromZod } from './zod-to-ts.js';
|
|
4
|
+
export { BaseArgs, GeneratedDefinition, GeneratedFunction, GeneratedType, ReturnField, Tags, TypeField } from './types.js';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'zod';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { TSDoc } from "./tsdoc.js";
|
|
3
|
+
import { generateDefinition } from "./base.js";
|
|
4
|
+
import { generateTsFromZod } from "./zod-to-ts.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export {
|
|
7
|
+
TSDoc,
|
|
8
|
+
generateDefinition,
|
|
9
|
+
generateTsFromZod
|
|
10
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { generateDefinition } from './base.js';
|
|
3
|
+
import './types.js';
|
|
4
|
+
|
|
5
|
+
type TSDocProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Parsed `type`, `interface` or `function` definition from
|
|
8
|
+
* [`generateDefinition` function](https://nextra.site/api/generatedefinition).
|
|
9
|
+
*/
|
|
10
|
+
definition: ReturnType<typeof generateDefinition>;
|
|
11
|
+
/**
|
|
12
|
+
* Override the function to render markdown into JSX nodes.
|
|
13
|
+
* @default
|
|
14
|
+
* async function renderMarkdownDefault(description?: string): Promise<ReactNode> {
|
|
15
|
+
* if (!description) return
|
|
16
|
+
* const rawJs = await compileMdx(description)
|
|
17
|
+
* return <MDXRemote compiledSource={rawJs} />
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
renderMarkdown?: typeof renderMarkdownDefault;
|
|
21
|
+
/**
|
|
22
|
+
* Type links map.
|
|
23
|
+
* @default {}
|
|
24
|
+
*/
|
|
25
|
+
typeLinkMap?: Record<string, string>;
|
|
26
|
+
/**
|
|
27
|
+
* Custom content to display when a function has no parameters.
|
|
28
|
+
* @default <Callout type="info">This function does not accept any parameters.</Callout>
|
|
29
|
+
*/
|
|
30
|
+
noParametersContent?: ReactNode;
|
|
31
|
+
};
|
|
32
|
+
declare function renderMarkdownDefault(description?: string): Promise<ReactNode>;
|
|
33
|
+
/**
|
|
34
|
+
* A built-in component lets you generate documentation from `type`, `interface`, and `function`
|
|
35
|
+
* definitions using [TSDoc](https://tsdoc.org) annotations.
|
|
36
|
+
*
|
|
37
|
+
* ## What it generates
|
|
38
|
+
*
|
|
39
|
+
* ### For `type` and `interface`
|
|
40
|
+
*
|
|
41
|
+
* Generates a **properties table** with:
|
|
42
|
+
*
|
|
43
|
+
* - Name
|
|
44
|
+
* - Type and description
|
|
45
|
+
* - Default Value
|
|
46
|
+
* - Permalink
|
|
47
|
+
*
|
|
48
|
+
* ### For `function`
|
|
49
|
+
*
|
|
50
|
+
* 1. **Parameters table**, including:
|
|
51
|
+
*
|
|
52
|
+
* - Name
|
|
53
|
+
* - Type and description
|
|
54
|
+
* - Default value
|
|
55
|
+
* - Permalink
|
|
56
|
+
*
|
|
57
|
+
* 2. **Return signature table**, including:
|
|
58
|
+
* - Description
|
|
59
|
+
* - Return values table
|
|
60
|
+
*
|
|
61
|
+
* > [!TIP]
|
|
62
|
+
* >
|
|
63
|
+
* > - Permalink is a `#` anchor link for easy reference to individual rows.
|
|
64
|
+
* > - Descriptions are parsed from inline TSDoc comments or the `@description`
|
|
65
|
+
* > tag.
|
|
66
|
+
* > - Supports full Markdown/MDX syntax in descriptions.
|
|
67
|
+
* > - Default values are extracted from the `@default` or `@defaultValue` tags.
|
|
68
|
+
* > - Return descriptions come from the `@returns` tag.
|
|
69
|
+
*
|
|
70
|
+
* > [!WARNING]
|
|
71
|
+
* >
|
|
72
|
+
* > **Server Component Only** – TSDoc component cannot be used in a client
|
|
73
|
+
* > component.<br />
|
|
74
|
+
* > **Available from:** Nextra 4.3 (alpha).<br />
|
|
75
|
+
* > **Dependency:** Uses TypeScript Compiler API from
|
|
76
|
+
* > [`ts-morph`](https://github.com/dsherret/ts-morph).
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* To generate the props table for the `TSDoc` component shown on this page:
|
|
80
|
+
*
|
|
81
|
+
* ```mdx
|
|
82
|
+
* import { generateDefinition, TSDoc } from 'nextra/tsdoc'
|
|
83
|
+
*
|
|
84
|
+
* <TSDoc
|
|
85
|
+
* definition={generateDefinition({
|
|
86
|
+
* code: `
|
|
87
|
+
* import type { TSDoc } from 'nextra/tsdoc'
|
|
88
|
+
* type MyProps = React.ComponentProps<typeof TSDoc>
|
|
89
|
+
* export default MyProps`
|
|
90
|
+
* })}
|
|
91
|
+
* />
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* ### Overriding a type
|
|
95
|
+
*
|
|
96
|
+
* You can override the inferred type using the `@remarks` tag using backticks (`).
|
|
97
|
+
*
|
|
98
|
+
* <ExampleTSDoc />
|
|
99
|
+
*/
|
|
100
|
+
declare const TSDoc: FC<TSDocProps>;
|
|
101
|
+
|
|
102
|
+
export { TSDoc };
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import cn from "clsx";
|
|
3
|
+
import Slugger from "github-slugger";
|
|
4
|
+
import { Callout } from "../../client/components/callout.js";
|
|
5
|
+
import { Tabs } from "../../client/components/tabs/index.js";
|
|
6
|
+
import { Anchor } from "../../client/mdx-components/anchor.js";
|
|
7
|
+
import { Code } from "../../client/mdx-components/code.js";
|
|
8
|
+
import { MDXRemote } from "../../client/mdx-remote.js";
|
|
9
|
+
import { compileMdx } from "../compile.js";
|
|
10
|
+
const Link = ({ className, ...props }) => {
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
Anchor,
|
|
13
|
+
{
|
|
14
|
+
className: cn(
|
|
15
|
+
"x:text-primary-600 x:underline x:hover:no-underline x:decoration-from-font x:[text-underline-position:from-font]",
|
|
16
|
+
className
|
|
17
|
+
),
|
|
18
|
+
...props
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
async function renderMarkdownDefault(description) {
|
|
23
|
+
if (!description) return;
|
|
24
|
+
const rawJs = await compileMdx(description);
|
|
25
|
+
return /* @__PURE__ */ jsx(MDXRemote, { compiledSource: rawJs });
|
|
26
|
+
}
|
|
27
|
+
const classes = {
|
|
28
|
+
card: cn(
|
|
29
|
+
"x:rounded-xl nextra-border x:hover:bg-primary-50 x:dark:hover:bg-primary-500/10"
|
|
30
|
+
),
|
|
31
|
+
anchor: cn(
|
|
32
|
+
"x:absolute x:top-0 x:right-0 x:text-lg x:font-black",
|
|
33
|
+
'x:before:content-["#"] x:hover:text-black x:dark:hover:text-white',
|
|
34
|
+
"x:px-3 x:py-[min(1%,12px)]"
|
|
35
|
+
// Increase click box
|
|
36
|
+
)
|
|
37
|
+
};
|
|
38
|
+
const TSDoc = ({
|
|
39
|
+
definition,
|
|
40
|
+
renderMarkdown = renderMarkdownDefault,
|
|
41
|
+
typeLinkMap = {},
|
|
42
|
+
noParametersContent = /* @__PURE__ */ jsx(Callout, { type: "info", children: "This function does not accept any parameters." })
|
|
43
|
+
}) => {
|
|
44
|
+
if ("entries" in definition) {
|
|
45
|
+
return /* @__PURE__ */ jsx(
|
|
46
|
+
FieldsTable,
|
|
47
|
+
{
|
|
48
|
+
fields: definition.entries,
|
|
49
|
+
typeLinkMap,
|
|
50
|
+
renderMarkdown
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const { signatures, tags } = definition;
|
|
55
|
+
const withSignatures = signatures.length > 1;
|
|
56
|
+
if (!withSignatures) {
|
|
57
|
+
return /* @__PURE__ */ jsx(FunctionSignature, { signature: signatures[0] });
|
|
58
|
+
}
|
|
59
|
+
return /* @__PURE__ */ jsx(
|
|
60
|
+
Tabs,
|
|
61
|
+
{
|
|
62
|
+
items: signatures.map((_, index) => `Function Signature ${index + 1}`),
|
|
63
|
+
children: signatures.map((signature, index) => /* @__PURE__ */ jsx(Tabs.Tab, { children: /* @__PURE__ */ jsx(FunctionSignature, { signature, index: index + 1 }) }, index))
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
async function FunctionSignature({
|
|
67
|
+
signature,
|
|
68
|
+
index = ""
|
|
69
|
+
}) {
|
|
70
|
+
const slugger = new Slugger();
|
|
71
|
+
const description = await renderMarkdown(tags?.returns);
|
|
72
|
+
const unnamedReturnId = `returns${index}`;
|
|
73
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
74
|
+
/* @__PURE__ */ jsx("b", { className: "x:mt-[1.25em] x:block", children: "Parameters:" }),
|
|
75
|
+
signature.params.length ? /* @__PURE__ */ jsx(
|
|
76
|
+
FieldsTable,
|
|
77
|
+
{
|
|
78
|
+
fields: signature.params,
|
|
79
|
+
typeLinkMap,
|
|
80
|
+
renderMarkdown
|
|
81
|
+
}
|
|
82
|
+
) : noParametersContent,
|
|
83
|
+
/* @__PURE__ */ jsx("b", { className: "x:mt-[1.25em] x:block", children: "Returns:" }),
|
|
84
|
+
Array.isArray(signature.returns) ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
85
|
+
description,
|
|
86
|
+
/* @__PURE__ */ jsxs("table", { className: "x:my-6 x:w-full x:text-sm", children: [
|
|
87
|
+
/* @__PURE__ */ jsx("thead", { className: "nextra-border x:border-b x:text-left x:max-lg:hidden", children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
88
|
+
/* @__PURE__ */ jsx("th", { className: "x:py-1.5", children: "Name" }),
|
|
89
|
+
/* @__PURE__ */ jsx("th", { className: "x:p-1.5 x:px-3", children: "Type" })
|
|
90
|
+
] }) }),
|
|
91
|
+
/* @__PURE__ */ jsx("tbody", { children: signature.returns.map(async (prop) => {
|
|
92
|
+
const id = slugger.slug(prop.name);
|
|
93
|
+
const description2 = await renderMarkdown(
|
|
94
|
+
prop.description || prop.tags?.description
|
|
95
|
+
);
|
|
96
|
+
return /* @__PURE__ */ jsxs(Row, { id, children: [
|
|
97
|
+
/* @__PURE__ */ jsx(
|
|
98
|
+
NameCell,
|
|
99
|
+
{
|
|
100
|
+
id,
|
|
101
|
+
optional: prop.optional,
|
|
102
|
+
name: prop.name
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
/* @__PURE__ */ jsx(
|
|
106
|
+
TypeAndDescriptionCell,
|
|
107
|
+
{
|
|
108
|
+
type: prop.type,
|
|
109
|
+
description: description2,
|
|
110
|
+
typeLinkMap
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
] }, id);
|
|
114
|
+
}) })
|
|
115
|
+
] })
|
|
116
|
+
] }) : /* @__PURE__ */ jsxs(
|
|
117
|
+
"div",
|
|
118
|
+
{
|
|
119
|
+
id: unnamedReturnId,
|
|
120
|
+
className: cn(
|
|
121
|
+
classes.card,
|
|
122
|
+
'x:text-sm x:relative x:p-3 x:border x:before:content-["Type:_"] x:mt-5'
|
|
123
|
+
),
|
|
124
|
+
children: [
|
|
125
|
+
/* @__PURE__ */ jsx("a", { href: `#${unnamedReturnId}`, className: cn(classes.anchor) }),
|
|
126
|
+
/* @__PURE__ */ jsx(Code, { children: linkify(signature.returns.type, typeLinkMap) }),
|
|
127
|
+
description && /* @__PURE__ */ jsx("div", { className: "x:mt-2", children: description })
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
] });
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const Row = ({ children, id }) => {
|
|
135
|
+
return /* @__PURE__ */ jsx(
|
|
136
|
+
"tr",
|
|
137
|
+
{
|
|
138
|
+
id,
|
|
139
|
+
className: cn(
|
|
140
|
+
classes.card,
|
|
141
|
+
"x:group x:mb-5 x:max-lg:block x:max-lg:border x:lg:border-b",
|
|
142
|
+
"x:lg:not-target:[&>td>a]:opacity-0"
|
|
143
|
+
),
|
|
144
|
+
children
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
const NameCell = ({ name, id, optional }) => {
|
|
149
|
+
return /* @__PURE__ */ jsxs(
|
|
150
|
+
"td",
|
|
151
|
+
{
|
|
152
|
+
className: cn(
|
|
153
|
+
"x:relative x:max-lg:block",
|
|
154
|
+
name && "x:py-3 x:max-lg:px-3"
|
|
155
|
+
),
|
|
156
|
+
children: [
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
"a",
|
|
159
|
+
{
|
|
160
|
+
href: `#${id}`,
|
|
161
|
+
className: cn(
|
|
162
|
+
classes.anchor,
|
|
163
|
+
"x:group-hover:opacity-100! x:lg:top-1/2 x:lg:right-full x:lg:-translate-y-1/2"
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
name && /* @__PURE__ */ jsx(
|
|
168
|
+
Code,
|
|
169
|
+
{
|
|
170
|
+
className: cn(
|
|
171
|
+
"x:max-md:break-all",
|
|
172
|
+
// add `?` via CSS `content` property so value will be not selectable
|
|
173
|
+
optional && 'x:after:content-["?"]'
|
|
174
|
+
),
|
|
175
|
+
children: name
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
const TypeAndDescriptionCell = ({ type, description, typeLinkMap }) => {
|
|
183
|
+
return /* @__PURE__ */ jsxs(
|
|
184
|
+
"td",
|
|
185
|
+
{
|
|
186
|
+
className: 'x:p-3 x:max-lg:block x:max-lg:before:content-["Type:_"]',
|
|
187
|
+
children: [
|
|
188
|
+
/* @__PURE__ */ jsx(Code, { children: linkify(type, typeLinkMap) }),
|
|
189
|
+
description && /* @__PURE__ */ jsx("div", { className: "x:mt-2", children: description })
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
const FieldsTable = ({ fields, typeLinkMap, renderMarkdown }) => {
|
|
195
|
+
const slugger = new Slugger();
|
|
196
|
+
return /* @__PURE__ */ jsxs("table", { className: "x:my-8 x:w-full x:text-sm", children: [
|
|
197
|
+
/* @__PURE__ */ jsx("thead", { className: "nextra-border x:border-b x:text-left x:max-lg:hidden", children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
198
|
+
/* @__PURE__ */ jsx("th", { className: "x:py-1.5", children: "Name" }),
|
|
199
|
+
/* @__PURE__ */ jsx("th", { className: "x:p-1.5 x:px-3", children: "Type" }),
|
|
200
|
+
/* @__PURE__ */ jsx("th", { className: "x:py-1.5", children: "Default" })
|
|
201
|
+
] }) }),
|
|
202
|
+
/* @__PURE__ */ jsx("tbody", { children: fields.map(async (field) => {
|
|
203
|
+
const id = slugger.slug(field.name);
|
|
204
|
+
const tags = field.tags ?? {};
|
|
205
|
+
const defaultValue = tags.default || tags.defaultValue;
|
|
206
|
+
const description = await renderMarkdown(
|
|
207
|
+
[
|
|
208
|
+
field.description || tags.description,
|
|
209
|
+
tags.deprecated && `**Deprecated**: ${tags.deprecated}`
|
|
210
|
+
].filter(Boolean).join("\n")
|
|
211
|
+
);
|
|
212
|
+
return /* @__PURE__ */ jsxs(Row, { id, children: [
|
|
213
|
+
/* @__PURE__ */ jsx(NameCell, { id, optional: field.optional, name: field.name }),
|
|
214
|
+
/* @__PURE__ */ jsx(
|
|
215
|
+
TypeAndDescriptionCell,
|
|
216
|
+
{
|
|
217
|
+
type: field.type,
|
|
218
|
+
description,
|
|
219
|
+
typeLinkMap
|
|
220
|
+
}
|
|
221
|
+
),
|
|
222
|
+
/* @__PURE__ */ jsx(
|
|
223
|
+
"td",
|
|
224
|
+
{
|
|
225
|
+
className: cn(
|
|
226
|
+
"x:max-lg:block",
|
|
227
|
+
// For the mobile view, we want to hide the default column entirely if there is no
|
|
228
|
+
// content for it. We want this because otherwise, the default padding applied to
|
|
229
|
+
// table cells will add some extra blank space we don't want.
|
|
230
|
+
defaultValue ? (
|
|
231
|
+
// add `Default: ` via CSS `content` property so value will be not selectable
|
|
232
|
+
'x:py-3 x:max-lg:pt-0 x:max-lg:px-3 x:max-lg:before:content-["Default:_"]'
|
|
233
|
+
) : 'x:lg:after:content-["\u2013"]'
|
|
234
|
+
),
|
|
235
|
+
children: defaultValue && /* @__PURE__ */ jsx(Code, { className: "x:whitespace-pre-wrap x:inline-block", children: linkify(defaultValue, typeLinkMap) })
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
] }, id);
|
|
239
|
+
}) })
|
|
240
|
+
] });
|
|
241
|
+
};
|
|
242
|
+
function linkify(type, typeLinkMap = {}) {
|
|
243
|
+
const result = [];
|
|
244
|
+
for (const chunk of type.match(/(\w+|\W+)/g)) {
|
|
245
|
+
const href = typeLinkMap[chunk];
|
|
246
|
+
if (href) {
|
|
247
|
+
result.push(
|
|
248
|
+
/* @__PURE__ */ jsx(Link, { href, children: /* @__PURE__ */ jsx(Fragment, { children: chunk }) }, result.length)
|
|
249
|
+
);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (typeof result.at(-1) === "string") {
|
|
253
|
+
result[result.length - 1] += chunk;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
result.push(chunk);
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
export {
|
|
261
|
+
TSDoc
|
|
262
|
+
};
|