@lobehub/ui 1.168.17 → 1.168.19
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/Highlighter/SyntaxHighlighter/index.js +10 -9
- package/es/Highlighter/style.d.ts +1 -1
- package/es/Hotkey/index.d.ts +1 -0
- package/es/Hotkey/index.js +15 -7
- package/es/Hotkey/style.js +1 -1
- package/es/Hotkey/type.d.ts +1 -0
- package/es/Hotkey/type.js +1 -0
- package/es/Markdown/Typography.d.ts +5 -5
- package/es/Markdown/Typography.js +4 -3
- package/es/Markdown/index.d.ts +1 -1
- package/es/Markdown/index.js +166 -90
- package/es/Markdown/markdown.style.d.ts +1 -18
- package/es/Markdown/markdown.style.js +19 -19
- package/es/Markdown/style.d.ts +1 -6
- package/es/Markdown/style.js +4 -12
- package/es/Mermaid/{Controls.js → components/Controls.js} +1 -1
- package/es/Mermaid/components/MermaidContainer.d.ts +5 -0
- package/es/Mermaid/components/MermaidContainer.js +43 -0
- package/es/Mermaid/components/MermaidZoomableContainer.d.ts +5 -0
- package/es/Mermaid/components/MermaidZoomableContainer.js +21 -0
- package/es/Mermaid/components/style.d.ts +3 -0
- package/es/Mermaid/components/style.js +12 -0
- package/es/Mermaid/index.js +9 -7
- package/es/Mermaid/style.d.ts +1 -1
- package/es/Swatches/index.d.ts +2 -1
- package/es/Swatches/index.js +34 -22
- package/es/Swatches/style.js +2 -2
- package/es/chat/MessageInput/index.js +37 -20
- package/es/components.d.ts +1 -1
- package/es/components.js +1 -1
- package/es/hooks/useHighlight.d.ts +8 -1
- package/es/hooks/useHighlight.js +121 -41
- package/es/hooks/useMermaid.d.ts +9 -0
- package/es/{Mermaid → hooks}/useMermaid.js +137 -73
- package/es/mdx/Mdx/index.js +1 -1
- package/es/utils/genCdnUrl.d.ts +3 -0
- package/es/utils/genCdnUrl.js +3 -1
- package/package.json +6 -6
- package/es/Mermaid/useMermaid.d.ts +0 -3
- /package/es/Mermaid/{Controls.d.ts → components/Controls.d.ts} +0 -0
|
@@ -21,16 +21,17 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
21
21
|
var _useHighlight = useHighlight(children, language, enableTransformer),
|
|
22
22
|
data = _useHighlight.data,
|
|
23
23
|
isLoading = _useHighlight.isLoading;
|
|
24
|
-
return /*#__PURE__*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
children: /*#__PURE__*/_jsx("
|
|
29
|
-
children:
|
|
30
|
-
children: children
|
|
31
|
-
})
|
|
24
|
+
if (!data) return /*#__PURE__*/_jsx("div", {
|
|
25
|
+
className: cx(styles.unshiki, className),
|
|
26
|
+
style: style,
|
|
27
|
+
children: /*#__PURE__*/_jsx("pre", {
|
|
28
|
+
children: /*#__PURE__*/_jsx("code", {
|
|
29
|
+
children: children
|
|
32
30
|
})
|
|
33
|
-
})
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
34
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
34
35
|
className: cx(styles.shiki, className),
|
|
35
36
|
dangerouslySetInnerHTML: {
|
|
36
37
|
__html: data
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const useStyles: (props?: "block" | "
|
|
1
|
+
export declare const useStyles: (props?: "block" | "pure" | "ghost" | undefined) => import("antd-style").ReturnStyles<{
|
|
2
2
|
button: string;
|
|
3
3
|
container: string;
|
|
4
4
|
header: import("antd-style").SerializedStyles;
|
package/es/Hotkey/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface HotkeyProps extends Omit<FlexboxProps, 'children'> {
|
|
|
13
13
|
descStyle?: CSSProperties;
|
|
14
14
|
kbdStyle?: CSSProperties;
|
|
15
15
|
};
|
|
16
|
+
variant?: 'default' | 'pure';
|
|
16
17
|
}
|
|
17
18
|
declare const Hotkey: import("react").NamedExoticComponent<HotkeyProps>;
|
|
18
19
|
export default Hotkey;
|
package/es/Hotkey/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
var _excluded = ["classNames", "styles", "keys", "inverseTheme", "isApple", "compact", "className", "style"];
|
|
3
|
+
var _excluded = ["variant", "classNames", "styles", "keys", "inverseTheme", "isApple", "compact", "className", "style"];
|
|
4
4
|
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); }
|
|
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; }
|
|
@@ -94,7 +94,9 @@ var mappingKey = function mappingKey(isAppleDevice) {
|
|
|
94
94
|
})), KeyMapEnum.Comma, ','), KeyMapEnum.Period, '.'), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref, KeyMapEnum.Slash, '/'), KeyMapEnum.Semicolon, ';'), KeyMapEnum.Quote, "'"), KeyMapEnum.Backquote, '`'), KeyMapEnum.Backslash, '\\'), KeyMapEnum.BracketLeft, '['), KeyMapEnum.BracketRight, ']'), KeyMapEnum.Minus, '-'), KeyMapEnum.Equal, '=');
|
|
95
95
|
};
|
|
96
96
|
var Hotkey = /*#__PURE__*/memo(function (_ref2) {
|
|
97
|
-
var
|
|
97
|
+
var _ref2$variant = _ref2.variant,
|
|
98
|
+
variant = _ref2$variant === void 0 ? 'default' : _ref2$variant,
|
|
99
|
+
classNames = _ref2.classNames,
|
|
98
100
|
styles = _ref2.styles,
|
|
99
101
|
keys = _ref2.keys,
|
|
100
102
|
inverseTheme = _ref2.inverseTheme,
|
|
@@ -106,6 +108,7 @@ var Hotkey = /*#__PURE__*/memo(function (_ref2) {
|
|
|
106
108
|
var _useStyles = useStyles(inverseTheme),
|
|
107
109
|
cx = _useStyles.cx,
|
|
108
110
|
s = _useStyles.styles;
|
|
111
|
+
var isPure = variant === 'pure';
|
|
109
112
|
var _useState = useState(splitKeysByPlus(keys)),
|
|
110
113
|
_useState2 = _slicedToArray(_useState, 2),
|
|
111
114
|
keysGroup = _useState2[0],
|
|
@@ -130,7 +133,12 @@ var Hotkey = /*#__PURE__*/memo(function (_ref2) {
|
|
|
130
133
|
visibility: visibility
|
|
131
134
|
}, style)
|
|
132
135
|
}, rest), {}, {
|
|
133
|
-
children:
|
|
136
|
+
children: isPure ? keysGroup.map(function (key, index) {
|
|
137
|
+
var _mapping$key;
|
|
138
|
+
return /*#__PURE__*/_jsx("span", {
|
|
139
|
+
children: (_mapping$key = mapping[key]) !== null && _mapping$key !== void 0 ? _mapping$key : startCase(key)
|
|
140
|
+
}, index);
|
|
141
|
+
}) : compact ? /*#__PURE__*/_jsx(Flexbox, {
|
|
134
142
|
align: 'center',
|
|
135
143
|
as: 'kbd',
|
|
136
144
|
className: classNames === null || classNames === void 0 ? void 0 : classNames.descClassName,
|
|
@@ -138,17 +146,17 @@ var Hotkey = /*#__PURE__*/memo(function (_ref2) {
|
|
|
138
146
|
horizontal: true,
|
|
139
147
|
style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
|
|
140
148
|
children: keysGroup.map(function (key, index) {
|
|
141
|
-
var _mapping$
|
|
149
|
+
var _mapping$key2;
|
|
142
150
|
return /*#__PURE__*/_jsx("div", {
|
|
143
|
-
children: (_mapping$
|
|
151
|
+
children: (_mapping$key2 = mapping[key]) !== null && _mapping$key2 !== void 0 ? _mapping$key2 : startCase(key)
|
|
144
152
|
}, index);
|
|
145
153
|
})
|
|
146
154
|
}) : keysGroup.map(function (key, index) {
|
|
147
|
-
var _mapping$
|
|
155
|
+
var _mapping$key3;
|
|
148
156
|
return /*#__PURE__*/_jsx("kbd", {
|
|
149
157
|
className: classNames === null || classNames === void 0 ? void 0 : classNames.descClassName,
|
|
150
158
|
style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
|
|
151
|
-
children: (_mapping$
|
|
159
|
+
children: (_mapping$key3 = mapping[key]) !== null && _mapping$key3 !== void 0 ? _mapping$key3 : startCase(key)
|
|
152
160
|
}, index);
|
|
153
161
|
})
|
|
154
162
|
}));
|
package/es/Hotkey/style.js
CHANGED
|
@@ -5,5 +5,5 @@ import { rgba } from 'polished';
|
|
|
5
5
|
export var useStyles = createStyles(function (_ref, inverseTheme) {
|
|
6
6
|
var css = _ref.css,
|
|
7
7
|
token = _ref.token;
|
|
8
|
-
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n kbd {\n overflow: hidden;\n display: flex;\n flex: none;\n align-items: center;\n justify-content: center;\n\n min-width: 16px;\n height: 22px;\n padding-block: 0;\n padding-inline: 8px;\n\n font-family: ", ";\n font-size: 12px;\n line-height: 1.1;\n color:
|
|
8
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n color: ", ";\n\n kbd {\n overflow: hidden;\n display: flex;\n flex: none;\n align-items: center;\n justify-content: center;\n\n min-width: 16px;\n height: 22px;\n padding-block: 0;\n padding-inline: 8px;\n\n font-family: ", ";\n font-size: 12px;\n line-height: 1.1;\n color: inherit;\n text-align: center;\n white-space: nowrap;\n\n background: ", ";\n border: none;\n border-radius: ", "px;\n }\n "])), inverseTheme ? token.colorTextTertiary : token.colorTextSecondary, token.fontFamily, inverseTheme ? rgba(token.colorTextTertiary, 0.15) : token.colorFillTertiary, token.borderRadiusSM);
|
|
9
9
|
});
|
package/es/Hotkey/type.d.ts
CHANGED
package/es/Hotkey/type.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { DivProps } from "../types";
|
|
3
|
+
export interface TypographyProps extends DivProps {
|
|
4
4
|
fontSize?: number;
|
|
5
5
|
headerMultiple?: number;
|
|
6
6
|
lineHeight?: number;
|
|
7
7
|
marginMultiple?: number;
|
|
8
|
-
style?: CSSProperties;
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
declare const Typography: FC<TypographyProps>;
|
|
10
|
+
export default Typography;
|
|
@@ -11,7 +11,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
11
11
|
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; }
|
|
12
12
|
import { useStyles } from "./markdown.style";
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
|
|
14
|
+
var Typography = function Typography(_ref) {
|
|
15
15
|
var children = _ref.children,
|
|
16
16
|
className = _ref.className,
|
|
17
17
|
fontSize = _ref.fontSize,
|
|
@@ -28,8 +28,9 @@ export var Typography = function Typography(_ref) {
|
|
|
28
28
|
cx = _useStyles.cx,
|
|
29
29
|
styles = _useStyles.styles;
|
|
30
30
|
return /*#__PURE__*/_jsx("article", _objectSpread(_objectSpread({
|
|
31
|
-
className: cx(styles
|
|
31
|
+
className: cx(styles, className)
|
|
32
32
|
}, rest), {}, {
|
|
33
33
|
children: children
|
|
34
34
|
}));
|
|
35
|
-
};
|
|
35
|
+
};
|
|
36
|
+
export default Typography;
|
package/es/Markdown/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { type PreProps } from "../mdx/mdxComponents/Pre";
|
|
|
9
9
|
import { type VideoProps } from "../mdx/mdxComponents/Video";
|
|
10
10
|
import type { AProps } from "../types";
|
|
11
11
|
import { CitationItem } from "../types/citation";
|
|
12
|
-
import type
|
|
12
|
+
import { type TypographyProps } from './Typography';
|
|
13
13
|
export interface MarkdownProps extends TypographyProps {
|
|
14
14
|
allowHtml?: boolean;
|
|
15
15
|
children: string;
|
package/es/Markdown/index.js
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
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); }
|
|
4
4
|
var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableLatex", "enableMermaid", "enableImageGallery", "enableCustomFootnotes", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "showFootnotes", "variant", "lineHeight", "rehypePlugins", "remarkPlugins", "remarkPluginsAhead", "components", "customRender", "citations"];
|
|
5
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
|
-
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."); }
|
|
7
|
-
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); }
|
|
8
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
-
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; }
|
|
11
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; }
|
|
12
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; }
|
|
13
7
|
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; }
|
|
@@ -15,7 +9,13 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
15
9
|
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); }
|
|
16
10
|
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; }
|
|
17
11
|
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; }
|
|
18
|
-
|
|
12
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
13
|
+
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."); }
|
|
14
|
+
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); }
|
|
15
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
16
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
17
|
+
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; }
|
|
18
|
+
import { memo, useCallback, useMemo } from 'react';
|
|
19
19
|
import ReactMarkdown from 'react-markdown';
|
|
20
20
|
import rehypeKatex from 'rehype-katex';
|
|
21
21
|
import rehypeRaw from 'rehype-raw';
|
|
@@ -28,12 +28,53 @@ import Link from "../mdx/mdxComponents/Link";
|
|
|
28
28
|
import Section from "../mdx/mdxComponents/Section";
|
|
29
29
|
import Video from "../mdx/mdxComponents/Video";
|
|
30
30
|
import { CodeFullFeatured, CodeLite } from "./CodeBlock";
|
|
31
|
-
import
|
|
31
|
+
import Typography from "./Typography";
|
|
32
32
|
import { rehypeFootnoteLinks, remarkCustomFootnotes } from "./plugins/footnote";
|
|
33
33
|
import { rehypeKatexDir } from "./plugins/katexDir";
|
|
34
34
|
import { useStyles } from "./style";
|
|
35
35
|
import { escapeBrackets, escapeMhchem, fixMarkdownBold, transformCitations } from "./utils";
|
|
36
|
+
|
|
37
|
+
// 使用普通 Map 代替 WeakMap,并限制缓存大小
|
|
36
38
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
39
|
+
var CACHE_SIZE = 50;
|
|
40
|
+
var contentCache = new Map();
|
|
41
|
+
|
|
42
|
+
// 添加内容到缓存时,保持缓存大小不超过限制
|
|
43
|
+
var addToCache = function addToCache(key, value) {
|
|
44
|
+
if (contentCache.size >= CACHE_SIZE) {
|
|
45
|
+
// 移除最早加入的缓存项
|
|
46
|
+
var firstKey = contentCache.keys().next().value;
|
|
47
|
+
if (firstKey) contentCache.delete(firstKey);
|
|
48
|
+
}
|
|
49
|
+
contentCache.set(key, value);
|
|
50
|
+
};
|
|
51
|
+
// 使用工厂函数处理插件,减少组件中的逻辑负担
|
|
52
|
+
var createPlugins = function createPlugins(props) {
|
|
53
|
+
var allowHtml = props.allowHtml,
|
|
54
|
+
enableLatex = props.enableLatex,
|
|
55
|
+
enableCustomFootnotes = props.enableCustomFootnotes,
|
|
56
|
+
isChatMode = props.isChatMode,
|
|
57
|
+
rehypePlugins = props.rehypePlugins,
|
|
58
|
+
remarkPlugins = props.remarkPlugins,
|
|
59
|
+
remarkPluginsAhead = props.remarkPluginsAhead;
|
|
60
|
+
|
|
61
|
+
// 预处理插件数组
|
|
62
|
+
var normalizedRehypePlugins = Array.isArray(rehypePlugins) ? rehypePlugins : rehypePlugins ? [rehypePlugins] : [];
|
|
63
|
+
var normalizedRemarkPlugins = Array.isArray(remarkPlugins) ? remarkPlugins : remarkPlugins ? [remarkPlugins] : [];
|
|
64
|
+
var normalizedRemarkPluginsAhead = Array.isArray(remarkPluginsAhead) ? remarkPluginsAhead : remarkPluginsAhead ? [remarkPluginsAhead] : [];
|
|
65
|
+
|
|
66
|
+
// 创建 rehype 插件列表
|
|
67
|
+
var rehypePluginsList = [allowHtml && rehypeRaw, enableLatex && rehypeKatex, enableLatex && rehypeKatexDir, enableCustomFootnotes && rehypeFootnoteLinks].concat(_toConsumableArray(normalizedRehypePlugins)).filter(Boolean);
|
|
68
|
+
|
|
69
|
+
// 创建 remark 插件列表
|
|
70
|
+
var remarkPluginsList = [].concat(_toConsumableArray(normalizedRemarkPluginsAhead), [[remarkGfm, {
|
|
71
|
+
singleTilde: false
|
|
72
|
+
}], enableCustomFootnotes && remarkCustomFootnotes, enableLatex && remarkMath, isChatMode && remarkBreaks], _toConsumableArray(normalizedRemarkPlugins)).filter(Boolean);
|
|
73
|
+
return {
|
|
74
|
+
rehypePluginsList: rehypePluginsList,
|
|
75
|
+
remarkPluginsList: remarkPluginsList
|
|
76
|
+
};
|
|
77
|
+
};
|
|
37
78
|
var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
38
79
|
var children = _ref.children,
|
|
39
80
|
className = _ref.className,
|
|
@@ -49,13 +90,17 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
49
90
|
enableCustomFootnotes = _ref.enableCustomFootnotes,
|
|
50
91
|
componentProps = _ref.componentProps,
|
|
51
92
|
allowHtml = _ref.allowHtml,
|
|
52
|
-
fontSize = _ref.fontSize,
|
|
53
|
-
|
|
54
|
-
|
|
93
|
+
_ref$fontSize = _ref.fontSize,
|
|
94
|
+
fontSize = _ref$fontSize === void 0 ? 14 : _ref$fontSize,
|
|
95
|
+
_ref$headerMultiple = _ref.headerMultiple,
|
|
96
|
+
headerMultiple = _ref$headerMultiple === void 0 ? 0.25 : _ref$headerMultiple,
|
|
97
|
+
_ref$marginMultiple = _ref.marginMultiple,
|
|
98
|
+
marginMultiple = _ref$marginMultiple === void 0 ? 1 : _ref$marginMultiple,
|
|
55
99
|
showFootnotes = _ref.showFootnotes,
|
|
56
100
|
_ref$variant = _ref.variant,
|
|
57
101
|
variant = _ref$variant === void 0 ? 'normal' : _ref$variant,
|
|
58
|
-
lineHeight = _ref.lineHeight,
|
|
102
|
+
_ref$lineHeight = _ref.lineHeight,
|
|
103
|
+
lineHeight = _ref$lineHeight === void 0 ? 1.6 : _ref$lineHeight,
|
|
59
104
|
rehypePlugins = _ref.rehypePlugins,
|
|
60
105
|
remarkPlugins = _ref.remarkPlugins,
|
|
61
106
|
remarkPluginsAhead = _ref.remarkPluginsAhead,
|
|
@@ -64,95 +109,126 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
64
109
|
customRender = _ref.customRender,
|
|
65
110
|
citations = _ref.citations,
|
|
66
111
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
67
|
-
var _useStyles = useStyles(
|
|
68
|
-
fontSize: fontSize,
|
|
69
|
-
headerMultiple: headerMultiple,
|
|
70
|
-
lineHeight: lineHeight,
|
|
71
|
-
marginMultiple: marginMultiple
|
|
72
|
-
}),
|
|
112
|
+
var _useStyles = useStyles(),
|
|
73
113
|
cx = _useStyles.cx,
|
|
74
114
|
styles = _useStyles.styles;
|
|
75
|
-
var _useMarkdownStyles = useMarkdownStyles({
|
|
76
|
-
fontSize: fontSize,
|
|
77
|
-
headerMultiple: headerMultiple,
|
|
78
|
-
marginMultiple: marginMultiple
|
|
79
|
-
}),
|
|
80
|
-
mdStyles = _useMarkdownStyles.styles;
|
|
81
115
|
var isChatMode = variant === 'chat';
|
|
116
|
+
|
|
117
|
+
// 计算缓存键
|
|
118
|
+
var cacheKey = useMemo(function () {
|
|
119
|
+
return "".concat(children, "-").concat(enableLatex, "-").concat(enableCustomFootnotes, "-").concat((citations === null || citations === void 0 ? void 0 : citations.length) || 0);
|
|
120
|
+
}, [children, enableLatex, enableCustomFootnotes, citations === null || citations === void 0 ? void 0 : citations.length]);
|
|
121
|
+
|
|
122
|
+
// 处理内容并利用缓存避免重复计算
|
|
82
123
|
var escapedContent = useMemo(function () {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
124
|
+
// 尝试从缓存获取
|
|
125
|
+
if (contentCache.has(cacheKey)) {
|
|
126
|
+
return contentCache.get(cacheKey);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 处理新内容
|
|
130
|
+
var processedContent;
|
|
131
|
+
if (enableLatex) {
|
|
132
|
+
var baseContent = fixMarkdownBold(escapeMhchem(escapeBrackets(children)));
|
|
133
|
+
processedContent = enableCustomFootnotes ? transformCitations(baseContent, citations === null || citations === void 0 ? void 0 : citations.length) : baseContent;
|
|
134
|
+
} else {
|
|
135
|
+
processedContent = fixMarkdownBold(children);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 缓存处理结果
|
|
139
|
+
addToCache(cacheKey, processedContent);
|
|
140
|
+
return processedContent;
|
|
141
|
+
}, [cacheKey, children, enableLatex, enableCustomFootnotes, citations === null || citations === void 0 ? void 0 : citations.length]);
|
|
142
|
+
|
|
143
|
+
// 创建插件
|
|
144
|
+
var _useMemo = useMemo(function () {
|
|
145
|
+
return createPlugins({
|
|
146
|
+
allowHtml: allowHtml,
|
|
147
|
+
enableCustomFootnotes: enableCustomFootnotes,
|
|
148
|
+
enableLatex: enableLatex,
|
|
149
|
+
isChatMode: isChatMode,
|
|
150
|
+
rehypePlugins: rehypePlugins,
|
|
151
|
+
remarkPlugins: remarkPlugins,
|
|
152
|
+
remarkPluginsAhead: remarkPluginsAhead
|
|
153
|
+
});
|
|
154
|
+
}, [allowHtml, enableLatex, enableCustomFootnotes, isChatMode, rehypePlugins, remarkPlugins, remarkPluginsAhead]),
|
|
155
|
+
rehypePluginsList = _useMemo.rehypePluginsList,
|
|
156
|
+
remarkPluginsList = _useMemo.remarkPluginsList;
|
|
157
|
+
|
|
158
|
+
// 使用 useCallback 优化渲染子组件
|
|
159
|
+
var renderLink = useCallback(function (props) {
|
|
160
|
+
return /*#__PURE__*/_jsx(Link, _objectSpread(_objectSpread({
|
|
161
|
+
citations: citations
|
|
162
|
+
}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.a));
|
|
163
|
+
}, [citations, componentProps === null || componentProps === void 0 ? void 0 : componentProps.a]);
|
|
164
|
+
var renderImage = useCallback(function (props) {
|
|
165
|
+
var _componentProps$img, _componentProps$img2;
|
|
166
|
+
return /*#__PURE__*/_jsx(Image, _objectSpread(_objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.img), {}, {
|
|
167
|
+
style: isChatMode ? _objectSpread({
|
|
168
|
+
height: 'auto',
|
|
169
|
+
maxWidth: 640
|
|
170
|
+
}, componentProps === null || componentProps === void 0 || (_componentProps$img = componentProps.img) === null || _componentProps$img === void 0 ? void 0 : _componentProps$img.style) : componentProps === null || componentProps === void 0 || (_componentProps$img2 = componentProps.img) === null || _componentProps$img2 === void 0 ? void 0 : _componentProps$img2.style
|
|
171
|
+
}));
|
|
172
|
+
}, [isChatMode, componentProps === null || componentProps === void 0 ? void 0 : componentProps.img]);
|
|
173
|
+
var renderCodeBlock = useCallback(function (props) {
|
|
174
|
+
return fullFeaturedCodeBlock ? /*#__PURE__*/_jsx(CodeFullFeatured, _objectSpread(_objectSpread({
|
|
175
|
+
enableMermaid: enableMermaid,
|
|
176
|
+
highlight: componentProps === null || componentProps === void 0 ? void 0 : componentProps.highlight,
|
|
177
|
+
mermaid: componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid
|
|
178
|
+
}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre)) : /*#__PURE__*/_jsx(CodeLite, _objectSpread(_objectSpread({
|
|
179
|
+
enableMermaid: enableMermaid,
|
|
180
|
+
highlight: componentProps === null || componentProps === void 0 ? void 0 : componentProps.highlight,
|
|
181
|
+
mermaid: componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid
|
|
182
|
+
}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre));
|
|
183
|
+
}, [enableMermaid, fullFeaturedCodeBlock, componentProps === null || componentProps === void 0 ? void 0 : componentProps.highlight, componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid, componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre]);
|
|
184
|
+
var renderSection = useCallback(function (props) {
|
|
185
|
+
return /*#__PURE__*/_jsx(Section, _objectSpread({
|
|
186
|
+
showCitations: showFootnotes
|
|
187
|
+
}, props));
|
|
188
|
+
}, [showFootnotes]);
|
|
189
|
+
var renderVideo = useCallback(function (props) {
|
|
190
|
+
return /*#__PURE__*/_jsx(Video, _objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.video));
|
|
191
|
+
}, [componentProps === null || componentProps === void 0 ? void 0 : componentProps.video]);
|
|
192
|
+
|
|
193
|
+
// 创建组件映射
|
|
88
194
|
var memoComponents = useMemo(function () {
|
|
89
195
|
return _objectSpread({
|
|
90
|
-
a:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
img: enableImageGallery ? function (props) {
|
|
96
|
-
var _componentProps$img, _componentProps$img2;
|
|
97
|
-
return /*#__PURE__*/_jsx(Image, _objectSpread(_objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.img), {}, {
|
|
98
|
-
style: isChatMode ? _objectSpread({
|
|
99
|
-
height: 'auto',
|
|
100
|
-
maxWidth: 640
|
|
101
|
-
}, componentProps === null || componentProps === void 0 || (_componentProps$img = componentProps.img) === null || _componentProps$img === void 0 ? void 0 : _componentProps$img.style) : componentProps === null || componentProps === void 0 || (_componentProps$img2 = componentProps.img) === null || _componentProps$img2 === void 0 ? void 0 : _componentProps$img2.style
|
|
102
|
-
}));
|
|
103
|
-
} : undefined,
|
|
104
|
-
pre: function pre(props) {
|
|
105
|
-
return fullFeaturedCodeBlock ? /*#__PURE__*/_jsx(CodeFullFeatured, _objectSpread(_objectSpread({
|
|
106
|
-
enableMermaid: enableMermaid,
|
|
107
|
-
highlight: componentProps === null || componentProps === void 0 ? void 0 : componentProps.highlight,
|
|
108
|
-
mermaid: componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid
|
|
109
|
-
}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre)) : /*#__PURE__*/_jsx(CodeLite, _objectSpread(_objectSpread({
|
|
110
|
-
enableMermaid: enableMermaid,
|
|
111
|
-
highlight: componentProps === null || componentProps === void 0 ? void 0 : componentProps.highlight,
|
|
112
|
-
mermaid: componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid
|
|
113
|
-
}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre));
|
|
114
|
-
},
|
|
115
|
-
section: function section(props) {
|
|
116
|
-
return /*#__PURE__*/_jsx(Section, _objectSpread({
|
|
117
|
-
showCitations: showFootnotes
|
|
118
|
-
}, props));
|
|
119
|
-
},
|
|
120
|
-
video: function video(props) {
|
|
121
|
-
return /*#__PURE__*/_jsx(Video, _objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.video));
|
|
122
|
-
}
|
|
196
|
+
a: renderLink,
|
|
197
|
+
img: enableImageGallery ? renderImage : undefined,
|
|
198
|
+
pre: renderCodeBlock,
|
|
199
|
+
section: renderSection,
|
|
200
|
+
video: renderVideo
|
|
123
201
|
}, components);
|
|
124
|
-
}, [
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
components: memoComponents,
|
|
141
|
-
rehypePlugins: memoRehypePlugins,
|
|
142
|
-
remarkPlugins: memoRemarkPlugins
|
|
143
|
-
}, rest), {}, {
|
|
144
|
-
children: escapedContent
|
|
145
|
-
}))
|
|
146
|
-
});
|
|
202
|
+
}, [renderLink, renderImage, renderCodeBlock, renderSection, renderVideo, enableImageGallery, components]);
|
|
203
|
+
|
|
204
|
+
// 渲染默认内容
|
|
205
|
+
var defaultDOM = useMemo(function () {
|
|
206
|
+
return /*#__PURE__*/_jsx(ImageGallery, {
|
|
207
|
+
enable: enableImageGallery,
|
|
208
|
+
children: /*#__PURE__*/_jsx(ReactMarkdown, {
|
|
209
|
+
components: memoComponents,
|
|
210
|
+
rehypePlugins: rehypePluginsList,
|
|
211
|
+
remarkPlugins: remarkPluginsList,
|
|
212
|
+
children: escapedContent
|
|
213
|
+
})
|
|
214
|
+
});
|
|
215
|
+
}, [escapedContent, memoComponents, rehypePluginsList, remarkPluginsList, enableImageGallery]);
|
|
216
|
+
|
|
217
|
+
// 应用自定义渲染
|
|
147
218
|
var markdownContent = customRender ? customRender(defaultDOM, {
|
|
148
|
-
text: escapedContent
|
|
219
|
+
text: escapedContent || ''
|
|
149
220
|
}) : defaultDOM;
|
|
150
|
-
return /*#__PURE__*/_jsx(
|
|
151
|
-
className: cx(styles.root, className),
|
|
221
|
+
return /*#__PURE__*/_jsx(Typography, _objectSpread(_objectSpread({
|
|
222
|
+
className: cx(styles.root, enableLatex && styles.latex, isChatMode && styles.chat, className),
|
|
152
223
|
"data-code-type": "markdown",
|
|
224
|
+
fontSize: fontSize,
|
|
225
|
+
headerMultiple: headerMultiple,
|
|
226
|
+
lineHeight: lineHeight,
|
|
227
|
+
marginMultiple: marginMultiple,
|
|
153
228
|
onDoubleClick: onDoubleClick,
|
|
154
|
-
style: style
|
|
229
|
+
style: style
|
|
230
|
+
}, rest), {}, {
|
|
155
231
|
children: markdownContent
|
|
156
|
-
});
|
|
232
|
+
}));
|
|
157
233
|
});
|
|
158
234
|
export default Markdown;
|
|
@@ -3,21 +3,4 @@ export declare const useStyles: (props?: {
|
|
|
3
3
|
headerMultiple?: number | undefined;
|
|
4
4
|
lineHeight?: number | undefined;
|
|
5
5
|
marginMultiple?: number | undefined;
|
|
6
|
-
} | undefined) => import("antd-style").ReturnStyles<
|
|
7
|
-
__root: import("antd-style").SerializedStyles;
|
|
8
|
-
a: import("antd-style").SerializedStyles;
|
|
9
|
-
blockquote: import("antd-style").SerializedStyles;
|
|
10
|
-
code: import("antd-style").SerializedStyles;
|
|
11
|
-
details: import("antd-style").SerializedStyles;
|
|
12
|
-
header: import("antd-style").SerializedStyles;
|
|
13
|
-
hr: import("antd-style").SerializedStyles;
|
|
14
|
-
img: import("antd-style").SerializedStyles;
|
|
15
|
-
kbd: import("antd-style").SerializedStyles;
|
|
16
|
-
list: import("antd-style").SerializedStyles;
|
|
17
|
-
p: import("antd-style").SerializedStyles;
|
|
18
|
-
pre: import("antd-style").SerializedStyles;
|
|
19
|
-
strong: import("antd-style").SerializedStyles;
|
|
20
|
-
svg: import("antd-style").SerializedStyles;
|
|
21
|
-
table: import("antd-style").SerializedStyles;
|
|
22
|
-
video: import("antd-style").SerializedStyles;
|
|
23
|
-
}>;
|
|
6
|
+
} | undefined) => import("antd-style").ReturnStyles<string>;
|