@agentscope-ai/chat 1.1.17 → 1.1.19-beta.1761468580294
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/lib/Accordion/Accordion.d.ts +5 -0
- package/lib/Accordion/Accordion.js +7 -4
- package/lib/Accordion/DeepThinking.d.ts +15 -0
- package/lib/Accordion/DeepThinking.js +26 -7
- package/lib/DefaultCards/DeepThinking/index.d.ts +4 -0
- package/lib/DefaultCards/DeepThinking/index.js +5 -2
- package/lib/DefaultCards/Text/index.js +4 -2
- package/lib/ImageGenerator/index.js +1 -1
- package/lib/Markdown/Markdown/AnimationNode.d.ts +20 -0
- package/lib/Markdown/Markdown/AnimationNode.js +84 -0
- package/lib/Markdown/Markdown/Markdown.d.ts +4 -0
- package/lib/Markdown/Markdown/Markdown.js +58 -0
- package/lib/Markdown/Markdown/core/Parser.d.ts +16 -0
- package/lib/Markdown/Markdown/core/Parser.js +64 -0
- package/lib/Markdown/Markdown/core/Renderer.d.ts +24 -0
- package/lib/Markdown/Markdown/core/Renderer.js +137 -0
- package/lib/Markdown/Markdown/core/index.d.ts +3 -0
- package/lib/Markdown/Markdown/core/index.js +3 -0
- package/lib/Markdown/{CodeBlock.js → Markdown/defaultComponents/CodeBlock.js} +7 -4
- package/lib/Markdown/{ImageOrMedia.js → Markdown/defaultComponents/Media.js} +4 -4
- package/lib/Markdown/Markdown/hooks/index.d.ts +3 -0
- package/lib/Markdown/Markdown/hooks/index.js +3 -0
- package/lib/Markdown/Markdown/hooks/useAnimation.d.ts +4 -0
- package/lib/Markdown/Markdown/hooks/useAnimation.js +30 -0
- package/lib/Markdown/Markdown/hooks/useCitationsData.d.ts +2 -0
- package/lib/Markdown/Markdown/hooks/useCitationsData.js +24 -0
- package/lib/Markdown/Markdown/hooks/useStreaming.d.ts +3 -0
- package/lib/Markdown/Markdown/hooks/useStreaming.js +544 -0
- package/lib/Markdown/{useTyping.js → Markdown/hooks/useTyping.js} +2 -2
- package/lib/Markdown/Markdown/index.d.ts +77 -0
- package/lib/Markdown/Markdown/index.js +98 -0
- package/lib/Markdown/Markdown/interface.d.ts +203 -0
- package/lib/Markdown/Markdown/style.js +32 -0
- package/lib/Markdown/index.d.ts +1 -63
- package/lib/Markdown/index.js +1 -42
- package/lib/Markdown/plugins/citations/CitationComponent.d.ts +11 -0
- package/lib/Markdown/{Link.js → plugins/citations/CitationComponent.js} +56 -39
- package/lib/Markdown/plugins/citations/index.d.ts +13 -0
- package/lib/Markdown/plugins/citations/index.js +27 -0
- package/lib/Markdown/{cursor → plugins/cursor}/Dot.js +1 -1
- package/lib/Markdown/{cursor → plugins/cursor}/Underline.js +5 -2
- package/lib/Markdown/plugins/cursor/index.d.ts +13 -0
- package/lib/Markdown/plugins/cursor/index.js +55 -0
- package/lib/Markdown/plugins/latex/index.d.ts +9 -0
- package/lib/Markdown/plugins/latex/index.js +97 -0
- package/lib/Markdown/plugins/type.d.ts +60 -0
- package/lib/Markdown/plugins/type.js +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/package.json +9 -1
- package/lib/Markdown/Citation.d.ts +0 -16
- package/lib/Markdown/Citation.js +0 -60
- package/lib/Markdown/Link.d.ts +0 -3
- package/lib/Markdown/Markdown.d.ts +0 -4
- package/lib/Markdown/Markdown.js +0 -130
- package/lib/Markdown/plugins/footnote.d.ts +0 -2
- package/lib/Markdown/plugins/footnote.js +0 -89
- package/lib/Markdown/plugins/katexDir.d.ts +0 -1
- package/lib/Markdown/plugins/katexDir.js +0 -15
- package/lib/Markdown/rehype/fadeIn.d.ts +0 -2
- package/lib/Markdown/rehype/fadeIn.js +0 -43
- package/lib/Markdown/style.js +0 -30
- package/lib/Markdown/type.d.ts +0 -186
- package/lib/Markdown/utils.d.ts +0 -22
- package/lib/Markdown/utils.js +0 -124
- /package/lib/Markdown/{CodeBlock.d.ts → Markdown/defaultComponents/CodeBlock.d.ts} +0 -0
- /package/lib/Markdown/{ImageOrMedia.d.ts → Markdown/defaultComponents/Media.d.ts} +0 -0
- /package/lib/Markdown/{useTyping.d.ts → Markdown/hooks/useTyping.d.ts} +0 -0
- /package/lib/Markdown/{type.js → Markdown/interface.js} +0 -0
- /package/lib/Markdown/{style.d.ts → Markdown/style.d.ts} +0 -0
- /package/lib/Markdown/{cursor → plugins/cursor}/Dot.d.ts +0 -0
- /package/lib/Markdown/{cursor → plugins/cursor}/Underline.d.ts +0 -0
|
@@ -45,6 +45,11 @@ export interface IAccordionProps {
|
|
|
45
45
|
* @descriptionEn Whether the component is expanded by default when initialized
|
|
46
46
|
*/
|
|
47
47
|
defaultOpen?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* @description 受控模式:控制组件是否展开
|
|
50
|
+
* @descriptionEn Controlled mode: controls whether the component is expanded
|
|
51
|
+
*/
|
|
52
|
+
open?: boolean;
|
|
48
53
|
/**
|
|
49
54
|
* @description 内容区域的样式对象
|
|
50
55
|
* @descriptionEn Style object for the content area
|
|
@@ -29,7 +29,10 @@ function Item(props) {
|
|
|
29
29
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
30
30
|
stateOpen = _React$useState2[0],
|
|
31
31
|
setStateOpen = _React$useState2[1];
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
// 支持受控模式:如果提供了 open prop,则使用它;否则使用内部状态
|
|
34
|
+
var isOpen = props.open !== undefined ? props.open : stateOpen;
|
|
35
|
+
var status = props.inline ? 'close' : isOpen ? 'open' : 'close';
|
|
33
36
|
var icon = useMemo(function () {
|
|
34
37
|
if (props.icon) return props.icon;
|
|
35
38
|
if (props.status === 'generating') return /*#__PURE__*/_jsx(SparkLoadingLine, {
|
|
@@ -65,7 +68,7 @@ function Item(props) {
|
|
|
65
68
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
66
69
|
className: cls("".concat(prefixCls, "-header"), "".concat(prefixCls, "-header-").concat(status)),
|
|
67
70
|
onClick: function onClick() {
|
|
68
|
-
return content && setStateOpen(!stateOpen);
|
|
71
|
+
return content && props.open === undefined && setStateOpen(!stateOpen);
|
|
69
72
|
},
|
|
70
73
|
children: [icon ? /*#__PURE__*/_jsx("div", {
|
|
71
74
|
className: cls("".concat(prefixCls, "-header-icon"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-header-icon-line"), props.iconLine), "".concat(prefixCls, "-header-icon-first"), props.isFirst), "".concat(prefixCls, "-header-icon-last"), props.isLast && status === 'close' || props.level)),
|
|
@@ -74,7 +77,7 @@ function Item(props) {
|
|
|
74
77
|
children: props.title
|
|
75
78
|
}), content && /*#__PURE__*/_jsx("div", {
|
|
76
79
|
className: cls("".concat(prefixCls, "-header-arrow")),
|
|
77
|
-
children: !
|
|
80
|
+
children: !isOpen ? /*#__PURE__*/_jsx(SparkDownLine, {}) : /*#__PURE__*/_jsx(SparkUpLine, {})
|
|
78
81
|
}), /*#__PURE__*/_jsxs(_Fragment, {
|
|
79
82
|
children: [/*#__PURE__*/_jsx("span", {
|
|
80
83
|
style: {
|
|
@@ -84,7 +87,7 @@ function Item(props) {
|
|
|
84
87
|
})]
|
|
85
88
|
}), /*#__PURE__*/_jsx(Children, {
|
|
86
89
|
prefixCls: prefixCls,
|
|
87
|
-
stateOpen:
|
|
90
|
+
stateOpen: isOpen,
|
|
88
91
|
status: status,
|
|
89
92
|
inline: props.inline,
|
|
90
93
|
content: content,
|
|
@@ -19,6 +19,21 @@ export interface IDeepThinking {
|
|
|
19
19
|
* @descriptionEn Whether to expand by default when component initializes, controls initial display state
|
|
20
20
|
*/
|
|
21
21
|
defaultOpen?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @description 受控模式:控制组件是否展开
|
|
24
|
+
* @descriptionEn Controlled mode: controls whether the component is expanded
|
|
25
|
+
*/
|
|
26
|
+
open?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description 生成结束后是否自动关闭(默认 false)
|
|
29
|
+
* @descriptionEn Whether to automatically close after generation is complete (default false)
|
|
30
|
+
*/
|
|
31
|
+
autoCloseOnFinish?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @description 内容区域的最大高度(单位:像素)
|
|
34
|
+
* @descriptionEn Maximum height of the content area (in pixels)
|
|
35
|
+
*/
|
|
36
|
+
maxHeight?: number;
|
|
22
37
|
/**
|
|
23
38
|
* @description 组件的CSS类名,用于自定义样式
|
|
24
39
|
* @descriptionEn CSS class name for the component for custom styling
|
|
@@ -5,10 +5,10 @@ import cls from 'classnames';
|
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
export default function (props) {
|
|
7
7
|
var _useProviderContext = useProviderContext(),
|
|
8
|
-
|
|
8
|
+
providerTheme = _useProviderContext.theme,
|
|
9
9
|
getPrefixCls = _useProviderContext.getPrefixCls;
|
|
10
10
|
var prefixCls = getPrefixCls('accordion-deep-thinking');
|
|
11
|
-
var isDarkMode = (
|
|
11
|
+
var isDarkMode = (providerTheme === null || providerTheme === void 0 ? void 0 : providerTheme.algorithm) === AntdTheme.darkAlgorithm;
|
|
12
12
|
var icon = /*#__PURE__*/_jsx("img", {
|
|
13
13
|
style: {
|
|
14
14
|
display: 'block',
|
|
@@ -18,14 +18,33 @@ export default function (props) {
|
|
|
18
18
|
},
|
|
19
19
|
src: "https://img.alicdn.com/imgextra/i2/O1CN01QZgWRv1I4JM0BAZ9O_!!6000000000839-54-tps-56-56.apng"
|
|
20
20
|
});
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
// 构建标题文本
|
|
23
|
+
var titleText = props.title || 'Deep thinking';
|
|
24
|
+
if (props.loading) {
|
|
25
|
+
titleText += '...';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 构建标题
|
|
29
|
+
var title = props.loading ? /*#__PURE__*/_jsx(Accordion.SoftLightTitle, {
|
|
30
|
+
children: titleText
|
|
31
|
+
}) : titleText;
|
|
32
|
+
|
|
33
|
+
// 构建 bodyStyle,添加 maxHeight 支持
|
|
34
|
+
var bodyStyle = props.maxHeight ? {
|
|
35
|
+
maxHeight: props.maxHeight,
|
|
36
|
+
overflowY: 'auto'
|
|
37
|
+
} : {};
|
|
38
|
+
|
|
39
|
+
// 确定默认展开状态:如果设置了 autoCloseOnFinish 且不在 loading 状态,默认关闭
|
|
40
|
+
var finalDefaultOpen = props.defaultOpen !== undefined ? props.defaultOpen : props.autoCloseOnFinish && !props.loading ? false : undefined;
|
|
22
41
|
return /*#__PURE__*/_jsx(Accordion, {
|
|
23
|
-
title:
|
|
24
|
-
children: title
|
|
25
|
-
}) : title,
|
|
42
|
+
title: title,
|
|
26
43
|
status: props.loading ? 'generating' : 'finished',
|
|
27
44
|
icon: props.loading ? icon : null,
|
|
28
|
-
defaultOpen:
|
|
45
|
+
defaultOpen: finalDefaultOpen,
|
|
46
|
+
open: props.open,
|
|
47
|
+
bodyStyle: bodyStyle,
|
|
29
48
|
inline: true,
|
|
30
49
|
children: /*#__PURE__*/_jsx("div", {
|
|
31
50
|
className: cls(prefixCls, props.className),
|
|
@@ -6,6 +6,10 @@ interface IProps {
|
|
|
6
6
|
loading?: boolean;
|
|
7
7
|
content?: string;
|
|
8
8
|
className?: string;
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
open?: boolean;
|
|
11
|
+
autoCloseOnFinish?: boolean;
|
|
12
|
+
maxHeight?: number;
|
|
9
13
|
};
|
|
10
14
|
}
|
|
11
15
|
export default function (props: IProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,10 +3,13 @@ import { DeepThinking } from "../..";
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
export default function (props) {
|
|
5
5
|
return /*#__PURE__*/_jsx(DeepThinking, {
|
|
6
|
-
defaultOpen: true,
|
|
6
|
+
defaultOpen: props.data.defaultOpen !== undefined ? props.data.defaultOpen : true,
|
|
7
7
|
title: props.data.title,
|
|
8
8
|
loading: props.data.loading,
|
|
9
9
|
content: props.data.content,
|
|
10
|
-
className: props.data.className
|
|
10
|
+
className: props.data.className,
|
|
11
|
+
open: props.data.open,
|
|
12
|
+
autoCloseOnFinish: props.data.autoCloseOnFinish,
|
|
13
|
+
maxHeight: props.data.maxHeight
|
|
11
14
|
});
|
|
12
15
|
}
|
|
@@ -9,7 +9,9 @@ import { Markdown } from "../..";
|
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
export default function (props) {
|
|
11
11
|
var cursor = props.data.msgStatus === 'generating';
|
|
12
|
-
return /*#__PURE__*/_jsx(Markdown, _objectSpread({
|
|
12
|
+
return /*#__PURE__*/_jsx(Markdown, _objectSpread(_objectSpread({
|
|
13
13
|
cursor: cursor
|
|
14
|
-
}, props.data)
|
|
14
|
+
}, props.data), {}, {
|
|
15
|
+
typing: props.data.msgStatus === 'generating' ? props.data.typing : false
|
|
16
|
+
}));
|
|
15
17
|
}
|
|
@@ -3,7 +3,7 @@ import Style from "./style";
|
|
|
3
3
|
import { useProviderContext } from "../Provider";
|
|
4
4
|
import { ConfigProvider, Image } from 'antd';
|
|
5
5
|
import { SparkCheckCircleFill } from '@agentscope-ai/icons';
|
|
6
|
-
import Dot from "../Markdown/cursor/Dot";
|
|
6
|
+
import Dot from "../Markdown/plugins/cursor/Dot";
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DOMNode } from 'html-react-parser';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { HTMLTag } from './hooks/useAnimation';
|
|
4
|
+
import { AnimationConfig } from './interface';
|
|
5
|
+
export interface AnimationNodeProps extends React.HTMLAttributes<HTMLElement> {
|
|
6
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
7
|
+
nodeTag: HTMLTag;
|
|
8
|
+
animationConfig?: AnimationConfig;
|
|
9
|
+
streamStatus?: 'loading' | 'done';
|
|
10
|
+
domNode?: DOMNode;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface AnimationTextProps {
|
|
14
|
+
text: string;
|
|
15
|
+
animationConfig?: AnimationConfig;
|
|
16
|
+
}
|
|
17
|
+
declare const AnimationText: React.NamedExoticComponent<AnimationTextProps>;
|
|
18
|
+
declare const AnimationNode: React.FC<AnimationNodeProps>;
|
|
19
|
+
export default AnimationNode;
|
|
20
|
+
export { AnimationText };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var _excluded = ["nodeTag", "children", "animationConfig", "domNode", "streamStatus"];
|
|
2
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
15
|
+
import { useProviderContext } from "../..";
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
|
+
var AnimationText = /*#__PURE__*/React.memo(function (props) {
|
|
19
|
+
var text = props.text,
|
|
20
|
+
animationConfig = props.animationConfig;
|
|
21
|
+
var _ref = animationConfig || {},
|
|
22
|
+
_ref$fadeDuration = _ref.fadeDuration,
|
|
23
|
+
fadeDuration = _ref$fadeDuration === void 0 ? 200 : _ref$fadeDuration,
|
|
24
|
+
_ref$easing = _ref.easing,
|
|
25
|
+
easing = _ref$easing === void 0 ? 'ease-in-out' : _ref$easing;
|
|
26
|
+
var _useState = useState([]),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
chunks = _useState2[0],
|
|
29
|
+
setChunks = _useState2[1];
|
|
30
|
+
var prevTextRef = useRef('');
|
|
31
|
+
var _useProviderContext = useProviderContext(),
|
|
32
|
+
getPrefixCls = _useProviderContext.getPrefixCls;
|
|
33
|
+
var prefixCls = getPrefixCls('markdown');
|
|
34
|
+
useEffect(function () {
|
|
35
|
+
if (text === prevTextRef.current) return;
|
|
36
|
+
if (!(prevTextRef.current && text.indexOf(prevTextRef.current) === 0)) {
|
|
37
|
+
setChunks([text]);
|
|
38
|
+
prevTextRef.current = text;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
var newText = text.slice(prevTextRef.current.length);
|
|
42
|
+
if (!newText) return;
|
|
43
|
+
setChunks(function (prev) {
|
|
44
|
+
return [].concat(_toConsumableArray(prev), [newText]);
|
|
45
|
+
});
|
|
46
|
+
prevTextRef.current = text;
|
|
47
|
+
}, [text]);
|
|
48
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
49
|
+
children: chunks.map(function (text, index) {
|
|
50
|
+
return /*#__PURE__*/_jsx("span", {
|
|
51
|
+
style: {
|
|
52
|
+
animation: "".concat(prefixCls, "-fadeIn ").concat(fadeDuration, "ms ").concat(easing, " forwards")
|
|
53
|
+
},
|
|
54
|
+
children: text
|
|
55
|
+
}, "".concat(index, "-").concat(text));
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
var AnimationNode = function AnimationNode(props) {
|
|
60
|
+
var nodeTag = props.nodeTag,
|
|
61
|
+
children = props.children,
|
|
62
|
+
animationConfig = props.animationConfig,
|
|
63
|
+
domNode = props.domNode,
|
|
64
|
+
streamStatus = props.streamStatus,
|
|
65
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
66
|
+
var renderChildren = function renderChildren() {
|
|
67
|
+
if (!children) return null;
|
|
68
|
+
if (Array.isArray(children)) {
|
|
69
|
+
return children.map(function (child, index) {
|
|
70
|
+
return typeof child === 'string' ? /*#__PURE__*/_jsx(AnimationText, {
|
|
71
|
+
animationConfig: animationConfig,
|
|
72
|
+
text: child
|
|
73
|
+
}, index) : child;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return typeof children === 'string' ? /*#__PURE__*/_jsx(AnimationText, {
|
|
77
|
+
text: children,
|
|
78
|
+
animationConfig: animationConfig
|
|
79
|
+
}) : children;
|
|
80
|
+
};
|
|
81
|
+
return /*#__PURE__*/React.createElement(nodeTag, restProps, renderChildren());
|
|
82
|
+
};
|
|
83
|
+
export default AnimationNode;
|
|
84
|
+
export { AnimationText };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import classnames from 'classnames';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { Parser, Renderer } from "./core";
|
|
10
|
+
import { useAnimation, useStreaming } from "./hooks";
|
|
11
|
+
import Style from "./style";
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
var Markdown = function Markdown(props) {
|
|
16
|
+
var cursor = props.cursor,
|
|
17
|
+
baseFontSize = props.baseFontSize,
|
|
18
|
+
baseLineHeight = props.baseLineHeight,
|
|
19
|
+
streaming = props.streaming,
|
|
20
|
+
config = props.config,
|
|
21
|
+
components = props.components,
|
|
22
|
+
_props$paragraphTag = props.paragraphTag,
|
|
23
|
+
paragraphTag = _props$paragraphTag === void 0 ? 'p' : _props$paragraphTag,
|
|
24
|
+
content = props.content,
|
|
25
|
+
children = props.children,
|
|
26
|
+
rootClassName = props.rootClassName,
|
|
27
|
+
className = props.className,
|
|
28
|
+
style = props.style,
|
|
29
|
+
openLinksInNewTab = props.openLinksInNewTab,
|
|
30
|
+
dompurifyConfig = props.dompurifyConfig;
|
|
31
|
+
var mergedCls = classnames(rootClassName, className);
|
|
32
|
+
var mergedStyle = _objectSpread({
|
|
33
|
+
fontSize: baseFontSize,
|
|
34
|
+
lineHeight: baseLineHeight
|
|
35
|
+
}, style);
|
|
36
|
+
var displayContent = useStreaming(content || children || '', streaming, cursor);
|
|
37
|
+
var animationComponents = useAnimation(streaming);
|
|
38
|
+
if (!displayContent) return null;
|
|
39
|
+
var parser = new Parser({
|
|
40
|
+
markedConfig: config,
|
|
41
|
+
paragraphTag: paragraphTag,
|
|
42
|
+
openLinksInNewTab: openLinksInNewTab
|
|
43
|
+
});
|
|
44
|
+
var renderComponents = _objectSpread(_objectSpread({}, animationComponents), components || {});
|
|
45
|
+
var renderer = new Renderer({
|
|
46
|
+
components: renderComponents,
|
|
47
|
+
dompurifyConfig: dompurifyConfig
|
|
48
|
+
});
|
|
49
|
+
var htmlString = parser.parse(displayContent);
|
|
50
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
51
|
+
children: [/*#__PURE__*/_jsx(Style, {}), /*#__PURE__*/_jsx("div", {
|
|
52
|
+
className: mergedCls,
|
|
53
|
+
style: mergedStyle,
|
|
54
|
+
children: renderer.render(htmlString)
|
|
55
|
+
})]
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
export default Markdown;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Marked } from 'marked';
|
|
2
|
+
import { MarkdownProps } from '../interface';
|
|
3
|
+
type ParserOptions = {
|
|
4
|
+
markedConfig?: MarkdownProps['config'];
|
|
5
|
+
paragraphTag?: string;
|
|
6
|
+
openLinksInNewTab?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare class Parser {
|
|
9
|
+
options: ParserOptions;
|
|
10
|
+
markdownInstance: Marked;
|
|
11
|
+
constructor(options?: ParserOptions);
|
|
12
|
+
private configureRenderer;
|
|
13
|
+
configureParagraph(): void;
|
|
14
|
+
parse(content: string): string;
|
|
15
|
+
}
|
|
16
|
+
export default Parser;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
import { Marked } from 'marked';
|
|
9
|
+
var Parser = /*#__PURE__*/function () {
|
|
10
|
+
function Parser() {
|
|
11
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12
|
+
_classCallCheck(this, Parser);
|
|
13
|
+
_defineProperty(this, "options", void 0);
|
|
14
|
+
_defineProperty(this, "markdownInstance", void 0);
|
|
15
|
+
var _options$markedConfig = options.markedConfig,
|
|
16
|
+
markedConfig = _options$markedConfig === void 0 ? {} : _options$markedConfig,
|
|
17
|
+
openLinksInNewTab = options.openLinksInNewTab;
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.markdownInstance = new Marked(markedConfig);
|
|
20
|
+
this.configureRenderer(openLinksInNewTab);
|
|
21
|
+
this.configureParagraph();
|
|
22
|
+
}
|
|
23
|
+
_createClass(Parser, [{
|
|
24
|
+
key: "configureRenderer",
|
|
25
|
+
value: function configureRenderer(openLinksInNewTab) {
|
|
26
|
+
if (!openLinksInNewTab) return;
|
|
27
|
+
var renderer = {
|
|
28
|
+
link: function link(_ref) {
|
|
29
|
+
var href = _ref.href,
|
|
30
|
+
title = _ref.title,
|
|
31
|
+
tokens = _ref.tokens;
|
|
32
|
+
var text = this.parser.parseInline(tokens);
|
|
33
|
+
var titleAttr = title ? " title=\"".concat(title, "\"") : '';
|
|
34
|
+
return "<a href=\"".concat(href, "\"").concat(titleAttr, " target=\"_blank\" rel=\"noopener noreferrer\">").concat(text, "</a>");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
this.markdownInstance.use({
|
|
38
|
+
renderer: renderer
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "configureParagraph",
|
|
43
|
+
value: function configureParagraph() {
|
|
44
|
+
var paragraphTag = this.options.paragraphTag;
|
|
45
|
+
if (!paragraphTag) return;
|
|
46
|
+
var renderer = {
|
|
47
|
+
paragraph: function paragraph(_ref2) {
|
|
48
|
+
var tokens = _ref2.tokens;
|
|
49
|
+
return "<".concat(paragraphTag, ">").concat(this.parser.parseInline(tokens), "</").concat(paragraphTag, ">\n");
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.markdownInstance.use({
|
|
53
|
+
renderer: renderer
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "parse",
|
|
58
|
+
value: function parse(content) {
|
|
59
|
+
return this.markdownInstance.parse(content);
|
|
60
|
+
}
|
|
61
|
+
}]);
|
|
62
|
+
return Parser;
|
|
63
|
+
}();
|
|
64
|
+
export default Parser;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Config as DOMPurifyConfig } from 'dompurify';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
import type { MarkdownProps } from '../interface';
|
|
4
|
+
interface RendererOptions {
|
|
5
|
+
components?: MarkdownProps['components'];
|
|
6
|
+
dompurifyConfig?: DOMPurifyConfig;
|
|
7
|
+
}
|
|
8
|
+
declare class Renderer {
|
|
9
|
+
private readonly options;
|
|
10
|
+
constructor(options: RendererOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Detect unclosed tags using regular expressions
|
|
13
|
+
*/
|
|
14
|
+
private detectUnclosedTags;
|
|
15
|
+
/**
|
|
16
|
+
* Configure DOMPurify to preserve components and target attributes, filter everything else
|
|
17
|
+
*/
|
|
18
|
+
private configureDOMPurify;
|
|
19
|
+
private replaceElement;
|
|
20
|
+
private processChildren;
|
|
21
|
+
processHtml(htmlString: string): React.ReactNode;
|
|
22
|
+
render(html: string): ReactNode | null;
|
|
23
|
+
}
|
|
24
|
+
export default Renderer;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
import parseHtml, { domToReact } from 'html-react-parser';
|
|
21
|
+
import React from 'react';
|
|
22
|
+
var Renderer = /*#__PURE__*/function () {
|
|
23
|
+
function Renderer(options) {
|
|
24
|
+
_classCallCheck(this, Renderer);
|
|
25
|
+
_defineProperty(this, "options", void 0);
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Detect unclosed tags using regular expressions
|
|
31
|
+
*/
|
|
32
|
+
_createClass(Renderer, [{
|
|
33
|
+
key: "detectUnclosedTags",
|
|
34
|
+
value: function detectUnclosedTags(htmlString) {
|
|
35
|
+
var unclosedTags = new Set();
|
|
36
|
+
var stack = [];
|
|
37
|
+
var tagRegex = /<\/?([a-zA-Z][a-zA-Z0-9-]*)(?:\s[^>]*)?>/g;
|
|
38
|
+
var match = tagRegex.exec(htmlString);
|
|
39
|
+
while (match !== null) {
|
|
40
|
+
var _this$options$compone;
|
|
41
|
+
var _match = match,
|
|
42
|
+
_match2 = _slicedToArray(_match, 2),
|
|
43
|
+
fullMatch = _match2[0],
|
|
44
|
+
tagName = _match2[1];
|
|
45
|
+
var isClosing = fullMatch.startsWith('</');
|
|
46
|
+
var isSelfClosing = fullMatch.endsWith('/>');
|
|
47
|
+
if ((_this$options$compone = this.options.components) !== null && _this$options$compone !== void 0 && _this$options$compone[tagName.toLowerCase()]) {
|
|
48
|
+
if (isClosing) {
|
|
49
|
+
// Found closing tag, pop from stack
|
|
50
|
+
var lastIndex = stack.lastIndexOf(tagName.toLowerCase());
|
|
51
|
+
if (lastIndex !== -1) {
|
|
52
|
+
stack.splice(lastIndex, 1);
|
|
53
|
+
}
|
|
54
|
+
} else if (!isSelfClosing) {
|
|
55
|
+
// Found opening tag, push to stack
|
|
56
|
+
stack.push(tagName.toLowerCase());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
match = tagRegex.exec(htmlString);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Remaining tags in stack are unclosed
|
|
63
|
+
stack.forEach(function (tag) {
|
|
64
|
+
unclosedTags.add(tag);
|
|
65
|
+
});
|
|
66
|
+
return unclosedTags;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Configure DOMPurify to preserve components and target attributes, filter everything else
|
|
71
|
+
*/
|
|
72
|
+
}, {
|
|
73
|
+
key: "configureDOMPurify",
|
|
74
|
+
value: function configureDOMPurify() {
|
|
75
|
+
var customComponents = Object.keys(this.options.components || {});
|
|
76
|
+
var userConfig = this.options.dompurifyConfig || {};
|
|
77
|
+
return _objectSpread(_objectSpread({}, userConfig), {}, {
|
|
78
|
+
ADD_TAGS: _toConsumableArray(new Set([].concat(customComponents, _toConsumableArray(userConfig.ALLOWED_TAGS || []))))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "replaceElement",
|
|
83
|
+
value: function replaceElement(unclosedTags) {
|
|
84
|
+
var _this = this;
|
|
85
|
+
return function (domNode) {
|
|
86
|
+
var _this$options$compone2;
|
|
87
|
+
if (!('name' in domNode)) return;
|
|
88
|
+
var _ref = domNode,
|
|
89
|
+
name = _ref.name,
|
|
90
|
+
attribs = _ref.attribs,
|
|
91
|
+
children = _ref.children;
|
|
92
|
+
var renderElement = (_this$options$compone2 = _this.options.components) === null || _this$options$compone2 === void 0 ? void 0 : _this$options$compone2[name];
|
|
93
|
+
if (renderElement) {
|
|
94
|
+
var streamStatus = unclosedTags !== null && unclosedTags !== void 0 && unclosedTags.has(name) ? 'loading' : 'done';
|
|
95
|
+
var props = _objectSpread({
|
|
96
|
+
domNode: domNode,
|
|
97
|
+
streamStatus: streamStatus
|
|
98
|
+
}, attribs);
|
|
99
|
+
|
|
100
|
+
// Handle class and className merging
|
|
101
|
+
var classes = [props.className, props.classname, props.class].filter(Boolean).join(' ').trim();
|
|
102
|
+
props.className = classes || '';
|
|
103
|
+
if (children) {
|
|
104
|
+
props.children = _this.processChildren(children, unclosedTags);
|
|
105
|
+
}
|
|
106
|
+
return /*#__PURE__*/React.createElement(renderElement, props);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "processChildren",
|
|
112
|
+
value: function processChildren(children, unclosedTags) {
|
|
113
|
+
return domToReact(children, {
|
|
114
|
+
replace: this.replaceElement(unclosedTags)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "processHtml",
|
|
119
|
+
value: function processHtml(htmlString) {
|
|
120
|
+
var unclosedTags = this.detectUnclosedTags(htmlString);
|
|
121
|
+
// Use DOMPurify to clean HTML while preserving custom components and target attributes
|
|
122
|
+
// const purifyConfig = this.configureDOMPurify();
|
|
123
|
+
// const cleanHtml = DOMPurify.sanitize(htmlString, purifyConfig);
|
|
124
|
+
|
|
125
|
+
return parseHtml(htmlString, {
|
|
126
|
+
replace: this.replaceElement(unclosedTags)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}, {
|
|
130
|
+
key: "render",
|
|
131
|
+
value: function render(html) {
|
|
132
|
+
return this.processHtml(html);
|
|
133
|
+
}
|
|
134
|
+
}]);
|
|
135
|
+
return Renderer;
|
|
136
|
+
}();
|
|
137
|
+
export default Renderer;
|
|
@@ -6,10 +6,10 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
6
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
7
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
8
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
-
import React, { useState } from 'react';
|
|
9
|
+
import React, { useMemo, useState } from 'react';
|
|
10
10
|
import { CodeBlock as Code, CodeBlockLangExtensionsMap } from "@agentscope-ai/design";
|
|
11
11
|
import { createStyles } from 'antd-style';
|
|
12
|
-
import { useProviderContext, Mermaid } from "
|
|
12
|
+
import { useProviderContext, Mermaid } from "../../..";
|
|
13
13
|
import { theme as AntdTheme } from 'antd';
|
|
14
14
|
import { SparkCopyLine, SparkTrueLine } from '@agentscope-ai/icons';
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -51,11 +51,14 @@ var CodeBlock = function CodeBlock(_ref) {
|
|
|
51
51
|
copied = _useState2[0],
|
|
52
52
|
setCopied = _useState2[1];
|
|
53
53
|
var _code$content = code.content,
|
|
54
|
-
|
|
54
|
+
_content = _code$content === void 0 ? '' : _code$content,
|
|
55
55
|
_code$lang = code.lang,
|
|
56
56
|
lang = _code$lang === void 0 ? '' : _code$lang;
|
|
57
|
+
var content = useMemo(function () {
|
|
58
|
+
return _content.replace(/ :(dot|underline):/g, '');
|
|
59
|
+
}, [_content]);
|
|
57
60
|
if (!content) return null;
|
|
58
|
-
if (
|
|
61
|
+
if (lang === 'mermaid') {
|
|
59
62
|
return /*#__PURE__*/_jsx(Mermaid, {
|
|
60
63
|
content: content,
|
|
61
64
|
width: "50%"
|