@alifd/chat 0.3.28-beta.3 → 0.3.28-beta.5
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/index.js +1 -1
- package/es/markdown/index.js +18 -60
- package/lib/index.js +1 -1
- package/lib/markdown/index.js +18 -60
- package/package.json +3 -3
package/es/index.js
CHANGED
|
@@ -31,4 +31,4 @@ export { default as RadioGroup } from './radio-group';
|
|
|
31
31
|
export { default as CheckboxGroup } from './checkbox-group';
|
|
32
32
|
export { default as Select } from './select';
|
|
33
33
|
export { default as Flip } from './flip';
|
|
34
|
-
export const version = '0.3.28-beta.
|
|
34
|
+
export const version = '0.3.28-beta.5';
|
package/es/markdown/index.js
CHANGED
|
@@ -46,68 +46,27 @@ const Markdown = forwardRef((_a, ref) => {
|
|
|
46
46
|
}
|
|
47
47
|
// 记录新的内容
|
|
48
48
|
previousContentRef.current = content;
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
// 清除任何现有的定时器
|
|
50
|
+
if (typeTimeoutRef.current) {
|
|
51
|
+
clearTimeout(typeTimeoutRef.current);
|
|
52
|
+
typeTimeoutRef.current = null;
|
|
53
|
+
}
|
|
54
|
+
// 将内容分成两部分:直接显示部分和打字效果部分
|
|
55
|
+
if (content.length <= 20) {
|
|
56
|
+
// 如果内容不超过20个字符,全部使用打字效果
|
|
53
57
|
setDisplayedContent('');
|
|
54
58
|
setContentQueue(content.split(''));
|
|
55
|
-
setTyping(true);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
// 如果新内容是当前内容的子集(内容被截断)
|
|
59
|
-
if (content.length < currentTotalContent.length && currentTotalContent.indexOf(content) === 0) {
|
|
60
|
-
// 计算应保留的已显示内容
|
|
61
|
-
if (content.length <= displayedContent.length) {
|
|
62
|
-
// 只需截断已显示内容
|
|
63
|
-
setDisplayedContent(content);
|
|
64
|
-
setContentQueue([]);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// 需要保留部分已显示内容和部分队列内容
|
|
68
|
-
setDisplayedContent(displayedContent);
|
|
69
|
-
setContentQueue(content.substring(displayedContent.length).split(''));
|
|
70
|
-
}
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
// 如果新内容包含当前内容,但有新增(最常见情况)
|
|
74
|
-
if (content.indexOf(currentTotalContent) === 0) {
|
|
75
|
-
// 将新增的部分添加到队列中
|
|
76
|
-
const newContent = content.substring(currentTotalContent.length);
|
|
77
|
-
if (newContent) {
|
|
78
|
-
setContentQueue(prevQueue => [...prevQueue, ...newContent.split('')]);
|
|
79
|
-
if (!typing) {
|
|
80
|
-
setTyping(true);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// 如果新内容与已显示内容有部分重叠,但不完全包含
|
|
86
|
-
// 查找重叠的最大前缀
|
|
87
|
-
let overlapLength = 0;
|
|
88
|
-
for (let i = 1; i <= Math.min(displayedContent.length, content.length); i++) {
|
|
89
|
-
if (content.substring(0, i) === displayedContent.substring(displayedContent.length - i)) {
|
|
90
|
-
overlapLength = i;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (overlapLength > 0) {
|
|
94
|
-
// 保留重叠部分,更新队列
|
|
95
|
-
const newDisplayed = displayedContent.substring(0, displayedContent.length - overlapLength) +
|
|
96
|
-
content.substring(0, overlapLength);
|
|
97
|
-
const newQueue = content.substring(overlapLength).split('');
|
|
98
|
-
setDisplayedContent(newDisplayed);
|
|
99
|
-
setContentQueue(newQueue);
|
|
100
|
-
if (newQueue.length > 0 && !typing) {
|
|
101
|
-
setTyping(true);
|
|
102
|
-
}
|
|
103
59
|
}
|
|
104
60
|
else {
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
61
|
+
// 如果内容超过20个字符,前面部分直接显示,后20个字符用于打字效果
|
|
62
|
+
const displayPart = content.slice(0, content.length - 20);
|
|
63
|
+
const typingPart = content.slice(content.length - 20);
|
|
64
|
+
setDisplayedContent(displayPart);
|
|
65
|
+
setContentQueue(typingPart.split(''));
|
|
109
66
|
}
|
|
110
|
-
|
|
67
|
+
// 启动打字机效果
|
|
68
|
+
setTyping(true);
|
|
69
|
+
}, [content, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
|
|
111
70
|
// 执行打字机效果
|
|
112
71
|
useEffect(() => {
|
|
113
72
|
if (!(others === null || others === void 0 ? void 0 : others.typewriterEffect) || contentQueue.length === 0 || !typing) {
|
|
@@ -118,9 +77,8 @@ const Markdown = forwardRef((_a, ref) => {
|
|
|
118
77
|
clearTimeout(typeTimeoutRef.current);
|
|
119
78
|
typeTimeoutRef.current = null;
|
|
120
79
|
}
|
|
121
|
-
//
|
|
122
|
-
const
|
|
123
|
-
const timePerChar = Math.max(Math.min(2000 / remainingChars, 50), 10); // 最快10ms,最慢50ms每字符
|
|
80
|
+
// 固定打字速度为50ms一个字
|
|
81
|
+
const timePerChar = 50;
|
|
124
82
|
const processNextChar = () => {
|
|
125
83
|
if (contentQueue.length === 0) {
|
|
126
84
|
if (typeTimeoutRef.current) {
|
package/lib/index.js
CHANGED
|
@@ -68,4 +68,4 @@ var select_1 = require("./select");
|
|
|
68
68
|
Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return tslib_1.__importDefault(select_1).default; } });
|
|
69
69
|
var flip_1 = require("./flip");
|
|
70
70
|
Object.defineProperty(exports, "Flip", { enumerable: true, get: function () { return tslib_1.__importDefault(flip_1).default; } });
|
|
71
|
-
exports.version = '0.3.28-beta.
|
|
71
|
+
exports.version = '0.3.28-beta.5';
|
package/lib/markdown/index.js
CHANGED
|
@@ -48,68 +48,27 @@ const Markdown = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
48
48
|
}
|
|
49
49
|
// 记录新的内容
|
|
50
50
|
previousContentRef.current = content;
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
// 清除任何现有的定时器
|
|
52
|
+
if (typeTimeoutRef.current) {
|
|
53
|
+
clearTimeout(typeTimeoutRef.current);
|
|
54
|
+
typeTimeoutRef.current = null;
|
|
55
|
+
}
|
|
56
|
+
// 将内容分成两部分:直接显示部分和打字效果部分
|
|
57
|
+
if (content.length <= 20) {
|
|
58
|
+
// 如果内容不超过20个字符,全部使用打字效果
|
|
55
59
|
setDisplayedContent('');
|
|
56
60
|
setContentQueue(content.split(''));
|
|
57
|
-
setTyping(true);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// 如果新内容是当前内容的子集(内容被截断)
|
|
61
|
-
if (content.length < currentTotalContent.length && currentTotalContent.indexOf(content) === 0) {
|
|
62
|
-
// 计算应保留的已显示内容
|
|
63
|
-
if (content.length <= displayedContent.length) {
|
|
64
|
-
// 只需截断已显示内容
|
|
65
|
-
setDisplayedContent(content);
|
|
66
|
-
setContentQueue([]);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// 需要保留部分已显示内容和部分队列内容
|
|
70
|
-
setDisplayedContent(displayedContent);
|
|
71
|
-
setContentQueue(content.substring(displayedContent.length).split(''));
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// 如果新内容包含当前内容,但有新增(最常见情况)
|
|
76
|
-
if (content.indexOf(currentTotalContent) === 0) {
|
|
77
|
-
// 将新增的部分添加到队列中
|
|
78
|
-
const newContent = content.substring(currentTotalContent.length);
|
|
79
|
-
if (newContent) {
|
|
80
|
-
setContentQueue(prevQueue => [...prevQueue, ...newContent.split('')]);
|
|
81
|
-
if (!typing) {
|
|
82
|
-
setTyping(true);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
// 如果新内容与已显示内容有部分重叠,但不完全包含
|
|
88
|
-
// 查找重叠的最大前缀
|
|
89
|
-
let overlapLength = 0;
|
|
90
|
-
for (let i = 1; i <= Math.min(displayedContent.length, content.length); i++) {
|
|
91
|
-
if (content.substring(0, i) === displayedContent.substring(displayedContent.length - i)) {
|
|
92
|
-
overlapLength = i;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (overlapLength > 0) {
|
|
96
|
-
// 保留重叠部分,更新队列
|
|
97
|
-
const newDisplayed = displayedContent.substring(0, displayedContent.length - overlapLength) +
|
|
98
|
-
content.substring(0, overlapLength);
|
|
99
|
-
const newQueue = content.substring(overlapLength).split('');
|
|
100
|
-
setDisplayedContent(newDisplayed);
|
|
101
|
-
setContentQueue(newQueue);
|
|
102
|
-
if (newQueue.length > 0 && !typing) {
|
|
103
|
-
setTyping(true);
|
|
104
|
-
}
|
|
105
61
|
}
|
|
106
62
|
else {
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
63
|
+
// 如果内容超过20个字符,前面部分直接显示,后20个字符用于打字效果
|
|
64
|
+
const displayPart = content.slice(0, content.length - 20);
|
|
65
|
+
const typingPart = content.slice(content.length - 20);
|
|
66
|
+
setDisplayedContent(displayPart);
|
|
67
|
+
setContentQueue(typingPart.split(''));
|
|
111
68
|
}
|
|
112
|
-
|
|
69
|
+
// 启动打字机效果
|
|
70
|
+
setTyping(true);
|
|
71
|
+
}, [content, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
|
|
113
72
|
// 执行打字机效果
|
|
114
73
|
(0, react_1.useEffect)(() => {
|
|
115
74
|
if (!(others === null || others === void 0 ? void 0 : others.typewriterEffect) || contentQueue.length === 0 || !typing) {
|
|
@@ -120,9 +79,8 @@ const Markdown = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
120
79
|
clearTimeout(typeTimeoutRef.current);
|
|
121
80
|
typeTimeoutRef.current = null;
|
|
122
81
|
}
|
|
123
|
-
//
|
|
124
|
-
const
|
|
125
|
-
const timePerChar = Math.max(Math.min(2000 / remainingChars, 50), 10); // 最快10ms,最慢50ms每字符
|
|
82
|
+
// 固定打字速度为50ms一个字
|
|
83
|
+
const timePerChar = 50;
|
|
126
84
|
const processNextChar = () => {
|
|
127
85
|
if (contentQueue.length === 0) {
|
|
128
86
|
if (typeTimeoutRef.current) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alifd/chat",
|
|
3
|
-
"version": "0.3.28-beta.
|
|
3
|
+
"version": "0.3.28-beta.5",
|
|
4
4
|
"description": "A configurable component library for chat built on React.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -483,7 +483,7 @@
|
|
|
483
483
|
"@types/fs-extra": "^11.0.4",
|
|
484
484
|
"@types/hoist-non-react-statics": "^3.3.5",
|
|
485
485
|
"@types/lodash": "^4.14.202",
|
|
486
|
-
"@types/markdown-it": "
|
|
486
|
+
"@types/markdown-it": "^14.1.0",
|
|
487
487
|
"@types/minimist": "^1.2.5",
|
|
488
488
|
"@types/react": "^16.0.0",
|
|
489
489
|
"@types/react-dom": "^16.0.0",
|
|
@@ -547,7 +547,7 @@
|
|
|
547
547
|
"hoist-non-react-statics": "^3.3.2",
|
|
548
548
|
"html-react-parser": "^1.4.14",
|
|
549
549
|
"ice": "^3.7.100",
|
|
550
|
-
"markdown-it": "
|
|
550
|
+
"markdown-it": "^14.1.0",
|
|
551
551
|
"query-string": "^7.1.3",
|
|
552
552
|
"react-copy-to-clipboard": "^5.1.0",
|
|
553
553
|
"react-photo-view": "^1.2.6",
|