@lobehub/ui 1.165.8 → 1.166.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.
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const Controls: import("react").MemoExoticComponent<() => import("react/jsx-runtime").JSX.Element>;
3
+ export default Controls;
@@ -0,0 +1,49 @@
1
+ import { AlignVerticalSpaceAroundIcon, MinusIcon, PlusIcon } from 'lucide-react';
2
+ import { memo } from 'react';
3
+ import { Flexbox } from 'react-layout-kit';
4
+ import { useControls } from 'react-zoom-pan-pinch';
5
+ import ActionIcon from "../ActionIcon";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "react/jsx-runtime";
8
+ var Controls = /*#__PURE__*/memo(function () {
9
+ var _useControls = useControls(),
10
+ zoomIn = _useControls.zoomIn,
11
+ zoomOut = _useControls.zoomOut,
12
+ resetTransform = _useControls.resetTransform;
13
+ return /*#__PURE__*/_jsxs(Flexbox, {
14
+ gap: 4,
15
+ horizontal: true,
16
+ style: {
17
+ bottom: 8,
18
+ position: 'absolute',
19
+ right: 8,
20
+ zIndex: 1
21
+ },
22
+ children: [/*#__PURE__*/_jsx(ActionIcon, {
23
+ active: true,
24
+ glass: true,
25
+ icon: PlusIcon,
26
+ onClick: function onClick() {
27
+ return zoomIn();
28
+ },
29
+ size: 'small'
30
+ }), /*#__PURE__*/_jsx(ActionIcon, {
31
+ active: true,
32
+ glass: true,
33
+ icon: MinusIcon,
34
+ onClick: function onClick() {
35
+ return zoomOut();
36
+ },
37
+ size: 'small'
38
+ }), /*#__PURE__*/_jsx(ActionIcon, {
39
+ active: true,
40
+ glass: true,
41
+ icon: AlignVerticalSpaceAroundIcon,
42
+ onClick: function onClick() {
43
+ return resetTransform();
44
+ },
45
+ size: 'small'
46
+ })]
47
+ });
48
+ });
49
+ export default Controls;
@@ -1,7 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { MermaidProps } from './type';
3
- export declare const MermaidFullFeatured: import("react").NamedExoticComponent<Omit<MermaidProps, "children"> & {
3
+ export interface MermaidFullFeaturedProps extends Omit<MermaidProps, 'children'> {
4
4
  children: ReactNode;
5
5
  content: string;
6
- }>;
6
+ }
7
+ export declare const MermaidFullFeatured: import("react").NamedExoticComponent<MermaidFullFeaturedProps>;
7
8
  export default MermaidFullFeatured;
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["showLanguage", "content", "children", "className", "copyable", "actionsRender", "style"];
2
+ var _excluded = ["showLanguage", "content", "children", "className", "copyable", "actionsRender", "style", "fileName"];
3
3
  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; }
4
4
  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; }
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -29,6 +29,8 @@ export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
29
29
  copyable = _ref.copyable,
30
30
  actionsRender = _ref.actionsRender,
31
31
  style = _ref.style,
32
+ _ref$fileName = _ref.fileName,
33
+ fileName = _ref$fileName === void 0 ? 'Mermaid' : _ref$fileName,
32
34
  rest = _objectWithoutProperties(_ref, _excluded);
33
35
  var _useState = useState(true),
34
36
  _useState2 = _slicedToArray(_useState, 2),
@@ -79,9 +81,7 @@ export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
79
81
  gap: 2,
80
82
  horizontal: true,
81
83
  justify: 'center',
82
- children: /*#__PURE__*/_jsx("span", {
83
- children: "mermaid"
84
- })
84
+ children: fileName
85
85
  }), /*#__PURE__*/_jsx(Flexbox, {
86
86
  align: 'center',
87
87
  flex: 'none',
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["children", "copyButtonSize", "fullFeatured", "copyable", "showLanguage", "style", "type", "className", "bodyRender", "actionsRender"];
2
+ var _excluded = ["children", "copyButtonSize", "fullFeatured", "copyable", "showLanguage", "style", "type", "enablePanZoom", "className", "bodyRender", "actionsRender"];
3
3
  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; }
4
4
  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; }
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -28,6 +28,7 @@ var Mermaid = /*#__PURE__*/memo(function (_ref) {
28
28
  style = _ref.style,
29
29
  _ref$type = _ref.type,
30
30
  type = _ref$type === void 0 ? 'block' : _ref$type,
31
+ enablePanZoom = _ref.enablePanZoom,
31
32
  className = _ref.className,
32
33
  bodyRender = _ref.bodyRender,
33
34
  actionsRender = _ref.actionsRender,
@@ -36,7 +37,9 @@ var Mermaid = /*#__PURE__*/memo(function (_ref) {
36
37
  cx = _useStyles.cx,
37
38
  styles = _useStyles.styles;
38
39
  var tirmedChildren = children.trim();
39
- var MermaidRender = useMermaid(tirmedChildren);
40
+ var MermaidRender = useMermaid(tirmedChildren, {
41
+ enablePanZoom: fullFeatured ? true : enablePanZoom
42
+ });
40
43
  var originalActions = copyable && /*#__PURE__*/_jsx(CopyButton, {
41
44
  content: children,
42
45
  placement: "left",
@@ -58,6 +61,7 @@ var Mermaid = /*#__PURE__*/memo(function (_ref) {
58
61
  className: className,
59
62
  content: tirmedChildren,
60
63
  copyable: copyable,
64
+ enablePanZoom: enablePanZoom,
61
65
  showLanguage: showLanguage,
62
66
  style: style,
63
67
  type: type
@@ -76,9 +80,9 @@ var Mermaid = /*#__PURE__*/memo(function (_ref) {
76
80
  gap: 4,
77
81
  horizontal: true,
78
82
  children: actions
79
- }), showLanguage && /*#__PURE__*/_jsx(Tag, {
83
+ }), !enablePanZoom && showLanguage && /*#__PURE__*/_jsx(Tag, {
80
84
  className: styles.lang,
81
- children: "mermaid"
85
+ children: "Mermaid"
82
86
  }), /*#__PURE__*/_jsx("div", {
83
87
  className: styles.scroller,
84
88
  children: body
@@ -15,6 +15,8 @@ export interface MermaidProps extends DivProps {
15
15
  children: string;
16
16
  copyButtonSize?: CopyButtonProps['size'];
17
17
  copyable?: boolean;
18
+ enablePanZoom?: boolean;
19
+ fileName?: string;
18
20
  fullFeatured?: boolean;
19
21
  showLanguage?: boolean;
20
22
  type?: 'ghost' | 'block' | 'pure';
@@ -1 +1,3 @@
1
- export declare const useMermaid: (content: string) => () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const useMermaid: (content: string, { enablePanZoom }?: {
2
+ enablePanZoom?: boolean | undefined;
3
+ }) => () => import("react/jsx-runtime").JSX.Element;
@@ -11,8 +11,14 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import { useTheme } from 'antd-style';
12
12
  import mermaid from 'mermaid';
13
13
  import { useCallback, useEffect, useState } from 'react';
14
+ import { Center } from 'react-layout-kit';
15
+ import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
16
+ import Controls from "./Controls";
14
17
  import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "react/jsx-runtime";
15
19
  export var useMermaid = function useMermaid(content) {
20
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
21
+ enablePanZoom = _ref.enablePanZoom;
16
22
  var _useState = useState(),
17
23
  _useState2 = _slicedToArray(_useState, 2),
18
24
  mermaidContent = _useState2[0],
@@ -26,23 +32,36 @@ export var useMermaid = function useMermaid(content) {
26
32
  },
27
33
  securityLevel: 'loose',
28
34
  startOnLoad: true,
29
- theme: theme.isDarkMode ? 'dark' : 'default',
35
+ theme: theme.isDarkMode ? 'dark' : 'neutral',
30
36
  themeVariables: {
31
- errorBkgColor: theme.colorError,
32
- errorTextColor: theme.colorText,
37
+ errorBkgColor: theme.colorTextDescription,
38
+ errorTextColor: theme.colorTextDescription,
39
+ fontFamily: theme.fontFamily,
33
40
  fontSize: 14,
34
- lineColor: theme.colorText,
35
- primaryBorderColor: theme.colorPrimaryBorder,
36
- primaryColor: theme.colorPrimaryBg,
41
+ lineColor: theme.colorTextSecondary,
42
+ mainBkg: theme.colorBgContainer,
43
+ noteBkgColor: theme.colorInfoBg,
44
+ noteTextColor: theme.colorInfoText,
45
+ pie1: theme.geekblue,
46
+ pie2: theme.colorWarning,
47
+ pie3: theme.colorSuccess,
48
+ pie4: theme.colorError,
49
+ primaryBorderColor: theme.colorBorder,
50
+ primaryColor: theme.colorBgContainer,
37
51
  primaryTextColor: theme.colorText,
38
- secondaryColor: theme.colorInfo,
39
- tertiaryColor: theme.colorSuccess
52
+ secondaryBorderColor: theme.colorInfoBorder,
53
+ secondaryColor: theme.colorInfoBg,
54
+ secondaryTextColor: theme.colorInfoText,
55
+ tertiaryBorderColor: theme.colorSuccessBorder,
56
+ tertiaryColor: theme.colorSuccessBg,
57
+ tertiaryTextColor: theme.colorSuccessText,
58
+ textColor: theme.colorText
40
59
  }
41
60
  });
42
61
  mermaid.contentLoaded();
43
62
  }, [mermaidContent, theme.isDarkMode]);
44
63
  var checkSyntax = /*#__PURE__*/function () {
45
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(textStr) {
64
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(textStr) {
46
65
  return _regeneratorRuntime().wrap(function _callee$(_context) {
47
66
  while (1) switch (_context.prev = _context.next) {
48
67
  case 0:
@@ -68,23 +87,33 @@ export var useMermaid = function useMermaid(content) {
68
87
  }, _callee, null, [[0, 7]]);
69
88
  }));
70
89
  return function checkSyntax(_x) {
71
- return _ref.apply(this, arguments);
90
+ return _ref2.apply(this, arguments);
72
91
  };
73
92
  }();
74
93
  useEffect(function () {
75
94
  checkSyntax(content);
76
95
  }, [content]);
77
96
  return useCallback(function () {
78
- return /*#__PURE__*/_jsx("pre", {
97
+ if (enablePanZoom) {
98
+ return /*#__PURE__*/_jsxs(TransformWrapper, {
99
+ children: [/*#__PURE__*/_jsx(Controls, {}), /*#__PURE__*/_jsx(TransformComponent, {
100
+ contentClass: 'mermaid',
101
+ contentStyle: {
102
+ padding: 16
103
+ },
104
+ wrapperStyle: {
105
+ minHeight: 240,
106
+ width: '100%'
107
+ },
108
+ children: mermaidContent
109
+ })]
110
+ });
111
+ }
112
+ return /*#__PURE__*/_jsx(Center, {
113
+ as: 'pre',
79
114
  className: 'mermaid',
80
- style: {
81
- alignItems: 'center',
82
- display: 'flex',
83
- fontSize: 14,
84
- justifyContent: 'center',
85
- overflow: 'auto'
86
- },
115
+ padding: 16,
87
116
  children: mermaidContent
88
117
  });
89
- }, [mermaidContent, theme.isDarkMode]);
118
+ }, [mermaidContent, theme.isDarkMode, enablePanZoom]);
90
119
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.165.8",
3
+ "version": "1.166.1",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -84,6 +84,7 @@
84
84
  "react-markdown": "^9.1.0",
85
85
  "react-merge-refs": "^2.1.1",
86
86
  "react-rnd": "^10.5.2",
87
+ "react-zoom-pan-pinch": "^3.7.0",
87
88
  "rehype-katex": "^7.0.1",
88
89
  "rehype-raw": "^7.0.0",
89
90
  "remark-breaks": "^4.0.0",