@lobehub/ui 1.168.20 → 1.168.21
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/hooks/useMermaid.js +10 -12
- package/package.json +1 -1
package/es/hooks/useMermaid.js
CHANGED
|
@@ -35,13 +35,12 @@ export var useMermaid = function useMermaid(id, content) {
|
|
|
35
35
|
_useState2 = _slicedToArray(_useState, 2),
|
|
36
36
|
validContent = _useState2[0],
|
|
37
37
|
setValidContent = _useState2[1];
|
|
38
|
-
console.log(id, content);
|
|
39
38
|
|
|
40
39
|
// 为长内容生成哈希键
|
|
41
40
|
var cacheKey = useMemo(function () {
|
|
42
41
|
var hash = content.length < MD5_LENGTH_THRESHOLD ? content : Md5.hashStr(content);
|
|
43
|
-
return "mermaid-".concat(hash);
|
|
44
|
-
}, [content]);
|
|
42
|
+
return "mermaid-".concat(id, "-").concat(hash);
|
|
43
|
+
}, [content, id]);
|
|
45
44
|
return useSWR(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
46
45
|
var mermaidInstance, isValid, _yield$mermaidInstanc, svg;
|
|
47
46
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -69,7 +68,7 @@ export var useMermaid = function useMermaid(id, content) {
|
|
|
69
68
|
case 10:
|
|
70
69
|
isValid = _context.sent;
|
|
71
70
|
if (!isValid) {
|
|
72
|
-
_context.next =
|
|
71
|
+
_context.next = 21;
|
|
73
72
|
break;
|
|
74
73
|
}
|
|
75
74
|
_context.next = 14;
|
|
@@ -77,27 +76,26 @@ export var useMermaid = function useMermaid(id, content) {
|
|
|
77
76
|
case 14:
|
|
78
77
|
_yield$mermaidInstanc = _context.sent;
|
|
79
78
|
svg = _yield$mermaidInstanc.svg;
|
|
80
|
-
console.log(svg);
|
|
81
79
|
setValidContent(svg);
|
|
82
80
|
// 缓存验证结果
|
|
83
81
|
mermaidCache.set(cacheKey, true);
|
|
84
82
|
return _context.abrupt("return", svg);
|
|
85
|
-
case
|
|
83
|
+
case 21:
|
|
86
84
|
throw new Error('Mermaid 语法无效');
|
|
87
|
-
case
|
|
88
|
-
_context.next =
|
|
85
|
+
case 22:
|
|
86
|
+
_context.next = 28;
|
|
89
87
|
break;
|
|
90
|
-
case
|
|
91
|
-
_context.prev =
|
|
88
|
+
case 24:
|
|
89
|
+
_context.prev = 24;
|
|
92
90
|
_context.t0 = _context["catch"](2);
|
|
93
91
|
console.error('Mermaid 解析错误:', _context.t0);
|
|
94
92
|
// 返回最近一次有效的内容,或空字符串
|
|
95
93
|
return _context.abrupt("return", validContent || '');
|
|
96
|
-
case
|
|
94
|
+
case 28:
|
|
97
95
|
case "end":
|
|
98
96
|
return _context.stop();
|
|
99
97
|
}
|
|
100
|
-
}, _callee, null, [[2,
|
|
98
|
+
}, _callee, null, [[2, 24]]);
|
|
101
99
|
})), {
|
|
102
100
|
dedupingInterval: 3000,
|
|
103
101
|
errorRetryCount: 2,
|