@windrun-huaiin/third-ui 22.0.1 → 23.0.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 (64) hide show
  1. package/dist/fuma/server/features/base.d.ts +2 -0
  2. package/dist/fuma/server/features/base.js +13 -0
  3. package/dist/fuma/server/features/base.mjs +11 -0
  4. package/dist/fuma/server/features/code.d.ts +3 -0
  5. package/dist/fuma/server/features/code.js +66 -0
  6. package/dist/fuma/server/features/code.mjs +64 -0
  7. package/dist/fuma/server/features/math.d.ts +2 -0
  8. package/dist/fuma/server/features/math.js +14 -0
  9. package/dist/fuma/server/features/math.mjs +12 -0
  10. package/dist/fuma/server/features/mermaid.d.ts +2 -0
  11. package/dist/fuma/server/features/mermaid.js +13 -0
  12. package/dist/fuma/server/features/mermaid.mjs +11 -0
  13. package/dist/fuma/server/features/type-table.d.ts +2 -0
  14. package/dist/fuma/server/features/type-table.js +12 -0
  15. package/dist/fuma/server/features/type-table.mjs +10 -0
  16. package/dist/fuma/server/features/widgets.d.ts +2 -0
  17. package/dist/fuma/server/features/widgets.js +26 -0
  18. package/dist/fuma/server/features/widgets.mjs +24 -0
  19. package/dist/fuma/server/optional-features.d.ts +6 -8
  20. package/dist/fuma/server/optional-features.js +13 -107
  21. package/dist/fuma/server/optional-features.mjs +6 -104
  22. package/dist/fuma/server/site-mdx-base.d.ts +13 -0
  23. package/dist/fuma/server/site-mdx-base.js +32 -0
  24. package/dist/fuma/server/site-mdx-base.mjs +29 -0
  25. package/dist/fuma/server/site-mdx-components.d.ts +1 -1
  26. package/dist/fuma/server/site-mdx-components.js +7 -8
  27. package/dist/fuma/server/site-mdx-components.mjs +8 -9
  28. package/dist/fuma/server/site-mdx-fallbacks.d.ts +18 -0
  29. package/dist/fuma/server/site-mdx-fallbacks.js +49 -0
  30. package/dist/fuma/server/site-mdx-fallbacks.mjs +45 -0
  31. package/dist/fuma/server/site-mdx-features/code.d.ts +1 -0
  32. package/dist/fuma/server/site-mdx-features/code.js +7 -0
  33. package/dist/fuma/server/site-mdx-features/code.mjs +1 -0
  34. package/dist/fuma/server/site-mdx-features/math.d.ts +1 -0
  35. package/dist/fuma/server/site-mdx-features/math.js +7 -0
  36. package/dist/fuma/server/site-mdx-features/math.mjs +1 -0
  37. package/dist/fuma/server/site-mdx-features/mermaid.d.ts +1 -0
  38. package/dist/fuma/server/site-mdx-features/mermaid.js +7 -0
  39. package/dist/fuma/server/site-mdx-features/mermaid.mjs +1 -0
  40. package/dist/fuma/server/site-mdx-features/type-table.d.ts +1 -0
  41. package/dist/fuma/server/site-mdx-features/type-table.js +7 -0
  42. package/dist/fuma/server/site-mdx-features/type-table.mjs +1 -0
  43. package/dist/fuma/server/site-mdx-presets.d.ts +2 -1
  44. package/dist/fuma/server/site-mdx-presets.js +22 -13
  45. package/dist/fuma/server/site-mdx-presets.mjs +22 -12
  46. package/dist/fuma/share/markdown-component-map.js +43 -29
  47. package/dist/fuma/share/markdown-component-map.mjs +42 -28
  48. package/package.json +29 -4
  49. package/src/fuma/server/features/base.tsx +23 -0
  50. package/src/fuma/server/features/code.tsx +104 -0
  51. package/src/fuma/server/features/math.ts +16 -0
  52. package/src/fuma/server/features/mermaid.tsx +21 -0
  53. package/src/fuma/server/features/type-table.ts +12 -0
  54. package/src/fuma/server/features/widgets.tsx +34 -0
  55. package/src/fuma/server/optional-features.tsx +6 -168
  56. package/src/fuma/server/site-mdx-base.tsx +62 -0
  57. package/src/fuma/server/site-mdx-components.tsx +10 -12
  58. package/src/fuma/server/site-mdx-fallbacks.tsx +122 -0
  59. package/src/fuma/server/site-mdx-features/code.ts +1 -0
  60. package/src/fuma/server/site-mdx-features/math.ts +1 -0
  61. package/src/fuma/server/site-mdx-features/mermaid.ts +1 -0
  62. package/src/fuma/server/site-mdx-features/type-table.ts +1 -0
  63. package/src/fuma/server/site-mdx-presets.ts +52 -1
  64. package/src/fuma/share/markdown-component-map.tsx +5 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/third-ui",
3
- "version": "22.0.1",
3
+ "version": "23.0.0",
4
4
  "description": "Third-party integrated UI components for windrun-huaiin projects",
5
5
  "exports": {
6
6
  "./clerk": {
@@ -53,6 +53,31 @@
53
53
  "import": "./dist/fuma/server/site-mdx-components.mjs",
54
54
  "require": "./dist/fuma/server/site-mdx-components.js"
55
55
  },
56
+ "./fuma/server/site-mdx/base": {
57
+ "types": "./dist/fuma/server/site-mdx-base.d.ts",
58
+ "import": "./dist/fuma/server/site-mdx-base.mjs",
59
+ "require": "./dist/fuma/server/site-mdx-base.js"
60
+ },
61
+ "./fuma/server/site-mdx/features/code": {
62
+ "types": "./dist/fuma/server/site-mdx-features/code.d.ts",
63
+ "import": "./dist/fuma/server/site-mdx-features/code.mjs",
64
+ "require": "./dist/fuma/server/site-mdx-features/code.js"
65
+ },
66
+ "./fuma/server/site-mdx/features/math": {
67
+ "types": "./dist/fuma/server/site-mdx-features/math.d.ts",
68
+ "import": "./dist/fuma/server/site-mdx-features/math.mjs",
69
+ "require": "./dist/fuma/server/site-mdx-features/math.js"
70
+ },
71
+ "./fuma/server/site-mdx/features/mermaid": {
72
+ "types": "./dist/fuma/server/site-mdx-features/mermaid.d.ts",
73
+ "import": "./dist/fuma/server/site-mdx-features/mermaid.mjs",
74
+ "require": "./dist/fuma/server/site-mdx-features/mermaid.js"
75
+ },
76
+ "./fuma/server/site-mdx/features/type-table": {
77
+ "types": "./dist/fuma/server/site-mdx-features/type-table.d.ts",
78
+ "import": "./dist/fuma/server/site-mdx-features/type-table.mjs",
79
+ "require": "./dist/fuma/server/site-mdx-features/type-table.js"
80
+ },
56
81
  "./fuma/share": {
57
82
  "types": "./dist/fuma/share/index.d.ts",
58
83
  "import": "./dist/fuma/share/index.mjs",
@@ -122,9 +147,9 @@
122
147
  "tslib": "^2.8.1",
123
148
  "unified": "^11.0.5",
124
149
  "zod": "^4.3.6",
125
- "@windrun-huaiin/base-ui": "^22.0.0",
126
- "@windrun-huaiin/lib": "^22.0.0",
127
- "@windrun-huaiin/contracts": "^22.0.0"
150
+ "@windrun-huaiin/base-ui": "^23.0.0",
151
+ "@windrun-huaiin/lib": "^23.0.0",
152
+ "@windrun-huaiin/contracts": "^23.0.0"
128
153
  },
129
154
  "peerDependencies": {
130
155
  "clsx": "^2.1.1",
@@ -0,0 +1,23 @@
1
+ import type { MDXComponents } from 'mdx/types';
2
+ import { baseMarkdownComponents } from '../../share/markdown-component-map';
3
+ import { lazy } from 'react';
4
+ import { createMissingMdxFeatureComponents } from '../site-mdx-fallbacks';
5
+
6
+ const ImageZoom = lazy(() =>
7
+ import('../../heavy/image-zoom').then((mod) => ({ default: mod.ImageZoom })),
8
+ );
9
+
10
+ export function createBaseMdxComponents(
11
+ imageFallbackSrc?: string,
12
+ ): MDXComponents {
13
+ return {
14
+ ...baseMarkdownComponents,
15
+ ...createMissingMdxFeatureComponents(),
16
+ img: (props) => (
17
+ <ImageZoom
18
+ {...(props as any)}
19
+ fallbackSrc={imageFallbackSrc}
20
+ />
21
+ ),
22
+ };
23
+ }
@@ -0,0 +1,104 @@
1
+ import type { MDXComponents, MDXProps } from 'mdx/types';
2
+ import { lazy, type ReactNode } from 'react';
3
+ import {
4
+ CSSIcon,
5
+ CSVIcon,
6
+ DiffIcon,
7
+ HtmlIcon,
8
+ HttpIcon,
9
+ JavaIcon,
10
+ JsonIcon,
11
+ LogIcon,
12
+ MDXIcon,
13
+ RegexIcon,
14
+ SQLIcon,
15
+ SchemeIcon,
16
+ SquareDashedBottomCodeIcon,
17
+ TxtIcon,
18
+ XMLIcon,
19
+ YamlIcon,
20
+ } from '@windrun-huaiin/base-ui/icons';
21
+
22
+ const CodeBlock = lazy(() =>
23
+ import('fumadocs-ui/components/codeblock').then((mod) => ({ default: mod.CodeBlock })),
24
+ );
25
+ const Pre = lazy(() =>
26
+ import('fumadocs-ui/components/codeblock').then((mod) => ({ default: mod.Pre })),
27
+ );
28
+
29
+ const defaultCodeLanguageIconMap: Record<string, ReactNode> = {
30
+ css: <CSSIcon />,
31
+ csv: <CSVIcon />,
32
+ diff: <DiffIcon />,
33
+ html: <HtmlIcon />,
34
+ http: <HttpIcon />,
35
+ java: <JavaIcon />,
36
+ json: <JsonIcon />,
37
+ jsonc: <SquareDashedBottomCodeIcon />,
38
+ log: <LogIcon />,
39
+ mdx: <MDXIcon />,
40
+ plaintext: <TxtIcon />,
41
+ regex: <RegexIcon />,
42
+ scheme: <SchemeIcon />,
43
+ sql: <SQLIcon />,
44
+ text: <TxtIcon />,
45
+ txt: <TxtIcon />,
46
+ xml: <XMLIcon />,
47
+ yaml: <YamlIcon />,
48
+ yml: <YamlIcon />,
49
+ };
50
+
51
+ function tryToMatchIcon(
52
+ props: Readonly<MDXProps & { 'data-language'?: string; title?: string }>,
53
+ iconMap: Record<string, ReactNode>,
54
+ ): ReactNode | undefined {
55
+ let lang: string | undefined;
56
+
57
+ const dataLanguage = props['data-language'] as string | undefined;
58
+
59
+ if (dataLanguage && dataLanguage.trim() !== '') {
60
+ lang = dataLanguage.trim().toLowerCase();
61
+ } else {
62
+ const title = props.title as string | undefined;
63
+ if (title) {
64
+ const titleParts = title.split('.');
65
+ if (titleParts.length > 1 && titleParts[0] !== '') {
66
+ const extension = titleParts.pop()?.toLowerCase();
67
+ if (extension) {
68
+ lang = extension;
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ if (lang && iconMap[lang]) {
75
+ return iconMap[lang];
76
+ }
77
+
78
+ return undefined;
79
+ }
80
+
81
+ export function createCodeMdxComponents(
82
+ iconMap: Record<string, ReactNode> = {},
83
+ ): MDXComponents {
84
+ const mergedIconMap = {
85
+ ...defaultCodeLanguageIconMap,
86
+ ...iconMap,
87
+ };
88
+
89
+ return {
90
+ pre: (props) => {
91
+ const customIcon = tryToMatchIcon(props as MDXProps & { 'data-language'?: string; title?: string }, mergedIconMap);
92
+ return (
93
+ <CodeBlock
94
+ {...props}
95
+ {...(customIcon && { icon: customIcon })}
96
+ >
97
+ <Pre>{props.children}</Pre>
98
+ </CodeBlock>
99
+ );
100
+ },
101
+ CodeBlock,
102
+ Pre,
103
+ };
104
+ }
@@ -0,0 +1,16 @@
1
+ import type { MDXComponents } from 'mdx/types';
2
+ import { lazy } from 'react';
3
+
4
+ const MathBlock = lazy(() =>
5
+ import('../../heavy/math').then((mod) => ({ default: mod.MathBlock })),
6
+ );
7
+ const InlineMath = lazy(() =>
8
+ import('../../heavy/math').then((mod) => ({ default: mod.InlineMath })),
9
+ );
10
+
11
+ export function createMathMdxComponents(): MDXComponents {
12
+ return {
13
+ MathBlock,
14
+ InlineMath,
15
+ };
16
+ }
@@ -0,0 +1,21 @@
1
+ import type { MDXComponents } from 'mdx/types';
2
+ import { lazy } from 'react';
3
+
4
+ const Mermaid = lazy(() =>
5
+ import('../../heavy/mermaid').then((mod) => ({ default: mod.Mermaid })),
6
+ );
7
+
8
+ export function createMermaidMdxComponents(
9
+ watermarkEnabled?: boolean,
10
+ watermarkText?: string,
11
+ ): MDXComponents {
12
+ return {
13
+ Mermaid: (props) => (
14
+ <Mermaid
15
+ {...props}
16
+ watermarkEnabled={watermarkEnabled}
17
+ watermarkText={watermarkText}
18
+ />
19
+ ),
20
+ };
21
+ }
@@ -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
+ }
@@ -1,168 +1,6 @@
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
+ export { createBaseMdxComponents } from './features/base';
2
+ export { createCodeMdxComponents } from './features/code';
3
+ export { createMathMdxComponents } from './features/math';
4
+ export { createMermaidMdxComponents } from './features/mermaid';
5
+ export { createTypeTableMdxComponents } from './features/type-table';
6
+ export { createWidgetMdxComponents } from './features/widgets';
@@ -0,0 +1,62 @@
1
+ import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
2
+ import { Callout } from 'fumadocs-ui/components/callout';
3
+ import { File, Folder, Files } from 'fumadocs-ui/components/files';
4
+ import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
5
+ import type { MDXComponents } from 'mdx/types';
6
+ import { SiteX } from '../site-x';
7
+ import { createBaseMdxComponents } from './features/base';
8
+ import { createWidgetMdxComponents } from './features/widgets';
9
+
10
+ export type SiteMdxFeatureComponents = MDXComponents;
11
+
12
+ export interface SiteMdxBaseOptions {
13
+ imageFallbackSrc?: string;
14
+ cdnBaseUrl?: string;
15
+ }
16
+
17
+ export interface CreateSiteMdxComponentsOptions {
18
+ baseOptions?: SiteMdxBaseOptions;
19
+ features?: SiteMdxFeatureComponents[];
20
+ additionalComponents?: MDXComponents;
21
+ }
22
+
23
+ const defaultFumaUiComponents: MDXComponents = {
24
+ Callout,
25
+ File,
26
+ Folder,
27
+ Files,
28
+ Accordion,
29
+ Accordions,
30
+ Tab,
31
+ Tabs,
32
+ };
33
+
34
+ export function createSiteMdxBaseComponents(
35
+ options: SiteMdxBaseOptions = {},
36
+ ): MDXComponents {
37
+ return {
38
+ ...defaultFumaUiComponents,
39
+ SiteX,
40
+ ...createBaseMdxComponents(options.imageFallbackSrc),
41
+ ...createWidgetMdxComponents(options.cdnBaseUrl, options.imageFallbackSrc),
42
+ };
43
+ }
44
+
45
+ export function createSiteMdxComponents(
46
+ options: CreateSiteMdxComponentsOptions = {},
47
+ ) {
48
+ const {
49
+ additionalComponents,
50
+ baseOptions,
51
+ features = [],
52
+ } = options;
53
+
54
+ return function getMDXComponents(components?: MDXComponents): MDXComponents {
55
+ return {
56
+ ...createSiteMdxBaseComponents(baseOptions),
57
+ ...features.reduce<MDXComponents>((acc, feature) => ({ ...acc, ...feature }), {}),
58
+ ...additionalComponents,
59
+ ...components,
60
+ };
61
+ };
62
+ }
@@ -1,10 +1,9 @@
1
1
  import type { MDXComponents } from 'mdx/types';
2
2
  import type { ReactNode } from 'react';
3
- import type { SiteMdxFeature } from '@windrun-huaiin/contracts/mdx';
4
3
  import {
5
- composeSiteMdxComponents,
6
- createSiteFeatureComponentMap,
4
+ createComposedSiteMdxComponents,
7
5
  DEFAULT_SITE_MDX_FEATURES,
6
+ type SiteMdxFeature,
8
7
  } from './site-mdx-presets';
9
8
 
10
9
  export interface SiteMdxComponentsOptions {
@@ -29,18 +28,17 @@ export function createSiteMdxComponents(
29
28
  watermarkEnabled,
30
29
  watermarkText,
31
30
  } = options;
32
- const featureMap = createSiteFeatureComponentMap({
33
- cdnBaseUrl,
34
- iconMap,
35
- imageFallbackSrc,
36
- watermarkEnabled,
37
- watermarkText,
38
- });
39
31
 
40
32
  return function getMDXComponents(components?: MDXComponents): MDXComponents {
41
- return composeSiteMdxComponents(
33
+ return createComposedSiteMdxComponents(
42
34
  features,
43
- featureMap,
35
+ {
36
+ cdnBaseUrl,
37
+ iconMap,
38
+ imageFallbackSrc,
39
+ watermarkEnabled,
40
+ watermarkText,
41
+ },
44
42
  additionalComponents,
45
43
  components,
46
44
  );
@@ -0,0 +1,122 @@
1
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2
+
3
+ type MissingFeatureBlockProps = ComponentPropsWithoutRef<'div'> & {
4
+ feature: string;
5
+ component: string;
6
+ };
7
+
8
+ type MissingFeatureInlineProps = ComponentPropsWithoutRef<'span'> & {
9
+ feature: string;
10
+ component: string;
11
+ };
12
+
13
+ type MdxFallbackExtraProps = Record<string, unknown>;
14
+
15
+ function renderChildren(children: ReactNode) {
16
+ if (children == null || children === '') {
17
+ return <span className="italic text-fd-muted-foreground">No fallback content.</span>;
18
+ }
19
+
20
+ return children;
21
+ }
22
+
23
+ function hasChildren(children: ReactNode) {
24
+ return children != null && children !== '';
25
+ }
26
+
27
+ function getDisplayProps(props: MdxFallbackExtraProps) {
28
+ return Object.entries(props)
29
+ .filter(([, value]) =>
30
+ typeof value === 'string' ||
31
+ typeof value === 'number' ||
32
+ typeof value === 'boolean',
33
+ )
34
+ .map(([key, value]) => [key, String(value)] as const);
35
+ }
36
+
37
+ export function MissingMdxFeatureBlock({
38
+ feature,
39
+ component,
40
+ children,
41
+ className,
42
+ ...props
43
+ }: MissingFeatureBlockProps) {
44
+ const displayProps = getDisplayProps(props);
45
+
46
+ return (
47
+ <div
48
+ className={[
49
+ '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',
50
+ className,
51
+ ].filter(Boolean).join(' ')}
52
+ >
53
+ <div className="mb-2 flex flex-wrap items-center gap-2 font-medium">
54
+ <span>MDX feature not enabled</span>
55
+ <code className="rounded bg-red-100 px-1.5 py-0.5 text-xs dark:bg-red-900/60">{feature}</code>
56
+ <code className="rounded bg-red-100 px-1.5 py-0.5 text-xs dark:bg-red-900/60">{component}</code>
57
+ </div>
58
+ {displayProps.length > 0 && (
59
+ <div className="mb-2 flex flex-wrap gap-1.5 text-xs">
60
+ {displayProps.map(([key, value]) => (
61
+ <span
62
+ key={key}
63
+ 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"
64
+ >
65
+ {key}={value}
66
+ </span>
67
+ ))}
68
+ </div>
69
+ )}
70
+ <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">
71
+ {renderChildren(children)}
72
+ </div>
73
+ </div>
74
+ );
75
+ }
76
+
77
+ export function MissingMdxFeatureInline({
78
+ feature,
79
+ component,
80
+ children,
81
+ className,
82
+ ...props
83
+ }: MissingFeatureInlineProps) {
84
+ const displayProps = getDisplayProps(props);
85
+
86
+ return (
87
+ <span
88
+ className={[
89
+ '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',
90
+ className,
91
+ ].filter(Boolean).join(' ')}
92
+ title={`MDX feature not enabled: ${feature} (${component})`}
93
+ >
94
+ <span className="font-medium">{component}</span>
95
+ {displayProps.map(([key, value]) => (
96
+ <span key={key} className="font-mono text-xs opacity-80">
97
+ {key}={value}
98
+ </span>
99
+ ))}
100
+ {hasChildren(children) && (
101
+ <span className="font-mono text-xs opacity-80">{children}</span>
102
+ )}
103
+ </span>
104
+ );
105
+ }
106
+
107
+ export function createMissingMdxFeatureComponents() {
108
+ return {
109
+ MathBlock: (props: ComponentPropsWithoutRef<'div'>) => (
110
+ <MissingMdxFeatureBlock {...props} feature="math" component="MathBlock" />
111
+ ),
112
+ InlineMath: (props: ComponentPropsWithoutRef<'span'>) => (
113
+ <MissingMdxFeatureInline {...props} feature="math" component="InlineMath" />
114
+ ),
115
+ Mermaid: (props: ComponentPropsWithoutRef<'div'>) => (
116
+ <MissingMdxFeatureBlock {...props} feature="diagram renderer" component="Mermaid" />
117
+ ),
118
+ TypeTable: (props: ComponentPropsWithoutRef<'div'>) => (
119
+ <MissingMdxFeatureBlock {...props} feature="API table renderer" component="TypeTable" />
120
+ ),
121
+ };
122
+ }
@@ -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';