@windrun-huaiin/third-ui 22.0.1 → 23.1.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.
Files changed (65) hide show
  1. package/README.md +152 -189
  2. package/dist/fuma/server/features/base.d.ts +2 -0
  3. package/dist/fuma/server/features/base.js +13 -0
  4. package/dist/fuma/server/features/base.mjs +11 -0
  5. package/dist/fuma/server/features/code.d.ts +2 -0
  6. package/dist/fuma/server/features/code.js +65 -0
  7. package/dist/fuma/server/features/code.mjs +63 -0
  8. package/dist/fuma/server/features/math.d.ts +2 -0
  9. package/dist/fuma/server/features/math.js +14 -0
  10. package/dist/fuma/server/features/math.mjs +12 -0
  11. package/dist/fuma/server/features/mermaid.d.ts +2 -0
  12. package/dist/fuma/server/features/mermaid.js +13 -0
  13. package/dist/fuma/server/features/mermaid.mjs +11 -0
  14. package/dist/fuma/server/features/type-table.d.ts +2 -0
  15. package/dist/fuma/server/features/type-table.js +12 -0
  16. package/dist/fuma/server/features/type-table.mjs +10 -0
  17. package/dist/fuma/server/features/widgets.d.ts +2 -0
  18. package/dist/fuma/server/features/widgets.js +26 -0
  19. package/dist/fuma/server/features/widgets.mjs +24 -0
  20. package/dist/fuma/server/optional-features.d.ts +6 -8
  21. package/dist/fuma/server/optional-features.js +13 -107
  22. package/dist/fuma/server/optional-features.mjs +6 -104
  23. package/dist/fuma/server/site-mdx-base.d.ts +13 -0
  24. package/dist/fuma/server/site-mdx-base.js +36 -0
  25. package/dist/fuma/server/site-mdx-base.mjs +33 -0
  26. package/dist/fuma/server/site-mdx-components.d.ts +1 -1
  27. package/dist/fuma/server/site-mdx-components.js +7 -8
  28. package/dist/fuma/server/site-mdx-components.mjs +8 -9
  29. package/dist/fuma/server/site-mdx-fallbacks.d.ts +25 -0
  30. package/dist/fuma/server/site-mdx-fallbacks.js +79 -0
  31. package/dist/fuma/server/site-mdx-fallbacks.mjs +73 -0
  32. package/dist/fuma/server/site-mdx-features/code.d.ts +1 -0
  33. package/dist/fuma/server/site-mdx-features/code.js +7 -0
  34. package/dist/fuma/server/site-mdx-features/code.mjs +1 -0
  35. package/dist/fuma/server/site-mdx-features/math.d.ts +1 -0
  36. package/dist/fuma/server/site-mdx-features/math.js +7 -0
  37. package/dist/fuma/server/site-mdx-features/math.mjs +1 -0
  38. package/dist/fuma/server/site-mdx-features/mermaid.d.ts +1 -0
  39. package/dist/fuma/server/site-mdx-features/mermaid.js +7 -0
  40. package/dist/fuma/server/site-mdx-features/mermaid.mjs +1 -0
  41. package/dist/fuma/server/site-mdx-features/type-table.d.ts +1 -0
  42. package/dist/fuma/server/site-mdx-features/type-table.js +7 -0
  43. package/dist/fuma/server/site-mdx-features/type-table.mjs +1 -0
  44. package/dist/fuma/server/site-mdx-presets.d.ts +2 -1
  45. package/dist/fuma/server/site-mdx-presets.js +22 -13
  46. package/dist/fuma/server/site-mdx-presets.mjs +22 -12
  47. package/dist/fuma/share/markdown-component-map.js +43 -29
  48. package/dist/fuma/share/markdown-component-map.mjs +42 -28
  49. package/package.json +28 -13
  50. package/src/fuma/server/features/base.tsx +23 -0
  51. package/src/fuma/server/features/code.tsx +100 -0
  52. package/src/fuma/server/features/math.ts +16 -0
  53. package/src/fuma/server/features/mermaid.tsx +21 -0
  54. package/src/fuma/server/features/type-table.ts +12 -0
  55. package/src/fuma/server/features/widgets.tsx +34 -0
  56. package/src/fuma/server/site-mdx-base.tsx +66 -0
  57. package/src/fuma/server/site-mdx-fallbacks.tsx +172 -0
  58. package/src/fuma/server/site-mdx-features/code.ts +1 -0
  59. package/src/fuma/server/site-mdx-features/math.ts +1 -0
  60. package/src/fuma/server/site-mdx-features/mermaid.ts +1 -0
  61. package/src/fuma/server/site-mdx-features/type-table.ts +1 -0
  62. package/src/fuma/share/markdown-component-map.tsx +5 -4
  63. package/src/fuma/server/optional-features.tsx +0 -168
  64. package/src/fuma/server/site-mdx-components.tsx +0 -48
  65. package/src/fuma/server/site-mdx-presets.ts +0 -80
@@ -0,0 +1,12 @@
1
+ import type { MDXComponents } from 'mdx/types';
2
+ import { lazy } from 'react';
3
+
4
+ const TypeTable = lazy(() =>
5
+ import('fumadocs-ui/components/type-table').then((mod) => ({ default: mod.TypeTable })),
6
+ );
7
+
8
+ export function createTypeTableMdxComponents(): MDXComponents {
9
+ return {
10
+ TypeTable,
11
+ };
12
+ }
@@ -0,0 +1,34 @@
1
+ import type { MDXComponents } from 'mdx/types';
2
+ import { lazy } from 'react';
3
+ import { TrophyCard } from '../../mdx/trophy-card';
4
+ import { ZiaCard } from '../../mdx/zia-card';
5
+ import { GradientButton } from '../../mdx/gradient-button';
6
+ import { ZiaFile, ZiaFolder } from '../../mdx/zia-file';
7
+ import { SunoEmbed } from '../../mdx/suno-embed';
8
+
9
+ const ImageGrid = lazy(() =>
10
+ import('../../heavy/image-grid').then((mod) => ({ default: mod.ImageGrid })),
11
+ );
12
+ const ImageZoom = lazy(() =>
13
+ import('../../heavy/image-zoom').then((mod) => ({ default: mod.ImageZoom })),
14
+ );
15
+
16
+ export function createWidgetMdxComponents(
17
+ cdnBaseUrl?: string,
18
+ imageFallbackSrc?: string,
19
+ ): MDXComponents {
20
+ return {
21
+ TrophyCard,
22
+ ZiaCard,
23
+ GradientButton,
24
+ ZiaFile,
25
+ ZiaFolder,
26
+ SunoEmbed,
27
+ ImageGrid: (props) => (
28
+ <ImageGrid {...props} cdnBaseUrl={cdnBaseUrl} />
29
+ ),
30
+ ImageZoom: (props) => (
31
+ <ImageZoom {...props} fallbackSrc={imageFallbackSrc} />
32
+ ),
33
+ };
34
+ }
@@ -0,0 +1,66 @@
1
+ import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
2
+ import { Callout } from 'fumadocs-ui/components/callout';
3
+ import { Card, Cards } from 'fumadocs-ui/components/card';
4
+ import { File, Folder, Files } from 'fumadocs-ui/components/files';
5
+ import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
6
+ import type { MDXComponents } from 'mdx/types';
7
+ import { SiteX } from '../site-x';
8
+ import { createBaseMdxComponents } from './features/base';
9
+ import { createWidgetMdxComponents } from './features/widgets';
10
+ import { withMissingMdxComponentFallback } from './site-mdx-fallbacks';
11
+
12
+ export type SiteMdxFeatureComponents = MDXComponents;
13
+
14
+ export interface SiteMdxBaseOptions {
15
+ imageFallbackSrc?: string;
16
+ cdnBaseUrl?: string;
17
+ }
18
+
19
+ export interface CreateSiteMdxComponentsOptions {
20
+ baseOptions?: SiteMdxBaseOptions;
21
+ features?: SiteMdxFeatureComponents[];
22
+ additionalComponents?: MDXComponents;
23
+ }
24
+
25
+ const defaultFumaUiComponents: MDXComponents = {
26
+ Card,
27
+ Cards,
28
+ Callout,
29
+ File,
30
+ Folder,
31
+ Files,
32
+ Accordion,
33
+ Accordions,
34
+ Tab,
35
+ Tabs,
36
+ };
37
+
38
+ export function createSiteMdxBaseComponents(
39
+ options: SiteMdxBaseOptions = {},
40
+ ): MDXComponents {
41
+ return {
42
+ ...defaultFumaUiComponents,
43
+ SiteX,
44
+ ...createBaseMdxComponents(options.imageFallbackSrc),
45
+ ...createWidgetMdxComponents(options.cdnBaseUrl, options.imageFallbackSrc),
46
+ };
47
+ }
48
+
49
+ export function createSiteMdxComponents(
50
+ options: CreateSiteMdxComponentsOptions = {},
51
+ ) {
52
+ const {
53
+ additionalComponents,
54
+ baseOptions,
55
+ features = [],
56
+ } = options;
57
+
58
+ return function getMDXComponents(components?: MDXComponents): MDXComponents {
59
+ return withMissingMdxComponentFallback({
60
+ ...createSiteMdxBaseComponents(baseOptions),
61
+ ...features.reduce<MDXComponents>((acc, feature) => ({ ...acc, ...feature }), {}),
62
+ ...additionalComponents,
63
+ ...components,
64
+ });
65
+ };
66
+ }
@@ -0,0 +1,172 @@
1
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2
+ import type { MDXComponents } from 'mdx/types';
3
+
4
+ type MissingFeatureBlockProps = ComponentPropsWithoutRef<'div'> & {
5
+ feature: string;
6
+ component: string;
7
+ };
8
+
9
+ type MissingFeatureInlineProps = ComponentPropsWithoutRef<'span'> & {
10
+ feature: string;
11
+ component: string;
12
+ };
13
+
14
+ type MdxFallbackExtraProps = Record<string, unknown>;
15
+
16
+ function renderChildren(children: ReactNode) {
17
+ if (children == null || children === '') {
18
+ return <span className="italic text-fd-muted-foreground">No fallback content.</span>;
19
+ }
20
+
21
+ return children;
22
+ }
23
+
24
+ function hasChildren(children: ReactNode) {
25
+ return children != null && children !== '';
26
+ }
27
+
28
+ function getDisplayProps(props: MdxFallbackExtraProps) {
29
+ return Object.entries(props)
30
+ .filter(([, value]) =>
31
+ typeof value === 'string' ||
32
+ typeof value === 'number' ||
33
+ typeof value === 'boolean',
34
+ )
35
+ .map(([key, value]) => [key, String(value)] as const);
36
+ }
37
+
38
+ export function MissingMdxFeatureBlock({
39
+ feature,
40
+ component,
41
+ children,
42
+ className,
43
+ ...props
44
+ }: MissingFeatureBlockProps) {
45
+ const displayProps = getDisplayProps(props);
46
+
47
+ return (
48
+ <div
49
+ className={[
50
+ 'my-4 rounded-xl border border-red-300 bg-red-50/80 p-4 text-sm text-red-950 shadow-sm dark:border-red-800/80 dark:bg-red-950/30 dark:text-red-100',
51
+ className,
52
+ ].filter(Boolean).join(' ')}
53
+ >
54
+ <div className="mb-2 flex flex-wrap items-center gap-2 font-medium">
55
+ <span>MDX feature not enabled</span>
56
+ <code className="rounded bg-red-100 px-1.5 py-0.5 text-xs dark:bg-red-900/60">{feature}</code>
57
+ <code className="rounded bg-red-100 px-1.5 py-0.5 text-xs dark:bg-red-900/60">{component}</code>
58
+ </div>
59
+ {displayProps.length > 0 && (
60
+ <div className="mb-2 flex flex-wrap gap-1.5 text-xs">
61
+ {displayProps.map(([key, value]) => (
62
+ <span
63
+ key={key}
64
+ className="rounded-md border border-red-200 bg-white/60 px-1.5 py-0.5 font-mono dark:border-red-900/70 dark:bg-black/20"
65
+ >
66
+ {key}={value}
67
+ </span>
68
+ ))}
69
+ </div>
70
+ )}
71
+ <div className="whitespace-pre-wrap break-words rounded-lg border border-red-200 bg-white/70 p-3 font-mono text-xs text-red-900 dark:border-red-900/70 dark:bg-black/20 dark:text-red-100">
72
+ {renderChildren(children)}
73
+ </div>
74
+ </div>
75
+ );
76
+ }
77
+
78
+ export function MissingMdxFeatureInline({
79
+ feature,
80
+ component,
81
+ children,
82
+ className,
83
+ ...props
84
+ }: MissingFeatureInlineProps) {
85
+ const displayProps = getDisplayProps(props);
86
+
87
+ return (
88
+ <span
89
+ className={[
90
+ 'inline-flex max-w-full items-center gap-1 rounded-md border border-red-300 bg-red-50 px-1.5 py-0.5 text-sm text-red-900 dark:border-red-800 dark:bg-red-950/40 dark:text-red-100',
91
+ className,
92
+ ].filter(Boolean).join(' ')}
93
+ title={`MDX feature not enabled: ${feature} (${component})`}
94
+ >
95
+ <span className="font-medium">{component}</span>
96
+ {displayProps.map(([key, value]) => (
97
+ <span key={key} className="font-mono text-xs opacity-80">
98
+ {key}={value}
99
+ </span>
100
+ ))}
101
+ {hasChildren(children) && (
102
+ <span className="font-mono text-xs opacity-80">{children}</span>
103
+ )}
104
+ </span>
105
+ );
106
+ }
107
+
108
+ export function createMissingMdxFeatureComponents() {
109
+ return {
110
+ MathBlock: (props: ComponentPropsWithoutRef<'div'>) => (
111
+ <MissingMdxFeatureBlock {...props} feature="math" component="MathBlock" />
112
+ ),
113
+ InlineMath: (props: ComponentPropsWithoutRef<'span'>) => (
114
+ <MissingMdxFeatureInline {...props} feature="math" component="InlineMath" />
115
+ ),
116
+ Mermaid: (props: ComponentPropsWithoutRef<'div'>) => (
117
+ <MissingMdxFeatureBlock {...props} feature="diagram renderer" component="Mermaid" />
118
+ ),
119
+ TypeTable: (props: ComponentPropsWithoutRef<'div'>) => (
120
+ <MissingMdxFeatureBlock {...props} feature="API table renderer" component="TypeTable" />
121
+ ),
122
+ CodeBlockTab: (props: ComponentPropsWithoutRef<'div'>) => (
123
+ <MissingMdxFeatureBlock {...props} feature="code" component="CodeBlockTab" />
124
+ ),
125
+ CodeBlockTabs: (props: ComponentPropsWithoutRef<'div'>) => (
126
+ <MissingMdxFeatureBlock {...props} feature="code" component="CodeBlockTabs" />
127
+ ),
128
+ CodeBlockTabsList: (props: ComponentPropsWithoutRef<'div'>) => (
129
+ <MissingMdxFeatureBlock {...props} feature="code" component="CodeBlockTabsList" />
130
+ ),
131
+ CodeBlockTabsTrigger: (props: ComponentPropsWithoutRef<'div'>) => (
132
+ <MissingMdxFeatureBlock {...props} feature="code" component="CodeBlockTabsTrigger" />
133
+ ),
134
+ };
135
+ }
136
+
137
+ export function createMissingMdxComponentFallback(component: string) {
138
+ return function MissingMdxComponent(props: ComponentPropsWithoutRef<'div'>) {
139
+ return (
140
+ <MissingMdxFeatureBlock
141
+ {...props}
142
+ feature="unknown MDX component"
143
+ component={component}
144
+ />
145
+ );
146
+ };
147
+ }
148
+
149
+ export function withMissingMdxComponentFallback(
150
+ components: MDXComponents,
151
+ ): MDXComponents {
152
+ return new Proxy(components, {
153
+ has(target, prop) {
154
+ if (typeof prop === 'string' && /^[A-Z]/.test(prop)) {
155
+ return true;
156
+ }
157
+
158
+ return prop in target;
159
+ },
160
+ get(target, prop, receiver) {
161
+ if (typeof prop !== 'string' || prop in target) {
162
+ return Reflect.get(target, prop, receiver);
163
+ }
164
+
165
+ if (/^[A-Z]/.test(prop)) {
166
+ return createMissingMdxComponentFallback(prop);
167
+ }
168
+
169
+ return Reflect.get(target, prop, receiver);
170
+ },
171
+ });
172
+ }
@@ -0,0 +1 @@
1
+ export { createCodeMdxComponents } from '../features/code';
@@ -0,0 +1 @@
1
+ export { createMathMdxComponents } from '../features/math';
@@ -0,0 +1 @@
1
+ export { createMermaidMdxComponents } from '../features/mermaid';
@@ -0,0 +1 @@
1
+ export { createTypeTableMdxComponents } from '../features/type-table';
@@ -1,7 +1,9 @@
1
1
  import { cn } from '@windrun-huaiin/lib/utils';
2
- import defaultMdxComponents from 'fumadocs-ui/mdx';
3
- import { type ComponentType } from 'react';
4
- import { ImageZoom } from '../heavy';
2
+ import { lazy, type ComponentType } from 'react';
3
+
4
+ const ImageZoom = lazy(() =>
5
+ import('../heavy/image-zoom').then((mod) => ({ default: mod.ImageZoom })),
6
+ );
5
7
 
6
8
  export type MarkdownComponentMap = Record<string, ComponentType<any>>;
7
9
 
@@ -18,7 +20,6 @@ function normalizeMarkdownProps<T extends Record<string, any>>(props: T) {
18
20
  }
19
21
 
20
22
  export const baseMarkdownComponents: MarkdownComponentMap = {
21
- ...defaultMdxComponents,
22
23
  a: ({ className, ...props }) => (
23
24
  <a
24
25
  {...normalizeMarkdownProps(props)}
@@ -1,168 +0,0 @@
1
- import type { MDXComponents, MDXProps } from 'mdx/types';
2
- import type { ReactNode } from 'react';
3
- import { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';
4
- import { TypeTable } from 'fumadocs-ui/components/type-table';
5
- import {
6
- CSSIcon,
7
- CSVIcon,
8
- DiffIcon,
9
- HtmlIcon,
10
- HttpIcon,
11
- JavaIcon,
12
- JsonIcon,
13
- LogIcon,
14
- MDXIcon,
15
- RegexIcon,
16
- SQLIcon,
17
- SchemeIcon,
18
- SquareDashedBottomCodeIcon,
19
- TxtIcon,
20
- XMLIcon,
21
- YamlIcon,
22
- } from '@windrun-huaiin/base-ui/icons';
23
- import { baseMarkdownComponents } from '../share/markdown-component-map';
24
- import { Mermaid, ImageGrid, ImageZoom, MathBlock, InlineMath } from '../heavy';
25
- import { TrophyCard } from '../mdx/trophy-card';
26
- import { ZiaCard } from '../mdx/zia-card';
27
- import { GradientButton } from '../mdx/gradient-button';
28
- import { ZiaFile, ZiaFolder } from '../mdx/zia-file';
29
- import { SunoEmbed } from '../mdx/suno-embed';
30
-
31
- const defaultCodeLanguageIconMap: Record<string, ReactNode> = {
32
- css: <CSSIcon />,
33
- csv: <CSVIcon />,
34
- diff: <DiffIcon />,
35
- html: <HtmlIcon />,
36
- http: <HttpIcon />,
37
- java: <JavaIcon />,
38
- json: <JsonIcon />,
39
- jsonc: <SquareDashedBottomCodeIcon />,
40
- log: <LogIcon />,
41
- mdx: <MDXIcon />,
42
- plaintext: <TxtIcon />,
43
- regex: <RegexIcon />,
44
- scheme: <SchemeIcon />,
45
- sql: <SQLIcon />,
46
- text: <TxtIcon />,
47
- txt: <TxtIcon />,
48
- xml: <XMLIcon />,
49
- yaml: <YamlIcon />,
50
- yml: <YamlIcon />,
51
- };
52
-
53
- function tryToMatchIcon(
54
- props: Readonly<MDXProps & { 'data-language'?: string; title?: string }>,
55
- iconMap: Record<string, ReactNode>,
56
- ): ReactNode | undefined {
57
- let lang: string | undefined;
58
-
59
- const dataLanguage = props['data-language'] as string | undefined;
60
-
61
- if (dataLanguage && dataLanguage.trim() !== '') {
62
- lang = dataLanguage.trim().toLowerCase();
63
- } else {
64
- const title = props.title as string | undefined;
65
- if (title) {
66
- const titleParts = title.split('.');
67
- if (titleParts.length > 1 && titleParts[0] !== '') {
68
- const extension = titleParts.pop()?.toLowerCase();
69
- if (extension) {
70
- lang = extension;
71
- }
72
- }
73
- }
74
- }
75
-
76
- if (lang && iconMap[lang]) {
77
- return iconMap[lang];
78
- }
79
-
80
- return undefined;
81
- }
82
-
83
- export function createBaseMdxComponents(
84
- imageFallbackSrc?: string,
85
- ): MDXComponents {
86
- return {
87
- ...baseMarkdownComponents,
88
- img: (props) => (
89
- <ImageZoom
90
- {...(props as any)}
91
- fallbackSrc={imageFallbackSrc}
92
- />
93
- ),
94
- };
95
- }
96
-
97
- export function createCodeMdxComponents(
98
- iconMap: Record<string, ReactNode> = {},
99
- ): MDXComponents {
100
- const mergedIconMap = {
101
- ...defaultCodeLanguageIconMap,
102
- ...iconMap,
103
- };
104
-
105
- return {
106
- pre: (props) => {
107
- const customIcon = tryToMatchIcon(props as MDXProps & { 'data-language'?: string; title?: string }, mergedIconMap);
108
- return (
109
- <CodeBlock
110
- {...props}
111
- {...(customIcon && { icon: customIcon })}
112
- >
113
- <Pre>{props.children}</Pre>
114
- </CodeBlock>
115
- );
116
- },
117
- CodeBlock,
118
- Pre,
119
- };
120
- }
121
-
122
- export function createMathMdxComponents(): MDXComponents {
123
- return {
124
- MathBlock,
125
- InlineMath,
126
- };
127
- }
128
-
129
- export function createMermaidMdxComponents(
130
- watermarkEnabled?: boolean,
131
- watermarkText?: string,
132
- ): MDXComponents {
133
- return {
134
- Mermaid: (props) => (
135
- <Mermaid
136
- {...props}
137
- watermarkEnabled={watermarkEnabled}
138
- watermarkText={watermarkText}
139
- />
140
- ),
141
- };
142
- }
143
-
144
- export function createTypeTableMdxComponents(): MDXComponents {
145
- return {
146
- TypeTable,
147
- };
148
- }
149
-
150
- export function createWidgetMdxComponents(
151
- cdnBaseUrl?: string,
152
- imageFallbackSrc?: string,
153
- ): MDXComponents {
154
- return {
155
- TrophyCard,
156
- ZiaCard,
157
- GradientButton,
158
- ZiaFile,
159
- ZiaFolder,
160
- SunoEmbed,
161
- ImageGrid: (props) => (
162
- <ImageGrid {...props} cdnBaseUrl={cdnBaseUrl} />
163
- ),
164
- ImageZoom: (props) => (
165
- <ImageZoom {...props} fallbackSrc={imageFallbackSrc} />
166
- ),
167
- };
168
- }
@@ -1,48 +0,0 @@
1
- import type { MDXComponents } from 'mdx/types';
2
- import type { ReactNode } from 'react';
3
- import type { SiteMdxFeature } from '@windrun-huaiin/contracts/mdx';
4
- import {
5
- composeSiteMdxComponents,
6
- createSiteFeatureComponentMap,
7
- DEFAULT_SITE_MDX_FEATURES,
8
- } from './site-mdx-presets';
9
-
10
- export interface SiteMdxComponentsOptions {
11
- imageFallbackSrc?: string;
12
- cdnBaseUrl?: string;
13
- watermarkEnabled?: boolean;
14
- watermarkText?: string;
15
- additionalComponents?: MDXComponents;
16
- iconMap?: Record<string, ReactNode>;
17
- features?: SiteMdxFeature[];
18
- }
19
-
20
- export function createSiteMdxComponents(
21
- options: SiteMdxComponentsOptions,
22
- ) {
23
- const {
24
- additionalComponents,
25
- cdnBaseUrl,
26
- features = DEFAULT_SITE_MDX_FEATURES,
27
- iconMap = {},
28
- imageFallbackSrc,
29
- watermarkEnabled,
30
- watermarkText,
31
- } = options;
32
- const featureMap = createSiteFeatureComponentMap({
33
- cdnBaseUrl,
34
- iconMap,
35
- imageFallbackSrc,
36
- watermarkEnabled,
37
- watermarkText,
38
- });
39
-
40
- return function getMDXComponents(components?: MDXComponents): MDXComponents {
41
- return composeSiteMdxComponents(
42
- features,
43
- featureMap,
44
- additionalComponents,
45
- components,
46
- );
47
- };
48
- }
@@ -1,80 +0,0 @@
1
- import defaultMdxComponents from 'fumadocs-ui/mdx';
2
- import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
3
- import { Callout } from 'fumadocs-ui/components/callout';
4
- import { File, Folder, Files } from 'fumadocs-ui/components/files';
5
- import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
6
- import type { MDXComponents } from 'mdx/types';
7
- import {
8
- createBaseMdxComponents,
9
- createCodeMdxComponents,
10
- createMathMdxComponents,
11
- createMermaidMdxComponents,
12
- createTypeTableMdxComponents,
13
- createWidgetMdxComponents,
14
- } from './optional-features';
15
- import { SiteX } from '../site-x';
16
- import type { SiteMdxComponentsOptions } from './site-mdx-components';
17
- import type { SiteMdxFeature } from '@windrun-huaiin/contracts/mdx';
18
-
19
- const defaultFumaUiComponents: MDXComponents = {
20
- Callout,
21
- File,
22
- Folder,
23
- Files,
24
- Accordion,
25
- Accordions,
26
- Tab,
27
- Tabs,
28
- };
29
-
30
- export const DEFAULT_SITE_MDX_FEATURES: SiteMdxFeature[] = [
31
- 'base',
32
- 'code',
33
- 'math',
34
- 'mermaid',
35
- 'type-table',
36
- ];
37
-
38
- export function createSiteFeatureComponentMap(
39
- options: SiteMdxComponentsOptions,
40
- ) {
41
- const {
42
- cdnBaseUrl,
43
- iconMap = {},
44
- imageFallbackSrc,
45
- watermarkEnabled,
46
- watermarkText,
47
- } = options;
48
-
49
- return {
50
- base: {
51
- ...defaultFumaUiComponents,
52
- SiteX,
53
- ...createBaseMdxComponents(imageFallbackSrc),
54
- ...createWidgetMdxComponents(cdnBaseUrl, imageFallbackSrc),
55
- },
56
- code: createCodeMdxComponents(iconMap),
57
- math: createMathMdxComponents(),
58
- mermaid: createMermaidMdxComponents(watermarkEnabled, watermarkText),
59
- 'type-table': createTypeTableMdxComponents(),
60
- } satisfies Record<SiteMdxFeature, MDXComponents>;
61
- }
62
-
63
- export function composeSiteMdxComponents(
64
- features: readonly SiteMdxFeature[],
65
- featureMap: Record<SiteMdxFeature, MDXComponents>,
66
- additionalComponents?: MDXComponents,
67
- components?: MDXComponents,
68
- ): MDXComponents {
69
- return {
70
- ...defaultMdxComponents,
71
- ...features.reduce<MDXComponents>((acc, feature) => {
72
- return {
73
- ...acc,
74
- ...featureMap[feature],
75
- };
76
- }, {}),
77
- ...additionalComponents,
78
- ...components,
79
- };
80
- }