@windrun-huaiin/third-ui 22.0.0 → 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.
- package/README.md +6 -6
- package/dist/fuma/server/features/base.d.ts +2 -0
- package/dist/fuma/server/features/base.js +13 -0
- package/dist/fuma/server/features/base.mjs +11 -0
- package/dist/fuma/server/features/code.d.ts +3 -0
- package/dist/fuma/server/features/code.js +66 -0
- package/dist/fuma/server/features/code.mjs +64 -0
- package/dist/fuma/server/features/math.d.ts +2 -0
- package/dist/fuma/server/features/math.js +14 -0
- package/dist/fuma/server/features/math.mjs +12 -0
- package/dist/fuma/server/features/mermaid.d.ts +2 -0
- package/dist/fuma/server/features/mermaid.js +13 -0
- package/dist/fuma/server/features/mermaid.mjs +11 -0
- package/dist/fuma/server/features/type-table.d.ts +2 -0
- package/dist/fuma/server/features/type-table.js +12 -0
- package/dist/fuma/server/features/type-table.mjs +10 -0
- package/dist/fuma/server/features/widgets.d.ts +2 -0
- package/dist/fuma/server/features/widgets.js +26 -0
- package/dist/fuma/server/features/widgets.mjs +24 -0
- package/dist/fuma/server/optional-features.d.ts +6 -8
- package/dist/fuma/server/optional-features.js +13 -107
- package/dist/fuma/server/optional-features.mjs +6 -104
- package/dist/fuma/server/site-mdx-base.d.ts +13 -0
- package/dist/fuma/server/site-mdx-base.js +32 -0
- package/dist/fuma/server/site-mdx-base.mjs +29 -0
- package/dist/fuma/server/site-mdx-components.d.ts +1 -1
- package/dist/fuma/server/site-mdx-components.js +7 -8
- package/dist/fuma/server/site-mdx-components.mjs +8 -9
- package/dist/fuma/server/site-mdx-fallbacks.d.ts +18 -0
- package/dist/fuma/server/site-mdx-fallbacks.js +49 -0
- package/dist/fuma/server/site-mdx-fallbacks.mjs +45 -0
- package/dist/fuma/server/site-mdx-features/code.d.ts +1 -0
- package/dist/fuma/server/site-mdx-features/code.js +7 -0
- package/dist/fuma/server/site-mdx-features/code.mjs +1 -0
- package/dist/fuma/server/site-mdx-features/math.d.ts +1 -0
- package/dist/fuma/server/site-mdx-features/math.js +7 -0
- package/dist/fuma/server/site-mdx-features/math.mjs +1 -0
- package/dist/fuma/server/site-mdx-features/mermaid.d.ts +1 -0
- package/dist/fuma/server/site-mdx-features/mermaid.js +7 -0
- package/dist/fuma/server/site-mdx-features/mermaid.mjs +1 -0
- package/dist/fuma/server/site-mdx-features/type-table.d.ts +1 -0
- package/dist/fuma/server/site-mdx-features/type-table.js +7 -0
- package/dist/fuma/server/site-mdx-features/type-table.mjs +1 -0
- package/dist/fuma/server/site-mdx-presets.d.ts +2 -1
- package/dist/fuma/server/site-mdx-presets.js +22 -13
- package/dist/fuma/server/site-mdx-presets.mjs +22 -12
- package/dist/fuma/share/markdown-component-map.js +43 -29
- package/dist/fuma/share/markdown-component-map.mjs +42 -28
- package/dist/lib/seo-metadata.js +34 -0
- package/dist/lib/seo-metadata.mjs +32 -0
- package/package.json +29 -7
- package/src/fuma/server/features/base.tsx +23 -0
- package/src/fuma/server/features/code.tsx +104 -0
- package/src/fuma/server/features/math.ts +16 -0
- package/src/fuma/server/features/mermaid.tsx +21 -0
- package/src/fuma/server/features/type-table.ts +12 -0
- package/src/fuma/server/features/widgets.tsx +34 -0
- package/src/fuma/server/optional-features.tsx +6 -168
- package/src/fuma/server/site-mdx-base.tsx +62 -0
- package/src/fuma/server/site-mdx-components.tsx +10 -12
- package/src/fuma/server/site-mdx-fallbacks.tsx +122 -0
- package/src/fuma/server/site-mdx-features/code.ts +1 -0
- package/src/fuma/server/site-mdx-features/math.ts +1 -0
- package/src/fuma/server/site-mdx-features/mermaid.ts +1 -0
- package/src/fuma/server/site-mdx-features/type-table.ts +1 -0
- package/src/fuma/server/site-mdx-presets.ts +52 -1
- package/src/fuma/share/markdown-component-map.tsx +5 -4
|
@@ -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
|
-
|
|
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
|
|
33
|
+
return createComposedSiteMdxComponents(
|
|
42
34
|
features,
|
|
43
|
-
|
|
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';
|
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
} from './optional-features';
|
|
15
15
|
import { SiteX } from '../site-x';
|
|
16
16
|
import type { SiteMdxComponentsOptions } from './site-mdx-components';
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
export type SiteMdxFeature = 'base' | 'code' | 'math' | 'mermaid' | 'type-table';
|
|
18
19
|
|
|
19
20
|
const defaultFumaUiComponents: MDXComponents = {
|
|
20
21
|
Callout,
|
|
@@ -60,6 +61,37 @@ export function createSiteFeatureComponentMap(
|
|
|
60
61
|
} satisfies Record<SiteMdxFeature, MDXComponents>;
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
function createSiteFeatureComponents(
|
|
65
|
+
feature: SiteMdxFeature,
|
|
66
|
+
options: SiteMdxComponentsOptions,
|
|
67
|
+
): MDXComponents {
|
|
68
|
+
const {
|
|
69
|
+
cdnBaseUrl,
|
|
70
|
+
iconMap = {},
|
|
71
|
+
imageFallbackSrc,
|
|
72
|
+
watermarkEnabled,
|
|
73
|
+
watermarkText,
|
|
74
|
+
} = options;
|
|
75
|
+
|
|
76
|
+
switch (feature) {
|
|
77
|
+
case 'base':
|
|
78
|
+
return {
|
|
79
|
+
...defaultFumaUiComponents,
|
|
80
|
+
SiteX,
|
|
81
|
+
...createBaseMdxComponents(imageFallbackSrc),
|
|
82
|
+
...createWidgetMdxComponents(cdnBaseUrl, imageFallbackSrc),
|
|
83
|
+
};
|
|
84
|
+
case 'code':
|
|
85
|
+
return createCodeMdxComponents(iconMap);
|
|
86
|
+
case 'math':
|
|
87
|
+
return createMathMdxComponents();
|
|
88
|
+
case 'mermaid':
|
|
89
|
+
return createMermaidMdxComponents(watermarkEnabled, watermarkText);
|
|
90
|
+
case 'type-table':
|
|
91
|
+
return createTypeTableMdxComponents();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
63
95
|
export function composeSiteMdxComponents(
|
|
64
96
|
features: readonly SiteMdxFeature[],
|
|
65
97
|
featureMap: Record<SiteMdxFeature, MDXComponents>,
|
|
@@ -78,3 +110,22 @@ export function composeSiteMdxComponents(
|
|
|
78
110
|
...components,
|
|
79
111
|
};
|
|
80
112
|
}
|
|
113
|
+
|
|
114
|
+
export function createComposedSiteMdxComponents(
|
|
115
|
+
features: readonly SiteMdxFeature[],
|
|
116
|
+
options: SiteMdxComponentsOptions,
|
|
117
|
+
additionalComponents?: MDXComponents,
|
|
118
|
+
components?: MDXComponents,
|
|
119
|
+
): MDXComponents {
|
|
120
|
+
return {
|
|
121
|
+
...defaultMdxComponents,
|
|
122
|
+
...features.reduce<MDXComponents>((acc, feature) => {
|
|
123
|
+
return {
|
|
124
|
+
...acc,
|
|
125
|
+
...createSiteFeatureComponents(feature, options),
|
|
126
|
+
};
|
|
127
|
+
}, {}),
|
|
128
|
+
...additionalComponents,
|
|
129
|
+
...components,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { cn } from '@windrun-huaiin/lib/utils';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
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)}
|