|
1
|
"use client" |
|
2
|
|
|
3
|
import React, { useEffect } from "react" |
|
4
|
import type { DocBlock, DocPage } from "types" |
|
5
|
import { useSiteConfig } from "@/providers/SiteConfig" |
|
6
|
import { TypeList } from "@/components/TypeList" |
|
7
|
import { CodeTabs } from "@/components/CodeTabs" |
|
8
|
import { CodeTab } from "@/components/CodeTabs/Item" |
|
9
|
import { CodeBlock } from "@/components/CodeBlock" |
|
10
|
import { WorkflowDiagram } from "@/components/WorkflowDiagram" |
|
11
|
import { Note } from "@/components/Note" |
|
12
|
import { SourceCodeLink } from "@/components/SourceCodeLink" |
|
13
|
import { MarkdownContent } from "@/components/MarkdownContent" |
|
14
|
import { BadgesList } from "@/components/BadgesList" |
|
15
|
import type { BadgeVariant } from "@/components/Badge" |
|
16
|
import { H1 } from "@/components/Heading/H1" |
|
17
|
import { Mdx, DocHeading } from "./shared" |
|
18
|
import { ReferenceWorkflowEvents } from "./WorkflowEvents" |
|
19
|
import { ReferenceEventsListing } from "./EventsListing" |
|
20
|
|
|
21
|
export type ReferenceContentProps = { |
|
22
|
page: DocPage |
|
23
|
} |
|
24
|
|
|
25
|
const noteTypeMap: Record<string, React.ComponentProps<typeof Note>["type"]> = { |
|
26
|
note: "default", |
|
27
|
default: "default", |
|
28
|
warning: "warning", |
|
29
|
success: "success", |
|
30
|
error: "error", |
|
31
|
check: "check", |
|
32
|
soon: "soon", |
|
33
|
} |
|
34
|
|
|
35
|
const Block = ({ block }: { block: DocBlock }) => { |
|
36
|
switch (block.kind) { |
|
37
|
case "markdown": |
|
38
|
return <MarkdownContent>{block.html}</MarkdownContent> |
|
39
|
case "heading": |
|
40
|
return ( |
|
41
|
<DocHeading level={block.level} id={block.id}> |
|
42
|
{block.text} |
|
43
|
</DocHeading> |
|
44
|
) |
|
45
|
case "typeList": |
|
46
|
return ( |
|
47
|
<TypeList |
|
48
|
types={block.types} |
|
49
|
sectionTitle={block.sectionTitle} |
|
50
|
expandUrl={block.expandUrl} |
|
51
|
openedLevel={block.openedLevel} |
|
52
|
/> |
|
53
|
) |
|
54
|
case "workflowDiagram": |
|
55
|
return <WorkflowDiagram workflow={block.workflow} /> |
|
56
|
case "codeTabs": |
|
57
|
return ( |
|
58
|
<CodeTabs group="reference"> |
|
59
|
{block.tabs.map((tab, index) => ( |
|
60
|
<CodeTab key={index} label={tab.label} value={`${tab.label}-${index}`}> |
|
61
|
<CodeBlock source={tab.code} lang={tab.language} title={tab.title} /> |
|
62
|
</CodeTab> |
|
63
|
))} |
|
64
|
</CodeTabs> |
|
65
|
) |
|
66
|
case "note": |
|
67
|
return ( |
|
68
|
<Note type={noteTypeMap[block.variant || "note"] || "default"} title={block.title}> |
|
69
|
<MarkdownContent>{block.html}</MarkdownContent> |
|
70
|
</Note> |
|
71
|
) |
|
72
|
case "sourceCodeLink": |
|
73
|
return <SourceCodeLink link={block.link} /> |
|
74
|
case "linkList": { |
|
75
|
const { ul: Ul, li: Li, a: Anchor } = Mdx |
|
76
|
return ( |
|
77
|
<Ul> |
|
78
|
{block.items.map((item, index) => ( |
|
79
|
<Li key={index}> |
|
80
|
<Anchor href={item.href}>{item.title}</Anchor> |
|
81
|
{item.description ? ` — ${item.description}` : null} |
|
82
|
</Li> |
|
83
|
))} |
|
84
|
</Ul> |
|
85
|
) |
|
86
|
} |
|
87
|
case "workflowEvents": |
|
88
|
return <ReferenceWorkflowEvents events={block.events} /> |
|
89
|
case "eventsListing": |
|
90
|
return <ReferenceEventsListing categories={block.categories} /> |
|
91
|
case "badges": |
|
92
|
return ( |
|
93
|
<BadgesList |
|
94
|
className="mb-docs_0.5" |
|
95
|
badges={block.badges.map((badge) => ({ |
|
96
|
variant: (badge.variant as BadgeVariant) || "neutral", |
|
97
|
children: badge.label, |
|
98
|
}))} |
|
99
|
/> |
|
100
|
) |
|
101
|
case "table": |
|
102
|
return null |
|
103
|
default: |
|
104
|
return null |
|
105
|
} |
|
106
|
} |
|
107
|
|
|
108
|
/** |
|
109
|
* Renders a references {@link DocPage} (the JSON doc-model) as React, mapping |
|
110
|
* each {@link DocBlock} to the corresponding `docs-ui` component. This replaces |
|
111
|
* the runtime MDX serialization + `MDXClient` path for migrated references. |
|
112
|
*/ |
|
113
|
export const ReferenceContent = ({ page }: ReferenceContentProps) => { |
|
114
|
const { setFrontmatter, setToc } = useSiteConfig() |
|
115
|
|
|
116
|
// Reference pages always build their "On this page" TOC by scanning the |
|
117
|
// rendered headings (generate_toc), which nests them by level — matching the |
|
118
|
// MDX pipeline. Force it on and start the TOC as null so the content menu |
|
119
|
// shows its loading state until the scan runs. |
|
120
|
useEffect(() => { |
|
121
|
setFrontmatter({ ...page.frontmatter, generate_toc: true }) |
|
122
|
}, [page]) |
|
123
|
|
|
124
|
useEffect(() => { |
|
125
|
setToc(null) |
|
126
|
}, [page]) |
|
127
|
|
|
128
|
return ( |
|
129
|
<> |
|
130
|
<H1 variant="content">{page.title}</H1> |
|
131
|
{page.blocks.map((block, index) => ( |
|
132
|
<Block key={index} block={block} /> |
|
133
|
))} |
|
134
|
</> |
|
135
|
) |
|
136
|
} |