@alifd/chat 0.3.0-beta.0 → 0.3.0-beta.1
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/es/HTMLRenderer/index.less +0 -2
- package/es/index.js +1 -1
- package/es/markdown/index.js +44 -7
- package/lib/HTMLRenderer/index.less +0 -2
- package/lib/index.js +1 -1
- package/lib/markdown/index.js +44 -7
- package/package.json +1 -1
package/es/index.js
CHANGED
|
@@ -17,4 +17,4 @@ export { default as ImagePreview } from './ImagePreview';
|
|
|
17
17
|
export { default as HTMLRenderer } from './HTMLRenderer';
|
|
18
18
|
export { default as Markdown } from './markdown';
|
|
19
19
|
export { default as CardLoading } from './card-loading';
|
|
20
|
-
export const version = '0.3.0-beta.
|
|
20
|
+
export const version = '0.3.0-beta.1';
|
package/es/markdown/index.js
CHANGED
|
@@ -23,6 +23,18 @@ const Markdown = forwardRef(({ className, onReady, content }, ref) => {
|
|
|
23
23
|
const containerRef = useRef(null);
|
|
24
24
|
// 处理 HTML 标签
|
|
25
25
|
const processedContent = useMemo(() => {
|
|
26
|
+
// 使用 Record 类型来定义映射关系
|
|
27
|
+
const sizeTokenToTagMap = {
|
|
28
|
+
common_hypertitle_text_style__font_size: 'h1',
|
|
29
|
+
common_largetitle_text_style__font_size: 'h1',
|
|
30
|
+
common_h1_text_style__font_size: 'h1',
|
|
31
|
+
common_h2_text_style__font_size: 'h2',
|
|
32
|
+
common_h3_text_style__font_size: 'h3',
|
|
33
|
+
common_h4_text_style__font_size: 'h4',
|
|
34
|
+
common_h5_text_style__font_size: 'h5',
|
|
35
|
+
common_body_text_style__font_size: 'span',
|
|
36
|
+
common_footnote_text_style__font_size: 'span'
|
|
37
|
+
};
|
|
26
38
|
const regex = /<font\s+([^>]+)>([^<]+)<\/font>/g;
|
|
27
39
|
return content.replace(regex, (match, attributes, text) => {
|
|
28
40
|
let sizeToken = '';
|
|
@@ -45,7 +57,10 @@ const Markdown = forwardRef(({ className, onReady, content }, ref) => {
|
|
|
45
57
|
styleParts.push(`color: var(--${colorTokenV2})`);
|
|
46
58
|
}
|
|
47
59
|
const style = styleParts.join('; ');
|
|
48
|
-
|
|
60
|
+
// 根据 sizeToken 选择适当的标签
|
|
61
|
+
const tag = sizeTokenToTagMap[sizeToken] || 'span';
|
|
62
|
+
return `<${tag} style="${style}" class="markdownFont">${text}</${tag}>`;
|
|
63
|
+
// return `<span style="${style}">${text}</span>`;
|
|
49
64
|
});
|
|
50
65
|
}, [content]);
|
|
51
66
|
// 转换表情符号
|
|
@@ -114,12 +129,34 @@ const Markdown = forwardRef(({ className, onReady, content }, ref) => {
|
|
|
114
129
|
copyButton.className = 'code-block-copy';
|
|
115
130
|
copyButton.textContent = '复制';
|
|
116
131
|
copyButton.onclick = () => {
|
|
117
|
-
navigator.clipboard.writeText
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
133
|
+
navigator.clipboard.writeText(code).then(() => {
|
|
134
|
+
copyButton.textContent = '已复制';
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
copyButton.textContent = '复制';
|
|
137
|
+
}, 1000);
|
|
138
|
+
}).catch(() => {
|
|
139
|
+
copyButton.textContent = '复制失败';
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
//有些环境还不支持navigator.clipboard,降级使用document.execCommand
|
|
144
|
+
const textArea = document.createElement('textarea');
|
|
145
|
+
textArea.value = code;
|
|
146
|
+
document.body.appendChild(textArea);
|
|
147
|
+
textArea.select();
|
|
148
|
+
try {
|
|
149
|
+
document.execCommand('copy');
|
|
150
|
+
copyButton.textContent = '已复制';
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
copyButton.textContent = '复制';
|
|
153
|
+
}, 1000);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
copyButton.textContent = '复制失败';
|
|
157
|
+
}
|
|
158
|
+
document.body.removeChild(textArea);
|
|
159
|
+
}
|
|
123
160
|
};
|
|
124
161
|
header.appendChild(languageSpan);
|
|
125
162
|
header.appendChild(copyButton);
|
package/lib/index.js
CHANGED
|
@@ -40,4 +40,4 @@ var markdown_1 = require("./markdown");
|
|
|
40
40
|
Object.defineProperty(exports, "Markdown", { enumerable: true, get: function () { return tslib_1.__importDefault(markdown_1).default; } });
|
|
41
41
|
var card_loading_1 = require("./card-loading");
|
|
42
42
|
Object.defineProperty(exports, "CardLoading", { enumerable: true, get: function () { return tslib_1.__importDefault(card_loading_1).default; } });
|
|
43
|
-
exports.version = '0.3.0-beta.
|
|
43
|
+
exports.version = '0.3.0-beta.1';
|
package/lib/markdown/index.js
CHANGED
|
@@ -26,6 +26,18 @@ const Markdown = (0, react_1.forwardRef)(({ className, onReady, content }, ref)
|
|
|
26
26
|
const containerRef = (0, react_1.useRef)(null);
|
|
27
27
|
// 处理 HTML 标签
|
|
28
28
|
const processedContent = (0, react_1.useMemo)(() => {
|
|
29
|
+
// 使用 Record 类型来定义映射关系
|
|
30
|
+
const sizeTokenToTagMap = {
|
|
31
|
+
common_hypertitle_text_style__font_size: 'h1',
|
|
32
|
+
common_largetitle_text_style__font_size: 'h1',
|
|
33
|
+
common_h1_text_style__font_size: 'h1',
|
|
34
|
+
common_h2_text_style__font_size: 'h2',
|
|
35
|
+
common_h3_text_style__font_size: 'h3',
|
|
36
|
+
common_h4_text_style__font_size: 'h4',
|
|
37
|
+
common_h5_text_style__font_size: 'h5',
|
|
38
|
+
common_body_text_style__font_size: 'span',
|
|
39
|
+
common_footnote_text_style__font_size: 'span'
|
|
40
|
+
};
|
|
29
41
|
const regex = /<font\s+([^>]+)>([^<]+)<\/font>/g;
|
|
30
42
|
return content.replace(regex, (match, attributes, text) => {
|
|
31
43
|
let sizeToken = '';
|
|
@@ -48,7 +60,10 @@ const Markdown = (0, react_1.forwardRef)(({ className, onReady, content }, ref)
|
|
|
48
60
|
styleParts.push(`color: var(--${colorTokenV2})`);
|
|
49
61
|
}
|
|
50
62
|
const style = styleParts.join('; ');
|
|
51
|
-
|
|
63
|
+
// 根据 sizeToken 选择适当的标签
|
|
64
|
+
const tag = sizeTokenToTagMap[sizeToken] || 'span';
|
|
65
|
+
return `<${tag} style="${style}" class="markdownFont">${text}</${tag}>`;
|
|
66
|
+
// return `<span style="${style}">${text}</span>`;
|
|
52
67
|
});
|
|
53
68
|
}, [content]);
|
|
54
69
|
// 转换表情符号
|
|
@@ -117,12 +132,34 @@ const Markdown = (0, react_1.forwardRef)(({ className, onReady, content }, ref)
|
|
|
117
132
|
copyButton.className = 'code-block-copy';
|
|
118
133
|
copyButton.textContent = '复制';
|
|
119
134
|
copyButton.onclick = () => {
|
|
120
|
-
navigator.clipboard.writeText
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
136
|
+
navigator.clipboard.writeText(code).then(() => {
|
|
137
|
+
copyButton.textContent = '已复制';
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
copyButton.textContent = '复制';
|
|
140
|
+
}, 1000);
|
|
141
|
+
}).catch(() => {
|
|
142
|
+
copyButton.textContent = '复制失败';
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
//有些环境还不支持navigator.clipboard,降级使用document.execCommand
|
|
147
|
+
const textArea = document.createElement('textarea');
|
|
148
|
+
textArea.value = code;
|
|
149
|
+
document.body.appendChild(textArea);
|
|
150
|
+
textArea.select();
|
|
151
|
+
try {
|
|
152
|
+
document.execCommand('copy');
|
|
153
|
+
copyButton.textContent = '已复制';
|
|
154
|
+
setTimeout(() => {
|
|
155
|
+
copyButton.textContent = '复制';
|
|
156
|
+
}, 1000);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
copyButton.textContent = '复制失败';
|
|
160
|
+
}
|
|
161
|
+
document.body.removeChild(textArea);
|
|
162
|
+
}
|
|
126
163
|
};
|
|
127
164
|
header.appendChild(languageSpan);
|
|
128
165
|
header.appendChild(copyButton);
|