@openpkg-ts/fumadocs-adapter 0.2.5 → 0.3.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/dist/index.d.ts +78 -3
- package/dist/index.js +135 -3
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Source } from "fumadocs-core/source";
|
|
2
|
+
import { DocsInstance, OpenPkg, SpecExport } from "@openpkg-ts/doc-generator";
|
|
3
|
+
interface OpenPkgSourceOptions {
|
|
4
|
+
/** OpenPkg spec or DocsInstance */
|
|
5
|
+
spec: OpenPkg | DocsInstance;
|
|
6
|
+
/** Base directory for pages (default: 'api') */
|
|
7
|
+
baseDir?: string;
|
|
8
|
+
}
|
|
9
|
+
interface OpenPkgPageData {
|
|
10
|
+
title: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
/** The from the spec */
|
|
13
|
+
export: SpecExport;
|
|
14
|
+
/** The full OpenPkg spec */
|
|
15
|
+
spec: OpenPkg;
|
|
16
|
+
}
|
|
17
|
+
interface OpenPkgMetaData {
|
|
18
|
+
title: string;
|
|
19
|
+
pages: string[];
|
|
20
|
+
defaultOpen?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a virtual source for Fumadocs from an OpenPkg spec.
|
|
24
|
+
*
|
|
25
|
+
* This generates virtual pages grouped by kind (functions, types, etc.)
|
|
26
|
+
* that integrate with Fumadocs' loader and sidebar.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { loader } from 'fumadocs-core/source';
|
|
31
|
+
* import { openpkgSource } from '@openpkg-ts/fumadocs-adapter';
|
|
32
|
+
* import spec from './openpkg.json';
|
|
33
|
+
*
|
|
34
|
+
* const source = loader({
|
|
35
|
+
* baseUrl: '/docs/api',
|
|
36
|
+
* source: openpkgSource({ spec }),
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function openpkgSource(options: OpenPkgSourceOptions): Source<{
|
|
41
|
+
pageData: OpenPkgPageData
|
|
42
|
+
metaData: OpenPkgMetaData
|
|
43
|
+
}>;
|
|
44
|
+
import { LoaderPlugin } from "fumadocs-core/source";
|
|
45
|
+
import { SpecExportKind } from "@openpkg-ts/doc-generator";
|
|
46
|
+
import { ReactNode as ReactNode2 } from "react";
|
|
47
|
+
interface KindBadgeProps {
|
|
48
|
+
kind: SpecExportKind;
|
|
49
|
+
className?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Badge component to display kind in sidebar.
|
|
53
|
+
*/
|
|
54
|
+
declare function KindBadge({ kind, className }: KindBadgeProps): ReactNode2;
|
|
55
|
+
interface OpenpkgPluginOptions {
|
|
56
|
+
/** Show kind badges in sidebar (default: true) */
|
|
57
|
+
showBadges?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Fumadocs loader plugin that enhances page tree nodes with kind badges.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { loader } from 'fumadocs-core/source';
|
|
65
|
+
* import { openpkgSource, openpkgPlugin } from '@openpkg-ts/fumadocs-adapter';
|
|
66
|
+
* import spec from './openpkg.json';
|
|
67
|
+
*
|
|
68
|
+
* const source = loader({
|
|
69
|
+
* baseUrl: '/docs/api',
|
|
70
|
+
* source: openpkgSource({ spec }),
|
|
71
|
+
* plugins: [openpkgPlugin()],
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function openpkgPlugin(options?: OpenpkgPluginOptions): LoaderPlugin;
|
|
76
|
+
import { DocsInstance as DocsInstance2, LoadOptions, OpenPkg as OpenPkg2, SpecExample, SpecExport as SpecExport2, SpecExportKind as SpecExportKind2, SpecMember, SpecSchema, SpecSignature, SpecSignatureParameter, SpecTag, SpecType, SpecTypeKind, SpecTypeParameter } from "@openpkg-ts/doc-generator";
|
|
77
|
+
import { AlgoliaRecord, buildSignatureString, createDocs, createDocs as createDocs2, DocsInstance as DocsInstance3, ExportMarkdownOptions, exportToMarkdown, formatParameters, formatReturnType, formatSchema, formatTypeParameters, getMethods, getProperties, groupByVisibility, HTMLOptions, isMethod, isProperty, JSONOptions, LoadOptions as LoadOptions2, loadSpec, MarkdownOptions, NavOptions, PagefindRecord, resolveTypeRef, SearchIndex, SearchOptions, SearchRecord, sortByKindThenName, sortByName, toAlgoliaRecords, toDocusaurusSidebarJS, toFumadocsMetaJSON, toHTML, toJSON, toJSONString, toMarkdown, toNavigation, toPagefindRecords, toSearchIndex, toSearchIndexJSON } from "@openpkg-ts/doc-generator";
|
|
3
78
|
import { APIPage, APIPageProps, ClassPage, ClassPageProps, CodeTabs, CodeTab, CodeTabsProps, EnumPage, EnumPageProps, ExportCard, ExportCardProps, ExportIndexPage, ExportIndexPageProps, FunctionPage, FunctionPageProps, ImportSection, ImportSectionProps, InterfacePage, InterfacePageProps, NestedPropertyItemProps, ParameterItem, ParameterItemProps, VariablePage, VariablePageProps } from "@openpkg-ts/doc-generator/react/styled";
|
|
4
79
|
/**
|
|
5
80
|
* Documentation drift information.
|
|
@@ -25,4 +100,4 @@ interface CoverageBadgeProps {
|
|
|
25
100
|
showDrift?: boolean;
|
|
26
101
|
}
|
|
27
102
|
declare function CoverageBadge({ docs, showMissing, showDrift }: CoverageBadgeProps): React.ReactNode;
|
|
28
|
-
export { toSearchIndexJSON, toSearchIndex, toPagefindRecords, toNavigation, toMarkdown, toJSONString, toJSON, toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords, sortByName, sortByKindThenName, resolveTypeRef, loadSpec, isProperty, isMethod, groupByVisibility, getProperties, getMethods, formatTypeParameters, formatSchema, formatReturnType, formatParameters, exportToMarkdown, createDocs2 as createOpenPkg, createDocs, buildSignatureString, VariablePageProps, VariablePage, SpecTypeParameter, SpecTypeKind, SpecType, SpecTag, SpecSignatureParameter, SpecSignature, SpecSchema, SpecMember, SpecExportKind, SpecExport, SpecExample, SearchRecord, SearchOptions, SearchIndex, ParameterItemProps, ParameterItem, PagefindRecord, LoadOptions as OpenPkgOptions,
|
|
103
|
+
export { toSearchIndexJSON, toSearchIndex, toPagefindRecords, toNavigation, toMarkdown, toJSONString, toJSON, toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords, sortByName, sortByKindThenName, resolveTypeRef, openpkgSource, openpkgPlugin, loadSpec, isProperty, isMethod, groupByVisibility, getProperties, getMethods, formatTypeParameters, formatSchema, formatReturnType, formatParameters, exportToMarkdown, createDocs2 as createOpenPkg, createDocs, buildSignatureString, VariablePageProps, VariablePage, SpecTypeParameter, SpecTypeKind, SpecType, SpecTag, SpecSignatureParameter, SpecSignature, SpecSchema, SpecMember, SpecExportKind2 as SpecExportKind, SpecExport2 as SpecExport, SpecExample, SearchRecord, SearchOptions, SearchIndex, ParameterItemProps, ParameterItem, PagefindRecord, OpenpkgPluginOptions, OpenPkgSourceOptions, OpenPkgPageData, LoadOptions as OpenPkgOptions, OpenPkgMetaData, DocsInstance2 as OpenPkgInstance, OpenPkg2 as OpenPkg, NestedPropertyItemProps, NavOptions, MarkdownOptions, LoadOptions2 as LoadOptions, KindBadgeProps, KindBadge, JSONOptions, InterfacePageProps, InterfacePage, ImportSectionProps, ImportSection, HTMLOptions, FunctionPageProps, FunctionPage, ExportMarkdownOptions, ExportIndexPageProps, ExportIndexPage, ExportCardProps, ExportCard, EnumPageProps, EnumPage, DocsMetadata, DocsInstance3 as DocsInstance, DocDrift, CoverageBadgeProps, CoverageBadge, CodeTabsProps, CodeTabs, CodeTab, ClassPageProps, ClassPage, AlgoliaRecord, APIPageProps, APIPage };
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,140 @@ import {
|
|
|
2
2
|
CoverageBadge
|
|
3
3
|
} from "./shared/chunk-a91ch1vp.js";
|
|
4
4
|
|
|
5
|
+
// src/source.ts
|
|
6
|
+
import { createDocs } from "@openpkg-ts/doc-generator";
|
|
7
|
+
var KIND_ORDER = [
|
|
8
|
+
"function",
|
|
9
|
+
"class",
|
|
10
|
+
"interface",
|
|
11
|
+
"type",
|
|
12
|
+
"enum",
|
|
13
|
+
"variable"
|
|
14
|
+
];
|
|
15
|
+
var KIND_LABELS = {
|
|
16
|
+
function: "Functions",
|
|
17
|
+
class: "Classes",
|
|
18
|
+
interface: "Interfaces",
|
|
19
|
+
type: "Types",
|
|
20
|
+
enum: "Enums",
|
|
21
|
+
variable: "Variables",
|
|
22
|
+
namespace: "Namespaces",
|
|
23
|
+
module: "Modules",
|
|
24
|
+
reference: "References",
|
|
25
|
+
external: "External"
|
|
26
|
+
};
|
|
27
|
+
function openpkgSource(options) {
|
|
28
|
+
const { baseDir = "api" } = options;
|
|
29
|
+
const docs = "getAllExports" in options.spec ? options.spec : createDocs(options.spec);
|
|
30
|
+
const spec = docs.spec;
|
|
31
|
+
const exports = docs.getAllExports();
|
|
32
|
+
const groupedByKind = new Map;
|
|
33
|
+
for (const exp of exports) {
|
|
34
|
+
const kind = exp.kind;
|
|
35
|
+
if (!groupedByKind.has(kind)) {
|
|
36
|
+
groupedByKind.set(kind, []);
|
|
37
|
+
}
|
|
38
|
+
groupedByKind.get(kind).push(exp);
|
|
39
|
+
}
|
|
40
|
+
const files = [];
|
|
41
|
+
const rootPages = [];
|
|
42
|
+
for (const kind of KIND_ORDER) {
|
|
43
|
+
if (groupedByKind.has(kind)) {
|
|
44
|
+
rootPages.push(`...${kind}s`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
files.push({
|
|
48
|
+
type: "meta",
|
|
49
|
+
path: `${baseDir}/meta.json`,
|
|
50
|
+
data: {
|
|
51
|
+
title: spec.meta.name || "API Reference",
|
|
52
|
+
pages: rootPages,
|
|
53
|
+
defaultOpen: true
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
for (const kind of KIND_ORDER) {
|
|
57
|
+
const kindExports = groupedByKind.get(kind);
|
|
58
|
+
if (!kindExports || kindExports.length === 0)
|
|
59
|
+
continue;
|
|
60
|
+
const kindDir = `${baseDir}/${kind}s`;
|
|
61
|
+
const label = KIND_LABELS[kind] || `${kind}s`;
|
|
62
|
+
const sortedExports = [...kindExports].sort((a, b) => a.name.localeCompare(b.name));
|
|
63
|
+
files.push({
|
|
64
|
+
type: "meta",
|
|
65
|
+
path: `${kindDir}/meta.json`,
|
|
66
|
+
data: {
|
|
67
|
+
title: label,
|
|
68
|
+
pages: sortedExports.map((exp) => exp.id),
|
|
69
|
+
defaultOpen: false
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
for (const exp of sortedExports) {
|
|
73
|
+
files.push({
|
|
74
|
+
type: "page",
|
|
75
|
+
path: `${kindDir}/${exp.id}.mdx`,
|
|
76
|
+
slugs: [kind + "s", exp.id],
|
|
77
|
+
data: {
|
|
78
|
+
title: exp.name,
|
|
79
|
+
description: exp.description,
|
|
80
|
+
export: exp,
|
|
81
|
+
spec
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { files };
|
|
87
|
+
}
|
|
88
|
+
// src/plugin.ts
|
|
89
|
+
import { createElement } from "react";
|
|
90
|
+
var KIND_BADGES = {
|
|
91
|
+
function: { label: "fn", className: "openpkg-badge-function" },
|
|
92
|
+
class: { label: "C", className: "openpkg-badge-class" },
|
|
93
|
+
interface: { label: "I", className: "openpkg-badge-interface" },
|
|
94
|
+
type: { label: "T", className: "openpkg-badge-type" },
|
|
95
|
+
enum: { label: "E", className: "openpkg-badge-enum" },
|
|
96
|
+
variable: { label: "V", className: "openpkg-badge-variable" },
|
|
97
|
+
namespace: { label: "N", className: "openpkg-badge-namespace" },
|
|
98
|
+
module: { label: "M", className: "openpkg-badge-module" },
|
|
99
|
+
reference: { label: "R", className: "openpkg-badge-reference" },
|
|
100
|
+
external: { label: "X", className: "openpkg-badge-external" }
|
|
101
|
+
};
|
|
102
|
+
function KindBadge({ kind, className }) {
|
|
103
|
+
const badge = KIND_BADGES[kind];
|
|
104
|
+
if (!badge)
|
|
105
|
+
return null;
|
|
106
|
+
return createElement("span", {
|
|
107
|
+
className: `openpkg-kind-badge ${badge.className} ${className || ""}`.trim(),
|
|
108
|
+
"data-kind": kind
|
|
109
|
+
}, badge.label);
|
|
110
|
+
}
|
|
111
|
+
function openpkgPlugin(options = {}) {
|
|
112
|
+
const { showBadges = true } = options;
|
|
113
|
+
return {
|
|
114
|
+
name: "openpkg",
|
|
115
|
+
transformPageTree: {
|
|
116
|
+
file(node, filePath) {
|
|
117
|
+
if (!showBadges || !filePath)
|
|
118
|
+
return node;
|
|
119
|
+
const file = this.storage.read(filePath);
|
|
120
|
+
if (!file || file.format !== "page")
|
|
121
|
+
return node;
|
|
122
|
+
const pageData = file.data;
|
|
123
|
+
const kind = pageData.export?.kind;
|
|
124
|
+
if (!kind || !KIND_BADGES[kind])
|
|
125
|
+
return node;
|
|
126
|
+
const badge = createElement(KindBadge, { kind });
|
|
127
|
+
const newName = createElement("span", { className: "openpkg-sidebar-item" }, badge, node.name);
|
|
128
|
+
return { ...node, name: newName };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
5
134
|
// src/index.ts
|
|
6
135
|
import {
|
|
7
136
|
buildSignatureString,
|
|
8
|
-
createDocs,
|
|
9
137
|
createDocs as createDocs2,
|
|
138
|
+
createDocs as createDocs3,
|
|
10
139
|
exportToMarkdown,
|
|
11
140
|
formatParameters,
|
|
12
141
|
formatReturnType,
|
|
@@ -61,6 +190,8 @@ export {
|
|
|
61
190
|
sortByName,
|
|
62
191
|
sortByKindThenName,
|
|
63
192
|
resolveTypeRef,
|
|
193
|
+
openpkgSource,
|
|
194
|
+
openpkgPlugin,
|
|
64
195
|
loadSpec,
|
|
65
196
|
isProperty,
|
|
66
197
|
isMethod,
|
|
@@ -72,11 +203,12 @@ export {
|
|
|
72
203
|
formatReturnType,
|
|
73
204
|
formatParameters,
|
|
74
205
|
exportToMarkdown,
|
|
75
|
-
|
|
76
|
-
createDocs,
|
|
206
|
+
createDocs3 as createOpenPkg,
|
|
207
|
+
createDocs2 as createDocs,
|
|
77
208
|
buildSignatureString,
|
|
78
209
|
VariablePage,
|
|
79
210
|
ParameterItem,
|
|
211
|
+
KindBadge,
|
|
80
212
|
InterfacePage,
|
|
81
213
|
ImportSection,
|
|
82
214
|
FunctionPage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/fumadocs-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fumadocs integration for OpenPkg API documentation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -28,14 +28,16 @@
|
|
|
28
28
|
"typecheck": "tsc --noEmit"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@openpkg-ts/doc-generator": "^0.2.
|
|
31
|
+
"@openpkg-ts/doc-generator": "^0.2.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
+
"fumadocs-core": "^16.0.0",
|
|
34
35
|
"react": "^18 || ^19"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/react": "^19.0.0",
|
|
38
39
|
"bunup": "^0.11.5",
|
|
40
|
+
"fumadocs-core": "^16.4.0",
|
|
39
41
|
"typescript": "^5.0.0"
|
|
40
42
|
}
|
|
41
43
|
}
|