@lobehub/ui 1.144.4 → 1.145.0

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.
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { DivProps, SvgProps } from "../types";
3
+ export interface FileTypeIconProps extends SvgProps {
4
+ color?: string;
5
+ filetype?: string;
6
+ size?: number;
7
+ type?: 'file' | 'folder';
8
+ variant?: 'color' | 'mono';
9
+ }
10
+ declare const FileTypeIcon: import("react").NamedExoticComponent<FileTypeIconProps & DivProps>;
11
+ export default FileTypeIcon;
@@ -0,0 +1,87 @@
1
+ 'use client';
2
+
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ var _excluded = ["color", "filetype", "type", "size", "style", "variant"];
6
+ import { useTheme } from 'antd-style';
7
+ import { memo, useMemo } from 'react';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ var FileTypeIcon = /*#__PURE__*/memo(function (_ref) {
11
+ var color = _ref.color,
12
+ filetype = _ref.filetype,
13
+ _ref$type = _ref.type,
14
+ type = _ref$type === void 0 ? 'file' : _ref$type,
15
+ _ref$size = _ref.size,
16
+ size = _ref$size === void 0 ? 48 : _ref$size,
17
+ style = _ref.style,
18
+ variant = _ref.variant,
19
+ rest = _objectWithoutProperties(_ref, _excluded);
20
+ var theme = useTheme();
21
+ var fontSize = useMemo(function () {
22
+ if (filetype && filetype.length > 3) {
23
+ return 24 / (4 + (filetype.length - 3));
24
+ }
25
+ return 6;
26
+ }, [filetype]);
27
+ var isMono = variant === 'mono';
28
+ var iconColor = isMono ? theme.isDarkMode ? theme.colorFill : theme.colorBgContainer : color || theme.geekblue;
29
+ if (type === 'file') return /*#__PURE__*/_jsxs("svg", _objectSpread(_objectSpread({
30
+ height: size,
31
+ style: _objectSpread({
32
+ flex: 'none',
33
+ lineHeight: 1
34
+ }, style),
35
+ viewBox: "0 0 24 24",
36
+ width: size,
37
+ xmlns: "http://www.w3.org/2000/svg"
38
+ }, rest), {}, {
39
+ children: [/*#__PURE__*/_jsx("path", {
40
+ d: "M6 2a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8l-6-6H6z",
41
+ fill: iconColor
42
+ }), /*#__PURE__*/_jsx("path", {
43
+ d: "M14 2l6 6h-4a2 2 0 01-2-2V2z",
44
+ fill: isMono ? theme.colorFill : '#fff',
45
+ fillOpacity: ".5"
46
+ }), filetype && /*#__PURE__*/_jsx("text", {
47
+ fill: isMono ? theme.colorTextSecondary : '#fff',
48
+ fontSize: fontSize,
49
+ fontWeight: "bold",
50
+ textAnchor: "middle",
51
+ x: "50%",
52
+ y: "70%",
53
+ children: filetype.toUpperCase()
54
+ }), /*#__PURE__*/_jsx("path", {
55
+ d: "M6 2a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8l-6-6H6z",
56
+ fill: 'transparent',
57
+ stroke: theme.colorFillSecondary,
58
+ strokeWidth: 0.5
59
+ })]
60
+ }));
61
+ return /*#__PURE__*/_jsxs("svg", _objectSpread(_objectSpread({
62
+ height: size,
63
+ style: _objectSpread({
64
+ flex: 'none',
65
+ lineHeight: 1
66
+ }, style),
67
+ viewBox: "0 0 24 24",
68
+ width: size,
69
+ xmlns: "http://www.w3.org/2000/svg"
70
+ }, rest), {}, {
71
+ children: [/*#__PURE__*/_jsx("path", {
72
+ d: "M10.46 5.076l-.92-.752A1.446 1.446 0 008.626 4H3.429c-.38 0-.743.147-1.01.41A1.386 1.386 0 002 5.4v13.2c0 .371.15.727.418.99.268.262.632.41 1.01.41h17.143c.38 0 .743-.148 1.01-.41.268-.263.419-.619.419-.99V6.8c0-.371-.15-.727-.418-.99a1.444 1.444 0 00-1.01-.41h-9.198c-.334 0-.657-.115-.914-.324z",
73
+ fill: iconColor,
74
+ stroke: theme.colorFillSecondary,
75
+ strokeWidth: 0.5
76
+ }), filetype && /*#__PURE__*/_jsx("text", {
77
+ fill: isMono ? theme.colorTextSecondary : '#fff',
78
+ fontSize: fontSize,
79
+ fontWeight: "bold",
80
+ textAnchor: "middle",
81
+ x: '50%',
82
+ y: "70%",
83
+ children: filetype.toUpperCase()
84
+ })]
85
+ }));
86
+ });
87
+ export default FileTypeIcon;
@@ -16,6 +16,7 @@ export interface MarkdownProps extends TypographyProps {
16
16
  video?: Partial<VideoProps>;
17
17
  };
18
18
  enableImageGallery?: boolean;
19
+ enableLatex?: boolean;
19
20
  fullFeaturedCodeBlock?: boolean;
20
21
  onDoubleClick?: () => void;
21
22
  style?: CSSProperties;
@@ -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", "enableImageGallery", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "variant", "lineHeight"];
5
+ var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableLatex", "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';
@@ -17,6 +17,7 @@ import Video from "../mdx/Video";
17
17
  import { CodeFullFeatured, CodeLite } from "./CodeBlock";
18
18
  import { useStyles as useMarkdownStyles } from "./markdown.style";
19
19
  import { useStyles } from "./style";
20
+ import { escapeBrackets, escapeDollarNumber, escapeMhchem } from "./utils";
20
21
  import { jsx as _jsx } from "react/jsx-runtime";
21
22
  var Markdown = /*#__PURE__*/memo(function (_ref) {
22
23
  var children = _ref.children,
@@ -24,6 +25,8 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
24
25
  style = _ref.style,
25
26
  fullFeaturedCodeBlock = _ref.fullFeaturedCodeBlock,
26
27
  onDoubleClick = _ref.onDoubleClick,
28
+ _ref$enableLatex = _ref.enableLatex,
29
+ enableLatex = _ref$enableLatex === void 0 ? true : _ref$enableLatex,
27
30
  _ref$enableImageGalle = _ref.enableImageGallery,
28
31
  enableImageGallery = _ref$enableImageGalle === void 0 ? true : _ref$enableImageGalle,
29
32
  componentProps = _ref.componentProps,
@@ -50,6 +53,10 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
50
53
  }),
51
54
  mdStyles = _useMarkdownStyles.styles;
52
55
  var isChatMode = variant === 'chat';
56
+ var escapedContent = useMemo(function () {
57
+ if (!enableLatex) return children;
58
+ return escapeMhchem(escapeBrackets(escapeDollarNumber(children)));
59
+ }, [children, enableLatex]);
53
60
  var components = useMemo(function () {
54
61
  return {
55
62
  a: function a(props) {
@@ -73,10 +80,10 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
73
80
  };
74
81
  }, [componentProps, enableImageGallery, fullFeaturedCodeBlock]);
75
82
  var rehypePlugins = useMemo(function () {
76
- return [allowHtml && rehypeRaw, rehypeKatex].filter(Boolean);
83
+ return [allowHtml && rehypeRaw, enableLatex && rehypeKatex].filter(Boolean);
77
84
  }, [allowHtml]);
78
85
  var remarkPlugins = useMemo(function () {
79
- return [remarkGfm, remarkMath, isChatMode && remarkBreaks].filter(Boolean);
86
+ return [remarkGfm, enableLatex && remarkMath, isChatMode && remarkBreaks].filter(Boolean);
80
87
  }, [isChatMode]);
81
88
  return /*#__PURE__*/_jsx("article", {
82
89
  className: cx(styles.root, className),
@@ -91,7 +98,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
91
98
  rehypePlugins: rehypePlugins,
92
99
  remarkPlugins: remarkPlugins
93
100
  }, rest), {}, {
94
- children: children
101
+ children: escapedContent
95
102
  }))
96
103
  })
97
104
  });
@@ -0,0 +1,3 @@
1
+ export declare function escapeDollarNumber(text: string): string;
2
+ export declare function escapeBrackets(text: string): string;
3
+ export declare function escapeMhchem(text: string): string;
@@ -0,0 +1,28 @@
1
+ export function escapeDollarNumber(text) {
2
+ var escapedText = '';
3
+ for (var i = 0; i < text.length; i += 1) {
4
+ var char = text[i];
5
+ var nextChar = text[i + 1] || ' ';
6
+ if (char === '$' && nextChar >= '0' && nextChar <= '9') {
7
+ char = '\\$';
8
+ }
9
+ escapedText += char;
10
+ }
11
+ return escapedText;
12
+ }
13
+ export function escapeBrackets(text) {
14
+ var pattern = /(```[\S\s]*?```|`.*?`)|\\\[([\S\s]*?[^\\])\\]|\\\((.*?)\\\)/g;
15
+ return text.replaceAll(pattern, function (match, codeBlock, squareBracket, roundBracket) {
16
+ if (codeBlock) {
17
+ return codeBlock;
18
+ } else if (squareBracket) {
19
+ return "$$".concat(squareBracket, "$$");
20
+ } else if (roundBracket) {
21
+ return "$".concat(roundBracket, "$");
22
+ }
23
+ return match;
24
+ });
25
+ }
26
+ export function escapeMhchem(text) {
27
+ return text.replaceAll('$\\ce{', '$\\\\ce{').replaceAll('$\\pu{', '$\\\\pu{');
28
+ }