@lobehub/ui 1.170.0 → 1.170.2

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.
@@ -60,6 +60,7 @@ export interface ActionIconProps extends LucideIconProps, FlexboxProps {
60
60
  * @default 0.5
61
61
  */
62
62
  tooltipDelay?: number;
63
+ variant?: 'default' | 'block' | 'ghost';
63
64
  }
64
65
  declare const ActionIcon: import("react").ForwardRefExoticComponent<ActionIconProps & import("react").RefAttributes<HTMLDivElement>>;
65
66
  export default ActionIcon;
@@ -1,7 +1,7 @@
1
1
  'use client';
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
- var _excluded = ["color", "fill", "className", "active", "icon", "size", "style", "glass", "title", "placement", "arrow", "spotlight", "onClick", "children", "loading", "tooltipDelay", "fillOpacity", "fillRule", "focusable", "disable", "spin", "styles"];
4
+ var _excluded = ["color", "fill", "className", "active", "icon", "size", "variant", "style", "glass", "title", "placement", "arrow", "spotlight", "onClick", "children", "loading", "tooltipDelay", "fillOpacity", "fillRule", "focusable", "disable", "spin", "styles"];
5
5
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
6
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
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); }
@@ -33,6 +33,8 @@ var ActionIcon = /*#__PURE__*/forwardRef(function (_ref, ref) {
33
33
  icon = _ref.icon,
34
34
  _ref$size = _ref.size,
35
35
  size = _ref$size === void 0 ? 'normal' : _ref$size,
36
+ _ref$variant = _ref.variant,
37
+ variant = _ref$variant === void 0 ? 'default' : _ref$variant,
36
38
  style = _ref.style,
37
39
  glass = _ref.glass,
38
40
  title = _ref.title,
@@ -54,7 +56,8 @@ var ActionIcon = /*#__PURE__*/forwardRef(function (_ref, ref) {
54
56
  rest = _objectWithoutProperties(_ref, _excluded);
55
57
  var _useStyles = useStyles({
56
58
  active: Boolean(active),
57
- glass: Boolean(glass)
59
+ glass: Boolean(glass),
60
+ variant: variant
58
61
  }),
59
62
  s = _useStyles.styles,
60
63
  cx = _useStyles.cx;
@@ -1,6 +1,7 @@
1
1
  export declare const useStyles: (props?: {
2
2
  active: boolean;
3
3
  glass: boolean;
4
+ variant: 'default' | 'block' | 'ghost';
4
5
  } | undefined) => import("antd-style").ReturnStyles<{
5
6
  block: string;
6
7
  disabled: import("antd-style").SerializedStyles;
@@ -1,4 +1,4 @@
1
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref, _ref2) {
@@ -7,11 +7,14 @@ export var useStyles = createStyles(function (_ref, _ref2) {
7
7
  stylish = _ref.stylish,
8
8
  cx = _ref.cx;
9
9
  var active = _ref2.active,
10
- glass = _ref2.glass;
10
+ glass = _ref2.glass,
11
+ variant = _ref2.variant;
12
+ var isBlock = variant === 'block';
13
+ var isGhost = variant === 'ghost';
11
14
  return {
12
- block: cx(glass && stylish.blur, css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n flex: none;\n\n color: ", ";\n\n background: ", ";\n\n transition:\n color 600ms ", ",\n scale 400ms ", ",\n background-color 100ms ", ";\n "])), active ? token.colorText : token.colorTextTertiary, active ? token.colorFillTertiary : 'transparent', token.motionEaseOut, token.motionEaseOut, token.motionEaseOut)),
13
- disabled: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: not-allowed;\n opacity: 0.5;\n "]))),
14
- icon: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n transition: scale 400ms ", ";\n\n &:active {\n scale: 0.8;\n }\n "])), token.motionEaseOut),
15
- normal: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n cursor: pointer;\n\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n\n &:active {\n color: ", ";\n background-color: ", ";\n }\n "])), token.colorText, token.colorFillSecondary, token.colorText, token.colorFill)
15
+ block: cx(glass && stylish.blur, isGhost && css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n border: 1px solid ", ";\n "])), token.colorBorderSecondary), css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: relative;\n\n flex: none;\n\n color: ", ";\n\n background: ", ";\n\n transition:\n color 600ms ", ",\n scale 400ms ", ",\n background-color 100ms ", ";\n "])), active ? token.colorText : token.colorTextTertiary, active || isBlock ? token.colorFillTertiary : 'transparent', token.motionEaseOut, token.motionEaseOut, token.motionEaseOut)),
16
+ disabled: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n cursor: not-allowed;\n opacity: 0.5;\n "]))),
17
+ icon: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n transition: scale 400ms ", ";\n\n &:active {\n scale: 0.8;\n }\n "])), token.motionEaseOut),
18
+ normal: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n cursor: pointer;\n\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n\n &:active {\n color: ", ";\n background-color: ", ";\n }\n "])), token.colorText, token.colorFillSecondary, token.colorText, token.colorFill)
16
19
  };
17
20
  });
@@ -12,7 +12,7 @@ export interface ColorSwatchesProps extends Omit<FlexboxProps, 'onChange'> {
12
12
  onChange?: (color?: string) => void;
13
13
  shape?: 'circle' | 'square';
14
14
  size?: number;
15
- texts: {
15
+ texts?: {
16
16
  custom: string;
17
17
  presets: string;
18
18
  };
@@ -28,7 +28,7 @@ export var useStyles = createStyles(function (_ref) {
28
28
  blockStyle: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background: ", ";\n border: none;\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.borderRadiusLG),
29
29
  defaultStyle: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n background: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.colorBorderSecondary, token.borderRadiusLG),
30
30
  flatGroup: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: hidden;\n padding-inline: 16px;\n "]))),
31
- ghostStyle: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n background: transparent;\n border: 1px solid ", ";\n "])), token.colorBorderSecondary),
31
+ ghostStyle: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n background: transparent;\n border: 1px solid ", ";\n border-radius: ", "px;\n "])), token.colorBorderSecondary, token.borderRadiusLG),
32
32
  icon: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n transition: all 100ms ", ";\n "])), token.motionEaseOut),
33
33
  mobileFlatGroup: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n border-radius: 0;\n "]))),
34
34
  mobileGroupBody: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n padding-block: 0;\n padding-inline: 16px;\n background: ", ";\n "])), token.colorBgContainer),
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { FormItemProps as AntdFormItemProps } from 'antd';
3
+ import { FormVariant } from "./FormGroup";
3
4
  import { type FormTitleProps } from './FormTitle';
4
5
  export declare const useStyles: (props?: {
5
6
  minWidth?: string | number | undefined;
@@ -16,6 +17,7 @@ export interface FormItemProps extends AntdFormItemProps {
16
17
  hidden?: boolean;
17
18
  minWidth?: string | number;
18
19
  tag?: FormTitleProps['tag'];
20
+ variant?: FormVariant;
19
21
  }
20
22
  declare const FormItem: import("react").NamedExoticComponent<FormItemProps>;
21
23
  export default FormItem;
@@ -1,7 +1,7 @@
1
1
  'use client';
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
- var _excluded = ["desc", "tag", "minWidth", "avatar", "className", "label", "children", "divider", "layout"];
4
+ var _excluded = ["desc", "tag", "minWidth", "avatar", "className", "label", "children", "divider", "layout", "variant"];
5
5
  var _templateObject, _templateObject2, _templateObject3, _templateObject4;
6
6
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
7
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -43,6 +43,7 @@ var FormItem = /*#__PURE__*/memo(function (_ref3) {
43
43
  children = _ref3.children,
44
44
  divider = _ref3.divider,
45
45
  layout = _ref3.layout,
46
+ variant = _ref3.variant,
46
47
  rest = _objectWithoutProperties(_ref3, _excluded);
47
48
  var _useStyles = useStyles({
48
49
  minWidth: minWidth
@@ -51,7 +52,11 @@ var FormItem = /*#__PURE__*/memo(function (_ref3) {
51
52
  styles = _useStyles.styles;
52
53
  var isVertical = layout === 'vertical';
53
54
  return /*#__PURE__*/_jsxs(_Fragment, {
54
- children: [divider && /*#__PURE__*/_jsx(FormDivider, {}), /*#__PURE__*/_jsx(Item, _objectSpread(_objectSpread({
55
+ children: [divider && /*#__PURE__*/_jsx(FormDivider, {
56
+ style: {
57
+ opacity: variant === 'pure' ? 0 : undefined
58
+ }
59
+ }), /*#__PURE__*/_jsx(Item, _objectSpread(_objectSpread({
55
60
  className: cx(styles.item, Boolean(minWidth) && styles.itemMinWidth, !divider && styles.itemNoDivider, isVertical && styles.verticalLayout, className),
56
61
  label: /*#__PURE__*/_jsx(FormTitle, {
57
62
  avatar: avatar,
@@ -73,19 +73,20 @@ var FormSubmitFooter = /*#__PURE__*/memo(function (_ref2) {
73
73
  var v = merge({}, initialValues, values);
74
74
  setHasUnsavedChanges(!isEqual(v, initialValues));
75
75
  }, [values, initialValues, submitLoading]);
76
+ var fn = function fn(e) {
77
+ if (hasUnsavedChanges) {
78
+ e.returnValue = (texts === null || texts === void 0 ? void 0 : texts.unSavedWarning) || 'You have unsaved changes. Are you sure you want to leave?';
79
+ } else {
80
+ delete e.returnValue;
81
+ }
82
+ };
76
83
  useEffect(function () {
77
84
  if (!enableUnsavedWarning) return;
78
85
  if (typeof window === 'undefined' || !hasUnsavedChanges) return;
79
86
  // 添加离开页面的提示
80
- window.addEventListener('beforeunload', function (e) {
81
- if (hasUnsavedChanges) {
82
- e.preventDefault();
83
- e.returnValue = (texts === null || texts === void 0 ? void 0 : texts.unSavedWarning) || 'You have unsaved changes. Are you sure you want to leave?';
84
- }
85
- });
87
+ window.addEventListener('beforeunload', fn);
86
88
  return function () {
87
- // eslint-disable-next-line unicorn/no-invalid-remove-event-listener
88
- window.removeEventListener('beforeunload', function () {});
89
+ return window.removeEventListener('beforeunload', fn);
89
90
  };
90
91
  }, [enableUnsavedWarning, hasUnsavedChanges]);
91
92
  var content = /*#__PURE__*/_jsxs(_Fragment, {
package/es/Form/index.js CHANGED
@@ -64,7 +64,8 @@ var FormParent = /*#__PURE__*/forwardRef(function (_ref, ref) {
64
64
  var mapFlat = function mapFlat(item, itemIndex) {
65
65
  return /*#__PURE__*/_jsx(FormItem, _objectSpread({
66
66
  divider: itemIndex !== 0,
67
- minWidth: itemMinWidth
67
+ minWidth: itemMinWidth,
68
+ variant: variant
68
69
  }, item), itemIndex);
69
70
  };
70
71
  var mapTree = function mapTree(group, groupIndex) {
@@ -3,7 +3,7 @@ import { Loader2 } from 'lucide-react';
3
3
  import { memo, useId } from 'react';
4
4
  import { Center, Flexbox } from 'react-layout-kit';
5
5
  import Icon from "../../Icon";
6
- import { useMermaid, useMermaidInit } from "../../hooks/useMermaid";
6
+ import { useMermaid } from "../../hooks/useMermaid";
7
7
  import { useStyles } from "./style";
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -15,7 +15,6 @@ var MermaidContainer = /*#__PURE__*/memo(function (_ref) {
15
15
  styles = _useStyles.styles;
16
16
  var id = useId();
17
17
  var mermaidId = kebabCase("mermaid-".concat(id));
18
- useMermaidInit();
19
18
  var _useMermaid = useMermaid(mermaidId, children),
20
19
  data = _useMermaid.data,
21
20
  isLoading = _useMermaid.isLoading;
@@ -4,5 +4,5 @@ import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref) {
5
5
  var css = _ref.css,
6
6
  token = _ref.token;
7
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 64px;\n height: 100%;\n min-height: 640px;\n padding-block: 16px;\n padding-inline: 0;\n\n background: ", ";\n border-inline-end: 1px solid ", ";\n "])), token.colorBgContainer, token.colorBorder);
7
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 64px;\n height: 100%;\n min-height: 640px;\n padding-block: 16px;\n padding-inline: 0;\n\n background: ", ";\n border-inline-end: 1px solid ", ";\n "])), token.colorBgContainer, token.colorBorderSecondary);
8
8
  });
@@ -1,10 +1,9 @@
1
1
  import { SWRResponse } from 'swr';
2
2
  export declare const FALLBACK_LANG = "txt";
3
- declare const highlightCache: Map<string, string>;
4
3
  declare const MD5_LENGTH_THRESHOLD = 10000;
5
4
  declare const loadShiki: () => Promise<(code: string, options: import("@shikijs/types").CodeToHastOptions<import("shiki/dist/langs.mjs").BundledLanguage, import("shiki/dist/themes.mjs").BundledTheme>) => Promise<string>>;
6
5
  declare const shikiPromise: Promise<(code: string, options: import("@shikijs/types").CodeToHastOptions<import("shiki/dist/langs.mjs").BundledLanguage, import("shiki/dist/themes.mjs").BundledTheme>) => Promise<string>>;
7
6
  declare const escapeHtml: (str: string) => string;
8
7
  export declare const useHighlight: (text: string, lang: string, enableTransformer?: boolean) => SWRResponse<string, Error>;
9
8
  export { default as languageMap } from './languageMap';
10
- export { escapeHtml, highlightCache, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };
9
+ export { escapeHtml, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };
@@ -11,7 +11,6 @@ import languageMap from "./languageMap";
11
11
  export var FALLBACK_LANG = 'txt';
12
12
 
13
13
  // 应用级缓存,避免重复计算
14
- var highlightCache = new Map();
15
14
  var MD5_LENGTH_THRESHOLD = 10000; // 超过该长度使用异步MD5
16
15
 
17
16
  // 颜色替换映射类型
@@ -88,59 +87,49 @@ export var useHighlight = function useHighlight(text, lang, enableTransformer) {
88
87
  return _regeneratorRuntime().wrap(function _callee$(_context) {
89
88
  while (1) switch (_context.prev = _context.next) {
90
89
  case 0:
91
- if (!(cacheKey && highlightCache.has(cacheKey))) {
92
- _context.next = 2;
93
- break;
94
- }
95
- return _context.abrupt("return", highlightCache.get(cacheKey));
96
- case 2:
97
- _context.prev = 2;
98
- _context.next = 5;
90
+ _context.prev = 0;
91
+ _context.next = 3;
99
92
  return shikiPromise;
100
- case 5:
93
+ case 3:
101
94
  codeToHtml = _context.sent;
102
- _context.next = 8;
95
+ _context.next = 6;
103
96
  return codeToHtml(text, {
104
97
  colorReplacements: colorReplacements,
105
98
  lang: matchedLanguage,
106
99
  theme: isDarkMode ? 'slack-dark' : 'slack-ochin',
107
100
  transformers: transformers
108
101
  });
109
- case 8:
102
+ case 6:
110
103
  html = _context.sent;
111
- // 缓存结果
112
- if (cacheKey) highlightCache.set(cacheKey, html);
113
104
  return _context.abrupt("return", html);
114
- case 13:
115
- _context.prev = 13;
116
- _context.t0 = _context["catch"](2);
105
+ case 10:
106
+ _context.prev = 10;
107
+ _context.t0 = _context["catch"](0);
117
108
  console.error('高级渲染失败:', _context.t0);
118
- _context.prev = 16;
119
- _context.next = 19;
109
+ _context.prev = 13;
110
+ _context.next = 16;
120
111
  return shikiPromise;
121
- case 19:
112
+ case 16:
122
113
  _codeToHtml = _context.sent;
123
- _context.next = 22;
114
+ _context.next = 19;
124
115
  return _codeToHtml(text, {
125
116
  lang: matchedLanguage,
126
117
  theme: isDarkMode ? 'dark-plus' : 'light-plus'
127
118
  });
128
- case 22:
119
+ case 19:
129
120
  _html = _context.sent;
130
- if (cacheKey) highlightCache.set(cacheKey, _html);
131
121
  return _context.abrupt("return", _html);
132
- case 27:
133
- _context.prev = 27;
134
- _context.t1 = _context["catch"](16);
122
+ case 23:
123
+ _context.prev = 23;
124
+ _context.t1 = _context["catch"](13);
135
125
  // 最终降级到纯文本
136
126
  fallbackHtml = "<pre class=\"fallback\"><code>".concat(escapeHtml(text), "</code></pre>");
137
- if (cacheKey) highlightCache.set(cacheKey, fallbackHtml);
138
127
  return _context.abrupt("return", fallbackHtml);
139
- case 32:
128
+ case 27:
140
129
  case "end":
141
130
  return _context.stop();
142
131
  }
143
- }, _callee, null, [[2, 13], [16, 27]]);
132
+ }, _callee, null, [[0, 10], [13, 23]]);
144
133
  })), {
145
134
  dedupingInterval: 3000,
146
135
  // 3秒内相同请求只执行一次
@@ -151,4 +140,4 @@ export var useHighlight = function useHighlight(text, lang, enableTransformer) {
151
140
  });
152
141
  };
153
142
  export { default as languageMap } from "./languageMap";
154
- export { escapeHtml, highlightCache, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };
143
+ export { escapeHtml, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };
@@ -3,7 +3,3 @@ import { SWRResponse } from 'swr';
3
3
  * 验证并处理 Mermaid 图表内容
4
4
  */
5
5
  export declare const useMermaid: (id: string, content: string) => SWRResponse<string, Error>;
6
- /**
7
- * 初始化 Mermaid 配置
8
- */
9
- export declare const useMermaidInit: () => void;
@@ -9,12 +9,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import { useTheme } from 'antd-style';
12
- import { useEffect, useMemo, useState } from 'react';
12
+ import { useMemo, useState } from 'react';
13
13
  import useSWR from 'swr';
14
14
  import { Md5 } from 'ts-md5';
15
15
 
16
16
  // 缓存已验证的图表内容
17
- var mermaidCache = new Map();
18
17
  var MD5_LENGTH_THRESHOLD = 10000;
19
18
 
20
19
  // 懒加载 mermaid 实例
@@ -30,152 +29,109 @@ var mermaidPromise = loadMermaid();
30
29
  * 验证并处理 Mermaid 图表内容
31
30
  */
32
31
  export var useMermaid = function useMermaid(id, content) {
32
+ var theme = useTheme();
33
33
  // 用于存储最近一次有效的内容
34
34
  var _useState = useState(''),
35
35
  _useState2 = _slicedToArray(_useState, 2),
36
36
  validContent = _useState2[0],
37
37
  setValidContent = _useState2[1];
38
38
 
39
+ // 提取主题相关配置到 useMemo 中
40
+ var mermaidConfig = useMemo(function () {
41
+ return {
42
+ fontFamily: theme.fontFamilyCode,
43
+ gantt: {
44
+ useWidth: 1920
45
+ },
46
+ securityLevel: 'loose',
47
+ startOnLoad: false,
48
+ theme: theme.isDarkMode ? 'dark' : 'neutral',
49
+ themeVariables: {
50
+ errorBkgColor: theme.colorTextDescription,
51
+ errorTextColor: theme.colorTextDescription,
52
+ fontFamily: theme.fontFamily,
53
+ fontSize: 14,
54
+ lineColor: theme.colorTextSecondary,
55
+ mainBkg: theme.colorBgContainer,
56
+ noteBkgColor: theme.colorInfoBg,
57
+ noteTextColor: theme.colorInfoText,
58
+ pie1: theme.geekblue,
59
+ pie2: theme.colorWarning,
60
+ pie3: theme.colorSuccess,
61
+ pie4: theme.colorError,
62
+ primaryBorderColor: theme.colorBorder,
63
+ primaryColor: theme.colorBgContainer,
64
+ primaryTextColor: theme.colorText,
65
+ secondaryBorderColor: theme.colorInfoBorder,
66
+ secondaryColor: theme.colorInfoBg,
67
+ secondaryTextColor: theme.colorInfoText,
68
+ tertiaryBorderColor: theme.colorSuccessBorder,
69
+ tertiaryColor: theme.colorSuccessBg,
70
+ tertiaryTextColor: theme.colorSuccessText,
71
+ textColor: theme.colorText
72
+ }
73
+ };
74
+ }, [theme.isDarkMode]);
75
+
39
76
  // 为长内容生成哈希键
40
77
  var cacheKey = useMemo(function () {
41
78
  var hash = content.length < MD5_LENGTH_THRESHOLD ? content : Md5.hashStr(content);
42
- return "mermaid-".concat(id, "-").concat(hash);
43
- }, [content, id]);
79
+ return "".concat(id, "-").concat(theme.isDarkMode ? 'd' : 'l', "-").concat(hash);
80
+ }, [content, id, theme.isDarkMode]);
44
81
  return useSWR(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
45
82
  var mermaidInstance, isValid, _yield$mermaidInstanc, svg;
46
83
  return _regeneratorRuntime().wrap(function _callee$(_context) {
47
84
  while (1) switch (_context.prev = _context.next) {
48
85
  case 0:
49
- if (!mermaidCache.has(cacheKey)) {
50
- _context.next = 2;
51
- break;
52
- }
53
- return _context.abrupt("return", validContent);
54
- case 2:
55
- _context.prev = 2;
56
- _context.next = 5;
86
+ _context.prev = 0;
87
+ _context.next = 3;
57
88
  return mermaidPromise;
58
- case 5:
89
+ case 3:
59
90
  mermaidInstance = _context.sent;
60
91
  if (mermaidInstance) {
61
- _context.next = 8;
92
+ _context.next = 6;
62
93
  break;
63
94
  }
64
95
  return _context.abrupt("return", content);
65
- case 8:
66
- _context.next = 10;
96
+ case 6:
97
+ _context.next = 8;
67
98
  return mermaidInstance.parse(content);
68
- case 10:
99
+ case 8:
69
100
  isValid = _context.sent;
70
101
  if (!isValid) {
71
- _context.next = 21;
102
+ _context.next = 19;
72
103
  break;
73
104
  }
74
- _context.next = 14;
105
+ // 更新有效内容状态
106
+ mermaidInstance.initialize(mermaidConfig);
107
+ _context.next = 13;
75
108
  return mermaidInstance.render(id, content);
76
- case 14:
109
+ case 13:
77
110
  _yield$mermaidInstanc = _context.sent;
78
111
  svg = _yield$mermaidInstanc.svg;
79
112
  setValidContent(svg);
80
113
  // 缓存验证结果
81
- mermaidCache.set(cacheKey, true);
82
114
  return _context.abrupt("return", svg);
83
- case 21:
115
+ case 19:
84
116
  throw new Error('Mermaid 语法无效');
85
- case 22:
86
- _context.next = 28;
117
+ case 20:
118
+ _context.next = 26;
87
119
  break;
88
- case 24:
89
- _context.prev = 24;
90
- _context.t0 = _context["catch"](2);
120
+ case 22:
121
+ _context.prev = 22;
122
+ _context.t0 = _context["catch"](0);
91
123
  console.error('Mermaid 解析错误:', _context.t0);
92
124
  // 返回最近一次有效的内容,或空字符串
93
125
  return _context.abrupt("return", validContent || '');
94
- case 28:
126
+ case 26:
95
127
  case "end":
96
128
  return _context.stop();
97
129
  }
98
- }, _callee, null, [[2, 24]]);
130
+ }, _callee, null, [[0, 22]]);
99
131
  })), {
100
132
  dedupingInterval: 3000,
101
133
  errorRetryCount: 2,
102
134
  revalidateOnFocus: false,
103
135
  revalidateOnReconnect: false
104
136
  });
105
- };
106
-
107
- /**
108
- * 初始化 Mermaid 配置
109
- */
110
- export var useMermaidInit = function useMermaidInit() {
111
- var theme = useTheme();
112
-
113
- // 提取主题相关配置到 useMemo 中
114
- var mermaidConfig = useMemo(function () {
115
- return {
116
- fontFamily: theme.fontFamilyCode,
117
- gantt: {
118
- useWidth: 1920
119
- },
120
- securityLevel: 'loose',
121
- startOnLoad: false,
122
- theme: theme.isDarkMode ? 'dark' : 'neutral',
123
- themeVariables: {
124
- errorBkgColor: theme.colorTextDescription,
125
- errorTextColor: theme.colorTextDescription,
126
- fontFamily: theme.fontFamily,
127
- fontSize: 14,
128
- lineColor: theme.colorTextSecondary,
129
- mainBkg: theme.colorBgContainer,
130
- noteBkgColor: theme.colorInfoBg,
131
- noteTextColor: theme.colorInfoText,
132
- pie1: theme.geekblue,
133
- pie2: theme.colorWarning,
134
- pie3: theme.colorSuccess,
135
- pie4: theme.colorError,
136
- primaryBorderColor: theme.colorBorder,
137
- primaryColor: theme.colorBgContainer,
138
- primaryTextColor: theme.colorText,
139
- secondaryBorderColor: theme.colorInfoBorder,
140
- secondaryColor: theme.colorInfoBg,
141
- secondaryTextColor: theme.colorInfoText,
142
- tertiaryBorderColor: theme.colorSuccessBorder,
143
- tertiaryColor: theme.colorSuccessBg,
144
- tertiaryTextColor: theme.colorSuccessText,
145
- textColor: theme.colorText
146
- }
147
- };
148
- }, [theme.isDarkMode]);
149
-
150
- // 初始化 mermaid 配置
151
- useEffect(function () {
152
- var initMermaid = /*#__PURE__*/function () {
153
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
154
- var mermaidInstance;
155
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
156
- while (1) switch (_context2.prev = _context2.next) {
157
- case 0:
158
- _context2.next = 2;
159
- return mermaidPromise;
160
- case 2:
161
- mermaidInstance = _context2.sent;
162
- if (mermaidInstance) {
163
- _context2.next = 5;
164
- break;
165
- }
166
- return _context2.abrupt("return");
167
- case 5:
168
- mermaidInstance.initialize(mermaidConfig);
169
- case 6:
170
- case "end":
171
- return _context2.stop();
172
- }
173
- }, _callee2);
174
- }));
175
- return function initMermaid() {
176
- return _ref2.apply(this, arguments);
177
- };
178
- }();
179
- initMermaid();
180
- }, [mermaidConfig]);
181
137
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.170.0",
3
+ "version": "1.170.2",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",