@lobehub/ui 1.147.1 → 1.148.1
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/ChatItem/components/MessageContent.d.ts +2 -0
- package/es/ChatItem/components/MessageContent.js +3 -1
- package/es/ChatItem/index.js +3 -1
- package/es/ChatItem/type.d.ts +2 -0
- package/es/EditableMessage/index.d.ts +2 -0
- package/es/EditableMessage/index.js +6 -4
- package/es/Highlighter/FullFeatured.d.ts +4 -17
- package/es/Highlighter/FullFeatured.js +49 -25
- package/es/Highlighter/index.d.ts +3 -39
- package/es/Highlighter/index.js +40 -25
- package/es/Highlighter/style.js +2 -2
- package/es/Highlighter/type.d.ts +51 -0
- package/es/Highlighter/type.js +1 -0
- package/es/Markdown/CodeBlock.d.ts +17 -3
- package/es/Markdown/CodeBlock.js +14 -6
- package/es/Markdown/index.d.ts +6 -1
- package/es/Markdown/index.js +13 -3
- package/es/Markdown/markdown.style.js +1 -1
- package/es/Mermaid/FullFeatured.d.ts +7 -0
- package/es/Mermaid/FullFeatured.js +90 -0
- package/es/Mermaid/index.d.ts +5 -0
- package/es/Mermaid/index.js +81 -0
- package/es/Mermaid/style.d.ts +8 -0
- package/es/Mermaid/style.js +22 -0
- package/es/Mermaid/type.d.ts +21 -0
- package/es/Mermaid/type.js +1 -0
- package/es/Mermaid/useMermaid.d.ts +1 -0
- package/es/Mermaid/useMermaid.js +38 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/mdx/Pre.d.ts +2 -0
- package/es/mdx/Pre.js +25 -1
- package/package.json +2 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { ChatItemProps } from "..";
|
|
3
|
+
import type { MarkdownProps } from "../../Markdown";
|
|
3
4
|
export interface MessageContentProps {
|
|
4
5
|
editing?: ChatItemProps['editing'];
|
|
5
6
|
fontSize?: number;
|
|
7
|
+
markdownProps?: Omit<MarkdownProps, 'className' | 'style' | 'children'>;
|
|
6
8
|
message?: ReactNode;
|
|
7
9
|
messageExtra?: ChatItemProps['messageExtra'];
|
|
8
10
|
onChange?: ChatItemProps['onChange'];
|
|
@@ -17,7 +17,8 @@ var MessageContent = /*#__PURE__*/memo(function (_ref) {
|
|
|
17
17
|
type = _ref.type,
|
|
18
18
|
primary = _ref.primary,
|
|
19
19
|
onDoubleClick = _ref.onDoubleClick,
|
|
20
|
-
fontSize = _ref.fontSize
|
|
20
|
+
fontSize = _ref.fontSize,
|
|
21
|
+
markdownProps = _ref.markdownProps;
|
|
21
22
|
var _useStyles = useStyles({
|
|
22
23
|
editing: editing,
|
|
23
24
|
placement: placement,
|
|
@@ -36,6 +37,7 @@ var MessageContent = /*#__PURE__*/memo(function (_ref) {
|
|
|
36
37
|
editing: editing,
|
|
37
38
|
fontSize: fontSize,
|
|
38
39
|
fullFeaturedCodeBlock: true,
|
|
40
|
+
markdownProps: markdownProps,
|
|
39
41
|
onChange: onChange,
|
|
40
42
|
onEditingChange: onEditingChange,
|
|
41
43
|
openModal: mobile ? editing : undefined,
|
package/es/ChatItem/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["avatarAddon", "onAvatarClick", "avatarProps", "actions", "className", "primary", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "renderMessage", "text", "errorMessage", "onDoubleClick", "fontSize", "aboveMessage", "belowMessage"];
|
|
5
|
+
var _excluded = ["avatarAddon", "onAvatarClick", "avatarProps", "actions", "className", "primary", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "renderMessage", "text", "errorMessage", "onDoubleClick", "fontSize", "aboveMessage", "belowMessage", "markdownProps"];
|
|
6
6
|
import { useResponsive } from 'antd-style';
|
|
7
7
|
import { memo } from 'react';
|
|
8
8
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -44,6 +44,7 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
44
44
|
fontSize = _ref.fontSize,
|
|
45
45
|
aboveMessage = _ref.aboveMessage,
|
|
46
46
|
belowMessage = _ref.belowMessage,
|
|
47
|
+
markdownProps = _ref.markdownProps,
|
|
47
48
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
48
49
|
var _useResponsive = useResponsive(),
|
|
49
50
|
mobile = _useResponsive.mobile;
|
|
@@ -90,6 +91,7 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
90
91
|
}) : /*#__PURE__*/_jsx(MessageContent, {
|
|
91
92
|
editing: editing,
|
|
92
93
|
fontSize: fontSize,
|
|
94
|
+
markdownProps: markdownProps,
|
|
93
95
|
message: message,
|
|
94
96
|
messageExtra: messageExtra,
|
|
95
97
|
onChange: onChange,
|
package/es/ChatItem/type.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { FlexboxProps } from 'react-layout-kit';
|
|
|
3
3
|
import { AlertProps } from "../Alert";
|
|
4
4
|
import { AvatarProps } from "../Avatar";
|
|
5
5
|
import { EditableMessageProps } from "../EditableMessage";
|
|
6
|
+
import type { MarkdownProps } from "../Markdown";
|
|
6
7
|
import { DivProps, MetaData } from "../types";
|
|
7
8
|
export interface ChatItemProps extends Omit<FlexboxProps, 'children' | 'onChange'> {
|
|
8
9
|
aboveMessage?: ReactNode;
|
|
@@ -31,6 +32,7 @@ export interface ChatItemProps extends Omit<FlexboxProps, 'children' | 'onChange
|
|
|
31
32
|
* @description Whether the chat item is in loading state
|
|
32
33
|
*/
|
|
33
34
|
loading?: boolean;
|
|
35
|
+
markdownProps?: Omit<MarkdownProps, 'className' | 'style' | 'children'>;
|
|
34
36
|
/**
|
|
35
37
|
* @description The message content of the chat item
|
|
36
38
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
|
+
import { type MarkdownProps } from "../Markdown";
|
|
2
3
|
import { type MessageInputProps } from "../MessageInput";
|
|
3
4
|
import { type MessageModalProps } from "../MessageModal";
|
|
4
5
|
export interface EditableMessageProps {
|
|
@@ -26,6 +27,7 @@ export interface EditableMessageProps {
|
|
|
26
27
|
fullFeaturedCodeBlock?: boolean;
|
|
27
28
|
height?: MessageInputProps['height'];
|
|
28
29
|
inputType?: MessageInputProps['type'];
|
|
30
|
+
markdownProps?: Omit<MarkdownProps, 'className' | 'style' | 'children'>;
|
|
29
31
|
model?: {
|
|
30
32
|
extra?: MessageModalProps['extra'];
|
|
31
33
|
footer?: MessageModalProps['footer'];
|
|
@@ -29,7 +29,8 @@ var EditableMessage = /*#__PURE__*/memo(function (_ref) {
|
|
|
29
29
|
text = _ref.text,
|
|
30
30
|
fullFeaturedCodeBlock = _ref.fullFeaturedCodeBlock,
|
|
31
31
|
model = _ref.model,
|
|
32
|
-
fontSize = _ref.fontSize
|
|
32
|
+
fontSize = _ref.fontSize,
|
|
33
|
+
markdownProps = _ref.markdownProps;
|
|
33
34
|
var _useControlledState = useControlledState(false, {
|
|
34
35
|
onChange: onEditingChange,
|
|
35
36
|
value: editing
|
|
@@ -68,16 +69,17 @@ var EditableMessage = /*#__PURE__*/memo(function (_ref) {
|
|
|
68
69
|
});
|
|
69
70
|
if (!value && showEditWhenEmpty) return input;
|
|
70
71
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
71
|
-
children: [!expand && isEdit ? input : /*#__PURE__*/_jsx(Markdown, {
|
|
72
|
+
children: [!expand && isEdit ? input : /*#__PURE__*/_jsx(Markdown, _objectSpread(_objectSpread({
|
|
72
73
|
className: classNames === null || classNames === void 0 ? void 0 : classNames.markdown,
|
|
73
74
|
fontSize: fontSize,
|
|
74
75
|
fullFeaturedCodeBlock: fullFeaturedCodeBlock,
|
|
75
76
|
style: _objectSpread({
|
|
76
77
|
height: isAutoSize ? 'unset' : height
|
|
77
78
|
}, stylesProps === null || stylesProps === void 0 ? void 0 : stylesProps.markdown),
|
|
78
|
-
variant: 'chat'
|
|
79
|
+
variant: 'chat'
|
|
80
|
+
}, markdownProps), {}, {
|
|
79
81
|
children: value || placeholder || ''
|
|
80
|
-
}), expand && /*#__PURE__*/_jsx(MessageModal, {
|
|
82
|
+
})), expand && /*#__PURE__*/_jsx(MessageModal, {
|
|
81
83
|
editing: isEdit,
|
|
82
84
|
extra: model === null || model === void 0 ? void 0 : model.extra,
|
|
83
85
|
footer: model === null || model === void 0 ? void 0 : model.footer,
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description The code content to be highlighted
|
|
7
|
-
*/
|
|
8
|
-
children: string;
|
|
9
|
-
fileName?: string;
|
|
10
|
-
icon?: ReactNode;
|
|
11
|
-
/**
|
|
12
|
-
* @description The language of the code content
|
|
13
|
-
*/
|
|
14
|
-
language: string;
|
|
15
|
-
}
|
|
16
|
-
export declare const Highlighter: import("react").NamedExoticComponent<HighlighterProps>;
|
|
17
|
-
export default Highlighter;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { HighlighterProps } from './type';
|
|
3
|
+
export declare const HighlighterFullFeatured: import("react").NamedExoticComponent<HighlighterProps>;
|
|
4
|
+
export default HighlighterFullFeatured;
|
|
18
5
|
export { default as SyntaxHighlighter, type SyntaxHighlighterProps } from './SyntaxHighlighter';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["children", "language", "className", "style", "allowChangeLanguage", "fileName", "icon"];
|
|
4
|
+
var _excluded = ["children", "language", "showLanguage", "className", "style", "allowChangeLanguage", "fileName", "icon", "bodyRender", "actionsRender", "copyable", "type"];
|
|
5
5
|
import { Select } from 'antd';
|
|
6
6
|
import { ChevronDown, ChevronRight } from 'lucide-react';
|
|
7
7
|
import { memo, useState } from 'react';
|
|
@@ -19,16 +19,20 @@ var options = languageMap.map(function (item) {
|
|
|
19
19
|
value: item.toLowerCase()
|
|
20
20
|
};
|
|
21
21
|
});
|
|
22
|
-
export var
|
|
22
|
+
export var HighlighterFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
23
23
|
var children = _ref.children,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
language = _ref.language,
|
|
25
|
+
showLanguage = _ref.showLanguage,
|
|
26
26
|
className = _ref.className,
|
|
27
27
|
style = _ref.style,
|
|
28
28
|
_ref$allowChangeLangu = _ref.allowChangeLanguage,
|
|
29
29
|
allowChangeLanguage = _ref$allowChangeLangu === void 0 ? true : _ref$allowChangeLangu,
|
|
30
30
|
fileName = _ref.fileName,
|
|
31
31
|
icon = _ref.icon,
|
|
32
|
+
bodyRender = _ref.bodyRender,
|
|
33
|
+
actionsRender = _ref.actionsRender,
|
|
34
|
+
copyable = _ref.copyable,
|
|
35
|
+
type = _ref.type,
|
|
32
36
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
33
37
|
var _useState = useState(true),
|
|
34
38
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -38,12 +42,40 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
38
42
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
39
43
|
lang = _useState4[0],
|
|
40
44
|
setLang = _useState4[1];
|
|
41
|
-
var _useStyles = useStyles(
|
|
45
|
+
var _useStyles = useStyles(type),
|
|
42
46
|
styles = _useStyles.styles,
|
|
43
47
|
cx = _useStyles.cx;
|
|
44
|
-
var
|
|
48
|
+
var size = {
|
|
49
|
+
blockSize: 24,
|
|
50
|
+
fontSize: 14,
|
|
51
|
+
strokeWidth: 2
|
|
52
|
+
};
|
|
53
|
+
var origianlActions = copyable && /*#__PURE__*/_jsx(CopyButton, {
|
|
54
|
+
content: children,
|
|
55
|
+
placement: "left",
|
|
56
|
+
size: size
|
|
57
|
+
});
|
|
58
|
+
var actions = actionsRender ? actionsRender({
|
|
59
|
+
actionIconSize: size,
|
|
60
|
+
content: children,
|
|
61
|
+
language: language,
|
|
62
|
+
originalNode: origianlActions
|
|
63
|
+
}) : origianlActions;
|
|
64
|
+
var originalBody = /*#__PURE__*/_jsx(SyntaxHighlighter, {
|
|
65
|
+
language: lang === null || lang === void 0 ? void 0 : lang.toLowerCase(),
|
|
66
|
+
style: expand ? {} : {
|
|
67
|
+
height: 0,
|
|
68
|
+
overflow: 'hidden'
|
|
69
|
+
},
|
|
70
|
+
children: children
|
|
71
|
+
});
|
|
72
|
+
var body = bodyRender ? bodyRender({
|
|
73
|
+
content: children,
|
|
74
|
+
language: language,
|
|
75
|
+
originalNode: originalBody
|
|
76
|
+
}) : originalBody;
|
|
45
77
|
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
|
|
46
|
-
className: container,
|
|
78
|
+
className: cx(styles.container, className),
|
|
47
79
|
"data-code-type": "highlighter",
|
|
48
80
|
style: style
|
|
49
81
|
}, rest), {}, {
|
|
@@ -62,7 +94,7 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
62
94
|
fontSize: 14,
|
|
63
95
|
strokeWidth: 3
|
|
64
96
|
}
|
|
65
|
-
}), allowChangeLanguage && !fileName ? /*#__PURE__*/_jsx(Select, {
|
|
97
|
+
}), allowChangeLanguage && !fileName ? showLanguage && /*#__PURE__*/_jsx(Select, {
|
|
66
98
|
className: styles.select,
|
|
67
99
|
onSelect: setLang,
|
|
68
100
|
options: options,
|
|
@@ -75,27 +107,19 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
75
107
|
className: styles.select,
|
|
76
108
|
gap: 2,
|
|
77
109
|
horizontal: true,
|
|
110
|
+
justify: 'center',
|
|
78
111
|
children: [icon, /*#__PURE__*/_jsx("span", {
|
|
79
112
|
children: fileName || lang
|
|
80
113
|
})]
|
|
81
|
-
}), /*#__PURE__*/_jsx(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
strokeWidth: 2
|
|
88
|
-
}
|
|
114
|
+
}), /*#__PURE__*/_jsx(Flexbox, {
|
|
115
|
+
align: 'center',
|
|
116
|
+
flex: 'none',
|
|
117
|
+
gap: 4,
|
|
118
|
+
horizontal: true,
|
|
119
|
+
children: actions
|
|
89
120
|
})]
|
|
90
|
-
}),
|
|
91
|
-
language: lang === null || lang === void 0 ? void 0 : lang.toLowerCase(),
|
|
92
|
-
style: expand ? {} : {
|
|
93
|
-
height: 0,
|
|
94
|
-
overflow: 'hidden'
|
|
95
|
-
},
|
|
96
|
-
children: children
|
|
97
|
-
})]
|
|
121
|
+
}), body]
|
|
98
122
|
}));
|
|
99
123
|
});
|
|
100
|
-
export default
|
|
124
|
+
export default HighlighterFullFeatured;
|
|
101
125
|
export { default as SyntaxHighlighter } from "./SyntaxHighlighter";
|
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { DivProps } from "../types";
|
|
4
|
-
export interface HighlighterProps extends DivProps {
|
|
5
|
-
allowChangeLanguage?: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* @description The code content to be highlighted
|
|
8
|
-
*/
|
|
9
|
-
children: string;
|
|
10
|
-
copyButtonSize?: CopyButtonProps['size'];
|
|
11
|
-
/**
|
|
12
|
-
* @description Whether to show the copy button
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
copyable?: boolean;
|
|
16
|
-
fileName?: string;
|
|
17
|
-
fullFeatured?: boolean;
|
|
18
|
-
icon?: ReactNode;
|
|
19
|
-
/**
|
|
20
|
-
* @description The language of the code content
|
|
21
|
-
*/
|
|
22
|
-
language: string;
|
|
23
|
-
/**
|
|
24
|
-
* @description Whether to show language tag
|
|
25
|
-
* @default true
|
|
26
|
-
*/
|
|
27
|
-
showLanguage?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* @description Whether add spotlight background
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
spotlight?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* @description The type of the code block
|
|
35
|
-
* @default 'block'
|
|
36
|
-
*/
|
|
37
|
-
type?: 'ghost' | 'block' | 'pure';
|
|
38
|
-
wrap?: boolean;
|
|
39
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { HighlighterProps } from './type';
|
|
40
3
|
export declare const Highlighter: import("react").NamedExoticComponent<HighlighterProps>;
|
|
41
4
|
export default Highlighter;
|
|
42
5
|
export { default as SyntaxHighlighter, type SyntaxHighlighterProps } from './SyntaxHighlighter';
|
|
6
|
+
export { type HighlighterProps } from './type';
|
package/es/Highlighter/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["fullFeatured", "copyButtonSize", "children", "language", "className", "style", "copyable", "showLanguage", "type", "
|
|
5
|
+
var _excluded = ["fullFeatured", "copyButtonSize", "children", "language", "className", "style", "copyable", "showLanguage", "type", "wrap", "bodyRender", "actionsRender"];
|
|
6
6
|
import { memo } from 'react';
|
|
7
|
+
import { Flexbox } from 'react-layout-kit';
|
|
7
8
|
import CopyButton from "../CopyButton";
|
|
8
|
-
import Spotlight from "../Spotlight";
|
|
9
9
|
import Tag from "../Tag";
|
|
10
10
|
import FullFeatured from "./FullFeatured";
|
|
11
11
|
import SyntaxHighlighter from "./SyntaxHighlighter";
|
|
@@ -17,7 +17,8 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
17
17
|
_ref$copyButtonSize = _ref.copyButtonSize,
|
|
18
18
|
copyButtonSize = _ref$copyButtonSize === void 0 ? 'site' : _ref$copyButtonSize,
|
|
19
19
|
children = _ref.children,
|
|
20
|
-
language = _ref.language,
|
|
20
|
+
_ref$language = _ref.language,
|
|
21
|
+
language = _ref$language === void 0 ? 'markdown' : _ref$language,
|
|
21
22
|
className = _ref.className,
|
|
22
23
|
style = _ref.style,
|
|
23
24
|
_ref$copyable = _ref.copyable,
|
|
@@ -26,48 +27,62 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
26
27
|
showLanguage = _ref$showLanguage === void 0 ? true : _ref$showLanguage,
|
|
27
28
|
_ref$type = _ref.type,
|
|
28
29
|
type = _ref$type === void 0 ? 'block' : _ref$type,
|
|
29
|
-
spotlight = _ref.spotlight,
|
|
30
|
-
_ref$allowChangeLangu = _ref.allowChangeLanguage,
|
|
31
|
-
allowChangeLanguage = _ref$allowChangeLangu === void 0 ? true : _ref$allowChangeLangu,
|
|
32
|
-
fileName = _ref.fileName,
|
|
33
|
-
icon = _ref.icon,
|
|
34
30
|
wrap = _ref.wrap,
|
|
31
|
+
bodyRender = _ref.bodyRender,
|
|
32
|
+
actionsRender = _ref.actionsRender,
|
|
35
33
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
36
34
|
var _useStyles = useStyles(type),
|
|
37
35
|
styles = _useStyles.styles,
|
|
38
36
|
cx = _useStyles.cx;
|
|
39
|
-
var
|
|
37
|
+
var originalActions = copyable && /*#__PURE__*/_jsx(CopyButton, {
|
|
38
|
+
content: children,
|
|
39
|
+
placement: "left",
|
|
40
|
+
size: copyButtonSize
|
|
41
|
+
});
|
|
42
|
+
var actions = actionsRender ? actionsRender({
|
|
43
|
+
actionIconSize: copyButtonSize,
|
|
44
|
+
content: children,
|
|
45
|
+
language: language,
|
|
46
|
+
originalNode: originalActions
|
|
47
|
+
}) : originalActions;
|
|
48
|
+
var originalBody = /*#__PURE__*/_jsx(SyntaxHighlighter, {
|
|
49
|
+
language: language === null || language === void 0 ? void 0 : language.toLowerCase(),
|
|
50
|
+
children: children
|
|
51
|
+
});
|
|
52
|
+
var body = bodyRender ? bodyRender({
|
|
53
|
+
content: children,
|
|
54
|
+
language: language,
|
|
55
|
+
originalNode: originalBody
|
|
56
|
+
}) : originalBody;
|
|
40
57
|
if (fullFeatured) return /*#__PURE__*/_jsx(FullFeatured, _objectSpread(_objectSpread({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
icon: icon,
|
|
58
|
+
actionsRender: actionsRender,
|
|
59
|
+
bodyRender: bodyRender,
|
|
60
|
+
copyable: copyable,
|
|
45
61
|
language: language,
|
|
46
|
-
|
|
62
|
+
showLanguage: showLanguage,
|
|
63
|
+
type: type,
|
|
64
|
+
wrap: wrap
|
|
47
65
|
}, rest), {}, {
|
|
48
66
|
children: children
|
|
49
67
|
}));
|
|
50
68
|
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
|
|
51
|
-
className: container,
|
|
69
|
+
className: cx(styles.container, !wrap && styles.nowrap, className),
|
|
52
70
|
"data-code-type": "highlighter",
|
|
53
71
|
style: style
|
|
54
72
|
}, rest), {}, {
|
|
55
|
-
children: [
|
|
56
|
-
|
|
57
|
-
}), copyable && /*#__PURE__*/_jsx(CopyButton, {
|
|
73
|
+
children: [/*#__PURE__*/_jsx(Flexbox, {
|
|
74
|
+
align: 'center',
|
|
58
75
|
className: styles.button,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
flex: 'none',
|
|
77
|
+
gap: 4,
|
|
78
|
+
horizontal: true,
|
|
79
|
+
children: actions
|
|
62
80
|
}), showLanguage && language && /*#__PURE__*/_jsx(Tag, {
|
|
63
81
|
className: styles.lang,
|
|
64
82
|
children: language.toLowerCase()
|
|
65
83
|
}), /*#__PURE__*/_jsx("div", {
|
|
66
84
|
className: styles.scroller,
|
|
67
|
-
children:
|
|
68
|
-
language: language === null || language === void 0 ? void 0 : language.toLowerCase(),
|
|
69
|
-
children: children
|
|
70
|
-
})
|
|
85
|
+
children: body
|
|
71
86
|
})]
|
|
72
87
|
}));
|
|
73
88
|
});
|
package/es/Highlighter/style.js
CHANGED
|
@@ -14,10 +14,10 @@ export var useStyles = createStyles(function (_ref, type) {
|
|
|
14
14
|
return {
|
|
15
15
|
button: cx(buttonHoverCls, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-start: ", ";\n inset-inline-end: ", ";\n\n opacity: 0;\n "])), type === 'pure' ? 0 : '8px', type === 'pure' ? 0 : '8px')),
|
|
16
16
|
container: cx(prefix, type !== 'pure' && typeStylish, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n\n &:hover {\n .", " {\n opacity: 1;\n }\n\n .", " {\n opacity: 1;\n }\n }\n\n .prism-code {\n background: none !important;\n }\n\n pre {\n overflow: auto hidden;\n\n margin: 0 !important;\n padding: ", " !important;\n\n white-space: break-spaces;\n\n background: none !important;\n }\n\n code {\n background: transparent !important;\n }\n "])), token.borderRadius, token.motionEaseOut, buttonHoverCls, langHoverCls, type === 'pure' ? 0 : "16px")),
|
|
17
|
-
header: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n padding-block: 4px;\n padding-inline: 8px;\n background: ", ";\n "])), token.colorFillQuaternary),
|
|
17
|
+
header: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n padding-block: 4px;\n padding-inline: 8px;\n background: ", ";\n "])), token.colorFillQuaternary),
|
|
18
18
|
lang: cx(langHoverCls, stylish.blur, css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-end: 8px;\n inset-inline-end: 0;\n\n font-family: ", ";\n color: ", ";\n\n opacity: 0;\n\n transition: opacity 0.1s;\n "])), token.fontFamilyCode, token.colorTextSecondary)),
|
|
19
19
|
nowrap: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n code {\n text-wrap: nowrap !important;\n }\n "]))),
|
|
20
20
|
scroller: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n overflow: auto;\n width: 100%;\n height: 100%;\n "]))),
|
|
21
|
-
select: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n user-select: none;\n font-size: 14px;\n color: ", ";\n .", "-select-selection-item {\n min-width: 100px;\n padding-inline-end: 0 !important;\n color: ", ";\n text-align: center;\n }\n "])), token.colorTextDescription, prefixCls, token.colorTextDescription)
|
|
21
|
+
select: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n user-select: none;\n\n position: absolute;\n inset-inline-start: 50%;\n transform: translateX(-50%);\n\n min-width: 100px;\n\n font-size: 14px;\n color: ", ";\n text-align: center;\n .", "-select-selection-item {\n min-width: 100px;\n padding-inline-end: 0 !important;\n color: ", ";\n text-align: center;\n }\n "])), token.colorTextDescription, prefixCls, token.colorTextDescription)
|
|
22
22
|
};
|
|
23
23
|
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { ActionIconProps } from "../ActionIcon";
|
|
3
|
+
import type { CopyButtonProps } from "../CopyButton";
|
|
4
|
+
import type { DivProps } from "../types";
|
|
5
|
+
export interface HighlighterProps extends DivProps {
|
|
6
|
+
actionsRender?: (props: {
|
|
7
|
+
actionIconSize: ActionIconProps['size'];
|
|
8
|
+
content: string;
|
|
9
|
+
language: string;
|
|
10
|
+
originalNode: ReactNode;
|
|
11
|
+
}) => ReactNode;
|
|
12
|
+
allowChangeLanguage?: boolean;
|
|
13
|
+
bodyRender?: (props: {
|
|
14
|
+
content: string;
|
|
15
|
+
language: string;
|
|
16
|
+
originalNode: ReactNode;
|
|
17
|
+
}) => ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* @description The code content to be highlighted
|
|
20
|
+
*/
|
|
21
|
+
children: string;
|
|
22
|
+
copyButtonSize?: CopyButtonProps['size'];
|
|
23
|
+
/**
|
|
24
|
+
* @description Whether to show the copy button
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
copyable?: boolean;
|
|
28
|
+
fileName?: string;
|
|
29
|
+
fullFeatured?: boolean;
|
|
30
|
+
icon?: ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* @description The language of the code content
|
|
33
|
+
*/
|
|
34
|
+
language: string;
|
|
35
|
+
/**
|
|
36
|
+
* @description Whether to show language tag
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
showLanguage?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* @description Whether add spotlight background
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
spotlight?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* @description The type of the code block
|
|
47
|
+
* @default 'block'
|
|
48
|
+
*/
|
|
49
|
+
type?: 'ghost' | 'block' | 'pure';
|
|
50
|
+
wrap?: boolean;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
2
|
+
import { type HighlighterProps } from "../Highlighter";
|
|
3
|
+
import { type MermaidProps } from "../Mermaid";
|
|
4
|
+
export declare const useCode: (raw: any) => {
|
|
5
|
+
content: any;
|
|
6
|
+
isSingleLine: boolean;
|
|
7
|
+
lang: any;
|
|
8
|
+
} | undefined;
|
|
9
|
+
interface CodeBlockProps {
|
|
10
|
+
children: any;
|
|
11
|
+
enableMermaid?: boolean;
|
|
12
|
+
fullFeatured?: boolean;
|
|
13
|
+
highlight?: HighlighterProps;
|
|
14
|
+
mermaid?: MermaidProps;
|
|
15
|
+
}
|
|
16
|
+
export declare const CodeLite: FC<CodeBlockProps>;
|
|
17
|
+
export declare const CodeFullFeatured: FC<CodeBlockProps>;
|
|
18
|
+
export {};
|
package/es/Markdown/CodeBlock.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["fullFeatured"];
|
|
3
|
+
var _excluded = ["fullFeatured", "enableMermaid", "highlight", "mermaid"];
|
|
4
4
|
import { FALLBACK_LANG } from "../hooks/useHighlight";
|
|
5
|
-
import Pre, { PreSingleLine } from "../mdx/Pre";
|
|
5
|
+
import Pre, { PreMermaid, PreSingleLine } from "../mdx/Pre";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
var countLines = function countLines(str) {
|
|
8
8
|
var regex = /\n/g;
|
|
9
9
|
var matches = str.match(regex);
|
|
10
10
|
return matches ? matches.length : 1;
|
|
11
11
|
};
|
|
12
|
-
var useCode = function useCode(raw) {
|
|
12
|
+
export var useCode = function useCode(raw) {
|
|
13
13
|
if (!raw) return;
|
|
14
14
|
var _raw$props = raw.props,
|
|
15
15
|
children = _raw$props.children,
|
|
@@ -27,17 +27,25 @@ var useCode = function useCode(raw) {
|
|
|
27
27
|
var CodeBlock = function CodeBlock(_ref) {
|
|
28
28
|
var _rest$children;
|
|
29
29
|
var fullFeatured = _ref.fullFeatured,
|
|
30
|
+
enableMermaid = _ref.enableMermaid,
|
|
31
|
+
highlight = _ref.highlight,
|
|
32
|
+
mermaid = _ref.mermaid,
|
|
30
33
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
31
34
|
var code = useCode(rest === null || rest === void 0 || (_rest$children = rest.children) === null || _rest$children === void 0 ? void 0 : _rest$children[0]);
|
|
32
35
|
if (!code) return;
|
|
33
|
-
if (code.
|
|
36
|
+
if (enableMermaid && code.lang === 'mermaid') return /*#__PURE__*/_jsx(PreMermaid, _objectSpread(_objectSpread({
|
|
37
|
+
fullFeatured: fullFeatured
|
|
38
|
+
}, mermaid), {}, {
|
|
39
|
+
children: code.content
|
|
40
|
+
}));
|
|
41
|
+
if (!highlight && code.isSingleLine) return /*#__PURE__*/_jsx(PreSingleLine, {
|
|
34
42
|
language: code.lang,
|
|
35
43
|
children: code.content
|
|
36
44
|
});
|
|
37
|
-
return /*#__PURE__*/_jsx(Pre, _objectSpread(_objectSpread({
|
|
45
|
+
return /*#__PURE__*/_jsx(Pre, _objectSpread(_objectSpread(_objectSpread({
|
|
38
46
|
fullFeatured: fullFeatured,
|
|
39
47
|
language: code.lang
|
|
40
|
-
}, rest), {}, {
|
|
48
|
+
}, highlight), rest), {}, {
|
|
41
49
|
children: code.content
|
|
42
50
|
}));
|
|
43
51
|
};
|
package/es/Markdown/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { AnchorProps } from 'antd';
|
|
2
2
|
import { CSSProperties } from 'react';
|
|
3
|
+
import { type HighlighterProps } from "../Highlighter";
|
|
4
|
+
import { type MermaidProps } from "../Mermaid";
|
|
3
5
|
import { type ImageProps } from "../mdx/Image";
|
|
4
|
-
import type
|
|
6
|
+
import { type PreProps } from "../mdx/Pre";
|
|
5
7
|
import { type VideoProps } from "../mdx/Video";
|
|
6
8
|
import type { AProps } from "../types";
|
|
7
9
|
import type { TypographyProps } from './Typography';
|
|
@@ -11,12 +13,15 @@ export interface MarkdownProps extends TypographyProps {
|
|
|
11
13
|
className?: string;
|
|
12
14
|
componentProps?: {
|
|
13
15
|
a?: Partial<AProps & AnchorProps>;
|
|
16
|
+
highlight?: Partial<HighlighterProps>;
|
|
14
17
|
img?: Partial<ImageProps>;
|
|
18
|
+
mermaid?: Partial<MermaidProps>;
|
|
15
19
|
pre?: Partial<PreProps>;
|
|
16
20
|
video?: Partial<VideoProps>;
|
|
17
21
|
};
|
|
18
22
|
enableImageGallery?: boolean;
|
|
19
23
|
enableLatex?: boolean;
|
|
24
|
+
enableMermaid?: boolean;
|
|
20
25
|
fullFeaturedCodeBlock?: boolean;
|
|
21
26
|
onDoubleClick?: () => void;
|
|
22
27
|
style?: CSSProperties;
|
package/es/Markdown/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableLatex", "enableImageGallery", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "variant", "lineHeight"];
|
|
5
|
+
var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableLatex", "enableMermaid", "enableImageGallery", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "variant", "lineHeight"];
|
|
6
6
|
import { memo, useMemo } from 'react';
|
|
7
7
|
import ReactMarkdown from 'react-markdown';
|
|
8
8
|
import rehypeKatex from 'rehype-katex';
|
|
@@ -27,6 +27,8 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
27
27
|
onDoubleClick = _ref.onDoubleClick,
|
|
28
28
|
_ref$enableLatex = _ref.enableLatex,
|
|
29
29
|
enableLatex = _ref$enableLatex === void 0 ? true : _ref$enableLatex,
|
|
30
|
+
_ref$enableMermaid = _ref.enableMermaid,
|
|
31
|
+
enableMermaid = _ref$enableMermaid === void 0 ? true : _ref$enableMermaid,
|
|
30
32
|
_ref$enableImageGalle = _ref.enableImageGallery,
|
|
31
33
|
enableImageGallery = _ref$enableImageGalle === void 0 ? true : _ref$enableImageGalle,
|
|
32
34
|
componentProps = _ref.componentProps,
|
|
@@ -72,13 +74,21 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
72
74
|
}));
|
|
73
75
|
} : undefined,
|
|
74
76
|
pre: function pre(props) {
|
|
75
|
-
return fullFeaturedCodeBlock ? /*#__PURE__*/_jsx(CodeFullFeatured, _objectSpread(_objectSpread({
|
|
77
|
+
return fullFeaturedCodeBlock ? /*#__PURE__*/_jsx(CodeFullFeatured, _objectSpread(_objectSpread({
|
|
78
|
+
enableMermaid: enableMermaid,
|
|
79
|
+
highlight: componentProps === null || componentProps === void 0 ? void 0 : componentProps.highlight,
|
|
80
|
+
mermaid: componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid
|
|
81
|
+
}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre)) : /*#__PURE__*/_jsx(CodeLite, _objectSpread(_objectSpread({
|
|
82
|
+
enableMermaid: enableMermaid,
|
|
83
|
+
highlight: componentProps === null || componentProps === void 0 ? void 0 : componentProps.highlight,
|
|
84
|
+
mermaid: componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid
|
|
85
|
+
}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre));
|
|
76
86
|
},
|
|
77
87
|
video: function video(props) {
|
|
78
88
|
return /*#__PURE__*/_jsx(Video, _objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.video));
|
|
79
89
|
}
|
|
80
90
|
};
|
|
81
|
-
}, [componentProps, enableImageGallery, fullFeaturedCodeBlock]);
|
|
91
|
+
}, [componentProps, enableImageGallery, enableMermaid, fullFeaturedCodeBlock]);
|
|
82
92
|
var rehypePlugins = useMemo(function () {
|
|
83
93
|
return [allowHtml && rehypeRaw, enableLatex && rehypeKatex].filter(Boolean);
|
|
84
94
|
}, [allowHtml]);
|
|
@@ -15,7 +15,7 @@ export var useStyles = createStyles(function (_ref, _ref2) {
|
|
|
15
15
|
_ref2$lineHeight = _ref2.lineHeight,
|
|
16
16
|
lineHeight = _ref2$lineHeight === void 0 ? 1.8 : _ref2$lineHeight;
|
|
17
17
|
return {
|
|
18
|
-
__root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: ", "px;\n --lobe-markdown-header-multiple: ", ";\n --lobe-markdown-margin-multiple: ", ";\n --lobe-markdown-line-height: ", ";\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n width: 100%;\n max-width: 100%;\n padding-inline: 1px;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n "])), fontSize, headerMultiple, marginMultiple, lineHeight, token.borderRadiusLG, isDarkMode ? token.colorBorderSecondary : rgba(token.colorBorderSecondary, 0.5)),
|
|
18
|
+
__root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: ", "px;\n --lobe-markdown-header-multiple: ", ";\n --lobe-markdown-margin-multiple: ", ";\n --lobe-markdown-line-height: ", ";\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n width: 100%;\n max-width: 100%;\n padding-inline: 1px;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n\n svg {\n line-height: 1;\n }\n "])), fontSize, headerMultiple, marginMultiple, lineHeight, token.borderRadiusLG, isDarkMode ? token.colorBorderSecondary : rgba(token.colorBorderSecondary, 0.5)),
|
|
19
19
|
a: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n a {\n color: ", ";\n\n &:hover {\n color: ", ";\n }\n }\n "])), token.colorInfoText, token.colorInfoHover),
|
|
20
20
|
blockquote: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n blockquote {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 1em);\n margin-inline: 0;\n padding-block: 0;\n padding-inline: 1em;\n\n color: ", ";\n\n border-inline-start: solid 4px ", ";\n }\n "])), token.colorTextSecondary, token.colorBorder),
|
|
21
21
|
code: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n code:not(:has(span)) {\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n\n font-family: ", ";\n font-size: 0.875em;\n line-height: 1;\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n border: 1px solid var(--lobe-markdown-border-color);\n border-radius: 0.25em;\n }\n "])), token.fontFamilyCode, token.colorFillSecondary),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { MermaidProps } from './type';
|
|
3
|
+
export declare const MermaidFullFeatured: import("react").NamedExoticComponent<Omit<MermaidProps, "children"> & {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
content: string;
|
|
6
|
+
}>;
|
|
7
|
+
export default MermaidFullFeatured;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["showLanguage", "content", "children", "className", "copyable", "actionsRender", "style"];
|
|
5
|
+
import { ChevronDown, ChevronRight } from 'lucide-react';
|
|
6
|
+
import { memo, useState } from 'react';
|
|
7
|
+
import { Flexbox } from 'react-layout-kit';
|
|
8
|
+
import ActionIcon from "../ActionIcon";
|
|
9
|
+
import CopyButton from "../CopyButton";
|
|
10
|
+
import { useStyles } from "./style";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
14
|
+
var showLanguage = _ref.showLanguage,
|
|
15
|
+
content = _ref.content,
|
|
16
|
+
children = _ref.children,
|
|
17
|
+
className = _ref.className,
|
|
18
|
+
copyable = _ref.copyable,
|
|
19
|
+
actionsRender = _ref.actionsRender,
|
|
20
|
+
style = _ref.style,
|
|
21
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
22
|
+
var _useState = useState(true),
|
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
+
expand = _useState2[0],
|
|
25
|
+
setExpand = _useState2[1];
|
|
26
|
+
var _useStyles = useStyles('block'),
|
|
27
|
+
styles = _useStyles.styles,
|
|
28
|
+
cx = _useStyles.cx;
|
|
29
|
+
var container = cx(styles.container, className);
|
|
30
|
+
var size = {
|
|
31
|
+
blockSize: 24,
|
|
32
|
+
fontSize: 14,
|
|
33
|
+
strokeWidth: 2
|
|
34
|
+
};
|
|
35
|
+
var originalActions = copyable && /*#__PURE__*/_jsx(CopyButton, {
|
|
36
|
+
content: content,
|
|
37
|
+
placement: "left",
|
|
38
|
+
size: size
|
|
39
|
+
});
|
|
40
|
+
var actions = actionsRender ? actionsRender({
|
|
41
|
+
actionIconSize: size,
|
|
42
|
+
content: content,
|
|
43
|
+
originalNode: originalActions
|
|
44
|
+
}) : originalActions;
|
|
45
|
+
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
|
|
46
|
+
className: container,
|
|
47
|
+
"data-code-type": "mermaid",
|
|
48
|
+
style: style
|
|
49
|
+
}, rest), {}, {
|
|
50
|
+
children: [/*#__PURE__*/_jsxs(Flexbox, {
|
|
51
|
+
align: 'center',
|
|
52
|
+
className: styles.header,
|
|
53
|
+
horizontal: true,
|
|
54
|
+
justify: 'space-between',
|
|
55
|
+
children: [/*#__PURE__*/_jsx(ActionIcon, {
|
|
56
|
+
icon: expand ? ChevronDown : ChevronRight,
|
|
57
|
+
onClick: function onClick() {
|
|
58
|
+
return setExpand(!expand);
|
|
59
|
+
},
|
|
60
|
+
size: {
|
|
61
|
+
blockSize: 24,
|
|
62
|
+
fontSize: 14,
|
|
63
|
+
strokeWidth: 3
|
|
64
|
+
}
|
|
65
|
+
}), showLanguage && /*#__PURE__*/_jsx(Flexbox, {
|
|
66
|
+
align: 'center',
|
|
67
|
+
className: styles.select,
|
|
68
|
+
gap: 2,
|
|
69
|
+
horizontal: true,
|
|
70
|
+
justify: 'center',
|
|
71
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
72
|
+
children: "mermaid"
|
|
73
|
+
})
|
|
74
|
+
}), /*#__PURE__*/_jsx(Flexbox, {
|
|
75
|
+
align: 'center',
|
|
76
|
+
flex: 'none',
|
|
77
|
+
gap: 4,
|
|
78
|
+
horizontal: true,
|
|
79
|
+
children: actions
|
|
80
|
+
})]
|
|
81
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
82
|
+
style: expand ? {} : {
|
|
83
|
+
height: 0,
|
|
84
|
+
overflow: 'hidden'
|
|
85
|
+
},
|
|
86
|
+
children: children
|
|
87
|
+
})]
|
|
88
|
+
}));
|
|
89
|
+
});
|
|
90
|
+
export default MermaidFullFeatured;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children", "copyButtonSize", "fullFeatured", "copyable", "showLanguage", "style", "type", "className", "bodyRender", "actionsRender"];
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { Flexbox } from 'react-layout-kit';
|
|
6
|
+
import CopyButton from "../CopyButton";
|
|
7
|
+
import Tag from "../Tag";
|
|
8
|
+
import FullFeatured from "./FullFeatured";
|
|
9
|
+
import { useStyles } from "./style";
|
|
10
|
+
import { useMermaid } from "./useMermaid";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
var Mermaid = /*#__PURE__*/memo(function (_ref) {
|
|
14
|
+
var children = _ref.children,
|
|
15
|
+
_ref$copyButtonSize = _ref.copyButtonSize,
|
|
16
|
+
copyButtonSize = _ref$copyButtonSize === void 0 ? 'site' : _ref$copyButtonSize,
|
|
17
|
+
fullFeatured = _ref.fullFeatured,
|
|
18
|
+
_ref$copyable = _ref.copyable,
|
|
19
|
+
copyable = _ref$copyable === void 0 ? true : _ref$copyable,
|
|
20
|
+
_ref$showLanguage = _ref.showLanguage,
|
|
21
|
+
showLanguage = _ref$showLanguage === void 0 ? true : _ref$showLanguage,
|
|
22
|
+
style = _ref.style,
|
|
23
|
+
_ref$type = _ref.type,
|
|
24
|
+
type = _ref$type === void 0 ? 'block' : _ref$type,
|
|
25
|
+
className = _ref.className,
|
|
26
|
+
bodyRender = _ref.bodyRender,
|
|
27
|
+
actionsRender = _ref.actionsRender,
|
|
28
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
+
var _useStyles = useStyles(type),
|
|
30
|
+
cx = _useStyles.cx,
|
|
31
|
+
styles = _useStyles.styles;
|
|
32
|
+
var MermaidRender = useMermaid(children);
|
|
33
|
+
var originalActions = copyable && /*#__PURE__*/_jsx(CopyButton, {
|
|
34
|
+
content: children,
|
|
35
|
+
placement: "left",
|
|
36
|
+
size: copyButtonSize
|
|
37
|
+
});
|
|
38
|
+
var actions = actionsRender ? actionsRender({
|
|
39
|
+
actionIconSize: copyButtonSize,
|
|
40
|
+
content: children,
|
|
41
|
+
originalNode: originalActions
|
|
42
|
+
}) : originalActions;
|
|
43
|
+
var defaultBody = /*#__PURE__*/_jsx(MermaidRender, {});
|
|
44
|
+
var body = bodyRender ? bodyRender({
|
|
45
|
+
content: children,
|
|
46
|
+
originalNode: defaultBody
|
|
47
|
+
}) : defaultBody;
|
|
48
|
+
if (fullFeatured) return /*#__PURE__*/_jsx(FullFeatured, _objectSpread(_objectSpread({
|
|
49
|
+
actionsRender: actionsRender,
|
|
50
|
+
bodyRender: bodyRender,
|
|
51
|
+
className: className,
|
|
52
|
+
content: children,
|
|
53
|
+
copyable: copyable,
|
|
54
|
+
showLanguage: showLanguage,
|
|
55
|
+
style: style,
|
|
56
|
+
type: type
|
|
57
|
+
}, rest), {}, {
|
|
58
|
+
children: body
|
|
59
|
+
}));
|
|
60
|
+
return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
|
|
61
|
+
className: cx(styles.container, className),
|
|
62
|
+
"data-code-type": "mermaid",
|
|
63
|
+
style: style
|
|
64
|
+
}, rest), {}, {
|
|
65
|
+
children: [/*#__PURE__*/_jsx(Flexbox, {
|
|
66
|
+
align: 'center',
|
|
67
|
+
className: styles.button,
|
|
68
|
+
flex: 'none',
|
|
69
|
+
gap: 4,
|
|
70
|
+
horizontal: true,
|
|
71
|
+
children: actions
|
|
72
|
+
}), showLanguage && /*#__PURE__*/_jsx(Tag, {
|
|
73
|
+
className: styles.lang,
|
|
74
|
+
children: "mermaid"
|
|
75
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
76
|
+
className: styles.scroller,
|
|
77
|
+
children: body
|
|
78
|
+
})]
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
export default Mermaid;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const useStyles: (props?: "block" | "ghost" | "pure" | undefined) => import("antd-style").ReturnStyles<{
|
|
2
|
+
button: string;
|
|
3
|
+
container: string;
|
|
4
|
+
header: import("antd-style").SerializedStyles;
|
|
5
|
+
lang: string;
|
|
6
|
+
scroller: import("antd-style").SerializedStyles;
|
|
7
|
+
select: import("antd-style").SerializedStyles;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
export var useStyles = createStyles(function (_ref, type) {
|
|
5
|
+
var token = _ref.token,
|
|
6
|
+
css = _ref.css,
|
|
7
|
+
cx = _ref.cx,
|
|
8
|
+
prefixCls = _ref.prefixCls,
|
|
9
|
+
stylish = _ref.stylish;
|
|
10
|
+
var prefix = "".concat(prefixCls, "-highlighter");
|
|
11
|
+
var buttonHoverCls = "".concat(prefix, "-hover-btn");
|
|
12
|
+
var langHoverCls = "".concat(prefix, "-hover-lang");
|
|
13
|
+
var typeStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n border: 1px solid ", ";\n\n &:hover {\n background-color: ", ";\n }\n "])), type === 'block' ? token.colorFillTertiary : 'transparent', type === 'block' ? 'transparent' : token.colorBorder, type === 'block' ? token.colorFillTertiary : token.colorFillQuaternary);
|
|
14
|
+
return {
|
|
15
|
+
button: cx(buttonHoverCls, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-start: ", ";\n inset-inline-end: ", ";\n\n opacity: 0;\n "])), type === 'pure' ? 0 : '8px', type === 'pure' ? 0 : '8px')),
|
|
16
|
+
container: cx(prefix, type !== 'pure' && typeStylish, css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n\n &:hover {\n .", " {\n opacity: 1;\n }\n\n .", " {\n opacity: 1;\n }\n }\n\n .prism-code {\n background: none !important;\n }\n\n pre {\n overflow: auto hidden;\n\n margin: 0 !important;\n padding: ", " !important;\n\n white-space: break-spaces;\n\n background: none !important;\n }\n\n code {\n background: transparent !important;\n }\n\n svg {\n height: fit-content;\n line-height: 1.2;\n }\n "])), token.borderRadius, token.motionEaseOut, buttonHoverCls, langHoverCls, type === 'pure' ? 0 : "16px")),
|
|
17
|
+
header: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n padding-block: 4px;\n padding-inline: 8px;\n background: ", ";\n "])), token.colorFillQuaternary),
|
|
18
|
+
lang: cx(langHoverCls, stylish.blur, css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-end: 8px;\n inset-inline-end: 0;\n\n font-family: ", ";\n color: ", ";\n\n opacity: 0;\n\n transition: opacity 0.1s;\n "])), token.fontFamilyCode, token.colorTextSecondary)),
|
|
19
|
+
scroller: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n overflow: auto;\n width: 100%;\n height: 100%;\n "]))),
|
|
20
|
+
select: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n user-select: none;\n\n position: absolute;\n inset-inline-start: 50%;\n transform: translateX(-50%);\n\n min-width: 100px;\n\n font-size: 14px;\n color: ", ";\n text-align: center;\n .", "-select-selection-item {\n min-width: 100px;\n padding-inline-end: 0 !important;\n color: ", ";\n text-align: center;\n }\n "])), token.colorTextDescription, prefixCls, token.colorTextDescription)
|
|
21
|
+
};
|
|
22
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { ActionIconProps } from "../ActionIcon";
|
|
3
|
+
import type { CopyButtonProps } from "../CopyButton";
|
|
4
|
+
import { DivProps } from "../types";
|
|
5
|
+
export interface MermaidProps extends DivProps {
|
|
6
|
+
actionsRender?: (props: {
|
|
7
|
+
actionIconSize: ActionIconProps['size'];
|
|
8
|
+
content: string;
|
|
9
|
+
originalNode: ReactNode;
|
|
10
|
+
}) => ReactNode;
|
|
11
|
+
bodyRender?: (props: {
|
|
12
|
+
content: string;
|
|
13
|
+
originalNode: ReactNode;
|
|
14
|
+
}) => ReactNode;
|
|
15
|
+
children: string;
|
|
16
|
+
copyButtonSize?: CopyButtonProps['size'];
|
|
17
|
+
copyable?: boolean;
|
|
18
|
+
fullFeatured?: boolean;
|
|
19
|
+
showLanguage?: boolean;
|
|
20
|
+
type?: 'ghost' | 'block' | 'pure';
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useMermaid: (content: string) => () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useTheme } from 'antd-style';
|
|
2
|
+
import mermaid from 'mermaid';
|
|
3
|
+
import { useCallback, useEffect } from 'react';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
export var useMermaid = function useMermaid(content) {
|
|
6
|
+
var theme = useTheme();
|
|
7
|
+
useEffect(function () {
|
|
8
|
+
mermaid.initialize({
|
|
9
|
+
fontFamily: theme.fontFamilyCode,
|
|
10
|
+
securityLevel: 'loose',
|
|
11
|
+
startOnLoad: true,
|
|
12
|
+
theme: 'base',
|
|
13
|
+
themeVariables: {
|
|
14
|
+
fontSize: 14,
|
|
15
|
+
lineColor: theme.colorBorderSecondary,
|
|
16
|
+
primaryBorderColor: theme.colorPrimaryBorder,
|
|
17
|
+
primaryColor: theme.colorPrimaryBg,
|
|
18
|
+
primaryTextColor: theme.colorText,
|
|
19
|
+
secondaryColor: theme.colorInfo,
|
|
20
|
+
tertiaryColor: theme.colorSuccess
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
mermaid.contentLoaded();
|
|
24
|
+
}, [content, theme.isDarkMode]);
|
|
25
|
+
return useCallback(function () {
|
|
26
|
+
return /*#__PURE__*/_jsx("pre", {
|
|
27
|
+
className: 'mermaid',
|
|
28
|
+
style: {
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
display: 'flex',
|
|
31
|
+
fontSize: 14,
|
|
32
|
+
justifyContent: 'center',
|
|
33
|
+
overflow: 'auto'
|
|
34
|
+
},
|
|
35
|
+
children: content
|
|
36
|
+
});
|
|
37
|
+
}, [content, theme.isDarkMode]);
|
|
38
|
+
};
|
package/es/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export { default as LogoSpline, type LogoSplineProps } from './LogoThree/LogoSpl
|
|
|
61
61
|
export { default as Markdown, type MarkdownProps } from './Markdown';
|
|
62
62
|
export { Typography, type TypographyProps } from './Markdown/Typography';
|
|
63
63
|
export { default as MaterialFileTypeIcon, type MaterialFileTypeIconProps, } from './MaterialFileTypeIcon';
|
|
64
|
+
export { default as Mermaid, type MermaidProps } from './Mermaid';
|
|
64
65
|
export { default as MessageInput, type MessageInputProps } from './MessageInput';
|
|
65
66
|
export { default as MessageModal, type MessageModalProps } from './MessageModal';
|
|
66
67
|
export { default as MobileNavBar, type MobileNavBarProps } from './MobileNavBar';
|
package/es/index.js
CHANGED
|
@@ -60,6 +60,7 @@ export { default as LogoSpline } from "./LogoThree/LogoSpline";
|
|
|
60
60
|
export { default as Markdown } from "./Markdown";
|
|
61
61
|
export { Typography } from "./Markdown/Typography";
|
|
62
62
|
export { default as MaterialFileTypeIcon } from "./MaterialFileTypeIcon";
|
|
63
|
+
export { default as Mermaid } from "./Mermaid";
|
|
63
64
|
export { default as MessageInput } from "./MessageInput";
|
|
64
65
|
export { default as MessageModal } from "./MessageModal";
|
|
65
66
|
export { default as MobileNavBar } from "./MobileNavBar";
|
package/es/mdx/Pre.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { type HighlighterProps } from "../Highlighter";
|
|
3
|
+
import { type MermaidProps } from "../Mermaid";
|
|
3
4
|
import { type SnippetProps } from "../Snippet";
|
|
4
5
|
export type PreProps = HighlighterProps;
|
|
5
6
|
export declare const Pre: FC<PreProps>;
|
|
6
7
|
export declare const PreSingleLine: FC<SnippetProps>;
|
|
8
|
+
export declare const PreMermaid: FC<MermaidProps>;
|
|
7
9
|
export default Pre;
|
package/es/mdx/Pre.js
CHANGED
|
@@ -4,10 +4,12 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
5
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
6
6
|
var _excluded = ["fullFeatured", "fileName", "allowChangeLanguage", "language", "children", "className", "style", "icon"],
|
|
7
|
-
_excluded2 = ["language", "children", "className", "style"]
|
|
7
|
+
_excluded2 = ["language", "children", "className", "style"],
|
|
8
|
+
_excluded3 = ["fullFeatured", "children", "className", "style"];
|
|
8
9
|
var _templateObject;
|
|
9
10
|
import { createStyles } from 'antd-style';
|
|
10
11
|
import Highlighter from "../Highlighter";
|
|
12
|
+
import Mermaid from "../Mermaid";
|
|
11
13
|
import Snippet from "../Snippet";
|
|
12
14
|
import { FALLBACK_LANG } from "../hooks/useHighlight";
|
|
13
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -68,4 +70,26 @@ export var PreSingleLine = function PreSingleLine(_ref3) {
|
|
|
68
70
|
children: children
|
|
69
71
|
}));
|
|
70
72
|
};
|
|
73
|
+
export var PreMermaid = function PreMermaid(_ref4) {
|
|
74
|
+
var fullFeatured = _ref4.fullFeatured,
|
|
75
|
+
children = _ref4.children,
|
|
76
|
+
className = _ref4.className,
|
|
77
|
+
style = _ref4.style,
|
|
78
|
+
rest = _objectWithoutProperties(_ref4, _excluded3);
|
|
79
|
+
var _useStyles3 = useStyles(),
|
|
80
|
+
styles = _useStyles3.styles,
|
|
81
|
+
cx = _useStyles3.cx;
|
|
82
|
+
return /*#__PURE__*/_jsx(Mermaid, _objectSpread(_objectSpread({
|
|
83
|
+
className: cx(styles.container, className),
|
|
84
|
+
copyButtonSize: {
|
|
85
|
+
blockSize: 28,
|
|
86
|
+
fontSize: 16
|
|
87
|
+
},
|
|
88
|
+
fullFeatured: fullFeatured,
|
|
89
|
+
style: style,
|
|
90
|
+
type: "block"
|
|
91
|
+
}, rest), {}, {
|
|
92
|
+
children: children
|
|
93
|
+
}));
|
|
94
|
+
};
|
|
71
95
|
export default Pre;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.148.1",
|
|
4
4
|
"description": "Lobe UI is an open-source UI component library for building AIGC web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -96,6 +96,7 @@
|
|
|
96
96
|
"immer": "^10.1.1",
|
|
97
97
|
"leva": "^0.9.35",
|
|
98
98
|
"lodash-es": "^4.17.21",
|
|
99
|
+
"mermaid": "^10.9.1",
|
|
99
100
|
"numeral": "^2.0.6",
|
|
100
101
|
"polished": "^4.3.1",
|
|
101
102
|
"prism-react-renderer": "^2.3.1",
|