@lobehub/ui 1.105.0 → 1.106.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/ChatList/Item.js +4 -1
- package/es/hooks/useHighlight.d.ts +2 -2
- package/es/hooks/useHighlight.js +24 -19
- package/package.json +1 -1
package/es/ChatList/Item.js
CHANGED
|
@@ -123,7 +123,10 @@ var Item = /*#__PURE__*/memo(function (props) {
|
|
|
123
123
|
return onMessageChange === null || onMessageChange === void 0 ? void 0 : onMessageChange(item.id, value);
|
|
124
124
|
},
|
|
125
125
|
onDoubleClick: function onDoubleClick(e) {
|
|
126
|
-
|
|
126
|
+
if (item.id === 'default' || item.error) return;
|
|
127
|
+
if (item.role && ['assistant', 'user'].includes(item.role) && e.altKey) {
|
|
128
|
+
setEditing(true);
|
|
129
|
+
}
|
|
127
130
|
},
|
|
128
131
|
onEditingChange: setEditing,
|
|
129
132
|
placement: type === 'chat' ? item.role === 'user' ? 'right' : 'left' : 'left',
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const FALLBACK_LANG = "
|
|
2
|
-
export declare const useHighlight: (text: string,
|
|
1
|
+
export declare const FALLBACK_LANG = "txt";
|
|
2
|
+
export declare const useHighlight: (text: string, lang: string, isDarkMode: boolean) => import("swr/_internal").SWRResponse<string, any, any>;
|
|
3
3
|
export { default as languageMap } from './languageMap';
|
package/es/hooks/useHighlight.js
CHANGED
|
@@ -3,33 +3,37 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
3
3
|
import { getHighlighter } from 'shikiji';
|
|
4
4
|
import useSWR from 'swr';
|
|
5
5
|
import { themeConfig } from "../Highlighter/theme";
|
|
6
|
-
|
|
6
|
+
import languageMap from "./languageMap";
|
|
7
|
+
export var FALLBACK_LANG = 'txt';
|
|
7
8
|
var FALLBACK_LANGS = [FALLBACK_LANG];
|
|
8
9
|
var cacheHighlighter;
|
|
9
10
|
var initHighlighter = /*#__PURE__*/function () {
|
|
10
11
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(lang) {
|
|
11
|
-
var highlighter;
|
|
12
|
+
var highlighter, language;
|
|
12
13
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
13
14
|
while (1) switch (_context.prev = _context.next) {
|
|
14
15
|
case 0:
|
|
15
16
|
highlighter = cacheHighlighter;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
language = lang.toLowerCase();
|
|
18
|
+
if (!(highlighter && FALLBACK_LANGS.includes(language))) {
|
|
19
|
+
_context.next = 4;
|
|
18
20
|
break;
|
|
19
21
|
}
|
|
20
22
|
return _context.abrupt("return", highlighter);
|
|
21
|
-
case
|
|
22
|
-
FALLBACK_LANGS.
|
|
23
|
-
|
|
23
|
+
case 4:
|
|
24
|
+
if (languageMap.includes(language) && !FALLBACK_LANGS.includes(language)) {
|
|
25
|
+
FALLBACK_LANGS.push(language);
|
|
26
|
+
}
|
|
27
|
+
_context.next = 7;
|
|
24
28
|
return getHighlighter({
|
|
25
29
|
langs: FALLBACK_LANGS,
|
|
26
30
|
themes: [themeConfig(true), themeConfig(false)]
|
|
27
31
|
});
|
|
28
|
-
case
|
|
32
|
+
case 7:
|
|
29
33
|
highlighter = _context.sent;
|
|
30
34
|
cacheHighlighter = highlighter;
|
|
31
35
|
return _context.abrupt("return", highlighter);
|
|
32
|
-
case
|
|
36
|
+
case 10:
|
|
33
37
|
case "end":
|
|
34
38
|
return _context.stop();
|
|
35
39
|
}
|
|
@@ -39,31 +43,32 @@ var initHighlighter = /*#__PURE__*/function () {
|
|
|
39
43
|
return _ref.apply(this, arguments);
|
|
40
44
|
};
|
|
41
45
|
}();
|
|
42
|
-
export var useHighlight = function useHighlight(text,
|
|
43
|
-
return useSWR([
|
|
44
|
-
var highlighter, html;
|
|
46
|
+
export var useHighlight = function useHighlight(text, lang, isDarkMode) {
|
|
47
|
+
return useSWR([lang.toLowerCase(), isDarkMode ? 'dark' : 'light', text].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
48
|
+
var language, highlighter, html;
|
|
45
49
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
46
50
|
while (1) switch (_context2.prev = _context2.next) {
|
|
47
51
|
case 0:
|
|
48
52
|
_context2.prev = 0;
|
|
49
|
-
|
|
53
|
+
language = lang.toLowerCase();
|
|
54
|
+
_context2.next = 4;
|
|
50
55
|
return initHighlighter(language);
|
|
51
|
-
case
|
|
56
|
+
case 4:
|
|
52
57
|
highlighter = _context2.sent;
|
|
53
58
|
html = highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
|
|
54
|
-
lang: language,
|
|
59
|
+
lang: languageMap.includes(language) ? language : FALLBACK_LANG,
|
|
55
60
|
theme: isDarkMode ? 'dark' : 'light'
|
|
56
61
|
});
|
|
57
62
|
return _context2.abrupt("return", html);
|
|
58
|
-
case
|
|
59
|
-
_context2.prev =
|
|
63
|
+
case 9:
|
|
64
|
+
_context2.prev = 9;
|
|
60
65
|
_context2.t0 = _context2["catch"](0);
|
|
61
66
|
return _context2.abrupt("return", "<pre><code>".concat(text, "</code></pre>"));
|
|
62
|
-
case
|
|
67
|
+
case 12:
|
|
63
68
|
case "end":
|
|
64
69
|
return _context2.stop();
|
|
65
70
|
}
|
|
66
|
-
}, _callee2, null, [[0,
|
|
71
|
+
}, _callee2, null, [[0, 9]]);
|
|
67
72
|
})));
|
|
68
73
|
};
|
|
69
74
|
export { default as languageMap } from "./languageMap";
|