@alifd/chat 0.3.28-beta.6 → 0.3.28-beta.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/es/index.js +1 -1
- package/es/markdown/index.js +28 -27
- package/lib/index.js +1 -1
- package/lib/markdown/index.js +28 -27
- package/package.json +1 -1
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.7';
|
package/es/markdown/index.js
CHANGED
|
@@ -44,16 +44,20 @@ const Markdown = forwardRef((_a, ref) => {
|
|
|
44
44
|
setContentQueue([]);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
// 比较传入的content和当前的displayedContent的长度
|
|
48
|
+
const contentLength = content.length;
|
|
49
|
+
const displayedContentLength = displayedContent.length;
|
|
50
|
+
const diffLength = contentLength - displayedContentLength;
|
|
51
|
+
if (diffLength <= 0) {
|
|
52
|
+
// 如果content的长度小于等于displayedContent的长度,则清空contentQueue,直接展示content
|
|
53
|
+
setDisplayedContent(content);
|
|
54
|
+
setContentQueue([]);
|
|
52
55
|
}
|
|
53
56
|
else {
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
+
// 如果content的长度大于displayedContent的长度,将 content 分为两部分,
|
|
58
|
+
// 前 contentLength - diffLength 个字符直接显示,后 diffLength 个字符使用打字效果
|
|
59
|
+
const displayPart = content.slice(0, contentLength - diffLength);
|
|
60
|
+
const typingPart = content.slice(contentLength - diffLength);
|
|
57
61
|
setDisplayedContent(displayPart);
|
|
58
62
|
setContentQueue(typingPart.split(''));
|
|
59
63
|
}
|
|
@@ -65,31 +69,28 @@ const Markdown = forwardRef((_a, ref) => {
|
|
|
65
69
|
clearTypeTimer();
|
|
66
70
|
return;
|
|
67
71
|
}
|
|
68
|
-
//
|
|
69
|
-
const timePerChar =
|
|
72
|
+
// 固定吐字速度为50ms一次
|
|
73
|
+
const timePerChar = 100;
|
|
74
|
+
// 动态调整一次吐字的字数,确保1s内吐完,最少吐2个字符
|
|
75
|
+
const charsPerTime = Math.max(Math.floor(contentQueue.length / 10), 2);
|
|
70
76
|
const processNextChar = () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (newQueue.length > 0) {
|
|
83
|
-
typeTimeoutRef.current = setTimeout(processNextChar, timePerChar);
|
|
84
|
-
}
|
|
85
|
-
return newQueue;
|
|
86
|
-
});
|
|
77
|
+
const currentQueue = contentQueue;
|
|
78
|
+
if (currentQueue.length === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// 获取并移除队列中的第charsPerTime个字符
|
|
82
|
+
const nextChars = currentQueue.slice(0, charsPerTime);
|
|
83
|
+
const newQueue = currentQueue.slice(charsPerTime);
|
|
84
|
+
// 更新显示内容
|
|
85
|
+
setDisplayedContent(prev => prev + nextChars.join(''));
|
|
86
|
+
// 更新队列
|
|
87
|
+
setContentQueue(newQueue);
|
|
87
88
|
};
|
|
88
89
|
// 开始处理第一个字符
|
|
89
90
|
clearTypeTimer(); // 确保没有并发定时器
|
|
90
91
|
typeTimeoutRef.current = setTimeout(processNextChar, timePerChar);
|
|
91
92
|
return clearTypeTimer;
|
|
92
|
-
}, [contentQueue.length, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
|
|
93
|
+
}, [contentQueue.length, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
|
|
93
94
|
// 处理 HTML 标签
|
|
94
95
|
const processedContent = useMemo(() => {
|
|
95
96
|
// 使用 Record 类型来定义映射关系
|
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.7';
|
package/lib/markdown/index.js
CHANGED
|
@@ -46,16 +46,20 @@ const Markdown = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
46
46
|
setContentQueue([]);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
// 比较传入的content和当前的displayedContent的长度
|
|
50
|
+
const contentLength = content.length;
|
|
51
|
+
const displayedContentLength = displayedContent.length;
|
|
52
|
+
const diffLength = contentLength - displayedContentLength;
|
|
53
|
+
if (diffLength <= 0) {
|
|
54
|
+
// 如果content的长度小于等于displayedContent的长度,则清空contentQueue,直接展示content
|
|
55
|
+
setDisplayedContent(content);
|
|
56
|
+
setContentQueue([]);
|
|
54
57
|
}
|
|
55
58
|
else {
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
+
// 如果content的长度大于displayedContent的长度,将 content 分为两部分,
|
|
60
|
+
// 前 contentLength - diffLength 个字符直接显示,后 diffLength 个字符使用打字效果
|
|
61
|
+
const displayPart = content.slice(0, contentLength - diffLength);
|
|
62
|
+
const typingPart = content.slice(contentLength - diffLength);
|
|
59
63
|
setDisplayedContent(displayPart);
|
|
60
64
|
setContentQueue(typingPart.split(''));
|
|
61
65
|
}
|
|
@@ -67,31 +71,28 @@ const Markdown = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
67
71
|
clearTypeTimer();
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
|
-
//
|
|
71
|
-
const timePerChar =
|
|
74
|
+
// 固定吐字速度为50ms一次
|
|
75
|
+
const timePerChar = 100;
|
|
76
|
+
// 动态调整一次吐字的字数,确保1s内吐完,最少吐2个字符
|
|
77
|
+
const charsPerTime = Math.max(Math.floor(contentQueue.length / 10), 2);
|
|
72
78
|
const processNextChar = () => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (newQueue.length > 0) {
|
|
85
|
-
typeTimeoutRef.current = setTimeout(processNextChar, timePerChar);
|
|
86
|
-
}
|
|
87
|
-
return newQueue;
|
|
88
|
-
});
|
|
79
|
+
const currentQueue = contentQueue;
|
|
80
|
+
if (currentQueue.length === 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// 获取并移除队列中的第charsPerTime个字符
|
|
84
|
+
const nextChars = currentQueue.slice(0, charsPerTime);
|
|
85
|
+
const newQueue = currentQueue.slice(charsPerTime);
|
|
86
|
+
// 更新显示内容
|
|
87
|
+
setDisplayedContent(prev => prev + nextChars.join(''));
|
|
88
|
+
// 更新队列
|
|
89
|
+
setContentQueue(newQueue);
|
|
89
90
|
};
|
|
90
91
|
// 开始处理第一个字符
|
|
91
92
|
clearTypeTimer(); // 确保没有并发定时器
|
|
92
93
|
typeTimeoutRef.current = setTimeout(processNextChar, timePerChar);
|
|
93
94
|
return clearTypeTimer;
|
|
94
|
-
}, [contentQueue.length, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
|
|
95
|
+
}, [contentQueue.length, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
|
|
95
96
|
// 处理 HTML 标签
|
|
96
97
|
const processedContent = (0, react_1.useMemo)(() => {
|
|
97
98
|
// 使用 Record 类型来定义映射关系
|