@openpkg-ts/fumadocs-adapter 0.6.0 → 0.6.1
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 +103 -59
- package/dist/index.js +20 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @openpkg-ts/fumadocs-adapter
|
|
2
2
|
|
|
3
|
-
Fumadocs integration for OpenPkg API documentation. Provides
|
|
3
|
+
Fumadocs integration for OpenPkg API documentation. Provides virtual source generation, styled components, and theming.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -33,24 +33,30 @@ Tailwind v4 excludes `node_modules` by default. Add this directive to include st
|
|
|
33
33
|
@source "../node_modules/@openpkg-ts/doc-generator/dist/**/*.js";
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
Without this, utility classes like `lg:grid-cols-[1fr,minmax(0,420px)]` won't be included in your production build.
|
|
37
|
-
|
|
38
|
-
## Layout Requirements
|
|
39
|
-
|
|
40
|
-
Styled components use a two-column layout at the `lg:` breakpoint (1024px). For best results:
|
|
41
|
-
|
|
42
|
-
- Content area should be >= 1024px wide
|
|
43
|
-
- Consider using `full` layout for API pages or hiding the TOC to maximize content width
|
|
44
|
-
- On narrower viewports, the layout automatically stacks vertically
|
|
45
|
-
|
|
46
36
|
## Navigation Modes
|
|
47
37
|
|
|
48
|
-
Two navigation patterns are supported
|
|
38
|
+
Two navigation patterns are supported via `openpkgSource`:
|
|
49
39
|
|
|
50
|
-
###
|
|
40
|
+
### Single-Page Mode
|
|
51
41
|
|
|
52
42
|
All exports on one scrollable page with filters and optional TOC:
|
|
53
43
|
|
|
44
|
+
```ts
|
|
45
|
+
// lib/api-source.ts
|
|
46
|
+
import { loader } from 'fumadocs-core/source';
|
|
47
|
+
import { openpkgSource, type OpenPkg } from '@openpkg-ts/fumadocs-adapter';
|
|
48
|
+
import spec from './openpkg.json';
|
|
49
|
+
|
|
50
|
+
export const apiSource = loader({
|
|
51
|
+
baseUrl: '/docs/api',
|
|
52
|
+
source: openpkgSource({
|
|
53
|
+
spec: spec as OpenPkg,
|
|
54
|
+
baseDir: 'api',
|
|
55
|
+
mode: 'single',
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
54
60
|
```tsx
|
|
55
61
|
// app/docs/(api)/api/page.tsx
|
|
56
62
|
import { FullAPIReferencePage, type OpenPkg } from '@openpkg-ts/fumadocs-adapter';
|
|
@@ -61,76 +67,118 @@ export default function APIPage() {
|
|
|
61
67
|
<FullAPIReferencePage
|
|
62
68
|
spec={spec as OpenPkg}
|
|
63
69
|
title="API Reference"
|
|
64
|
-
showTOC
|
|
65
|
-
showFilters
|
|
70
|
+
showTOC // sticky sidebar navigation
|
|
71
|
+
showFilters // kind filter buttons
|
|
66
72
|
/>
|
|
67
73
|
);
|
|
68
74
|
}
|
|
69
75
|
```
|
|
70
76
|
|
|
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
77
|
```tsx
|
|
81
|
-
// app/docs/(api)/api/
|
|
82
|
-
import {
|
|
83
|
-
import
|
|
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';
|
|
78
|
+
// app/docs/(api)/api/layout.tsx
|
|
79
|
+
import { apiSource } from '@/lib/api-source';
|
|
80
|
+
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
|
|
99
81
|
|
|
100
|
-
export default function
|
|
101
|
-
|
|
102
|
-
return <FunctionPage export={exp as SpecExport} spec={spec as OpenPkg} />;
|
|
82
|
+
export default function APILayout({ children }) {
|
|
83
|
+
return <DocsLayout tree={apiSource.pageTree}>{children}</DocsLayout>;
|
|
103
84
|
}
|
|
104
85
|
```
|
|
105
86
|
|
|
106
|
-
|
|
87
|
+
### Multi-Page Mode
|
|
107
88
|
|
|
108
|
-
|
|
89
|
+
Index page with cards + individual pages per export:
|
|
109
90
|
|
|
110
|
-
```
|
|
91
|
+
```ts
|
|
111
92
|
// lib/api-source.ts
|
|
112
93
|
import { loader } from 'fumadocs-core/source';
|
|
113
|
-
import { openpkgSource, type OpenPkg } from '@openpkg-ts/fumadocs-adapter';
|
|
94
|
+
import { openpkgSource, openpkgPlugin, type OpenPkg } from '@openpkg-ts/fumadocs-adapter';
|
|
114
95
|
import spec from './openpkg.json';
|
|
115
96
|
|
|
116
97
|
export const apiSource = loader({
|
|
117
|
-
baseUrl: '/docs/
|
|
118
|
-
source: openpkgSource({
|
|
98
|
+
baseUrl: '/docs/reference',
|
|
99
|
+
source: openpkgSource({
|
|
100
|
+
spec: spec as OpenPkg,
|
|
101
|
+
baseDir: 'reference',
|
|
102
|
+
mode: 'pages', // individual pages per export
|
|
103
|
+
indexPage: true, // generate index page with cards
|
|
104
|
+
}),
|
|
105
|
+
plugins: [openpkgPlugin()], // adds kind badges to sidebar
|
|
119
106
|
});
|
|
120
107
|
```
|
|
121
108
|
|
|
122
|
-
|
|
109
|
+
```tsx
|
|
110
|
+
// app/docs/(reference)/reference/[[...slug]]/page.tsx
|
|
111
|
+
import { apiSource } from '@/lib/api-source';
|
|
112
|
+
import { notFound } from 'next/navigation';
|
|
113
|
+
import {
|
|
114
|
+
APIPage,
|
|
115
|
+
ExportIndexPage,
|
|
116
|
+
type OpenPkgIndexPageData,
|
|
117
|
+
type OpenPkgPageData,
|
|
118
|
+
} from '@openpkg-ts/fumadocs-adapter';
|
|
119
|
+
|
|
120
|
+
export default async function ReferencePage({ params }) {
|
|
121
|
+
const { slug } = await params;
|
|
122
|
+
const page = apiSource.getPage(slug);
|
|
123
|
+
if (!page) notFound();
|
|
124
|
+
|
|
125
|
+
const data = page.data;
|
|
126
|
+
|
|
127
|
+
// Index page
|
|
128
|
+
if ('isIndex' in data && data.isIndex) {
|
|
129
|
+
return (
|
|
130
|
+
<ExportIndexPage
|
|
131
|
+
spec={data.spec}
|
|
132
|
+
baseHref="/docs/reference"
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Individual export page
|
|
138
|
+
return (
|
|
139
|
+
<APIPage
|
|
140
|
+
spec={data.spec}
|
|
141
|
+
id={data.export.id}
|
|
142
|
+
baseHref="/docs/reference"
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function generateStaticParams() {
|
|
148
|
+
return apiSource.generateParams();
|
|
149
|
+
}
|
|
150
|
+
```
|
|
123
151
|
|
|
124
152
|
```tsx
|
|
125
|
-
// app/docs/(
|
|
126
|
-
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
|
|
153
|
+
// app/docs/(reference)/reference/layout.tsx
|
|
127
154
|
import { apiSource } from '@/lib/api-source';
|
|
155
|
+
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
|
|
128
156
|
|
|
129
|
-
export default function
|
|
157
|
+
export default function ReferenceLayout({ children }) {
|
|
130
158
|
return <DocsLayout tree={apiSource.pageTree}>{children}</DocsLayout>;
|
|
131
159
|
}
|
|
132
160
|
```
|
|
133
161
|
|
|
162
|
+
## openpkgSource Options
|
|
163
|
+
|
|
164
|
+
| Option | Type | Default | Description |
|
|
165
|
+
|--------|------|---------|-------------|
|
|
166
|
+
| `spec` | `OpenPkg` | required | The OpenPkg spec object |
|
|
167
|
+
| `baseDir` | `string` | `'api'` | Base directory for generated pages |
|
|
168
|
+
| `mode` | `'pages' \| 'single'` | `'pages'` | Navigation mode |
|
|
169
|
+
| `indexPage` | `boolean` | `true` | Generate index page (pages mode only) |
|
|
170
|
+
|
|
171
|
+
## FullAPIReferencePage Props
|
|
172
|
+
|
|
173
|
+
| Prop | Type | Default | Description |
|
|
174
|
+
|------|------|---------|-------------|
|
|
175
|
+
| `spec` | `OpenPkg` | required | The OpenPkg spec |
|
|
176
|
+
| `title` | `string` | spec.meta.name | Page title |
|
|
177
|
+
| `description` | `ReactNode` | - | Description below title |
|
|
178
|
+
| `showTOC` | `boolean` | `false` | Show sticky sidebar TOC |
|
|
179
|
+
| `showFilters` | `boolean` | `true` | Show kind filter buttons |
|
|
180
|
+
| `kinds` | `SpecExportKind[]` | all | Filter to specific kinds |
|
|
181
|
+
|
|
134
182
|
## CSS Variables Reference
|
|
135
183
|
|
|
136
184
|
### DocsKit Variables (`--dk-*`)
|
|
@@ -144,10 +192,6 @@ export default function APILayout({ children }) {
|
|
|
144
192
|
| `--dk-tab-active-foreground` | Active tab text |
|
|
145
193
|
| `--dk-selection` | Text selection color |
|
|
146
194
|
|
|
147
|
-
### CodeHike Variables (`--ch-*`)
|
|
148
|
-
|
|
149
|
-
GitHub syntax theme colors (`--ch-0` through `--ch-26`). Automatically adapts to light/dark mode.
|
|
150
|
-
|
|
151
195
|
### API Reference Variables (`--api-*`)
|
|
152
196
|
|
|
153
197
|
| Variable | Purpose |
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,21 @@ var KIND_LABELS = {
|
|
|
24
24
|
reference: "References",
|
|
25
25
|
external: "External"
|
|
26
26
|
};
|
|
27
|
+
var KIND_SLUGS = {
|
|
28
|
+
function: "functions",
|
|
29
|
+
class: "classes",
|
|
30
|
+
interface: "interfaces",
|
|
31
|
+
type: "types",
|
|
32
|
+
enum: "enums",
|
|
33
|
+
variable: "variables",
|
|
34
|
+
namespace: "namespaces",
|
|
35
|
+
module: "modules",
|
|
36
|
+
reference: "references",
|
|
37
|
+
external: "externals"
|
|
38
|
+
};
|
|
39
|
+
function pluralizeKind(kind) {
|
|
40
|
+
return KIND_SLUGS[kind] || `${kind}s`;
|
|
41
|
+
}
|
|
27
42
|
function openpkgSource(options) {
|
|
28
43
|
const { baseDir = "api", indexPage = true, mode = "pages" } = options;
|
|
29
44
|
const docs = "getAllExports" in options.spec ? options.spec : createDocs(options.spec);
|
|
@@ -67,7 +82,7 @@ function openpkgSource(options) {
|
|
|
67
82
|
}
|
|
68
83
|
for (const kind of KIND_ORDER) {
|
|
69
84
|
if (groupedByKind.has(kind)) {
|
|
70
|
-
rootPages.push(`...${kind}
|
|
85
|
+
rootPages.push(`...${pluralizeKind(kind)}`);
|
|
71
86
|
}
|
|
72
87
|
}
|
|
73
88
|
files.push({
|
|
@@ -96,8 +111,9 @@ function openpkgSource(options) {
|
|
|
96
111
|
const kindExports = groupedByKind.get(kind);
|
|
97
112
|
if (!kindExports || kindExports.length === 0)
|
|
98
113
|
continue;
|
|
99
|
-
const
|
|
100
|
-
const
|
|
114
|
+
const kindSlug = pluralizeKind(kind);
|
|
115
|
+
const kindDir = `${baseDir}/${kindSlug}`;
|
|
116
|
+
const label = KIND_LABELS[kind] || kindSlug;
|
|
101
117
|
const sortedExports = [...kindExports].sort((a, b) => a.name.localeCompare(b.name));
|
|
102
118
|
files.push({
|
|
103
119
|
type: "meta",
|
|
@@ -112,7 +128,7 @@ function openpkgSource(options) {
|
|
|
112
128
|
files.push({
|
|
113
129
|
type: "page",
|
|
114
130
|
path: `${kindDir}/${exp.id}.mdx`,
|
|
115
|
-
slugs: [
|
|
131
|
+
slugs: [kindSlug, exp.id],
|
|
116
132
|
data: {
|
|
117
133
|
title: exp.name,
|
|
118
134
|
description: exp.description,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/fumadocs-adapter",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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.6.
|
|
31
|
+
"@openpkg-ts/doc-generator": "^0.6.1"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"fumadocs-core": "^16.0.0",
|