bhd-components 0.10.33 → 0.10.34
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/dist/index.esm.es5.development.css +14476 -0
- package/dist/index.esm.es5.development.js +16324 -0
- package/dist/index.esm.es5.production.css +10 -0
- package/dist/index.esm.es5.production.js +1 -0
- package/dist/vendor.esm.es5.development.css +119 -0
- package/dist/vendor.esm.es5.development.js +182678 -0
- package/dist/vendor.esm.es5.production.css +11 -0
- package/dist/vendor.esm.es5.production.js +493 -0
- package/es2017/customerService/function.d.ts +3 -1
- package/es2017/customerService/function.js +34 -1
- package/es2017/customerService/index.js +48 -37
- package/es2017/customerService/index.module.less +2 -1
- package/es2017/customerService/index2.module.less +2 -1
- package/esm/customerService/function.d.ts +3 -1
- package/esm/customerService/function.js +36 -1
- package/esm/customerService/index.js +51 -41
- package/esm/customerService/index.module.less +2 -1
- package/esm/customerService/index2.module.less +2 -1
- package/package.json +2 -3
|
@@ -22,4 +22,6 @@ declare const getBase64Image: (src: any) => Promise<unknown>;
|
|
|
22
22
|
declare const formatDate: (dateStr: any) => any;
|
|
23
23
|
declare const urlToBase64: (url: string) => Promise<unknown>;
|
|
24
24
|
declare const toHashString: (str: string) => string;
|
|
25
|
-
|
|
25
|
+
declare const removeMermaidBlockComments: (markdownContent: any) => any;
|
|
26
|
+
declare const handleRenderSyntaxBlock: (markdownContent: any, flag: boolean) => any;
|
|
27
|
+
export { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, getBase64Image, formatDate, urlToBase64, toHashString, removeMermaidBlockComments, handleRenderSyntaxBlock, };
|
|
@@ -191,4 +191,37 @@ const toHashString = (str)=>{
|
|
|
191
191
|
// 转换为正数并格式化为8位十六进制
|
|
192
192
|
return (result >>> 0).toString(16).padStart(8, '0');
|
|
193
193
|
};
|
|
194
|
-
|
|
194
|
+
// 正则:匹配```mermaid代码块内 ‘// 注释的内容’ 移除
|
|
195
|
+
const removeMermaidBlockComments = (markdownContent)=>{
|
|
196
|
+
// 正则匹配 ```mermaid 代码块,捕获块内内容
|
|
197
|
+
const mermaidBlockRegex = /(```mermaid\n)([\s\S]*?)(\n```)/gm;
|
|
198
|
+
// 替换逻辑:保留代码块标识,仅清理块内注释
|
|
199
|
+
return markdownContent.replace(mermaidBlockRegex, (match, prefix, content, suffix)=>{
|
|
200
|
+
// 清理块内注释的正则(同之前逻辑,优先保留字符串)
|
|
201
|
+
const commentRegex = /(".*?"|'.*?')|(\/\*[\s\S]*?\*\/)|(\/\/.*?$)/gm;
|
|
202
|
+
const cleanContent = content.replace(commentRegex, (m, stringPart)=>stringPart || '');
|
|
203
|
+
// 拼接回完整代码块(保留 ```mermaid 和 ``` 标识)
|
|
204
|
+
return `${prefix}${cleanContent}${suffix}`;
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
// 处理渲染语法
|
|
208
|
+
const handleRenderSyntaxBlock = (markdownContent, flag)=>{
|
|
209
|
+
if (flag) {
|
|
210
|
+
// 正则匹配  图片语法
|
|
211
|
+
const imgBlockRegex = /\[([^\]]*)\]\[\]\((https?:\/\/[^\s)]+)\)/gm;
|
|
212
|
+
markdownContent = markdownContent.replace(imgBlockRegex, (match, altText, url)=>{
|
|
213
|
+
return ``;
|
|
214
|
+
});
|
|
215
|
+
markdownContent = markdownContent.replaceAll('```mermaid-code', '```mermaid');
|
|
216
|
+
return markdownContent;
|
|
217
|
+
} else {
|
|
218
|
+
// 正则匹配  图片语法
|
|
219
|
+
const imgBlockRegex = /!\[([^\]]*)\]\((https?:\/\/[^\s)]+)\)/gm;
|
|
220
|
+
markdownContent = markdownContent.replace(imgBlockRegex, (match, altText, url)=>{
|
|
221
|
+
return `[${altText}][](${url})`;
|
|
222
|
+
});
|
|
223
|
+
markdownContent = markdownContent.replaceAll('```mermaid', '```mermaid-code');
|
|
224
|
+
return markdownContent;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
export { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, getBase64Image, formatDate, urlToBase64, toHashString, removeMermaidBlockComments, handleRenderSyntaxBlock };
|
|
@@ -25,14 +25,13 @@ import { Remarkable } from "remarkable";
|
|
|
25
25
|
import hljs from "highlight.js";
|
|
26
26
|
import "highlight.js/styles/github.css";
|
|
27
27
|
import mermaid from "mermaid";
|
|
28
|
-
import ViewMemaid from "./viewMemaid";
|
|
29
28
|
import { render } from "react-dom";
|
|
30
29
|
import Provider from "../provider";
|
|
31
30
|
const { TextArea } = Input;
|
|
32
31
|
// import './html2canvas.test.js';
|
|
33
32
|
import knowledge_icon from "./images/knowledge_icon.png";
|
|
34
33
|
// import { useMediaRecorder } from "./useMediaRecorder"; //录音使用文件
|
|
35
|
-
import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64, toHashString } from "./function"; //一些方法
|
|
34
|
+
import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64, toHashString, removeMermaidBlockComments, handleRenderSyntaxBlock } from "./function"; //一些方法
|
|
36
35
|
// import html2canvas from "html2canvas";
|
|
37
36
|
// const screenShot = require('./screenShotPlugin.esm')
|
|
38
37
|
import ScreenShot from "./js-screen-shot/main";
|
|
@@ -60,8 +59,13 @@ mermaid.initialize({
|
|
|
60
59
|
theme: 'default',
|
|
61
60
|
securityLevel: 'loose',
|
|
62
61
|
flowchart: {
|
|
62
|
+
useMaxWidth: true,
|
|
63
63
|
htmlLabels: true,
|
|
64
64
|
curve: 'basis'
|
|
65
|
+
},
|
|
66
|
+
pie: {
|
|
67
|
+
useMaxWidth: true,
|
|
68
|
+
useWidth: 360
|
|
65
69
|
}
|
|
66
70
|
});
|
|
67
71
|
const CustomerService = (props)=>{
|
|
@@ -136,9 +140,9 @@ const CustomerService = (props)=>{
|
|
|
136
140
|
html: true,
|
|
137
141
|
highlight: function(str, lang) {
|
|
138
142
|
// 特殊处理 mermaid 代码块
|
|
139
|
-
if (lang === 'mermaid') {
|
|
140
|
-
|
|
141
|
-
}
|
|
143
|
+
// if (lang === 'mermaid') {
|
|
144
|
+
// return str; // 不高亮 mermaid 代码
|
|
145
|
+
// }
|
|
142
146
|
if (lang && hljs.getLanguage(lang)) {
|
|
143
147
|
try {
|
|
144
148
|
return hljs.highlight(lang, str).value;
|
|
@@ -154,8 +158,16 @@ const CustomerService = (props)=>{
|
|
|
154
158
|
remarkable.renderer.rules.fence_custom = {
|
|
155
159
|
mermaid: function(tokens, idx) {
|
|
156
160
|
const token = tokens[idx];
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
try {
|
|
162
|
+
if (mermaid.parse(token.content)) {
|
|
163
|
+
const id = 'mermaid_' + toHashString(token.content);
|
|
164
|
+
return `<span class="${styles.maskZoomBox}"><pre class="${styles.mermaid}" id="${id}">${token.content}</pre><span class="${styles.zoomBox}" onclick="openViewMemaid('${id}')"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>`;
|
|
165
|
+
} else {
|
|
166
|
+
return `<pre><code class="language-mermaid">${token.content}</code></pre>`;
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
return `<pre><code class="language-mermaid">${token.content}</code></pre>`;
|
|
170
|
+
}
|
|
159
171
|
}
|
|
160
172
|
};
|
|
161
173
|
remarkable.renderer.rules.image = (tokens, idx)=>{
|
|
@@ -185,8 +197,16 @@ const CustomerService = (props)=>{
|
|
|
185
197
|
newRemarkable.renderer.rules.fence_custom = {
|
|
186
198
|
mermaid: function(tokens, idx) {
|
|
187
199
|
const token = tokens[idx];
|
|
188
|
-
|
|
189
|
-
|
|
200
|
+
try {
|
|
201
|
+
if (mermaid.parse(token.content)) {
|
|
202
|
+
const id = 'mermaid_' + toHashString(token.content);
|
|
203
|
+
return `<span class="${styles.maskZoomBox}"><pre class="${styles.mermaid}" id="${id}">${token.content}</pre><span class="${styles.zoomBox}" onclick="openViewMemaid('${id}')"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>`;
|
|
204
|
+
} else {
|
|
205
|
+
return `<pre><code class="language-mermaid">${token.content}</code></pre>`;
|
|
206
|
+
}
|
|
207
|
+
} catch (error) {
|
|
208
|
+
return `<pre><code class="language-mermaid">${token.content}</code></pre>`;
|
|
209
|
+
}
|
|
190
210
|
}
|
|
191
211
|
};
|
|
192
212
|
remarkable.renderer.rules.image = (tokens, idx)=>{
|
|
@@ -468,13 +488,7 @@ const CustomerService = (props)=>{
|
|
|
468
488
|
]);
|
|
469
489
|
useEffect(()=>{
|
|
470
490
|
historyMessageListRef.current = historyMessageList;
|
|
471
|
-
|
|
472
|
-
mermaid.init({
|
|
473
|
-
querySelector: `.${styles.mermaid}:not([data-processed="true"])`,
|
|
474
|
-
suppressErrors: true
|
|
475
|
-
}, `.${styles.mermaid}:not([data-processed="true"])`);
|
|
476
|
-
clearTimeout(timer);
|
|
477
|
-
}, 500);
|
|
491
|
+
renderMermaid(500);
|
|
478
492
|
}, [
|
|
479
493
|
historyMessageList
|
|
480
494
|
]);
|
|
@@ -609,6 +623,7 @@ const CustomerService = (props)=>{
|
|
|
609
623
|
if (!message) return;
|
|
610
624
|
let codeConment = '';
|
|
611
625
|
let i = 0;
|
|
626
|
+
message = removeMermaidBlockComments(message);
|
|
612
627
|
message.replaceAll(new RegExp(/```(?:.|\n)*?```/, "ig"), (con)=>{
|
|
613
628
|
i++;
|
|
614
629
|
if (i == position) {
|
|
@@ -1424,6 +1439,10 @@ const CustomerService = (props)=>{
|
|
|
1424
1439
|
//发送结束
|
|
1425
1440
|
finishedRef.current = true;
|
|
1426
1441
|
setFinished(true);
|
|
1442
|
+
renderMermaid();
|
|
1443
|
+
setTimeout(()=>{
|
|
1444
|
+
scrollToBottom();
|
|
1445
|
+
}, 500);
|
|
1427
1446
|
}
|
|
1428
1447
|
};
|
|
1429
1448
|
//问题记录到实验报告中
|
|
@@ -2251,6 +2270,15 @@ const CustomerService = (props)=>{
|
|
|
2251
2270
|
// setRoomId(id);
|
|
2252
2271
|
// }
|
|
2253
2272
|
};
|
|
2273
|
+
const renderMermaid = (duration = 100)=>{
|
|
2274
|
+
const t = setTimeout(()=>{
|
|
2275
|
+
mermaid.init({
|
|
2276
|
+
querySelector: `.${styles.mermaid}:not([data-processed="true"])`,
|
|
2277
|
+
suppressErrors: true
|
|
2278
|
+
}, `.${styles.mermaid}:not([data-processed="true"])`);
|
|
2279
|
+
clearTimeout(t);
|
|
2280
|
+
}, duration);
|
|
2281
|
+
};
|
|
2254
2282
|
//渲染问答
|
|
2255
2283
|
const renderQuestion = ()=>{
|
|
2256
2284
|
function itemContent(index, item) {
|
|
@@ -2291,6 +2319,8 @@ const CustomerService = (props)=>{
|
|
|
2291
2319
|
// let code = message.split("```");
|
|
2292
2320
|
// code = code[1];
|
|
2293
2321
|
// console.log(code,888888888);
|
|
2322
|
+
message = removeMermaidBlockComments(message);
|
|
2323
|
+
message = handleRenderSyntaxBlock(message, finishedRef.current);
|
|
2294
2324
|
if (lastId == item.id && keyWordProblem != "") {
|
|
2295
2325
|
//点击历史记录时,找到关键字,防止关键字和标签名重复
|
|
2296
2326
|
// let key_sign = 'sign_'+new Date().getTime();+'sign';
|
|
@@ -2344,13 +2374,6 @@ const CustomerService = (props)=>{
|
|
|
2344
2374
|
</span><span class="copyCode">复制代码</span></p><pre`;
|
|
2345
2375
|
return text;
|
|
2346
2376
|
});
|
|
2347
|
-
// message = message.replaceAll(
|
|
2348
|
-
// new RegExp(`<img`, "ig"),
|
|
2349
|
-
// (i: any, index: any) => {
|
|
2350
|
-
// let text = `<div class='${styles.a}'><img`;
|
|
2351
|
-
// return text;
|
|
2352
|
-
// }
|
|
2353
|
-
// );
|
|
2354
2377
|
if (item.sender == mid) {
|
|
2355
2378
|
//只有引用和复制功能
|
|
2356
2379
|
li = /*#__PURE__*/ _jsxs(_Fragment, {
|
|
@@ -2769,13 +2792,7 @@ const CustomerService = (props)=>{
|
|
|
2769
2792
|
},
|
|
2770
2793
|
initialItemCount: 10,
|
|
2771
2794
|
itemsRendered: ()=>{
|
|
2772
|
-
|
|
2773
|
-
mermaid.init({
|
|
2774
|
-
querySelector: `.${styles.mermaid}:not([data-processed="true"])`,
|
|
2775
|
-
suppressErrors: true
|
|
2776
|
-
}, `.${styles.mermaid}:not([data-processed="true"])`);
|
|
2777
|
-
clearTimeout(t);
|
|
2778
|
-
}, 100);
|
|
2795
|
+
renderMermaid();
|
|
2779
2796
|
},
|
|
2780
2797
|
// startReached={(index) => {
|
|
2781
2798
|
// console.log('atTopStateChange-startReached',index,lastIdRef.current)
|
|
@@ -2849,7 +2866,7 @@ const CustomerService = (props)=>{
|
|
|
2849
2866
|
},
|
|
2850
2867
|
// context={{ loading }}
|
|
2851
2868
|
firstItemIndex: firstItemIndex,
|
|
2852
|
-
logLevel
|
|
2869
|
+
// logLevel={0}
|
|
2853
2870
|
overscan: {
|
|
2854
2871
|
main: 1000,
|
|
2855
2872
|
reverse: 1000
|
|
@@ -4232,12 +4249,6 @@ const CustomerService = (props)=>{
|
|
|
4232
4249
|
resolve(viewBase64);
|
|
4233
4250
|
});
|
|
4234
4251
|
}
|
|
4235
|
-
}),
|
|
4236
|
-
showMemaid && memaidContent && /*#__PURE__*/ _jsx(ViewMemaid, {
|
|
4237
|
-
visible: showMemaid,
|
|
4238
|
-
onCancel: ()=>setShowMemaid(false),
|
|
4239
|
-
className: "",
|
|
4240
|
-
content: memaidContent
|
|
4241
4252
|
})
|
|
4242
4253
|
]
|
|
4243
4254
|
});
|
|
@@ -503,7 +503,6 @@
|
|
|
503
503
|
margin-bottom: 8px;
|
|
504
504
|
border-radius: 0 0 4px 4px;
|
|
505
505
|
&.mermaid{
|
|
506
|
-
text-align: center;
|
|
507
506
|
border-top: 1px solid rgba(0, 0, 0, 0.06);
|
|
508
507
|
border-radius: 4px;
|
|
509
508
|
margin: 0;
|
|
@@ -524,6 +523,8 @@
|
|
|
524
523
|
display: inline-block;
|
|
525
524
|
max-width: 100%;
|
|
526
525
|
padding: 0 !important;
|
|
526
|
+
margin-top: 8px;
|
|
527
|
+
margin-bottom: 8px;
|
|
527
528
|
>img{
|
|
528
529
|
max-width: 100%;
|
|
529
530
|
}
|
|
@@ -496,7 +496,6 @@
|
|
|
496
496
|
margin-bottom: 8px;
|
|
497
497
|
border-radius: 0 0 4px 4px;
|
|
498
498
|
&.mermaid{
|
|
499
|
-
text-align: center;
|
|
500
499
|
border-top: 1px solid rgba(0, 0, 0, 0.06);
|
|
501
500
|
border-radius: 4px;
|
|
502
501
|
margin:0;
|
|
@@ -518,6 +517,8 @@
|
|
|
518
517
|
display: inline-block;
|
|
519
518
|
max-width: 100%;
|
|
520
519
|
padding: 0 !important;
|
|
520
|
+
margin-top: 8px;
|
|
521
|
+
margin-bottom: 8px;
|
|
521
522
|
>img{
|
|
522
523
|
max-width: 100%;
|
|
523
524
|
}
|
|
@@ -22,4 +22,6 @@ declare const getBase64Image: (src: any) => Promise<unknown>;
|
|
|
22
22
|
declare const formatDate: (dateStr: any) => any;
|
|
23
23
|
declare const urlToBase64: (url: string) => Promise<unknown>;
|
|
24
24
|
declare const toHashString: (str: string) => string;
|
|
25
|
-
|
|
25
|
+
declare const removeMermaidBlockComments: (markdownContent: any) => any;
|
|
26
|
+
declare const handleRenderSyntaxBlock: (markdownContent: any, flag: boolean) => any;
|
|
27
|
+
export { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, getBase64Image, formatDate, urlToBase64, toHashString, removeMermaidBlockComments, handleRenderSyntaxBlock, };
|
|
@@ -195,4 +195,39 @@ var toHashString = function(str) {
|
|
|
195
195
|
// 转换为正数并格式化为8位十六进制
|
|
196
196
|
return (result >>> 0).toString(16).padStart(8, "0");
|
|
197
197
|
};
|
|
198
|
-
|
|
198
|
+
// 正则:匹配```mermaid代码块内 ‘// 注释的内容’ 移除
|
|
199
|
+
var removeMermaidBlockComments = function(markdownContent) {
|
|
200
|
+
// 正则匹配 ```mermaid 代码块,捕获块内内容
|
|
201
|
+
var mermaidBlockRegex = /(```mermaid\n)([\s\S]*?)(\n```)/gm;
|
|
202
|
+
// 替换逻辑:保留代码块标识,仅清理块内注释
|
|
203
|
+
return markdownContent.replace(mermaidBlockRegex, function(match, prefix, content, suffix) {
|
|
204
|
+
// 清理块内注释的正则(同之前逻辑,优先保留字符串)
|
|
205
|
+
var commentRegex = /(".*?"|'.*?')|(\/\*[\s\S]*?\*\/)|(\/\/.*?$)/gm;
|
|
206
|
+
var cleanContent = content.replace(commentRegex, function(m, stringPart) {
|
|
207
|
+
return stringPart || "";
|
|
208
|
+
});
|
|
209
|
+
// 拼接回完整代码块(保留 ```mermaid 和 ``` 标识)
|
|
210
|
+
return "".concat(prefix).concat(cleanContent).concat(suffix);
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
// 处理渲染语法
|
|
214
|
+
var handleRenderSyntaxBlock = function(markdownContent, flag) {
|
|
215
|
+
if (flag) {
|
|
216
|
+
// 正则匹配  图片语法
|
|
217
|
+
var imgBlockRegex = /\[([^\]]*)\]\[\]\((https?:\/\/[^\s)]+)\)/gm;
|
|
218
|
+
markdownContent = markdownContent.replace(imgBlockRegex, function(match, altText, url) {
|
|
219
|
+
return ".concat(url, ")");
|
|
220
|
+
});
|
|
221
|
+
markdownContent = markdownContent.replaceAll("```mermaid-code", "```mermaid");
|
|
222
|
+
return markdownContent;
|
|
223
|
+
} else {
|
|
224
|
+
// 正则匹配  图片语法
|
|
225
|
+
var imgBlockRegex1 = /!\[([^\]]*)\]\((https?:\/\/[^\s)]+)\)/gm;
|
|
226
|
+
markdownContent = markdownContent.replace(imgBlockRegex1, function(match, altText, url) {
|
|
227
|
+
return "[".concat(altText, "][](").concat(url, ")");
|
|
228
|
+
});
|
|
229
|
+
markdownContent = markdownContent.replaceAll("```mermaid", "```mermaid-code");
|
|
230
|
+
return markdownContent;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
export { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, getBase64Image, formatDate, urlToBase64, toHashString, removeMermaidBlockComments, handleRenderSyntaxBlock };
|
|
@@ -29,14 +29,13 @@ import { Remarkable } from "remarkable";
|
|
|
29
29
|
import hljs from "highlight.js";
|
|
30
30
|
import "highlight.js/styles/github.css";
|
|
31
31
|
import mermaid from "mermaid";
|
|
32
|
-
import ViewMemaid from "./viewMemaid";
|
|
33
32
|
import { render } from "react-dom";
|
|
34
33
|
import Provider from "../provider";
|
|
35
34
|
var TextArea = Input.TextArea;
|
|
36
35
|
// import './html2canvas.test.js';
|
|
37
36
|
import knowledge_icon from "./images/knowledge_icon.png";
|
|
38
37
|
// import { useMediaRecorder } from "./useMediaRecorder"; //录音使用文件
|
|
39
|
-
import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64, toHashString } from "./function"; //一些方法
|
|
38
|
+
import { readMessage, getByteLen, serverUrl, copyText, getDataTime, getQuery, resetStyles, findParent, delegate, urlToBase64, toHashString, removeMermaidBlockComments, handleRenderSyntaxBlock } from "./function"; //一些方法
|
|
40
39
|
// import html2canvas from "html2canvas";
|
|
41
40
|
// const screenShot = require('./screenShotPlugin.esm')
|
|
42
41
|
import ScreenShot from "./js-screen-shot/main";
|
|
@@ -64,8 +63,13 @@ mermaid.initialize({
|
|
|
64
63
|
theme: "default",
|
|
65
64
|
securityLevel: "loose",
|
|
66
65
|
flowchart: {
|
|
66
|
+
useMaxWidth: true,
|
|
67
67
|
htmlLabels: true,
|
|
68
68
|
curve: "basis"
|
|
69
|
+
},
|
|
70
|
+
pie: {
|
|
71
|
+
useMaxWidth: true,
|
|
72
|
+
useWidth: 360
|
|
69
73
|
}
|
|
70
74
|
});
|
|
71
75
|
var CustomerService = function(props) {
|
|
@@ -140,9 +144,9 @@ var CustomerService = function(props) {
|
|
|
140
144
|
html: true,
|
|
141
145
|
highlight: function highlight(str, lang) {
|
|
142
146
|
// 特殊处理 mermaid 代码块
|
|
143
|
-
if (lang ===
|
|
144
|
-
|
|
145
|
-
}
|
|
147
|
+
// if (lang === 'mermaid') {
|
|
148
|
+
// return str; // 不高亮 mermaid 代码
|
|
149
|
+
// }
|
|
146
150
|
if (lang && hljs.getLanguage(lang)) {
|
|
147
151
|
try {
|
|
148
152
|
return hljs.highlight(lang, str).value;
|
|
@@ -156,10 +160,18 @@ var CustomerService = function(props) {
|
|
|
156
160
|
});
|
|
157
161
|
// 添加自定义规则来处理 mermaid 代码块
|
|
158
162
|
remarkable.renderer.rules.fence_custom = {
|
|
159
|
-
mermaid: function
|
|
163
|
+
mermaid: function mermaid1(tokens, idx) {
|
|
160
164
|
var token = tokens[idx];
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
try {
|
|
166
|
+
if (mermaid.parse(token.content)) {
|
|
167
|
+
var id = "mermaid_" + toHashString(token.content);
|
|
168
|
+
return '<span class="'.concat(styles.maskZoomBox, '"><pre class="').concat(styles.mermaid, '" id="').concat(id, '">').concat(token.content, '</pre><span class="').concat(styles.zoomBox, '" onclick="openViewMemaid(\'').concat(id, '\')"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>');
|
|
169
|
+
} else {
|
|
170
|
+
return '<pre><code class="language-mermaid">'.concat(token.content, "</code></pre>");
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
return '<pre><code class="language-mermaid">'.concat(token.content, "</code></pre>");
|
|
174
|
+
}
|
|
163
175
|
}
|
|
164
176
|
};
|
|
165
177
|
remarkable.renderer.rules.image = function(tokens, idx) {
|
|
@@ -187,10 +199,18 @@ var CustomerService = function(props) {
|
|
|
187
199
|
};
|
|
188
200
|
// 添加自定义规则来处理 mermaid 代码块
|
|
189
201
|
newRemarkable.renderer.rules.fence_custom = {
|
|
190
|
-
mermaid: function
|
|
202
|
+
mermaid: function mermaid1(tokens, idx) {
|
|
191
203
|
var token = tokens[idx];
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
try {
|
|
205
|
+
if (mermaid.parse(token.content)) {
|
|
206
|
+
var id = "mermaid_" + toHashString(token.content);
|
|
207
|
+
return '<span class="'.concat(styles.maskZoomBox, '"><pre class="').concat(styles.mermaid, '" id="').concat(id, '">').concat(token.content, '</pre><span class="').concat(styles.zoomBox, '" onclick="openViewMemaid(\'').concat(id, '\')"><svg viewBox="64 64 896 896" focusable="false" data-icon="zoom-in" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M637 443H519V309c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v134H325c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h118v134c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V519h118c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm284 424L775 721c122.1-148.9 113.6-369.5-26-509-148-148.1-388.4-148.1-537 0-148.1 148.6-148.1 389 0 537 139.5 139.6 360.1 148.1 509 26l146 146c3.2 2.8 8.3 2.8 11 0l43-43c2.8-2.7 2.8-7.8 0-11zM696 696c-118.8 118.7-311.2 118.7-430 0-118.7-118.8-118.7-311.2 0-430 118.8-118.7 311.2-118.7 430 0 118.7 118.8 118.7 311.2 0 430z"></path></svg></span></span>');
|
|
208
|
+
} else {
|
|
209
|
+
return '<pre><code class="language-mermaid">'.concat(token.content, "</code></pre>");
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
return '<pre><code class="language-mermaid">'.concat(token.content, "</code></pre>");
|
|
213
|
+
}
|
|
194
214
|
}
|
|
195
215
|
};
|
|
196
216
|
remarkable.renderer.rules.image = function(tokens, idx) {
|
|
@@ -473,13 +493,7 @@ var CustomerService = function(props) {
|
|
|
473
493
|
]);
|
|
474
494
|
useEffect(function() {
|
|
475
495
|
historyMessageListRef.current = historyMessageList;
|
|
476
|
-
|
|
477
|
-
mermaid.init({
|
|
478
|
-
querySelector: ".".concat(styles.mermaid, ':not([data-processed="true"])'),
|
|
479
|
-
suppressErrors: true
|
|
480
|
-
}, ".".concat(styles.mermaid, ':not([data-processed="true"])'));
|
|
481
|
-
clearTimeout(timer);
|
|
482
|
-
}, 500);
|
|
496
|
+
renderMermaid(500);
|
|
483
497
|
}, [
|
|
484
498
|
historyMessageList
|
|
485
499
|
]);
|
|
@@ -616,6 +630,7 @@ var CustomerService = function(props) {
|
|
|
616
630
|
if (!message) return;
|
|
617
631
|
var codeConment = "";
|
|
618
632
|
var i = 0;
|
|
633
|
+
message = removeMermaidBlockComments(message);
|
|
619
634
|
message.replaceAll(new RegExp(/```(?:.|\n)*?```/, "ig"), function(con) {
|
|
620
635
|
i++;
|
|
621
636
|
if (i == position) {
|
|
@@ -1514,6 +1529,10 @@ var CustomerService = function(props) {
|
|
|
1514
1529
|
//发送结束
|
|
1515
1530
|
finishedRef.current = true;
|
|
1516
1531
|
setFinished(true);
|
|
1532
|
+
renderMermaid();
|
|
1533
|
+
setTimeout(function() {
|
|
1534
|
+
scrollToBottom();
|
|
1535
|
+
}, 500);
|
|
1517
1536
|
}
|
|
1518
1537
|
};
|
|
1519
1538
|
//问题记录到实验报告中
|
|
@@ -2367,6 +2386,16 @@ var CustomerService = function(props) {
|
|
|
2367
2386
|
// setRoomId(id);
|
|
2368
2387
|
// }
|
|
2369
2388
|
};
|
|
2389
|
+
var renderMermaid = function() {
|
|
2390
|
+
var duration = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 100;
|
|
2391
|
+
var t = setTimeout(function() {
|
|
2392
|
+
mermaid.init({
|
|
2393
|
+
querySelector: ".".concat(styles.mermaid, ':not([data-processed="true"])'),
|
|
2394
|
+
suppressErrors: true
|
|
2395
|
+
}, ".".concat(styles.mermaid, ':not([data-processed="true"])'));
|
|
2396
|
+
clearTimeout(t);
|
|
2397
|
+
}, duration);
|
|
2398
|
+
};
|
|
2370
2399
|
//渲染问答
|
|
2371
2400
|
var renderQuestion = function() {
|
|
2372
2401
|
var itemContent = function itemContent(index, item) {
|
|
@@ -2411,6 +2440,8 @@ var CustomerService = function(props) {
|
|
|
2411
2440
|
// let code = message.split("```");
|
|
2412
2441
|
// code = code[1];
|
|
2413
2442
|
// console.log(code,888888888);
|
|
2443
|
+
message = removeMermaidBlockComments(message);
|
|
2444
|
+
message = handleRenderSyntaxBlock(message, finishedRef.current);
|
|
2414
2445
|
if (lastId == item.id && keyWordProblem != "") {
|
|
2415
2446
|
//点击历史记录时,找到关键字,防止关键字和标签名重复
|
|
2416
2447
|
// let key_sign = 'sign_'+new Date().getTime();+'sign';
|
|
@@ -2431,13 +2462,6 @@ var CustomerService = function(props) {
|
|
|
2431
2462
|
var text = "<p class='".concat(styles.copyCode, " copyCodeFun' data-id=").concat(item.id, " data-position=").concat(position, ">\n <span class='").concat(styles.icon, ' copy\' >\n <svg\n width="1em"\n height="1em"\n viewBox="0 0 14 14"\n shape-rendering="geometricPrecision"\n fill="currentColor"\n xmlns="http://www.w3.org/2000/svg"\n >\n <g clip-path="url(#clip0_518_8403)">\n <path\n d="M6.16666 1.66666H13.1667C13.4761 1.66666 13.7728 1.78957 13.9916 2.00837C14.2104 2.22716 14.3333 2.5239 14.3333 2.83332V9.83332C14.3333 10.1427 14.2104 10.4395 13.9916 10.6583C13.7728 10.8771 13.4761 11 13.1667 11H6.16666C5.85724 11 5.5605 10.8771 5.34171 10.6583C5.12291 10.4395 5 10.1427 5 9.83332V2.83332C5 2.5239 5.12291 2.22716 5.34171 2.00837C5.5605 1.78957 5.85724 1.66666 6.16666 1.66666ZM6.16666 2.66666C6.12246 2.66666 6.08007 2.68422 6.04881 2.71547C6.01756 2.74673 6 2.78912 6 2.83332V9.83332C6 9.85521 6.00431 9.87688 6.01268 9.8971C6.02106 9.91732 6.03334 9.9357 6.04881 9.95117C6.06429 9.96665 6.08266 9.97893 6.10288 9.9873C6.1231 9.99568 6.14478 9.99999 6.16666 9.99999H13.1667C13.2109 9.99999 13.2533 9.98243 13.2845 9.95117C13.3158 9.91992 13.3333 9.87753 13.3333 9.83332V2.83332C13.3333 2.78912 13.3158 2.74673 13.2845 2.71547C13.2533 2.68422 13.2109 2.66666 13.1667 2.66666H6.16666ZM10 12C10 11.8674 10.0527 11.7402 10.1464 11.6464C10.2402 11.5527 10.3674 11.5 10.5 11.5C10.6326 11.5 10.7598 11.5527 10.8536 11.6464C10.9473 11.7402 11 11.8674 11 12V13.1667C11 13.4761 10.8771 13.7728 10.6583 13.9916C10.4395 14.2104 10.1427 14.3333 9.83333 14.3333H2.83333C2.52391 14.3333 2.22717 14.2104 2.00837 13.9916C1.78958 13.7728 1.66666 13.4761 1.66666 13.1667V6.16666C1.66666 5.85724 1.78958 5.56049 2.00837 5.3417C2.22717 5.12291 2.52391 4.99999 2.83333 4.99999H4C4.13261 4.99999 4.25978 5.05267 4.35355 5.14644C4.44732 5.2402 4.5 5.36738 4.5 5.49999C4.5 5.6326 4.44732 5.75978 4.35355 5.85354C4.25978 5.94731 4.13261 5.99999 4 5.99999H2.83333C2.78913 5.99999 2.74674 6.01755 2.71548 6.04881C2.68422 6.08006 2.66666 6.12245 2.66666 6.16666V13.1667C2.66666 13.2109 2.68422 13.2533 2.71548 13.2845C2.74674 13.3158 2.78913 13.3333 2.83333 13.3333H9.83333C9.87753 13.3333 9.91993 13.3158 9.95118 13.2845C9.98244 13.2533 10 13.2109 10 13.1667V12Z"\n />\n </g>\n <defs>\n <clipPath id="clip0_518_8403">\n <rect width="16" height="16" />\n </clipPath>\n </defs>\n </svg>\n </span>\n <span class=\'').concat(styles.icon, ' copy_success_flag\'>\n <svg\n width="1em"\n height="1em"\n shape-rendering="geometricPrecision"\n fill="currentColor"\n viewBox="0 0 12 7"\n xmlns="http://www.w3.org/2000/svg"\n >\n <path d="M11.2242 0.375687C11.4586 0.610002 11.4586 0.989901 11.2242 1.22422L4.82424 7.62422C4.58992 7.85853 4.21003 7.85853 3.97571 7.62422L0.775712 4.42422C0.541397 4.1899 0.541397 3.81 0.775712 3.57569C1.01003 3.34137 1.38993 3.34137 1.62424 3.57569L4.39998 6.35142L10.3757 0.375687C10.61 0.141373 10.9899 0.141373 11.2242 0.375687Z" />\n </svg>\n </span><span class="copyCode">复制代码</span></p><pre');
|
|
2432
2463
|
return text;
|
|
2433
2464
|
});
|
|
2434
|
-
// message = message.replaceAll(
|
|
2435
|
-
// new RegExp(`<img`, "ig"),
|
|
2436
|
-
// (i: any, index: any) => {
|
|
2437
|
-
// let text = `<div class='${styles.a}'><img`;
|
|
2438
|
-
// return text;
|
|
2439
|
-
// }
|
|
2440
|
-
// );
|
|
2441
2465
|
if (item.sender == mid) {
|
|
2442
2466
|
//只有引用和复制功能
|
|
2443
2467
|
li = /*#__PURE__*/ _jsxs(_Fragment, {
|
|
@@ -2864,13 +2888,7 @@ var CustomerService = function(props) {
|
|
|
2864
2888
|
},
|
|
2865
2889
|
initialItemCount: 10,
|
|
2866
2890
|
itemsRendered: function() {
|
|
2867
|
-
|
|
2868
|
-
mermaid.init({
|
|
2869
|
-
querySelector: ".".concat(styles.mermaid, ':not([data-processed="true"])'),
|
|
2870
|
-
suppressErrors: true
|
|
2871
|
-
}, ".".concat(styles.mermaid, ':not([data-processed="true"])'));
|
|
2872
|
-
clearTimeout(t);
|
|
2873
|
-
}, 100);
|
|
2891
|
+
renderMermaid();
|
|
2874
2892
|
},
|
|
2875
2893
|
// startReached={(index) => {
|
|
2876
2894
|
// console.log('atTopStateChange-startReached',index,lastIdRef.current)
|
|
@@ -2944,7 +2962,7 @@ var CustomerService = function(props) {
|
|
|
2944
2962
|
},
|
|
2945
2963
|
// context={{ loading }}
|
|
2946
2964
|
firstItemIndex: firstItemIndex,
|
|
2947
|
-
logLevel
|
|
2965
|
+
// logLevel={0}
|
|
2948
2966
|
overscan: {
|
|
2949
2967
|
main: 1000,
|
|
2950
2968
|
reverse: 1000
|
|
@@ -4362,14 +4380,6 @@ var CustomerService = function(props) {
|
|
|
4362
4380
|
resolve(viewBase64);
|
|
4363
4381
|
});
|
|
4364
4382
|
}
|
|
4365
|
-
}),
|
|
4366
|
-
showMemaid && memaidContent && /*#__PURE__*/ _jsx(ViewMemaid, {
|
|
4367
|
-
visible: showMemaid,
|
|
4368
|
-
onCancel: function() {
|
|
4369
|
-
return setShowMemaid(false);
|
|
4370
|
-
},
|
|
4371
|
-
className: "",
|
|
4372
|
-
content: memaidContent
|
|
4373
4383
|
})
|
|
4374
4384
|
]
|
|
4375
4385
|
});
|
|
@@ -503,7 +503,6 @@
|
|
|
503
503
|
margin-bottom: 8px;
|
|
504
504
|
border-radius: 0 0 4px 4px;
|
|
505
505
|
&.mermaid{
|
|
506
|
-
text-align: center;
|
|
507
506
|
border-top: 1px solid rgba(0, 0, 0, 0.06);
|
|
508
507
|
border-radius: 4px;
|
|
509
508
|
margin: 0;
|
|
@@ -524,6 +523,8 @@
|
|
|
524
523
|
display: inline-block;
|
|
525
524
|
max-width: 100%;
|
|
526
525
|
padding: 0 !important;
|
|
526
|
+
margin-top: 8px;
|
|
527
|
+
margin-bottom: 8px;
|
|
527
528
|
>img{
|
|
528
529
|
max-width: 100%;
|
|
529
530
|
}
|
|
@@ -496,7 +496,6 @@
|
|
|
496
496
|
margin-bottom: 8px;
|
|
497
497
|
border-radius: 0 0 4px 4px;
|
|
498
498
|
&.mermaid{
|
|
499
|
-
text-align: center;
|
|
500
499
|
border-top: 1px solid rgba(0, 0, 0, 0.06);
|
|
501
500
|
border-radius: 4px;
|
|
502
501
|
margin:0;
|
|
@@ -518,6 +517,8 @@
|
|
|
518
517
|
display: inline-block;
|
|
519
518
|
max-width: 100%;
|
|
520
519
|
padding: 0 !important;
|
|
520
|
+
margin-top: 8px;
|
|
521
|
+
margin-bottom: 8px;
|
|
521
522
|
>img{
|
|
522
523
|
max-width: 100%;
|
|
523
524
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bhd-components",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.34",
|
|
4
4
|
"description": "组件功能描述",
|
|
5
5
|
"config": {
|
|
6
6
|
"commitizen": {
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
"scripts": {
|
|
43
43
|
"start:large-memory": "node --max-old-space-size=8192 node_modules/.bin/ice-pkg start",
|
|
44
44
|
"start": "ice-pkg start",
|
|
45
|
-
"build
|
|
46
|
-
"build":"node --max-old-space-size=8192 node_modules/.bin/ice-pkg build",
|
|
45
|
+
"build": "node --max-old-space-size=8192 node_modules/.bin/ice-pkg build",
|
|
47
46
|
"build:esm": "cross-env NODE_TYPE=esm ice-pkg build",
|
|
48
47
|
"build:online": "cross-env NODE_TYPE=online ice-pkg build ",
|
|
49
48
|
"build:online_dev": "cross-env NODE_TYPE=online_dev ice-pkg build ",
|