@yuntijs/ui 1.0.0-beta.95 → 1.0.0-beta.97
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/ChatMarkdown/MarkdownElements/AntThinking/Component.js +17 -9
- package/es/ChatMarkdown/MarkdownElements/AntThinking/index.d.ts +1 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/index.js +2 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/remarkPlugin.d.ts +1 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/remarkPlugin.js +59 -0
- package/es/ChatMarkdown/MarkdownElements/index.d.ts +1 -0
- package/es/ChatMarkdown/index.js +15 -11
- package/es/ChatMarkdown/utils.d.ts +1 -0
- package/es/ChatMarkdown/utils.js +10 -0
- package/package.json +2 -1
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
3
|
-
var _templateObject, _templateObject2
|
|
4
|
-
|
|
4
|
+
var _templateObject, _templateObject2;
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { Icon, Markdown } from '@lobehub/ui';
|
|
5
8
|
import { createStyles } from 'antd-style';
|
|
6
9
|
import { ChevronDown, ChevronRight, Sparkles } from 'lucide-react';
|
|
7
10
|
import { memo, useState } from 'react';
|
|
@@ -13,11 +16,16 @@ var useStyles = createStyles(function (_ref) {
|
|
|
13
16
|
token = _ref.token,
|
|
14
17
|
isDarkMode = _ref.isDarkMode;
|
|
15
18
|
return {
|
|
16
|
-
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n padding-block: 12px;\n
|
|
17
|
-
titlebox: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding: 8px;\n color: ", ";\n background: ", ";\n border-radius: 8px;\n
|
|
18
|
-
title: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: hidden;\n display: box;\n -webkit-box-orient: vertical;\n\n font-size: 12px;\n text-overflow: ellipsis;\n\n -webkit-line-clamp: 1;\n "])))
|
|
19
|
+
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n padding-block: 12px;\n color: ", ";\n "])), token.colorTextSecondary),
|
|
20
|
+
titlebox: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding: 8px;\n\n font-size: 12px;\n color: ", ";\n\n background: ", ";\n border-radius: 8px;\n "])), token.colorText, isDarkMode ? token.colorFillTertiary : '#f3f5fc')
|
|
19
21
|
};
|
|
20
22
|
});
|
|
23
|
+
var mProps = {
|
|
24
|
+
fontSize: 12,
|
|
25
|
+
lineHeight: 1.625,
|
|
26
|
+
headerMultiple: 0.2,
|
|
27
|
+
marginMultiple: 0.6
|
|
28
|
+
};
|
|
21
29
|
var Render = /*#__PURE__*/memo(function (_ref2) {
|
|
22
30
|
var children = _ref2.children,
|
|
23
31
|
second = _ref2.second,
|
|
@@ -31,11 +39,9 @@ var Render = /*#__PURE__*/memo(function (_ref2) {
|
|
|
31
39
|
setShowDetail = _useState2[1];
|
|
32
40
|
return /*#__PURE__*/_jsxs(Flexbox, {
|
|
33
41
|
className: styles.container,
|
|
34
|
-
gap: 16,
|
|
35
42
|
onClick: function onClick() {
|
|
36
43
|
setShowDetail(!showDetail);
|
|
37
44
|
},
|
|
38
|
-
width: '100%',
|
|
39
45
|
children: [/*#__PURE__*/_jsxs(Flexbox, {
|
|
40
46
|
className: styles.titlebox,
|
|
41
47
|
distribution: 'space-between',
|
|
@@ -47,11 +53,13 @@ var Render = /*#__PURE__*/memo(function (_ref2) {
|
|
|
47
53
|
children: [/*#__PURE__*/_jsx(Icon, {
|
|
48
54
|
color: theme.purple,
|
|
49
55
|
icon: Sparkles
|
|
50
|
-
}), done ? "\u5DF2\u6DF1\u5EA6\u601D\u8003
|
|
56
|
+
}), done ? "\u5DF2\u6DF1\u5EA6\u601D\u8003".concat(second ? '(用时' + second + '秒)' : '', " ") : '思考中...']
|
|
51
57
|
}), /*#__PURE__*/_jsx(Icon, {
|
|
52
58
|
icon: showDetail ? ChevronDown : ChevronRight
|
|
53
59
|
})]
|
|
54
|
-
}), showDetail &&
|
|
60
|
+
}), showDetail && /*#__PURE__*/_jsx(Markdown, _objectSpread(_objectSpread({}, mProps), {}, {
|
|
61
|
+
children: children
|
|
62
|
+
}))]
|
|
55
63
|
});
|
|
56
64
|
});
|
|
57
65
|
export default Render;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
declare const AntThinkingElement: {
|
|
3
3
|
Component: import("react").NamedExoticComponent<import("react").PropsWithChildren<import("./Component").ThinkProps>>;
|
|
4
4
|
rehypePlugin: () => (tree: import("unist").Node) => void;
|
|
5
|
+
remarkPlugins: () => (tree: any) => void;
|
|
5
6
|
tag: string;
|
|
6
7
|
};
|
|
7
8
|
export default AntThinkingElement;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import Component from "./Component";
|
|
2
2
|
import rehypePlugin from "./rehypePlugin";
|
|
3
|
+
import { remarkCaptureThink } from "./remarkPlugin";
|
|
3
4
|
var AntThinkingElement = {
|
|
4
5
|
Component: Component,
|
|
5
6
|
rehypePlugin: rehypePlugin,
|
|
7
|
+
remarkPlugins: remarkCaptureThink,
|
|
6
8
|
tag: 'think'
|
|
7
9
|
};
|
|
8
10
|
export default AntThinkingElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const remarkCaptureThink: () => (tree: any) => void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { toMarkdown } from 'mdast-util-to-markdown';
|
|
2
|
+
import { SKIP, visit } from 'unist-util-visit';
|
|
3
|
+
export var remarkCaptureThink = function remarkCaptureThink() {
|
|
4
|
+
return function (tree) {
|
|
5
|
+
visit(tree, 'html', function (node, index, parent) {
|
|
6
|
+
if (node.value === '<think>') {
|
|
7
|
+
var startIndex = index;
|
|
8
|
+
var endIndex = startIndex + 1;
|
|
9
|
+
var hasCloseTag = false;
|
|
10
|
+
|
|
11
|
+
// 查找闭合标签
|
|
12
|
+
while (endIndex < parent.children.length) {
|
|
13
|
+
var sibling = parent.children[endIndex];
|
|
14
|
+
if (sibling.type === 'html' && sibling.value === '</think>') {
|
|
15
|
+
hasCloseTag = true;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
endIndex++;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 计算需要删除的节点范围
|
|
22
|
+
var deleteCount = hasCloseTag ? endIndex - startIndex + 1 : parent.children.length - startIndex;
|
|
23
|
+
|
|
24
|
+
// 提取内容节点
|
|
25
|
+
var contentNodes = parent.children.slice(startIndex + 1, hasCloseTag ? endIndex : undefined);
|
|
26
|
+
|
|
27
|
+
// 转换为 Markdown 字符串
|
|
28
|
+
var content = contentNodes.map(function (n) {
|
|
29
|
+
// fix https://github.com/lobehub/lobe-chat/issues/5668
|
|
30
|
+
if (n.type === 'paragraph') {
|
|
31
|
+
return n.children.map(function (child) {
|
|
32
|
+
return child.value;
|
|
33
|
+
}).join('');
|
|
34
|
+
}
|
|
35
|
+
return toMarkdown(n);
|
|
36
|
+
}).join('\n\n').trim();
|
|
37
|
+
|
|
38
|
+
// 创建自定义节点
|
|
39
|
+
var thinkNode = {
|
|
40
|
+
data: {
|
|
41
|
+
hChildren: [{
|
|
42
|
+
type: 'text',
|
|
43
|
+
value: content
|
|
44
|
+
}],
|
|
45
|
+
hName: 'think'
|
|
46
|
+
},
|
|
47
|
+
position: node.position,
|
|
48
|
+
type: 'thinkBlock'
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// 替换原始节点
|
|
52
|
+
parent.children.splice(startIndex, deleteCount, thinkNode);
|
|
53
|
+
|
|
54
|
+
// 跳过已处理的节点
|
|
55
|
+
return [SKIP, startIndex + 1];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
export declare const markdownElements: {
|
|
3
3
|
Component: import("react").NamedExoticComponent<import("react").PropsWithChildren<import("./AntThinking/Component").ThinkProps>>;
|
|
4
4
|
rehypePlugin: () => (tree: import("unist").Node) => void;
|
|
5
|
+
remarkPlugins: () => (tree: any) => void;
|
|
5
6
|
tag: string;
|
|
6
7
|
}[];
|
package/es/ChatMarkdown/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["components", "
|
|
4
|
+
var _excluded = ["components", "remarkPlugins", "customComponentProps", "children"];
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
7
|
import { Markdown } from '@lobehub/ui';
|
|
8
8
|
import React, { useMemo } from 'react';
|
|
9
9
|
import { markdownElements } from "./MarkdownElements";
|
|
10
|
+
import { normalizeThinkTags } from "./utils";
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
var
|
|
12
|
-
return element.
|
|
12
|
+
var defaultRemarkPlugins = markdownElements.map(function (element) {
|
|
13
|
+
return element.remarkPlugins;
|
|
13
14
|
});
|
|
14
15
|
export var ChatMarkdown = function ChatMarkdown(_ref) {
|
|
15
16
|
var _ref$components = _ref.components,
|
|
16
17
|
components = _ref$components === void 0 ? {} : _ref$components,
|
|
17
|
-
_ref$
|
|
18
|
-
|
|
18
|
+
_ref$remarkPlugins = _ref.remarkPlugins,
|
|
19
|
+
remarkPlugins = _ref$remarkPlugins === void 0 ? [] : _ref$remarkPlugins,
|
|
19
20
|
customComponentProps = _ref.customComponentProps,
|
|
21
|
+
children = _ref.children,
|
|
20
22
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
21
23
|
var allComponents = useMemo(function () {
|
|
22
24
|
var defaultComponents = Object.fromEntries(markdownElements.map(function (element) {
|
|
@@ -26,11 +28,13 @@ export var ChatMarkdown = function ChatMarkdown(_ref) {
|
|
|
26
28
|
}));
|
|
27
29
|
return _objectSpread(_objectSpread({}, defaultComponents), components);
|
|
28
30
|
}, [components, customComponentProps]);
|
|
29
|
-
var
|
|
30
|
-
return [].concat(_toConsumableArray(
|
|
31
|
-
}, [
|
|
32
|
-
return /*#__PURE__*/_jsx(Markdown, _objectSpread({
|
|
31
|
+
var allRemarkPlugins = useMemo(function () {
|
|
32
|
+
return [].concat(_toConsumableArray(defaultRemarkPlugins), _toConsumableArray(remarkPlugins));
|
|
33
|
+
}, [remarkPlugins]);
|
|
34
|
+
return /*#__PURE__*/_jsx(Markdown, _objectSpread(_objectSpread({
|
|
33
35
|
components: allComponents,
|
|
34
|
-
|
|
35
|
-
}, props)
|
|
36
|
+
remarkPlugins: allRemarkPlugins
|
|
37
|
+
}, props), {}, {
|
|
38
|
+
children: normalizeThinkTags(children)
|
|
39
|
+
}));
|
|
36
40
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const normalizeThinkTags: (markdown: string) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// 预处理函数:确保 think 标签前后有两个换行符
|
|
2
|
+
export var normalizeThinkTags = function normalizeThinkTags(markdown) {
|
|
3
|
+
return markdown
|
|
4
|
+
// 确保 <think> 标签前后有两个换行符
|
|
5
|
+
.replaceAll(/([^\n])\s*<think>/g, '$1\n\n<think>').replaceAll(/<think>\s*([^\n])/g, '<think>\n\n$1')
|
|
6
|
+
// 确保 </think> 标签前后有两个换行符
|
|
7
|
+
.replaceAll(/([^\n])\s*<\/think>/g, '$1\n\n</think>').replaceAll(/<\/think>\s*([^\n])/g, '</think>\n\n$1')
|
|
8
|
+
// 处理可能产生的多余换行符
|
|
9
|
+
.replaceAll(/\n{3,}/g, '\n\n');
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuntijs/ui",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.97",
|
|
4
4
|
"description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yuntijs",
|
|
@@ -129,6 +129,7 @@
|
|
|
129
129
|
"jest": "^27",
|
|
130
130
|
"jsdom": "^22",
|
|
131
131
|
"lint-staged": "^15",
|
|
132
|
+
"mdast-util-to-markdown": "^2.1.2",
|
|
132
133
|
"monaco-editor": "^0.45.0",
|
|
133
134
|
"prettier": "^3",
|
|
134
135
|
"react": "^18",
|