@yuntijs/ui 1.0.0-beta.94 → 1.0.0-beta.96
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.d.ts +7 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/Component.js +57 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/index.d.ts +8 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/index.js +10 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/rehypePlugin.d.ts +3 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/rehypePlugin.js +32 -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 +7 -0
- package/es/ChatMarkdown/MarkdownElements/index.js +2 -0
- package/es/ChatMarkdown/index.d.ts +10 -0
- package/es/ChatMarkdown/index.js +40 -0
- package/es/ChatMarkdown/utils.d.ts +1 -0
- package/es/ChatMarkdown/utils.js +10 -0
- package/es/EditableMessage/index.d.ts +3 -2
- package/es/EditableMessage/index.js +3 -2
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/package.json +4 -1
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
3
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
4
|
+
import { Icon, Markdown } from '@lobehub/ui';
|
|
5
|
+
import { createStyles } from 'antd-style';
|
|
6
|
+
import { ChevronDown, ChevronRight, Sparkles } from 'lucide-react';
|
|
7
|
+
import { memo, useState } from 'react';
|
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
var useStyles = createStyles(function (_ref) {
|
|
12
|
+
var css = _ref.css,
|
|
13
|
+
token = _ref.token,
|
|
14
|
+
isDarkMode = _ref.isDarkMode;
|
|
15
|
+
return {
|
|
16
|
+
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n padding-block: 12px;\n color: ", ";\n "])), token.colorTextTertiary),
|
|
17
|
+
titlebox: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding: 8px;\n color: ", ";\n background: ", ";\n border-radius: 8px;\n\n &:hover {\n background: ", ";\n }\n "])), token.colorTextSecondary, token.colorFillTertiary, isDarkMode ? '' : token.colorFillSecondary),
|
|
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
|
+
};
|
|
20
|
+
});
|
|
21
|
+
var Render = /*#__PURE__*/memo(function (_ref2) {
|
|
22
|
+
var children = _ref2.children,
|
|
23
|
+
second = _ref2.second,
|
|
24
|
+
done = _ref2.done;
|
|
25
|
+
var _useStyles = useStyles(),
|
|
26
|
+
styles = _useStyles.styles,
|
|
27
|
+
theme = _useStyles.theme;
|
|
28
|
+
var _useState = useState(true),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
showDetail = _useState2[0],
|
|
31
|
+
setShowDetail = _useState2[1];
|
|
32
|
+
return /*#__PURE__*/_jsxs(Flexbox, {
|
|
33
|
+
className: styles.container,
|
|
34
|
+
onClick: function onClick() {
|
|
35
|
+
setShowDetail(!showDetail);
|
|
36
|
+
},
|
|
37
|
+
children: [/*#__PURE__*/_jsxs(Flexbox, {
|
|
38
|
+
className: styles.titlebox,
|
|
39
|
+
distribution: 'space-between',
|
|
40
|
+
flex: 1,
|
|
41
|
+
horizontal: true,
|
|
42
|
+
children: [/*#__PURE__*/_jsxs(Flexbox, {
|
|
43
|
+
gap: 8,
|
|
44
|
+
horizontal: true,
|
|
45
|
+
children: [/*#__PURE__*/_jsx(Icon, {
|
|
46
|
+
color: theme.purple,
|
|
47
|
+
icon: Sparkles
|
|
48
|
+
}), done ? "\u5DF2\u6DF1\u5EA6\u601D\u8003\uFF08\u7528\u65F6 ".concat(second || 0, " \u79D2\uFF09") : '思考中...']
|
|
49
|
+
}), /*#__PURE__*/_jsx(Icon, {
|
|
50
|
+
icon: showDetail ? ChevronDown : ChevronRight
|
|
51
|
+
})]
|
|
52
|
+
}), showDetail && /*#__PURE__*/_jsx(Markdown, {
|
|
53
|
+
children: children
|
|
54
|
+
})]
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
export default Render;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const AntThinkingElement: {
|
|
3
|
+
Component: import("react").NamedExoticComponent<import("react").PropsWithChildren<import("./Component").ThinkProps>>;
|
|
4
|
+
rehypePlugin: () => (tree: import("unist").Node) => void;
|
|
5
|
+
remarkPlugins: () => (tree: any) => void;
|
|
6
|
+
tag: string;
|
|
7
|
+
};
|
|
8
|
+
export default AntThinkingElement;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Component from "./Component";
|
|
2
|
+
import rehypePlugin from "./rehypePlugin";
|
|
3
|
+
import { remarkCaptureThink } from "./remarkPlugin";
|
|
4
|
+
var AntThinkingElement = {
|
|
5
|
+
Component: Component,
|
|
6
|
+
rehypePlugin: rehypePlugin,
|
|
7
|
+
remarkPlugins: remarkCaptureThink,
|
|
8
|
+
tag: 'think'
|
|
9
|
+
};
|
|
10
|
+
export default AntThinkingElement;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
4
|
+
var rehypePlugin = function rehypePlugin() {
|
|
5
|
+
return function (tree) {
|
|
6
|
+
visit(tree, 'element', function (node, index, parent) {
|
|
7
|
+
if (node.type === 'element' && node.tagName === 'p') {
|
|
8
|
+
var children = node.children || [];
|
|
9
|
+
var openTagIndex = children.findIndex(function (child) {
|
|
10
|
+
return child.type === 'raw' && child.value === '<think>';
|
|
11
|
+
});
|
|
12
|
+
var closeTagIndex = children.findIndex(function (child) {
|
|
13
|
+
return child.type === 'raw' && child.value === '</think>';
|
|
14
|
+
});
|
|
15
|
+
if (openTagIndex !== -1 && closeTagIndex !== -1 && closeTagIndex > openTagIndex) {
|
|
16
|
+
var content = children.slice(openTagIndex + 1, closeTagIndex);
|
|
17
|
+
var thinkNode = {
|
|
18
|
+
children: content,
|
|
19
|
+
properties: {},
|
|
20
|
+
tagName: 'think',
|
|
21
|
+
type: 'element'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Replace the entire paragraph with our new thinkNode node
|
|
25
|
+
parent.children.splice(index, 1, thinkNode);
|
|
26
|
+
return index; // Skip processing the newly inserted node
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default rehypePlugin;
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const markdownElements: {
|
|
3
|
+
Component: import("react").NamedExoticComponent<import("react").PropsWithChildren<import("./AntThinking/Component").ThinkProps>>;
|
|
4
|
+
rehypePlugin: () => (tree: import("unist").Node) => void;
|
|
5
|
+
remarkPlugins: () => (tree: any) => void;
|
|
6
|
+
tag: string;
|
|
7
|
+
}[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type MarkdownProps } from '@lobehub/ui';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ThinkProps } from './MarkdownElements/AntThinking/Component';
|
|
4
|
+
export interface ChatMarkdownProps extends MarkdownProps {
|
|
5
|
+
customComponentProps?: {
|
|
6
|
+
think?: Partial<ThinkProps>;
|
|
7
|
+
[k: string]: any;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare const ChatMarkdown: React.FC<ChatMarkdownProps>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["components", "remarkPlugins", "customComponentProps", "children"];
|
|
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 { Markdown } from '@lobehub/ui';
|
|
8
|
+
import React, { useMemo } from 'react';
|
|
9
|
+
import { markdownElements } from "./MarkdownElements";
|
|
10
|
+
import { normalizeThinkTags } from "./utils";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
var defaultRemarkPlugins = markdownElements.map(function (element) {
|
|
13
|
+
return element.remarkPlugins;
|
|
14
|
+
});
|
|
15
|
+
export var ChatMarkdown = function ChatMarkdown(_ref) {
|
|
16
|
+
var _ref$components = _ref.components,
|
|
17
|
+
components = _ref$components === void 0 ? {} : _ref$components,
|
|
18
|
+
_ref$remarkPlugins = _ref.remarkPlugins,
|
|
19
|
+
remarkPlugins = _ref$remarkPlugins === void 0 ? [] : _ref$remarkPlugins,
|
|
20
|
+
customComponentProps = _ref.customComponentProps,
|
|
21
|
+
children = _ref.children,
|
|
22
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
23
|
+
var allComponents = useMemo(function () {
|
|
24
|
+
var defaultComponents = Object.fromEntries(markdownElements.map(function (element) {
|
|
25
|
+
return [element.tag, function (aprops) {
|
|
26
|
+
return /*#__PURE__*/_jsx(element.Component, _objectSpread(_objectSpread({}, aprops), customComponentProps === null || customComponentProps === void 0 ? void 0 : customComponentProps[element.tag]));
|
|
27
|
+
}];
|
|
28
|
+
}));
|
|
29
|
+
return _objectSpread(_objectSpread({}, defaultComponents), components);
|
|
30
|
+
}, [components, customComponentProps]);
|
|
31
|
+
var allRemarkPlugins = useMemo(function () {
|
|
32
|
+
return [].concat(_toConsumableArray(defaultRemarkPlugins), _toConsumableArray(remarkPlugins));
|
|
33
|
+
}, [remarkPlugins]);
|
|
34
|
+
return /*#__PURE__*/_jsx(Markdown, _objectSpread(_objectSpread({
|
|
35
|
+
components: allComponents,
|
|
36
|
+
remarkPlugins: allRemarkPlugins
|
|
37
|
+
}, props), {}, {
|
|
38
|
+
children: normalizeThinkTags(children)
|
|
39
|
+
}));
|
|
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
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type MessageInputProps, type MessageModalProps } from '@lobehub/ui';
|
|
2
2
|
import { CSSProperties } from 'react';
|
|
3
|
+
import { ChatMarkdownProps } from "../ChatMarkdown";
|
|
3
4
|
export interface EditableMessageProps {
|
|
4
5
|
/**
|
|
5
6
|
* @title The class name for the Markdown and MessageInput component
|
|
@@ -70,6 +71,6 @@ export interface EditableMessageProps {
|
|
|
70
71
|
* @title The current text value
|
|
71
72
|
*/
|
|
72
73
|
value: string;
|
|
73
|
-
markdownProps?: Omit<
|
|
74
|
+
markdownProps?: Omit<ChatMarkdownProps, 'children'>;
|
|
74
75
|
}
|
|
75
76
|
export declare const EditableMessage: import("react").NamedExoticComponent<EditableMessageProps>;
|
|
@@ -4,9 +4,10 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
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
|
-
import {
|
|
7
|
+
import { MessageInput, MessageModal } from '@lobehub/ui';
|
|
8
8
|
import { memo } from 'react';
|
|
9
9
|
import useControlledState from 'use-merge-value';
|
|
10
|
+
import { ChatMarkdown } from "../ChatMarkdown";
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
13
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -69,7 +70,7 @@ export var EditableMessage = /*#__PURE__*/memo(function (_ref) {
|
|
|
69
70
|
});
|
|
70
71
|
if (!value && showEditWhenEmpty) return input;
|
|
71
72
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
72
|
-
children: [!expand && isEdit ? input : /*#__PURE__*/_jsx(
|
|
73
|
+
children: [!expand && isEdit ? input : /*#__PURE__*/_jsx(ChatMarkdown, _objectSpread(_objectSpread({
|
|
73
74
|
className: classNames === null || classNames === void 0 ? void 0 : classNames.markdown,
|
|
74
75
|
fontSize: fontSize,
|
|
75
76
|
fullFeaturedCodeBlock: fullFeaturedCodeBlock,
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
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.96",
|
|
4
4
|
"description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yuntijs",
|
|
@@ -113,6 +113,7 @@
|
|
|
113
113
|
"@types/query-string": "^6",
|
|
114
114
|
"@types/react": "18.2.40",
|
|
115
115
|
"@types/react-dom": "^18",
|
|
116
|
+
"@types/unist": "^3.0.3",
|
|
116
117
|
"@vitest/coverage-v8": "latest",
|
|
117
118
|
"@yuntijs/lint": "^1.7.0",
|
|
118
119
|
"antd": "^5.23.0",
|
|
@@ -128,6 +129,7 @@
|
|
|
128
129
|
"jest": "^27",
|
|
129
130
|
"jsdom": "^22",
|
|
130
131
|
"lint-staged": "^15",
|
|
132
|
+
"mdast-util-to-markdown": "^2.1.2",
|
|
131
133
|
"monaco-editor": "^0.45.0",
|
|
132
134
|
"prettier": "^3",
|
|
133
135
|
"react": "^18",
|
|
@@ -137,6 +139,7 @@
|
|
|
137
139
|
"semantic-release": "^21",
|
|
138
140
|
"stylelint": "^15",
|
|
139
141
|
"typescript": "^5",
|
|
142
|
+
"unist-util-visit": "^5.0.0",
|
|
140
143
|
"vitest": "latest"
|
|
141
144
|
},
|
|
142
145
|
"peerDependencies": {
|