@openpkg-ts/fumadocs-adapter 0.5.2 → 0.6.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/README.md +82 -4
- package/dist/index.d.ts +37 -3
- package/dist/index.js +41 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -43,13 +43,91 @@ Styled components use a two-column layout at the `lg:` breakpoint (1024px). For
|
|
|
43
43
|
- Consider using `full` layout for API pages or hiding the TOC to maximize content width
|
|
44
44
|
- On narrower viewports, the layout automatically stacks vertically
|
|
45
45
|
|
|
46
|
-
##
|
|
46
|
+
## Navigation Modes
|
|
47
|
+
|
|
48
|
+
Two navigation patterns are supported:
|
|
49
|
+
|
|
50
|
+
### Mode A: Single Page (Stripe-style)
|
|
51
|
+
|
|
52
|
+
All exports on one scrollable page with filters and optional TOC:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
// app/docs/(api)/api/page.tsx
|
|
56
|
+
import { FullAPIReferencePage, type OpenPkg } from '@openpkg-ts/fumadocs-adapter';
|
|
57
|
+
import spec from '@/lib/openpkg.json';
|
|
58
|
+
|
|
59
|
+
export default function APIPage() {
|
|
60
|
+
return (
|
|
61
|
+
<FullAPIReferencePage
|
|
62
|
+
spec={spec as OpenPkg}
|
|
63
|
+
title="API Reference"
|
|
64
|
+
showTOC // sticky sidebar navigation
|
|
65
|
+
showFilters // kind filter buttons (functions, types, etc.)
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Props:
|
|
72
|
+
- `showTOC` - Enable sticky sidebar with anchor links
|
|
73
|
+
- `showFilters` - Show kind filter buttons (functions, classes, etc.)
|
|
74
|
+
- `kinds` - Limit to specific export kinds: `['function', 'type']`
|
|
75
|
+
|
|
76
|
+
### Mode B: Index + Individual Pages
|
|
77
|
+
|
|
78
|
+
Grid of cards linking to individual pages:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
// app/docs/(api)/api/page.tsx (index)
|
|
82
|
+
import { ExportIndexPage, type OpenPkg } from '@openpkg-ts/fumadocs-adapter';
|
|
83
|
+
import spec from '@/lib/openpkg.json';
|
|
84
|
+
|
|
85
|
+
export default function APIIndexPage() {
|
|
86
|
+
return (
|
|
87
|
+
<ExportIndexPage
|
|
88
|
+
spec={spec as OpenPkg}
|
|
89
|
+
baseHref="/docs/api"
|
|
90
|
+
showSearch // search input
|
|
91
|
+
showFilters // category filter buttons
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// app/docs/(api)/api/[kind]/[slug]/page.tsx (detail)
|
|
97
|
+
import { FunctionPage, type OpenPkg, type SpecExport } from '@openpkg-ts/fumadocs-adapter';
|
|
98
|
+
import spec from '@/lib/openpkg.json';
|
|
99
|
+
|
|
100
|
+
export default function ExportDetailPage({ params }) {
|
|
101
|
+
const exp = (spec as OpenPkg).exports.find(e => e.id === params.slug);
|
|
102
|
+
return <FunctionPage export={exp as SpecExport} spec={spec as OpenPkg} />;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Using openpkgSource for Fumadocs Integration
|
|
107
|
+
|
|
108
|
+
Generate a page tree for Fumadocs sidebar:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
// lib/api-source.ts
|
|
112
|
+
import { loader } from 'fumadocs-core/source';
|
|
113
|
+
import { openpkgSource, type OpenPkg } from '@openpkg-ts/fumadocs-adapter';
|
|
114
|
+
import spec from './openpkg.json';
|
|
115
|
+
|
|
116
|
+
export const apiSource = loader({
|
|
117
|
+
baseUrl: '/docs/api',
|
|
118
|
+
source: openpkgSource({ spec: spec as OpenPkg, baseDir: '' }),
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Then use in your layout:
|
|
47
123
|
|
|
48
124
|
```tsx
|
|
49
|
-
|
|
125
|
+
// app/docs/(api)/layout.tsx
|
|
126
|
+
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
|
|
127
|
+
import { apiSource } from '@/lib/api-source';
|
|
50
128
|
|
|
51
|
-
export default function
|
|
52
|
-
return <
|
|
129
|
+
export default function APILayout({ children }) {
|
|
130
|
+
return <DocsLayout tree={apiSource.pageTree}>{children}</DocsLayout>;
|
|
53
131
|
}
|
|
54
132
|
```
|
|
55
133
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,14 @@ interface OpenPkgSourceOptions {
|
|
|
5
5
|
spec: OpenPkg | DocsInstance;
|
|
6
6
|
/** Base directory for pages (default: 'api') */
|
|
7
7
|
baseDir?: string;
|
|
8
|
+
/** Generate index page at baseDir/index.mdx (default: true) */
|
|
9
|
+
indexPage?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Navigation mode:
|
|
12
|
+
* - 'pages': Individual pages per grouped by kind (default)
|
|
13
|
+
* - 'single': Single page with all exports and in-page navigation
|
|
14
|
+
*/
|
|
15
|
+
mode?: "pages" | "single";
|
|
8
16
|
}
|
|
9
17
|
interface OpenPkgPageData {
|
|
10
18
|
title: string;
|
|
@@ -14,6 +22,23 @@ interface OpenPkgPageData {
|
|
|
14
22
|
/** The full OpenPkg spec */
|
|
15
23
|
spec: OpenPkg;
|
|
16
24
|
}
|
|
25
|
+
interface OpenPkgIndexPageData {
|
|
26
|
+
title: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
/** Index page marker */
|
|
29
|
+
isIndex: true;
|
|
30
|
+
/** The full OpenPkg spec */
|
|
31
|
+
spec: OpenPkg;
|
|
32
|
+
}
|
|
33
|
+
/** Page data for single-page mode */
|
|
34
|
+
interface OpenPkgSinglePageData {
|
|
35
|
+
title: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
/** Single page mode marker */
|
|
38
|
+
isSinglePage: true;
|
|
39
|
+
/** The full OpenPkg spec */
|
|
40
|
+
spec: OpenPkg;
|
|
41
|
+
}
|
|
17
42
|
interface OpenPkgMetaData {
|
|
18
43
|
title: string;
|
|
19
44
|
pages: string[];
|
|
@@ -27,7 +52,7 @@ interface OpenPkgMetaData {
|
|
|
27
52
|
*
|
|
28
53
|
* @example
|
|
29
54
|
* ```ts
|
|
30
|
-
* import { loader } from 'fumadocs-core/source';
|
|
55
|
+
* // Multi-page mode (default) - individual pages per * import { loader } from 'fumadocs-core/source';
|
|
31
56
|
* import { openpkgSource } from '@openpkg-ts/fumadocs-adapter';
|
|
32
57
|
* import spec from './openpkg.json';
|
|
33
58
|
*
|
|
@@ -36,9 +61,18 @@ interface OpenPkgMetaData {
|
|
|
36
61
|
* source: openpkgSource({ spec }),
|
|
37
62
|
* });
|
|
38
63
|
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* // Single-page mode - all exports on one scrollable page
|
|
68
|
+
* const source = loader({
|
|
69
|
+
* baseUrl: '/docs/api',
|
|
70
|
+
* source: openpkgSource({ spec, mode: 'single' }),
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
39
73
|
*/
|
|
40
74
|
declare function openpkgSource(options: OpenPkgSourceOptions): Source<{
|
|
41
|
-
pageData: OpenPkgPageData
|
|
75
|
+
pageData: OpenPkgPageData | OpenPkgIndexPageData | OpenPkgSinglePageData
|
|
42
76
|
metaData: OpenPkgMetaData
|
|
43
77
|
}>;
|
|
44
78
|
import { LoaderPlugin } from "fumadocs-core/source";
|
|
@@ -100,4 +134,4 @@ interface CoverageBadgeProps {
|
|
|
100
134
|
showDrift?: boolean;
|
|
101
135
|
}
|
|
102
136
|
declare function CoverageBadge({ docs, showMissing, showDrift }: CoverageBadgeProps): React.ReactNode;
|
|
103
|
-
export { toSearchIndexJSON, toSearchIndex, toPagefindRecords, toNavigation, toMarkdown, toJSONString, toJSON, toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords, sortByName, resolveTypeRef, openpkgSource, openpkgPlugin, loadSpec, isProperty, isMethod, groupByVisibility, getProperties, getMethods, formatTypeParameters, formatSchema, formatReturnType, formatParameters, exportToMarkdown, createDocs2 as createOpenPkg, createDocs, buildSignatureString, VariableSectionProps, VariableSection, 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, InterfaceSectionProps, InterfaceSection, InterfacePageProps, InterfacePage, ImportSectionProps, ImportSection, HTMLOptions, FunctionSectionProps, FunctionSection, FunctionPageProps, FunctionPage, FullAPIReferencePageProps, FullAPIReferencePage, ExportSectionProps, ExportSection, ExportMarkdownOptions, ExportIndexPageProps, ExportIndexPage, ExportCardProps, ExportCard, EnumSectionProps, EnumSection, EnumPageProps, EnumPage, DocsMetadata, DocsInstance3 as DocsInstance, DocDrift, CoverageBadgeProps, CoverageBadge, CodeTabsProps, CodeTabs, CodeTab, ClassSectionProps, ClassSection, ClassPageProps, ClassPage, AlgoliaRecord, APIPageProps, APIPage };
|
|
137
|
+
export { toSearchIndexJSON, toSearchIndex, toPagefindRecords, toNavigation, toMarkdown, toJSONString, toJSON, toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords, sortByName, resolveTypeRef, openpkgSource, openpkgPlugin, loadSpec, isProperty, isMethod, groupByVisibility, getProperties, getMethods, formatTypeParameters, formatSchema, formatReturnType, formatParameters, exportToMarkdown, createDocs2 as createOpenPkg, createDocs, buildSignatureString, VariableSectionProps, VariableSection, 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, OpenPkgSinglePageData, OpenPkgPageData, LoadOptions as OpenPkgOptions, OpenPkgMetaData, DocsInstance2 as OpenPkgInstance, OpenPkgIndexPageData, OpenPkg2 as OpenPkg, NestedPropertyItemProps, NavOptions, MarkdownOptions, LoadOptions2 as LoadOptions, KindBadgeProps, KindBadge, JSONOptions, InterfaceSectionProps, InterfaceSection, InterfacePageProps, InterfacePage, ImportSectionProps, ImportSection, HTMLOptions, FunctionSectionProps, FunctionSection, FunctionPageProps, FunctionPage, FullAPIReferencePageProps, FullAPIReferencePage, ExportSectionProps, ExportSection, ExportMarkdownOptions, ExportIndexPageProps, ExportIndexPage, ExportCardProps, ExportCard, EnumSectionProps, EnumSection, EnumPageProps, EnumPage, DocsMetadata, DocsInstance3 as DocsInstance, DocDrift, CoverageBadgeProps, CoverageBadge, CodeTabsProps, CodeTabs, CodeTab, ClassSectionProps, ClassSection, ClassPageProps, ClassPage, AlgoliaRecord, APIPageProps, APIPage };
|
package/dist/index.js
CHANGED
|
@@ -25,10 +25,34 @@ var KIND_LABELS = {
|
|
|
25
25
|
external: "External"
|
|
26
26
|
};
|
|
27
27
|
function openpkgSource(options) {
|
|
28
|
-
const { baseDir = "api" } = options;
|
|
28
|
+
const { baseDir = "api", indexPage = true, mode = "pages" } = options;
|
|
29
29
|
const docs = "getAllExports" in options.spec ? options.spec : createDocs(options.spec);
|
|
30
30
|
const spec = docs.spec;
|
|
31
31
|
const exports = docs.getAllExports();
|
|
32
|
+
const files = [];
|
|
33
|
+
if (mode === "single") {
|
|
34
|
+
files.push({
|
|
35
|
+
type: "meta",
|
|
36
|
+
path: `${baseDir}/meta.json`,
|
|
37
|
+
data: {
|
|
38
|
+
title: spec.meta.name || "API Reference",
|
|
39
|
+
pages: ["index"],
|
|
40
|
+
defaultOpen: true
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
files.push({
|
|
44
|
+
type: "page",
|
|
45
|
+
path: `${baseDir}/index.mdx`,
|
|
46
|
+
slugs: [],
|
|
47
|
+
data: {
|
|
48
|
+
title: spec.meta.name || "API Reference",
|
|
49
|
+
description: spec.meta.description,
|
|
50
|
+
isSinglePage: true,
|
|
51
|
+
spec
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return { files };
|
|
55
|
+
}
|
|
32
56
|
const groupedByKind = new Map;
|
|
33
57
|
for (const exp of exports) {
|
|
34
58
|
const kind = exp.kind;
|
|
@@ -37,8 +61,10 @@ function openpkgSource(options) {
|
|
|
37
61
|
}
|
|
38
62
|
groupedByKind.get(kind).push(exp);
|
|
39
63
|
}
|
|
40
|
-
const files = [];
|
|
41
64
|
const rootPages = [];
|
|
65
|
+
if (indexPage) {
|
|
66
|
+
rootPages.push("index");
|
|
67
|
+
}
|
|
42
68
|
for (const kind of KIND_ORDER) {
|
|
43
69
|
if (groupedByKind.has(kind)) {
|
|
44
70
|
rootPages.push(`...${kind}s`);
|
|
@@ -53,6 +79,19 @@ function openpkgSource(options) {
|
|
|
53
79
|
defaultOpen: true
|
|
54
80
|
}
|
|
55
81
|
});
|
|
82
|
+
if (indexPage) {
|
|
83
|
+
files.push({
|
|
84
|
+
type: "page",
|
|
85
|
+
path: `${baseDir}/index.mdx`,
|
|
86
|
+
slugs: [],
|
|
87
|
+
data: {
|
|
88
|
+
title: spec.meta.name || "API Reference",
|
|
89
|
+
description: spec.meta.description,
|
|
90
|
+
isIndex: true,
|
|
91
|
+
spec
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
56
95
|
for (const kind of KIND_ORDER) {
|
|
57
96
|
const kindExports = groupedByKind.get(kind);
|
|
58
97
|
if (!kindExports || kindExports.length === 0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/fumadocs-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Fumadocs integration for OpenPkg API documentation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typecheck": "tsc --noEmit"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@openpkg-ts/doc-generator": "^0.
|
|
31
|
+
"@openpkg-ts/doc-generator": "^0.6.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"fumadocs-core": "^16.0.0",
|