@doccov/fumadocs-adapter 0.0.1 → 0.0.3
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/CHANGELOG.md +13 -0
- package/bunup.config.ts +0 -1
- package/dist/components/index.d.ts +76 -76
- package/dist/components/index.js +11 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/shared/{chunk-pqaj3kdh.js → chunk-edfpjshy.js} +633 -632
- package/package.json +1 -2
- package/src/components/api-page.tsx +4 -10
- package/src/components/class-page.tsx +4 -10
- package/src/components/code-example.tsx +6 -2
- package/src/components/collapsible-method.tsx +12 -24
- package/src/components/coverage-badge.tsx +19 -7
- package/src/components/enum-page.tsx +13 -7
- package/src/components/examples.tsx +17 -6
- package/src/components/expandable-property.tsx +14 -17
- package/src/components/function-page.tsx +9 -12
- package/src/components/index.ts +29 -44
- package/src/components/interface-page.tsx +19 -8
- package/src/components/members-section.tsx +12 -10
- package/src/components/method-section.tsx +4 -1
- package/src/components/parameter-card.tsx +3 -8
- package/src/components/signature.tsx +1 -3
- package/src/components/type-table.tsx +7 -12
- package/src/components/variable-page.tsx +3 -9
- package/src/index.ts +3 -4
- package/src/server.ts +0 -1
- package/src/styles/docskit.css +8 -7
- package/tsconfig.json +0 -1
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import type { OpenPkg
|
|
3
|
+
import type { OpenPkg } from '@openpkg-ts/spec';
|
|
4
4
|
import type { OpenPkgInstance } from '../server';
|
|
5
|
-
import { FunctionPage } from './function-page';
|
|
6
5
|
import { ClassPage } from './class-page';
|
|
7
|
-
import { InterfacePage } from './interface-page';
|
|
8
6
|
import { EnumPage } from './enum-page';
|
|
7
|
+
import { FunctionPage } from './function-page';
|
|
8
|
+
import { InterfacePage } from './interface-page';
|
|
9
9
|
import { VariablePage } from './variable-page';
|
|
10
10
|
|
|
11
11
|
export interface APIPageProps {
|
|
@@ -47,7 +47,7 @@ function NotFound({ id }: { id: string }) {
|
|
|
47
47
|
* <APIPage instance={openpkg} id="createClient" />
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
|
-
export function APIPage({ spec, instance, id }: APIPageProps) {
|
|
50
|
+
export function APIPage({ spec, instance, id }: APIPageProps): React.ReactNode {
|
|
51
51
|
const resolvedSpec = spec ?? instance?.spec;
|
|
52
52
|
|
|
53
53
|
if (!resolvedSpec) {
|
|
@@ -78,13 +78,7 @@ export function APIPage({ spec, instance, id }: APIPageProps) {
|
|
|
78
78
|
return <InterfacePage {...pageProps} />;
|
|
79
79
|
case 'enum':
|
|
80
80
|
return <EnumPage {...pageProps} />;
|
|
81
|
-
case 'variable':
|
|
82
|
-
case 'namespace':
|
|
83
|
-
case 'module':
|
|
84
|
-
case 'reference':
|
|
85
|
-
case 'external':
|
|
86
81
|
default:
|
|
87
82
|
return <VariablePage {...pageProps} />;
|
|
88
83
|
}
|
|
89
84
|
}
|
|
90
|
-
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import type { OpenPkg, SpecExport, SpecMember } from '@openpkg-ts/spec';
|
|
4
4
|
import { CodeExample } from './code-example';
|
|
5
|
+
import { CollapsibleMethod } from './collapsible-method';
|
|
5
6
|
import { CoverageBadge } from './coverage-badge';
|
|
6
7
|
import { ExpandableProperty } from './expandable-property';
|
|
7
|
-
import { CollapsibleMethod } from './collapsible-method';
|
|
8
8
|
|
|
9
9
|
export interface ClassPageProps {
|
|
10
10
|
export: SpecExport;
|
|
@@ -19,7 +19,6 @@ function formatSchema(schema: unknown): string {
|
|
|
19
19
|
if (s.$ref && typeof s.$ref === 'string') {
|
|
20
20
|
return s.$ref.replace('#/types/', '');
|
|
21
21
|
}
|
|
22
|
-
if (s.tsType) return String(s.tsType);
|
|
23
22
|
if (s.type) return String(s.type);
|
|
24
23
|
}
|
|
25
24
|
return 'unknown';
|
|
@@ -63,7 +62,7 @@ function PropertyItem({ member }: { member: SpecMember }) {
|
|
|
63
62
|
);
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
export function ClassPage({ export: exp, spec }: ClassPageProps) {
|
|
65
|
+
export function ClassPage({ export: exp, spec: _spec }: ClassPageProps): React.ReactNode {
|
|
67
66
|
const hasExamples = exp.examples && exp.examples.length > 0;
|
|
68
67
|
|
|
69
68
|
// Group members
|
|
@@ -79,9 +78,7 @@ export function ClassPage({ export: exp, spec }: ClassPageProps) {
|
|
|
79
78
|
<div className="space-y-8">
|
|
80
79
|
{/* Description */}
|
|
81
80
|
{exp.description && (
|
|
82
|
-
<p className="text-fd-muted-foreground text-lg leading-relaxed">
|
|
83
|
-
{exp.description}
|
|
84
|
-
</p>
|
|
81
|
+
<p className="text-fd-muted-foreground text-lg leading-relaxed">{exp.description}</p>
|
|
85
82
|
)}
|
|
86
83
|
|
|
87
84
|
{/* Declaration */}
|
|
@@ -150,10 +147,7 @@ export function ClassPage({ export: exp, spec }: ClassPageProps) {
|
|
|
150
147
|
<h3 className="text-sm font-semibold uppercase tracking-wide text-fd-muted-foreground mb-4">
|
|
151
148
|
Example
|
|
152
149
|
</h3>
|
|
153
|
-
<CodeExample
|
|
154
|
-
code={exp.examples![0]}
|
|
155
|
-
filename={`${exp.name.toLowerCase()}.ts`}
|
|
156
|
-
/>
|
|
150
|
+
<CodeExample code={exp.examples![0]} filename={`${exp.name.toLowerCase()}.ts`} />
|
|
157
151
|
</div>
|
|
158
152
|
)}
|
|
159
153
|
</div>
|
|
@@ -25,9 +25,13 @@ function cleanCode(code: string): string {
|
|
|
25
25
|
return cleaned;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function CodeExample({
|
|
28
|
+
export function CodeExample({
|
|
29
|
+
code,
|
|
30
|
+
filename = 'example.ts',
|
|
31
|
+
language = 'typescript',
|
|
32
|
+
}: CodeExampleProps): React.ReactNode {
|
|
29
33
|
const cleaned = cleanCode(code);
|
|
30
|
-
|
|
34
|
+
|
|
31
35
|
// Build RawCode object for ClientDocsKitCode
|
|
32
36
|
// The meta field uses flags: 'c' for copyButton, 'n' for lineNumbers
|
|
33
37
|
const codeblock: RawCode = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useState, useEffect } from 'react';
|
|
4
3
|
import type { SpecMember, SpecSchema } from '@openpkg-ts/spec';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
5
|
import { ExpandableProperty } from './expandable-property';
|
|
6
6
|
|
|
7
7
|
export interface CollapsibleMethodProps {
|
|
@@ -18,6 +18,7 @@ function ChevronIcon({ expanded }: { expanded: boolean }) {
|
|
|
18
18
|
viewBox="0 0 16 16"
|
|
19
19
|
fill="none"
|
|
20
20
|
className={`transition-transform duration-200 ${expanded ? 'rotate-90' : ''}`}
|
|
21
|
+
aria-hidden="true"
|
|
21
22
|
>
|
|
22
23
|
<path
|
|
23
24
|
d="M6 4L10 8L6 12"
|
|
@@ -38,23 +39,13 @@ function formatSchema(schema: unknown): string {
|
|
|
38
39
|
if (s.$ref && typeof s.$ref === 'string') {
|
|
39
40
|
return s.$ref.replace('#/types/', '');
|
|
40
41
|
}
|
|
41
|
-
if (s.tsType) {
|
|
42
|
-
const tsType = String(s.tsType);
|
|
43
|
-
if (tsType.length > 40) return tsType.slice(0, 37) + '...';
|
|
44
|
-
return tsType;
|
|
45
|
-
}
|
|
46
42
|
if (s.type) return String(s.type);
|
|
47
43
|
}
|
|
48
44
|
return 'unknown';
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
function formatReturnType(returns: { schema?: SpecSchema
|
|
47
|
+
function formatReturnType(returns: { schema?: SpecSchema } | undefined): string {
|
|
52
48
|
if (!returns) return 'void';
|
|
53
|
-
if (returns.tsType) {
|
|
54
|
-
const t = returns.tsType;
|
|
55
|
-
if (t.length > 40) return t.slice(0, 37) + '...';
|
|
56
|
-
return t;
|
|
57
|
-
}
|
|
58
49
|
return formatSchema(returns.schema);
|
|
59
50
|
}
|
|
60
51
|
|
|
@@ -68,7 +59,10 @@ function formatParamPreview(params: { name?: string }[] | undefined): string {
|
|
|
68
59
|
* Collapsible method section with expand/collapse behavior
|
|
69
60
|
* Shows compact signature when collapsed, full details when expanded
|
|
70
61
|
*/
|
|
71
|
-
export function CollapsibleMethod({
|
|
62
|
+
export function CollapsibleMethod({
|
|
63
|
+
member,
|
|
64
|
+
defaultExpanded = false,
|
|
65
|
+
}: CollapsibleMethodProps): React.ReactNode {
|
|
72
66
|
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
73
67
|
|
|
74
68
|
const sig = member.signatures?.[0];
|
|
@@ -90,12 +84,10 @@ export function CollapsibleMethod({ member, defaultExpanded = false }: Collapsib
|
|
|
90
84
|
}, [member.name]);
|
|
91
85
|
|
|
92
86
|
return (
|
|
93
|
-
<div
|
|
94
|
-
id={member.name}
|
|
95
|
-
className="scroll-mt-20 border-b border-fd-border last:border-0"
|
|
96
|
-
>
|
|
87
|
+
<div id={member.name} className="scroll-mt-20 border-b border-fd-border last:border-0">
|
|
97
88
|
{/* Clickable header */}
|
|
98
89
|
<button
|
|
90
|
+
type="button"
|
|
99
91
|
onClick={() => setExpanded(!expanded)}
|
|
100
92
|
className="w-full flex items-center gap-3 py-4 px-1 text-left hover:bg-fd-muted/30 transition-colors cursor-pointer group"
|
|
101
93
|
>
|
|
@@ -111,9 +103,7 @@ export function CollapsibleMethod({ member, defaultExpanded = false }: Collapsib
|
|
|
111
103
|
<span className="text-fd-muted-foreground font-normal">({paramPreview})</span>
|
|
112
104
|
</span>
|
|
113
105
|
<span className="text-fd-muted-foreground">→</span>
|
|
114
|
-
<span className="font-mono text-sm text-fd-muted-foreground truncate">
|
|
115
|
-
{returnType}
|
|
116
|
-
</span>
|
|
106
|
+
<span className="font-mono text-sm text-fd-muted-foreground truncate">{returnType}</span>
|
|
117
107
|
</div>
|
|
118
108
|
|
|
119
109
|
{/* Badges */}
|
|
@@ -141,9 +131,7 @@ export function CollapsibleMethod({ member, defaultExpanded = false }: Collapsib
|
|
|
141
131
|
<div className="pb-6 pl-8 pr-4">
|
|
142
132
|
{/* Description */}
|
|
143
133
|
{member.description && (
|
|
144
|
-
<p className="text-fd-muted-foreground mb-4 leading-relaxed">
|
|
145
|
-
{member.description}
|
|
146
|
-
</p>
|
|
134
|
+
<p className="text-fd-muted-foreground mb-4 leading-relaxed">{member.description}</p>
|
|
147
135
|
)}
|
|
148
136
|
|
|
149
137
|
{/* Parameters */}
|
|
@@ -168,7 +156,7 @@ export function CollapsibleMethod({ member, defaultExpanded = false }: Collapsib
|
|
|
168
156
|
</span>
|
|
169
157
|
<div className="border-l-2 border-fd-border pl-4 py-2">
|
|
170
158
|
<span className="font-mono text-sm text-fd-muted-foreground">
|
|
171
|
-
{
|
|
159
|
+
{formatSchema(sig.returns.schema)}
|
|
172
160
|
</span>
|
|
173
161
|
{returnDescription && (
|
|
174
162
|
<p className="text-sm text-fd-muted-foreground mt-1 leading-relaxed">
|
|
@@ -10,7 +10,8 @@ export interface CoverageBadgeProps {
|
|
|
10
10
|
|
|
11
11
|
function getScoreColor(score: number): string {
|
|
12
12
|
if (score >= 80) return 'text-green-600 dark:text-green-400 bg-green-500/10 border-green-500/20';
|
|
13
|
-
if (score >= 60)
|
|
13
|
+
if (score >= 60)
|
|
14
|
+
return 'text-yellow-600 dark:text-yellow-400 bg-yellow-500/10 border-yellow-500/20';
|
|
14
15
|
return 'text-red-600 dark:text-red-400 bg-red-500/10 border-red-500/20';
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -18,7 +19,11 @@ function formatSignal(signal: string): string {
|
|
|
18
19
|
return signal.charAt(0).toUpperCase() + signal.slice(1);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export function CoverageBadge({
|
|
22
|
+
export function CoverageBadge({
|
|
23
|
+
docs,
|
|
24
|
+
showMissing = true,
|
|
25
|
+
showDrift = true,
|
|
26
|
+
}: CoverageBadgeProps): React.ReactNode {
|
|
22
27
|
const score = docs.coverageScore;
|
|
23
28
|
const hasMissing = showMissing && docs.missing && docs.missing.length > 0;
|
|
24
29
|
const hasDrift = showDrift && docs.drift && docs.drift.length > 0;
|
|
@@ -31,7 +36,13 @@ export function CoverageBadge({ docs, showMissing = true, showDrift = true }: Co
|
|
|
31
36
|
<div
|
|
32
37
|
className={`inline-flex items-center gap-2 px-3 py-1.5 rounded-md border text-sm font-medium ${getScoreColor(score)}`}
|
|
33
38
|
>
|
|
34
|
-
<svg
|
|
39
|
+
<svg
|
|
40
|
+
className="w-4 h-4"
|
|
41
|
+
fill="none"
|
|
42
|
+
stroke="currentColor"
|
|
43
|
+
viewBox="0 0 24 24"
|
|
44
|
+
aria-hidden="true"
|
|
45
|
+
>
|
|
35
46
|
<path
|
|
36
47
|
strokeLinecap="round"
|
|
37
48
|
strokeLinejoin="round"
|
|
@@ -58,10 +69,12 @@ export function CoverageBadge({ docs, showMissing = true, showDrift = true }: Co
|
|
|
58
69
|
|
|
59
70
|
{hasDrift && (
|
|
60
71
|
<div className="rounded-md bg-red-500/10 border border-red-500/20 px-3 py-2">
|
|
61
|
-
<p className="text-sm font-medium text-red-600 dark:text-red-400 mb-1">
|
|
72
|
+
<p className="text-sm font-medium text-red-600 dark:text-red-400 mb-1">
|
|
73
|
+
Documentation Drift
|
|
74
|
+
</p>
|
|
62
75
|
<ul className="text-sm text-red-600/80 dark:text-red-400/80 space-y-1">
|
|
63
|
-
{docs.drift!.map((drift
|
|
64
|
-
<li key={
|
|
76
|
+
{docs.drift!.map((drift) => (
|
|
77
|
+
<li key={`${drift.type}-${drift.issue}`} className="flex flex-col">
|
|
65
78
|
<span className="font-medium">{drift.type}</span>
|
|
66
79
|
<span className="text-xs opacity-80">{drift.issue}</span>
|
|
67
80
|
{drift.suggestion && (
|
|
@@ -77,4 +90,3 @@ export function CoverageBadge({ docs, showMissing = true, showDrift = true }: Co
|
|
|
77
90
|
</div>
|
|
78
91
|
);
|
|
79
92
|
}
|
|
80
|
-
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import type { OpenPkg, SpecExport } from '@openpkg-ts/spec';
|
|
4
|
-
import { Signature } from './signature';
|
|
5
|
-
import { ExamplesSection } from './examples';
|
|
6
4
|
import { CoverageBadge } from './coverage-badge';
|
|
5
|
+
import { ExamplesSection } from './examples';
|
|
6
|
+
import { Signature } from './signature';
|
|
7
7
|
|
|
8
8
|
export interface EnumPageProps {
|
|
9
9
|
export: SpecExport;
|
|
10
10
|
spec: OpenPkg;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function EnumPage({ export: exp, spec }: EnumPageProps) {
|
|
13
|
+
export function EnumPage({ export: exp, spec: _spec }: EnumPageProps): React.ReactNode {
|
|
14
14
|
const members = exp.members ?? [];
|
|
15
15
|
|
|
16
16
|
return (
|
|
@@ -35,7 +35,9 @@ export function EnumPage({ export: exp, spec }: EnumPageProps) {
|
|
|
35
35
|
<thead>
|
|
36
36
|
<tr className="border-b border-fd-border">
|
|
37
37
|
<th className="text-left py-2 px-3 font-medium text-fd-muted-foreground">Name</th>
|
|
38
|
-
<th className="text-left py-2 px-3 font-medium text-fd-muted-foreground">
|
|
38
|
+
<th className="text-left py-2 px-3 font-medium text-fd-muted-foreground">
|
|
39
|
+
Value
|
|
40
|
+
</th>
|
|
39
41
|
<th className="text-left py-2 px-3 font-medium text-fd-muted-foreground">
|
|
40
42
|
Description
|
|
41
43
|
</th>
|
|
@@ -47,12 +49,17 @@ export function EnumPage({ export: exp, spec }: EnumPageProps) {
|
|
|
47
49
|
const value =
|
|
48
50
|
member.schema !== undefined
|
|
49
51
|
? typeof member.schema === 'object' && member.schema !== null
|
|
50
|
-
? (member.schema as
|
|
52
|
+
? ((member.schema as Record<string, unknown>).const ??
|
|
53
|
+
(member.schema as Record<string, unknown>).default ??
|
|
54
|
+
'-')
|
|
51
55
|
: member.schema
|
|
52
56
|
: '-';
|
|
53
57
|
|
|
54
58
|
return (
|
|
55
|
-
<tr
|
|
59
|
+
<tr
|
|
60
|
+
key={member.name ?? index}
|
|
61
|
+
className="border-b border-fd-border last:border-0"
|
|
62
|
+
>
|
|
56
63
|
<td className="py-2 px-3 align-top">
|
|
57
64
|
<code className="text-fd-primary font-mono text-xs bg-fd-secondary px-1.5 py-0.5 rounded">
|
|
58
65
|
{member.name}
|
|
@@ -83,4 +90,3 @@ export function EnumPage({ export: exp, spec }: EnumPageProps) {
|
|
|
83
90
|
</div>
|
|
84
91
|
);
|
|
85
92
|
}
|
|
86
|
-
|
|
@@ -23,11 +23,23 @@ function CopyButton({ text }: { text: string }) {
|
|
|
23
23
|
aria-label="Copy code"
|
|
24
24
|
>
|
|
25
25
|
{copied ? (
|
|
26
|
-
<svg
|
|
26
|
+
<svg
|
|
27
|
+
className="w-4 h-4"
|
|
28
|
+
fill="none"
|
|
29
|
+
stroke="currentColor"
|
|
30
|
+
viewBox="0 0 24 24"
|
|
31
|
+
aria-hidden="true"
|
|
32
|
+
>
|
|
27
33
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
|
28
34
|
</svg>
|
|
29
35
|
) : (
|
|
30
|
-
<svg
|
|
36
|
+
<svg
|
|
37
|
+
className="w-4 h-4"
|
|
38
|
+
fill="none"
|
|
39
|
+
stroke="currentColor"
|
|
40
|
+
viewBox="0 0 24 24"
|
|
41
|
+
aria-hidden="true"
|
|
42
|
+
>
|
|
31
43
|
<path
|
|
32
44
|
strokeLinecap="round"
|
|
33
45
|
strokeLinejoin="round"
|
|
@@ -40,7 +52,7 @@ function CopyButton({ text }: { text: string }) {
|
|
|
40
52
|
);
|
|
41
53
|
}
|
|
42
54
|
|
|
43
|
-
export function ExamplesSection({ examples }: ExamplesSectionProps) {
|
|
55
|
+
export function ExamplesSection({ examples }: ExamplesSectionProps): React.ReactNode {
|
|
44
56
|
const [activeIndex, setActiveIndex] = useState(0);
|
|
45
57
|
|
|
46
58
|
if (!examples?.length) return null;
|
|
@@ -53,9 +65,9 @@ export function ExamplesSection({ examples }: ExamplesSectionProps) {
|
|
|
53
65
|
|
|
54
66
|
{showTabs && (
|
|
55
67
|
<div className="flex gap-1 mb-2 border-b border-fd-border">
|
|
56
|
-
{examples.map((
|
|
68
|
+
{examples.map((example, index) => (
|
|
57
69
|
<button
|
|
58
|
-
key={index}
|
|
70
|
+
key={`example-${typeof example === 'string' ? example.slice(0, 20) : index}`}
|
|
59
71
|
type="button"
|
|
60
72
|
onClick={() => setActiveIndex(index)}
|
|
61
73
|
className={`px-3 py-1.5 text-sm font-medium transition-colors ${
|
|
@@ -81,4 +93,3 @@ export function ExamplesSection({ examples }: ExamplesSectionProps) {
|
|
|
81
93
|
</div>
|
|
82
94
|
);
|
|
83
95
|
}
|
|
84
|
-
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import type { SpecSchema, SpecSignatureParameter } from '@openpkg-ts/spec';
|
|
3
4
|
import { useState } from 'react';
|
|
4
|
-
import type { SpecSignatureParameter, SpecSchema } from '@openpkg-ts/spec';
|
|
5
5
|
|
|
6
6
|
export interface ExpandablePropertyProps {
|
|
7
7
|
param: SpecSignatureParameter;
|
|
@@ -24,6 +24,7 @@ function ChevronIcon({ expanded }: { expanded: boolean }) {
|
|
|
24
24
|
viewBox="0 0 12 12"
|
|
25
25
|
fill="none"
|
|
26
26
|
className={`transition-transform duration-200 ${expanded ? 'rotate-90' : ''}`}
|
|
27
|
+
aria-hidden="true"
|
|
27
28
|
>
|
|
28
29
|
<path
|
|
29
30
|
d="M4.5 2.5L8 6L4.5 9.5"
|
|
@@ -42,15 +43,6 @@ function formatType(schema: SpecSchema): string {
|
|
|
42
43
|
if (typeof schema === 'object' && schema !== null) {
|
|
43
44
|
const s = schema as Record<string, unknown>;
|
|
44
45
|
|
|
45
|
-
// Use tsType if available (most readable)
|
|
46
|
-
if (s.tsType && typeof s.tsType === 'string') {
|
|
47
|
-
const tsType = s.tsType as string;
|
|
48
|
-
if (tsType.length > 80) {
|
|
49
|
-
return tsType.slice(0, 77) + '...';
|
|
50
|
-
}
|
|
51
|
-
return tsType;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
46
|
// Handle refs
|
|
55
47
|
if (s.$ref && typeof s.$ref === 'string') {
|
|
56
48
|
return (s.$ref as string).replace('#/types/', '');
|
|
@@ -58,8 +50,8 @@ function formatType(schema: SpecSchema): string {
|
|
|
58
50
|
|
|
59
51
|
// Handle enums
|
|
60
52
|
if (s.enum && Array.isArray(s.enum)) {
|
|
61
|
-
const enumVals = (s.enum as unknown[]).map(v => JSON.stringify(v)).join(' | ');
|
|
62
|
-
if (enumVals.length > 50) return enumVals.slice(0, 47)
|
|
53
|
+
const enumVals = (s.enum as unknown[]).map((v) => JSON.stringify(v)).join(' | ');
|
|
54
|
+
if (enumVals.length > 50) return `${enumVals.slice(0, 47)}...`;
|
|
63
55
|
return enumVals;
|
|
64
56
|
}
|
|
65
57
|
|
|
@@ -108,7 +100,12 @@ function countProperties(schema: SpecSchema): number {
|
|
|
108
100
|
/**
|
|
109
101
|
* Nested property row with expandable nested objects
|
|
110
102
|
*/
|
|
111
|
-
export function NestedProperty({
|
|
103
|
+
export function NestedProperty({
|
|
104
|
+
name,
|
|
105
|
+
schema,
|
|
106
|
+
required = false,
|
|
107
|
+
depth = 0,
|
|
108
|
+
}: NestedPropertyProps): React.ReactNode {
|
|
112
109
|
const [expanded, setExpanded] = useState(false);
|
|
113
110
|
const type = formatType(schema);
|
|
114
111
|
const nestedProps = getNestedProperties(schema);
|
|
@@ -135,15 +132,14 @@ export function NestedProperty({ name, schema, required = false, depth = 0 }: Ne
|
|
|
135
132
|
</span>
|
|
136
133
|
</div>
|
|
137
134
|
{description && (
|
|
138
|
-
<p className="text-sm text-fd-muted-foreground mt-0.5 leading-relaxed">
|
|
139
|
-
{description}
|
|
140
|
-
</p>
|
|
135
|
+
<p className="text-sm text-fd-muted-foreground mt-0.5 leading-relaxed">{description}</p>
|
|
141
136
|
)}
|
|
142
137
|
</div>
|
|
143
138
|
|
|
144
139
|
{/* Expand badge for nested objects */}
|
|
145
140
|
{hasNested && (
|
|
146
141
|
<button
|
|
142
|
+
type="button"
|
|
147
143
|
onClick={() => setExpanded(!expanded)}
|
|
148
144
|
className="flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-md
|
|
149
145
|
bg-fd-muted text-fd-muted-foreground hover:bg-fd-accent hover:text-fd-accent-foreground
|
|
@@ -177,7 +173,7 @@ export function NestedProperty({ name, schema, required = false, depth = 0 }: Ne
|
|
|
177
173
|
* Top-level expandable property for method parameters
|
|
178
174
|
* Entry point for rendering a parameter with progressive disclosure
|
|
179
175
|
*/
|
|
180
|
-
export function ExpandableProperty({ param, depth = 0 }: ExpandablePropertyProps) {
|
|
176
|
+
export function ExpandableProperty({ param, depth = 0 }: ExpandablePropertyProps): React.ReactNode {
|
|
181
177
|
const [expanded, setExpanded] = useState(false);
|
|
182
178
|
const type = formatType(param.schema);
|
|
183
179
|
const isOptional = param.required === false;
|
|
@@ -210,6 +206,7 @@ export function ExpandableProperty({ param, depth = 0 }: ExpandablePropertyProps
|
|
|
210
206
|
{/* Expand badge for nested objects */}
|
|
211
207
|
{hasNested && (
|
|
212
208
|
<button
|
|
209
|
+
type="button"
|
|
213
210
|
onClick={() => setExpanded(!expanded)}
|
|
214
211
|
className="flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-md
|
|
215
212
|
bg-fd-muted text-fd-muted-foreground hover:bg-fd-accent hover:text-fd-accent-foreground
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import type { OpenPkg, SpecExport } from '@openpkg-ts/spec';
|
|
4
|
-
import { ParameterCard } from './parameter-card';
|
|
5
4
|
import { CodeExample } from './code-example';
|
|
6
5
|
import { CoverageBadge } from './coverage-badge';
|
|
6
|
+
import { ParameterCard } from './parameter-card';
|
|
7
7
|
|
|
8
8
|
export interface FunctionPageProps {
|
|
9
9
|
export: SpecExport;
|
|
@@ -18,13 +18,12 @@ function formatSchema(schema: unknown): string {
|
|
|
18
18
|
if (s.$ref && typeof s.$ref === 'string') {
|
|
19
19
|
return s.$ref.replace('#/types/', '');
|
|
20
20
|
}
|
|
21
|
-
if (s.tsType) return String(s.tsType);
|
|
22
21
|
if (s.type) return String(s.type);
|
|
23
22
|
}
|
|
24
23
|
return 'unknown';
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
export function FunctionPage({ export: exp, spec }: FunctionPageProps) {
|
|
26
|
+
export function FunctionPage({ export: exp, spec }: FunctionPageProps): React.ReactNode {
|
|
28
27
|
const sig = exp.signatures?.[0];
|
|
29
28
|
const hasExamples = exp.examples && exp.examples.length > 0;
|
|
30
29
|
const hasParams = sig?.parameters && sig.parameters.length > 0;
|
|
@@ -33,27 +32,25 @@ export function FunctionPage({ export: exp, spec }: FunctionPageProps) {
|
|
|
33
32
|
<div className="space-y-6 not-prose">
|
|
34
33
|
{/* Description */}
|
|
35
34
|
{exp.description && (
|
|
36
|
-
<p className="text-fd-muted-foreground leading-relaxed">
|
|
37
|
-
{exp.description}
|
|
38
|
-
</p>
|
|
35
|
+
<p className="text-fd-muted-foreground leading-relaxed">{exp.description}</p>
|
|
39
36
|
)}
|
|
40
37
|
|
|
41
38
|
{/* Returns */}
|
|
42
39
|
{sig?.returns && (
|
|
43
40
|
<p className="text-fd-muted-foreground text-sm">
|
|
44
41
|
<span className="font-medium text-fd-foreground">Returns:</span>{' '}
|
|
45
|
-
{sig.returns.description || `A ${
|
|
42
|
+
{sig.returns.description || `A ${formatSchema(sig.returns.schema)}`}
|
|
46
43
|
</p>
|
|
47
44
|
)}
|
|
48
45
|
|
|
49
46
|
{/* Two-column layout - using inline styles to override prose */}
|
|
50
|
-
<div
|
|
47
|
+
<div
|
|
51
48
|
className="not-prose"
|
|
52
|
-
style={{
|
|
49
|
+
style={{
|
|
53
50
|
display: hasExamples ? 'grid' : 'block',
|
|
54
51
|
gridTemplateColumns: hasExamples ? 'repeat(2, minmax(0, 1fr))' : undefined,
|
|
55
52
|
gap: '2rem',
|
|
56
|
-
alignItems: 'start'
|
|
53
|
+
alignItems: 'start',
|
|
57
54
|
}}
|
|
58
55
|
>
|
|
59
56
|
{/* Left column: Parameters */}
|
|
@@ -78,8 +75,8 @@ export function FunctionPage({ export: exp, spec }: FunctionPageProps) {
|
|
|
78
75
|
<h3 className="text-sm font-semibold uppercase tracking-wide text-fd-muted-foreground mb-4">
|
|
79
76
|
Example
|
|
80
77
|
</h3>
|
|
81
|
-
<CodeExample
|
|
82
|
-
code={exp.examples![0]}
|
|
78
|
+
<CodeExample
|
|
79
|
+
code={exp.examples![0]}
|
|
83
80
|
filename={`${exp.name.toLowerCase().replace(/[^a-z0-9]/g, '-')}.ts`}
|
|
84
81
|
/>
|
|
85
82
|
</div>
|
package/src/components/index.ts
CHANGED
|
@@ -1,51 +1,36 @@
|
|
|
1
1
|
// Main component
|
|
2
|
-
export { APIPage } from './api-page';
|
|
3
|
-
export type { APIPageProps } from './api-page';
|
|
4
|
-
|
|
5
|
-
// Page components
|
|
6
|
-
export { FunctionPage } from './function-page';
|
|
7
|
-
export type { FunctionPageProps } from './function-page';
|
|
8
2
|
|
|
9
|
-
export {
|
|
3
|
+
export type { APIPageProps } from './api-page';
|
|
4
|
+
export { APIPage } from './api-page';
|
|
10
5
|
export type { ClassPageProps } from './class-page';
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
export {
|
|
6
|
+
export { ClassPage } from './class-page';
|
|
7
|
+
export type { CodeExampleProps } from './code-example';
|
|
8
|
+
export { CodeExample } from './code-example';
|
|
9
|
+
export type { CollapsibleMethodProps } from './collapsible-method';
|
|
10
|
+
export { CollapsibleMethod } from './collapsible-method';
|
|
11
|
+
export type { CoverageBadgeProps } from './coverage-badge';
|
|
12
|
+
export { CoverageBadge } from './coverage-badge';
|
|
16
13
|
export type { EnumPageProps } from './enum-page';
|
|
17
|
-
|
|
18
|
-
export { VariablePage } from './variable-page';
|
|
19
|
-
export type { VariablePageProps } from './variable-page';
|
|
20
|
-
|
|
21
|
-
// Shared components
|
|
22
|
-
export { TypeTable } from './type-table';
|
|
23
|
-
export type { TypeTableProps } from './type-table';
|
|
24
|
-
|
|
25
|
-
export { Signature } from './signature';
|
|
26
|
-
export type { SignatureProps } from './signature';
|
|
27
|
-
|
|
28
|
-
export { ExamplesSection } from './examples';
|
|
14
|
+
export { EnumPage } from './enum-page';
|
|
29
15
|
export type { ExamplesSectionProps } from './examples';
|
|
30
|
-
|
|
31
|
-
export { CoverageBadge } from './coverage-badge';
|
|
32
|
-
export type { CoverageBadgeProps } from './coverage-badge';
|
|
33
|
-
|
|
34
|
-
export { MembersSection } from './members-section';
|
|
35
|
-
export type { MembersSectionProps } from './members-section';
|
|
36
|
-
|
|
37
|
-
export { ParameterCard } from './parameter-card';
|
|
38
|
-
export type { ParameterCardProps } from './parameter-card';
|
|
39
|
-
|
|
40
|
-
export { CodeExample } from './code-example';
|
|
41
|
-
export type { CodeExampleProps } from './code-example';
|
|
42
|
-
|
|
43
|
-
export { ExpandableProperty, NestedProperty } from './expandable-property';
|
|
16
|
+
export { ExamplesSection } from './examples';
|
|
44
17
|
export type { ExpandablePropertyProps, NestedPropertyProps } from './expandable-property';
|
|
45
|
-
|
|
46
|
-
export {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export {
|
|
18
|
+
export { ExpandableProperty, NestedProperty } from './expandable-property';
|
|
19
|
+
export type { FunctionPageProps } from './function-page';
|
|
20
|
+
// Page components
|
|
21
|
+
export { FunctionPage } from './function-page';
|
|
22
|
+
export type { InterfacePageProps } from './interface-page';
|
|
23
|
+
export { InterfacePage } from './interface-page';
|
|
24
|
+
export type { MembersSectionProps } from './members-section';
|
|
25
|
+
export { MembersSection } from './members-section';
|
|
50
26
|
export type { MethodSectionProps } from './method-section';
|
|
51
|
-
|
|
27
|
+
export { MethodSection } from './method-section';
|
|
28
|
+
export type { ParameterCardProps } from './parameter-card';
|
|
29
|
+
export { ParameterCard } from './parameter-card';
|
|
30
|
+
export type { SignatureProps } from './signature';
|
|
31
|
+
export { Signature } from './signature';
|
|
32
|
+
export type { TypeTableProps } from './type-table';
|
|
33
|
+
// Shared components
|
|
34
|
+
export { TypeTable } from './type-table';
|
|
35
|
+
export type { VariablePageProps } from './variable-page';
|
|
36
|
+
export { VariablePage } from './variable-page';
|