-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathmdx-components.tsx
More file actions
116 lines (110 loc) · 3.41 KB
/
mdx-components.tsx
File metadata and controls
116 lines (110 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import defaultMdxComponents from "fumadocs-ui/mdx";
import type { MDXComponents } from "mdx/types";
import React from "react";
import dynamic from "next/dynamic";
import { Mermaid } from "@/components/Mermaid";
import { Image } from "@/components/ui/image";
import { Frame } from "@/components/Frame";
import { LangTab, LangTabs, LangTabsWithTab } from "@/components/LangTabs";
import { FetchReadme } from "@/components/FetchReadme";
import {
Cards,
Card,
Steps,
FileTree,
FileTreeFile,
FileTreeFolder,
Playground,
} from "@/components/docs";
import { AvailabilityBanner } from "@/components/Availability";
import { Link as MdxLink, type LinkProps } from "@/components/ui/link";
import { Callout } from "@/components/ui/callout";
import { Table } from "@/components/ui/table";
import { LoopDiagram } from "@/components/academy/LoopDiagram";
import { OnlineLoop, OfflineLoop } from "@/components/academy/LoopSubset";
import { EvaluationEvolutionDiagram } from "@/components/academy/EvaluationEvolutionDiagram";
import { TracingHierarchyDiagram } from "@/components/academy/TracingHierarchyDiagram";
import { RagTraceViewDiagram } from "@/components/academy/RagTraceViewDiagram";
import { DatasetFieldsDiagram } from "@/components/academy/DatasetFieldsDiagram";
import { ErrorAnalysisProcessDiagram } from "@/components/academy/ErrorAnalysisProcessDiagram";
import { AgentPromptCallout } from "@/components/academy/AgentPromptCallout";
import { ManualGuideCallout } from "@/components/academy/ManualGuideCallout";
import { ManualGuideList } from "@/components/academy/ManualGuideList";
import { Details, Summary } from "@/components/Details";
// Lazy-load Video so @vidstack/react (~800 KB) is NOT bundled on every MDX page.
// It only downloads on pages that actually render a <Video> tag.
const Video = dynamic(() =>
import("@/components/Video").then((m) => ({ default: m.Video })),
);
const BLOCK_TAGS = new Set([
"div",
"details",
"summary",
"figure",
"pre",
"table",
"ul",
"ol",
"blockquote",
"section",
"article",
]);
function MdxParagraph({
children,
...props
}: React.HTMLAttributes<HTMLElement>) {
const childrenArray = React.Children.toArray(children);
const hasBlock = childrenArray.some(
(child) =>
React.isValidElement(child) &&
typeof child.type === "string" &&
BLOCK_TAGS.has(child.type),
);
if (hasBlock) {
return <div {...props}>{children}</div>;
}
return <p {...props}>{children}</p>;
}
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultMdxComponents,
a: (props: LinkProps) => <MdxLink variant="underline" {...props} />,
img: Image,
p: MdxParagraph,
Frame,
Video,
LangTabs,
Callout,
Tabs: LangTabsWithTab,
Tab: LangTab,
table: Table,
Cards,
Card,
"Cards.Card": Card,
Steps,
FileTree,
"FileTree.File": FileTreeFile,
"FileTree.Folder": FileTreeFolder,
FetchReadme,
AvailabilityBanner,
Mermaid,
Playground,
LoopDiagram,
OnlineLoop,
OfflineLoop,
EvaluationEvolutionDiagram,
TracingHierarchyDiagram,
RagTraceViewDiagram,
DatasetFieldsDiagram,
ErrorAnalysisProcessDiagram,
AgentPromptCallout,
ManualGuideCallout,
ManualGuideList,
details: Details,
summary: Summary,
...components,
};
}
export function useMDXComponents(components?: MDXComponents): MDXComponents {
return getMDXComponents(components);
}