@baishuyun/ai-design 2.1.5 → 2.1.7
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 +12 -0
- package/package.json +6 -3
- package/src/components/memoized-markdown.tsx +50 -2
- 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
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @baishuyun/ai-design
|
|
2
2
|
|
|
3
|
+
## 2.1.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8cd43ba: MemoizedMarkdown renders GitHub Flavored Markdown (tables, strikethrough, task lists, autolinks) and turns inline `<br>` into line breaks; markdown tables in ai-office messages get readable column widths and scroll horizontally when wide.
|
|
8
|
+
|
|
9
|
+
## 2.1.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 4e22cb5: Markdown 代码块支持 js、jsx、tsx、css 和 json 语法高亮,行内代码改为浅灰底样式。
|
|
14
|
+
|
|
3
15
|
## 2.1.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baishuyun/ai-design",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "AI 功能 UI 组件库 - 所有 AI 功能的 UI 表现唯一真相来源",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -49,13 +49,16 @@
|
|
|
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",
|
|
61
|
+
"remark-gfm": "4.0.1",
|
|
59
62
|
"tailwind-merge": "^3.4.0",
|
|
60
63
|
"vaul": "^1.1.2",
|
|
61
64
|
"zod": "^4.1.13",
|
|
@@ -69,15 +72,15 @@
|
|
|
69
72
|
"devDependencies": {
|
|
70
73
|
"@storybook/addon-docs": "^10.1.11",
|
|
71
74
|
"@storybook/addon-vitest": "^10.1.11",
|
|
72
|
-
"@storybook/react-vite": "^10.1.11",
|
|
73
75
|
"@storybook/react": "^10.1.11",
|
|
76
|
+
"@storybook/react-vite": "^10.1.11",
|
|
74
77
|
"@tailwindcss/cli": "^4.3.0",
|
|
78
|
+
"@tailwindcss/typography": "^0.5.19",
|
|
75
79
|
"@tailwindcss/vite": "^4.1.17",
|
|
76
80
|
"@types/codemirror": "^5.60.0",
|
|
77
81
|
"@types/react": "^19.0.0",
|
|
78
82
|
"@types/react-dom": "^19.0.0",
|
|
79
83
|
"@vitejs/plugin-react": "^5.1.1",
|
|
80
|
-
"@tailwindcss/typography": "^0.5.19",
|
|
81
84
|
"storybook": "^10.1.11",
|
|
82
85
|
"tailwindcss": "^4.1.17",
|
|
83
86
|
"tailwindcss-animate": "^1.0.7",
|
|
@@ -1,7 +1,50 @@
|
|
|
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';
|
|
11
|
+
import remarkGfm from 'remark-gfm';
|
|
12
|
+
|
|
13
|
+
interface MdNode {
|
|
14
|
+
type: string;
|
|
15
|
+
value?: string;
|
|
16
|
+
children?: MdNode[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 把行内 HTML 的 <br> 转为换行节点:表格单元格内无法换行,模型常写 <br>;
|
|
21
|
+
* 其余 HTML 仍不渲染(不引入 rehype-raw,避免注入)。
|
|
22
|
+
*/
|
|
23
|
+
const remarkBreakTags = () => (tree: MdNode) => {
|
|
24
|
+
const walk = (node: MdNode) => {
|
|
25
|
+
node.children?.forEach((child, i) => {
|
|
26
|
+
if (child.type === 'html' && /^<br\s*\/?>$/i.test(child.value?.trim() ?? '')) {
|
|
27
|
+
node.children![i] = { type: 'break' };
|
|
28
|
+
} else {
|
|
29
|
+
walk(child);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
walk(tree);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** GFM(表格、删除线、任务列表、自动链接)与 <br> 换行;breaks 时额外把单个换行渲染为换行 */
|
|
37
|
+
const BASE_REMARK_PLUGINS = [remarkGfm, remarkBreakTags];
|
|
38
|
+
const BREAKS_REMARK_PLUGINS = [...BASE_REMARK_PLUGINS, remarkBreaks];
|
|
39
|
+
|
|
40
|
+
/** 表格排版:表头不换行;单元格最小宽度、顶部对齐,避免短列被长列挤成逐字竖排;超宽时横向滚动 */
|
|
41
|
+
const TABLE_CLS =
|
|
42
|
+
'[&_table]:block [&_table]:overflow-x-auto [&_th]:whitespace-nowrap [&_th]:text-left ' +
|
|
43
|
+
'[&_td]:min-w-[5em] [&_td]:align-top [&_th]:px-2 [&_td]:px-2 [&_th:first-child]:pl-0 [&_td:first-child]:pl-0';
|
|
44
|
+
|
|
45
|
+
const highlightOptions = {
|
|
46
|
+
languages: { javascript, typescript, css, json, xml },
|
|
47
|
+
} satisfies HighlightOptions;
|
|
5
48
|
|
|
6
49
|
function parseMarkdownIntoBlocks(markdown: string): string[] {
|
|
7
50
|
const tokens = marked.lexer(markdown);
|
|
@@ -10,7 +53,12 @@ function parseMarkdownIntoBlocks(markdown: string): string[] {
|
|
|
10
53
|
|
|
11
54
|
const MemoizedMarkdownBlock = memo(({ content, breaks }: { content: string; breaks?: boolean }) => {
|
|
12
55
|
return (
|
|
13
|
-
<ReactMarkdown
|
|
56
|
+
<ReactMarkdown
|
|
57
|
+
rehypePlugins={[[rehypeHighlight, highlightOptions]]}
|
|
58
|
+
remarkPlugins={breaks ? BREAKS_REMARK_PLUGINS : BASE_REMARK_PLUGINS}
|
|
59
|
+
>
|
|
60
|
+
{content}
|
|
61
|
+
</ReactMarkdown>
|
|
14
62
|
);
|
|
15
63
|
});
|
|
16
64
|
|
|
@@ -27,7 +75,7 @@ const Prose = memo(function Prose({
|
|
|
27
75
|
const blocks = useMemo(() => parseMarkdownIntoBlocks(content), [content]);
|
|
28
76
|
|
|
29
77
|
return (
|
|
30
|
-
<article className=
|
|
78
|
+
<article className={`prose ${TABLE_CLS}`} style={style}>
|
|
31
79
|
{blocks.map((block, index) => (
|
|
32
80
|
<MemoizedMarkdownBlock breaks={breaks} content={block} key={`${id}-block_${index}`} />
|
|
33
81
|
))}
|
|
@@ -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
|
}
|