@clidey/dory 0.2.0 → 0.3.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/package.json +7 -9
- package/src/mdx/fence.tsx +2 -1
- package/src/mdx/mermaid.tsx +39 -11
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clidey/dory",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A CLI tool for building and previewing documentation sites",
|
|
7
7
|
"keywords": [
|
|
@@ -41,10 +41,13 @@
|
|
|
41
41
|
"@heroicons/react": "^2.2.0",
|
|
42
42
|
"@mdx-js/preact": "^3.1.0",
|
|
43
43
|
"@mdx-js/rollup": "^3.1.0",
|
|
44
|
+
"@preact/preset-vite": "^2.10.1",
|
|
44
45
|
"@tailwindcss/vite": "^4.1.8",
|
|
46
|
+
"@types/react-highlight-words": "^0.20.0",
|
|
45
47
|
"classnames": "^2.5.1",
|
|
46
48
|
"flexsearch": "^0.8.205",
|
|
47
49
|
"gray-matter": "^4.0.3",
|
|
50
|
+
"gzip-size-cli": "^5.1.0",
|
|
48
51
|
"katex": "^0.16.22",
|
|
49
52
|
"lucide-react": "^0.513.0",
|
|
50
53
|
"mermaid": "^11.6.0",
|
|
@@ -54,19 +57,14 @@
|
|
|
54
57
|
"react-highlight-words": "^0.21.0",
|
|
55
58
|
"remark-gfm": "^4.0.1",
|
|
56
59
|
"saas": "^1.0.0",
|
|
60
|
+
"sass-embedded": "^1.89.2",
|
|
57
61
|
"sirv": "^3.0.1",
|
|
58
62
|
"tailwindcss": "^4.1.8",
|
|
63
|
+
"typescript": "~5.8.3",
|
|
59
64
|
"unist-util-visit": "^5.0.0",
|
|
65
|
+
"vite": "^6.3.5",
|
|
60
66
|
"vite-plugin-mdx": "^3.6.1",
|
|
61
67
|
"wouter-preact": "^3.7.1"
|
|
62
68
|
},
|
|
63
|
-
"devDependencies": {
|
|
64
|
-
"@preact/preset-vite": "^2.10.1",
|
|
65
|
-
"@types/react-highlight-words": "^0.20.0",
|
|
66
|
-
"gzip-size-cli": "^5.1.0",
|
|
67
|
-
"sass-embedded": "^1.89.2",
|
|
68
|
-
"typescript": "~5.8.3",
|
|
69
|
-
"vite": "^6.3.5"
|
|
70
|
-
},
|
|
71
69
|
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
|
|
72
70
|
}
|
package/src/mdx/fence.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { Code, CodeGroup, CodeGroupContext, supportedLanguages } from './code'
|
|
|
4
4
|
import { MermaidRenderer } from './mermaid'
|
|
5
5
|
import { Loading } from '../components/loading'
|
|
6
6
|
import { useDarkMode } from '../utils/hooks'
|
|
7
|
+
import classNames from 'classnames'
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
export function Fence({
|
|
@@ -34,7 +35,7 @@ export function Fence({
|
|
|
34
35
|
theme={isDark ? themes.vsDark : themes.vsLight}>
|
|
35
36
|
{({ className, style, tokens, getTokenProps }) => (
|
|
36
37
|
<pre>
|
|
37
|
-
<Code className={className} style={style} title={supportedLanguage}>
|
|
38
|
+
<Code className={classNames(className, "whitespace-pre-wrap")} style={style} title={supportedLanguage}>
|
|
38
39
|
{tokens.map((line, lineIndex) => (
|
|
39
40
|
<Fragment key={lineIndex}>
|
|
40
41
|
{line
|
package/src/mdx/mermaid.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'
|
|
1
2
|
import classNames from 'classnames'
|
|
2
3
|
import { useEffect, useMemo, useRef, useState } from 'preact/compat'
|
|
3
4
|
|
|
@@ -6,6 +7,7 @@ export function MermaidRenderer({ content }: { content: string }) {
|
|
|
6
7
|
const [isFullscreen, setIsFullscreen] = useState(false)
|
|
7
8
|
const [isLoaded, setIsLoaded] = useState(false)
|
|
8
9
|
const [error, setError] = useState<string | null>(null)
|
|
10
|
+
const [isValid, setIsValid] = useState<boolean | null>(null)
|
|
9
11
|
|
|
10
12
|
const diagramId = useMemo(() => `mermaid-${btoa(content).replace(/[^a-zA-Z0-9]/g, '').substring(0, 10)}`, [content])
|
|
11
13
|
|
|
@@ -15,8 +17,7 @@ export function MermaidRenderer({ content }: { content: string }) {
|
|
|
15
17
|
const renderMermaid = async () => {
|
|
16
18
|
try {
|
|
17
19
|
const mermaid = (await import('mermaid')).default
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
if (!mounted || !mermaidRef.current) return
|
|
21
22
|
|
|
22
23
|
mermaid.initialize({
|
|
@@ -24,14 +25,14 @@ export function MermaidRenderer({ content }: { content: string }) {
|
|
|
24
25
|
theme: 'base',
|
|
25
26
|
themeVariables: {
|
|
26
27
|
fontSize: '14px',
|
|
27
|
-
nodePadding: 20,
|
|
28
|
+
nodePadding: 20,
|
|
28
29
|
notePadding: 15,
|
|
29
|
-
padding: 10,
|
|
30
|
-
nodeBorderRadius: 8,
|
|
30
|
+
padding: 10,
|
|
31
|
+
nodeBorderRadius: 8,
|
|
31
32
|
},
|
|
32
33
|
flowchart: {
|
|
33
|
-
nodeSpacing: 50,
|
|
34
|
-
rankSpacing: 80,
|
|
34
|
+
nodeSpacing: 50,
|
|
35
|
+
rankSpacing: 80,
|
|
35
36
|
padding: 20,
|
|
36
37
|
useMaxWidth: true,
|
|
37
38
|
},
|
|
@@ -45,9 +46,20 @@ export function MermaidRenderer({ content }: { content: string }) {
|
|
|
45
46
|
.replace(/^\s*style .*$/gm, '')
|
|
46
47
|
.replace(/^\s*classDef .*$/gm, '')
|
|
47
48
|
.replace(/^\s*class .*$/gm, '');
|
|
49
|
+
|
|
50
|
+
// Validate the mermaid syntax first
|
|
51
|
+
try {
|
|
52
|
+
await mermaid.parse(contentWithoutStyle)
|
|
53
|
+
setIsValid(true)
|
|
54
|
+
} catch (parseError) {
|
|
55
|
+
setIsValid(false)
|
|
56
|
+
if (mounted) {
|
|
57
|
+
setError(parseError instanceof Error ? parseError.message : 'Invalid diagram syntax')
|
|
58
|
+
}
|
|
59
|
+
return
|
|
60
|
+
}
|
|
48
61
|
|
|
49
62
|
const { svg } = await mermaid.render(diagramId, contentWithoutStyle);
|
|
50
|
-
|
|
51
63
|
|
|
52
64
|
if (mounted && mermaidRef.current) {
|
|
53
65
|
mermaidRef.current.innerHTML = svg
|
|
@@ -56,6 +68,7 @@ export function MermaidRenderer({ content }: { content: string }) {
|
|
|
56
68
|
} catch (err) {
|
|
57
69
|
console.error('Mermaid rendering error:', err)
|
|
58
70
|
if (mounted) {
|
|
71
|
+
setIsValid(false)
|
|
59
72
|
setError(err instanceof Error ? err.message : 'Failed to render diagram')
|
|
60
73
|
}
|
|
61
74
|
}
|
|
@@ -72,10 +85,25 @@ export function MermaidRenderer({ content }: { content: string }) {
|
|
|
72
85
|
setIsFullscreen(!isFullscreen)
|
|
73
86
|
}
|
|
74
87
|
|
|
75
|
-
if (error) {
|
|
88
|
+
if (error || isValid === false) {
|
|
76
89
|
return (
|
|
77
|
-
<div className="
|
|
78
|
-
<
|
|
90
|
+
<div className="mermaid-wrapper my-8">
|
|
91
|
+
<div className="flex flex-col items-center justify-center py-12 px-6 text-center bg-gradient-to-br from-red-50 to-red-100 dark:from-red-900/20 dark:to-red-800/20 border-2 border-dashed border-red-300 dark:border-red-700 rounded-lg">
|
|
92
|
+
<div className="w-16 h-16 mb-4 flex items-center justify-center bg-red-100 dark:bg-red-900/30 rounded-full">
|
|
93
|
+
<ExclamationTriangleIcon className="w-8 h-8 text-red-500" />
|
|
94
|
+
</div>
|
|
95
|
+
<h3 className="text-lg font-semibold text-red-700 dark:text-red-300 mb-2">
|
|
96
|
+
Diagram Syntax Error
|
|
97
|
+
</h3>
|
|
98
|
+
<p className="text-red-600 dark:text-red-400 mb-4 max-w-md">
|
|
99
|
+
The Mermaid diagram contains invalid syntax and cannot be rendered.
|
|
100
|
+
</p>
|
|
101
|
+
<div className="bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-800 rounded-md p-3 max-w-md">
|
|
102
|
+
<p className="text-sm text-red-700 dark:text-red-300 font-mono break-all">
|
|
103
|
+
{error}
|
|
104
|
+
</p>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
79
107
|
</div>
|
|
80
108
|
)
|
|
81
109
|
}
|