@baishuyun/ai-design 2.1.5 → 2.1.6
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/CHANGELOG.md +6 -0
- package/package.json +5 -3
- package/src/components/memoized-markdown.tsx +16 -1
- package/src/highlight-languages.d.ts +6 -0
- package/src/stories/MemoizedMarkdown.stories.tsx +38 -2
- package/src/style.css +61 -0
- package/style.css +37 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baishuyun/ai-design",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "AI 功能 UI 组件库 - 所有 AI 功能的 UI 表现唯一真相来源",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -49,12 +49,14 @@
|
|
|
49
49
|
"clsx": "^2.1.1",
|
|
50
50
|
"codemirror": "^5.65.0",
|
|
51
51
|
"date-fns": "^4.1.0",
|
|
52
|
+
"highlight.js": "^11.12.0",
|
|
52
53
|
"lucide-react": "^0.554.0",
|
|
53
54
|
"marked": "^14.1.4",
|
|
54
55
|
"radix-ui": "^1.5.0",
|
|
55
56
|
"react-day-picker": "^9.11.2",
|
|
56
57
|
"react-hook-form": "^7.76.0",
|
|
57
58
|
"react-markdown": "^10.1.0",
|
|
59
|
+
"rehype-highlight": "^7.0.2",
|
|
58
60
|
"remark-breaks": "^4.0.0",
|
|
59
61
|
"tailwind-merge": "^3.4.0",
|
|
60
62
|
"vaul": "^1.1.2",
|
|
@@ -69,15 +71,15 @@
|
|
|
69
71
|
"devDependencies": {
|
|
70
72
|
"@storybook/addon-docs": "^10.1.11",
|
|
71
73
|
"@storybook/addon-vitest": "^10.1.11",
|
|
72
|
-
"@storybook/react-vite": "^10.1.11",
|
|
73
74
|
"@storybook/react": "^10.1.11",
|
|
75
|
+
"@storybook/react-vite": "^10.1.11",
|
|
74
76
|
"@tailwindcss/cli": "^4.3.0",
|
|
77
|
+
"@tailwindcss/typography": "^0.5.19",
|
|
75
78
|
"@tailwindcss/vite": "^4.1.17",
|
|
76
79
|
"@types/codemirror": "^5.60.0",
|
|
77
80
|
"@types/react": "^19.0.0",
|
|
78
81
|
"@types/react-dom": "^19.0.0",
|
|
79
82
|
"@vitejs/plugin-react": "^5.1.1",
|
|
80
|
-
"@tailwindcss/typography": "^0.5.19",
|
|
81
83
|
"storybook": "^10.1.11",
|
|
82
84
|
"tailwindcss": "^4.1.17",
|
|
83
85
|
"tailwindcss-animate": "^1.0.7",
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import css from 'highlight.js/lib/languages/css';
|
|
2
|
+
import javascript from 'highlight.js/lib/languages/javascript';
|
|
3
|
+
import json from 'highlight.js/lib/languages/json';
|
|
4
|
+
import typescript from 'highlight.js/lib/languages/typescript';
|
|
5
|
+
import xml from 'highlight.js/lib/languages/xml';
|
|
1
6
|
import { marked } from 'marked';
|
|
2
7
|
import { CSSProperties, memo, useMemo } from 'react';
|
|
3
8
|
import ReactMarkdown from 'react-markdown';
|
|
9
|
+
import rehypeHighlight, { type Options as HighlightOptions } from 'rehype-highlight';
|
|
4
10
|
import remarkBreaks from 'remark-breaks';
|
|
5
11
|
|
|
12
|
+
const highlightOptions = {
|
|
13
|
+
languages: { javascript, typescript, css, json, xml },
|
|
14
|
+
} satisfies HighlightOptions;
|
|
15
|
+
|
|
6
16
|
function parseMarkdownIntoBlocks(markdown: string): string[] {
|
|
7
17
|
const tokens = marked.lexer(markdown);
|
|
8
18
|
return tokens.flatMap((token) => ((token.raw ?? '').trim() ? [token.raw] : []));
|
|
@@ -10,7 +20,12 @@ function parseMarkdownIntoBlocks(markdown: string): string[] {
|
|
|
10
20
|
|
|
11
21
|
const MemoizedMarkdownBlock = memo(({ content, breaks }: { content: string; breaks?: boolean }) => {
|
|
12
22
|
return (
|
|
13
|
-
<ReactMarkdown
|
|
23
|
+
<ReactMarkdown
|
|
24
|
+
rehypePlugins={[[rehypeHighlight, highlightOptions]]}
|
|
25
|
+
remarkPlugins={breaks ? [remarkBreaks] : undefined}
|
|
26
|
+
>
|
|
27
|
+
{content}
|
|
28
|
+
</ReactMarkdown>
|
|
14
29
|
);
|
|
15
30
|
});
|
|
16
31
|
|
|
@@ -26,10 +26,46 @@ export const PlainText: Story = {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export const CodeBlock: Story = {
|
|
29
|
+
parameters: {
|
|
30
|
+
layout: 'padded',
|
|
31
|
+
},
|
|
29
32
|
args: {
|
|
30
33
|
id: 'code-block',
|
|
31
|
-
content:
|
|
32
|
-
|
|
34
|
+
content: `
|
|
35
|
+
\`\`\`js
|
|
36
|
+
function greet(name) {
|
|
37
|
+
return \`Hello, \${name}!\`;
|
|
38
|
+
}
|
|
39
|
+
\`\`\`
|
|
40
|
+
|
|
41
|
+
\`\`\`jsx
|
|
42
|
+
export function Hello({ name }) {
|
|
43
|
+
return <div className="hello">Hello, {name}</div>;
|
|
44
|
+
}
|
|
45
|
+
\`\`\`
|
|
46
|
+
|
|
47
|
+
\`\`\`tsx
|
|
48
|
+
interface User {
|
|
49
|
+
name: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function Hello({ name }: User) {
|
|
53
|
+
return <div className="hello">Hello, {name}</div>;
|
|
54
|
+
}
|
|
55
|
+
\`\`\`
|
|
56
|
+
|
|
57
|
+
\`\`\`css
|
|
58
|
+
.hello {
|
|
59
|
+
color: #2563eb;
|
|
60
|
+
font-weight: 600;
|
|
61
|
+
}
|
|
62
|
+
\`\`\`
|
|
63
|
+
|
|
64
|
+
\`\`\`python
|
|
65
|
+
def greet(name):
|
|
66
|
+
return f"Hello, {name}!"
|
|
67
|
+
\`\`\`
|
|
68
|
+
`.trim(),
|
|
33
69
|
},
|
|
34
70
|
};
|
|
35
71
|
|
package/src/style.css
CHANGED
|
@@ -223,6 +223,67 @@
|
|
|
223
223
|
--tw-prose-body: #121111;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/* highlight.js tokens on the dark prose code block */
|
|
227
|
+
.prose pre .hljs-comment,
|
|
228
|
+
.prose pre .hljs-quote {
|
|
229
|
+
color: #8b949e;
|
|
230
|
+
}
|
|
231
|
+
.prose pre .hljs-keyword,
|
|
232
|
+
.prose pre .hljs-selector-tag,
|
|
233
|
+
.prose pre .hljs-type,
|
|
234
|
+
.prose pre .hljs-template-tag {
|
|
235
|
+
color: #ff7b72;
|
|
236
|
+
}
|
|
237
|
+
.prose pre .hljs-string,
|
|
238
|
+
.prose pre .hljs-regexp,
|
|
239
|
+
.prose pre .hljs-meta .hljs-string {
|
|
240
|
+
color: #a5d6ff;
|
|
241
|
+
}
|
|
242
|
+
.prose pre .hljs-title,
|
|
243
|
+
.prose pre .hljs-title.class_,
|
|
244
|
+
.prose pre .hljs-title.function_,
|
|
245
|
+
.prose pre .hljs-section {
|
|
246
|
+
color: #d2a8ff;
|
|
247
|
+
}
|
|
248
|
+
.prose pre .hljs-attr,
|
|
249
|
+
.prose pre .hljs-attribute,
|
|
250
|
+
.prose pre .hljs-number,
|
|
251
|
+
.prose pre .hljs-literal,
|
|
252
|
+
.prose pre .hljs-variable,
|
|
253
|
+
.prose pre .hljs-selector-attr,
|
|
254
|
+
.prose pre .hljs-selector-class,
|
|
255
|
+
.prose pre .hljs-selector-id,
|
|
256
|
+
.prose pre .hljs-selector-pseudo {
|
|
257
|
+
color: #79c0ff;
|
|
258
|
+
}
|
|
259
|
+
.prose pre .hljs-built_in,
|
|
260
|
+
.prose pre .hljs-symbol,
|
|
261
|
+
.prose pre .hljs-name {
|
|
262
|
+
color: #ffa657;
|
|
263
|
+
}
|
|
264
|
+
.prose pre .hljs-tag {
|
|
265
|
+
color: #7ee787;
|
|
266
|
+
}
|
|
267
|
+
.prose pre .hljs-subst {
|
|
268
|
+
color: #e6edf3;
|
|
269
|
+
}
|
|
270
|
+
.prose pre .hljs-punctuation {
|
|
271
|
+
color: #c9d1d9;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* single-backtick inline code */
|
|
275
|
+
.prose :not(pre) > code {
|
|
276
|
+
border-radius: 4px;
|
|
277
|
+
background: #f2f3f5;
|
|
278
|
+
padding: 0.1em 0.35em;
|
|
279
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
280
|
+
font-weight: 500;
|
|
281
|
+
}
|
|
282
|
+
.prose :not(pre) > code::before,
|
|
283
|
+
.prose :not(pre) > code::after {
|
|
284
|
+
content: none;
|
|
285
|
+
}
|
|
286
|
+
|
|
226
287
|
/* Hide scrollbar for Chrome, Safari and Opera */
|
|
227
288
|
.scrollbar-hide::-webkit-scrollbar {
|
|
228
289
|
display: none;
|
package/style.css
CHANGED
|
@@ -3722,6 +3722,43 @@
|
|
|
3722
3722
|
.prose {
|
|
3723
3723
|
--tw-prose-body: #121111;
|
|
3724
3724
|
}
|
|
3725
|
+
.prose pre .hljs-comment, .prose pre .hljs-quote {
|
|
3726
|
+
color: #8b949e;
|
|
3727
|
+
}
|
|
3728
|
+
.prose pre .hljs-keyword, .prose pre .hljs-selector-tag, .prose pre .hljs-type, .prose pre .hljs-template-tag {
|
|
3729
|
+
color: #ff7b72;
|
|
3730
|
+
}
|
|
3731
|
+
.prose pre .hljs-string, .prose pre .hljs-regexp, .prose pre .hljs-meta .hljs-string {
|
|
3732
|
+
color: #a5d6ff;
|
|
3733
|
+
}
|
|
3734
|
+
.prose pre .hljs-title, .prose pre .hljs-title.class_, .prose pre .hljs-title.function_, .prose pre .hljs-section {
|
|
3735
|
+
color: #d2a8ff;
|
|
3736
|
+
}
|
|
3737
|
+
.prose pre .hljs-attr, .prose pre .hljs-attribute, .prose pre .hljs-number, .prose pre .hljs-literal, .prose pre .hljs-variable, .prose pre .hljs-selector-attr, .prose pre .hljs-selector-class, .prose pre .hljs-selector-id, .prose pre .hljs-selector-pseudo {
|
|
3738
|
+
color: #79c0ff;
|
|
3739
|
+
}
|
|
3740
|
+
.prose pre .hljs-built_in, .prose pre .hljs-symbol, .prose pre .hljs-name {
|
|
3741
|
+
color: #ffa657;
|
|
3742
|
+
}
|
|
3743
|
+
.prose pre .hljs-tag {
|
|
3744
|
+
color: #7ee787;
|
|
3745
|
+
}
|
|
3746
|
+
.prose pre .hljs-subst {
|
|
3747
|
+
color: #e6edf3;
|
|
3748
|
+
}
|
|
3749
|
+
.prose pre .hljs-punctuation {
|
|
3750
|
+
color: #c9d1d9;
|
|
3751
|
+
}
|
|
3752
|
+
.prose :not(pre) > code {
|
|
3753
|
+
border-radius: 4px;
|
|
3754
|
+
background: #f2f3f5;
|
|
3755
|
+
padding: 0.1em 0.35em;
|
|
3756
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
3757
|
+
font-weight: 500;
|
|
3758
|
+
}
|
|
3759
|
+
.prose :not(pre) > code::before, .prose :not(pre) > code::after {
|
|
3760
|
+
content: none;
|
|
3761
|
+
}
|
|
3725
3762
|
.scrollbar-hide::-webkit-scrollbar {
|
|
3726
3763
|
display: none;
|
|
3727
3764
|
}
|