@lobehub/ui 1.94.4 → 1.94.5
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.
|
@@ -18,12 +18,9 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
18
18
|
cx = _useStyles.cx;
|
|
19
19
|
var _useThemeMode = useThemeMode(),
|
|
20
20
|
isDarkMode = _useThemeMode.isDarkMode;
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var _useCodeToHtml = useCodeToHtml(children.trim(), language, isDarkMode),
|
|
25
|
-
data = _useCodeToHtml.data,
|
|
26
|
-
isLoading = _useCodeToHtml.isLoading;
|
|
21
|
+
var _useHighlight = useHighlight(children.trim(), language, isDarkMode),
|
|
22
|
+
data = _useHighlight.data,
|
|
23
|
+
isLoading = _useHighlight.isLoading;
|
|
27
24
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
28
25
|
children: [isLoading ? /*#__PURE__*/_jsx("code", {
|
|
29
26
|
className: cx(styles.unshiki, className),
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { type Highlighter } from 'shikiji';
|
|
2
|
-
import { type SWRResponse } from 'swr';
|
|
3
1
|
export declare const FALLBACK_LANG = "markdown";
|
|
4
|
-
|
|
5
|
-
highlighter?: Highlighter;
|
|
6
|
-
initHighlighter: () => Promise<Highlighter>;
|
|
7
|
-
useCodeToHtml: (text: string, language: string, isDarkMode: boolean) => SWRResponse<string>;
|
|
8
|
-
}
|
|
9
|
-
export declare const useHighlight: import("zustand/traditional").UseBoundStoreWithEqualityFn<import("zustand/vanilla").StoreApi<Store>>;
|
|
2
|
+
export declare const useHighlight: (text: string, language: string, isDarkMode: boolean) => import("swr/_internal").SWRResponse<string, any, any>;
|
|
10
3
|
export { default as languageMap } from './languageMap';
|
package/es/hooks/useHighlight.js
CHANGED
|
@@ -2,99 +2,90 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { getHighlighter } from 'shikiji';
|
|
4
4
|
import useSWR from 'swr';
|
|
5
|
-
import { shallow } from 'zustand/shallow';
|
|
6
|
-
import { createWithEqualityFn } from 'zustand/traditional';
|
|
7
5
|
import { themeConfig } from "../Highlighter/theme";
|
|
8
6
|
import languageMap from "./languageMap";
|
|
9
7
|
export var FALLBACK_LANG = 'markdown';
|
|
10
8
|
var FALLBACK_LANGS = ['ts', 'typescript', 'js', 'javascript', 'markdown', 'md'];
|
|
11
9
|
var THEME = [themeConfig(true), themeConfig(false)];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_context.next = 5;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
return _context.abrupt("return", highlighter);
|
|
27
|
-
case 5:
|
|
28
|
-
_context.next = 7;
|
|
29
|
-
return getHighlighter({
|
|
30
|
-
langs: FALLBACK_LANGS,
|
|
31
|
-
themes: THEME
|
|
32
|
-
});
|
|
33
|
-
case 7:
|
|
34
|
-
highlighter = _context.sent;
|
|
35
|
-
set({
|
|
36
|
-
highlighter: highlighter
|
|
37
|
-
});
|
|
38
|
-
return _context.abrupt("return", highlighter);
|
|
39
|
-
case 10:
|
|
40
|
-
case "end":
|
|
41
|
-
return _context.stop();
|
|
10
|
+
var cacheHighlighter;
|
|
11
|
+
var initHighlighter = /*#__PURE__*/function () {
|
|
12
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
13
|
+
var highlighter;
|
|
14
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
|
+
while (1) switch (_context.prev = _context.next) {
|
|
16
|
+
case 0:
|
|
17
|
+
highlighter = cacheHighlighter;
|
|
18
|
+
if (!highlighter) {
|
|
19
|
+
_context.next = 5;
|
|
20
|
+
break;
|
|
42
21
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
return _context.abrupt("return", highlighter);
|
|
23
|
+
case 5:
|
|
24
|
+
_context.next = 7;
|
|
25
|
+
return getHighlighter({
|
|
26
|
+
langs: FALLBACK_LANGS,
|
|
27
|
+
themes: THEME
|
|
28
|
+
});
|
|
29
|
+
case 7:
|
|
30
|
+
highlighter = _context.sent;
|
|
31
|
+
cacheHighlighter = highlighter;
|
|
32
|
+
return _context.abrupt("return", highlighter);
|
|
33
|
+
case 10:
|
|
34
|
+
case "end":
|
|
35
|
+
return _context.stop();
|
|
47
36
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var theme, lang, highlighter, html;
|
|
53
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
54
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
55
|
-
case 0:
|
|
56
|
-
theme = isDarkMode ? 'dark' : 'light';
|
|
57
|
-
lang = language;
|
|
58
|
-
_context2.prev = 2;
|
|
59
|
-
_context2.next = 5;
|
|
60
|
-
return get().initHighlighter();
|
|
61
|
-
case 5:
|
|
62
|
-
highlighter = _context2.sent;
|
|
63
|
-
if (FALLBACK_LANGS.includes(lang)) {
|
|
64
|
-
_context2.next = 13;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
if (!languageMap.includes(lang)) {
|
|
68
|
-
_context2.next = 12;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
_context2.next = 10;
|
|
72
|
-
return highlighter === null || highlighter === void 0 ? void 0 : highlighter.loadLanguage(lang);
|
|
73
|
-
case 10:
|
|
74
|
-
_context2.next = 13;
|
|
75
|
-
break;
|
|
76
|
-
case 12:
|
|
77
|
-
lang = FALLBACK_LANG;
|
|
78
|
-
case 13:
|
|
79
|
-
_context2.next = 15;
|
|
80
|
-
return highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
|
|
81
|
-
lang: lang,
|
|
82
|
-
theme: theme
|
|
83
|
-
});
|
|
84
|
-
case 15:
|
|
85
|
-
html = _context2.sent;
|
|
86
|
-
return _context2.abrupt("return", html);
|
|
87
|
-
case 19:
|
|
88
|
-
_context2.prev = 19;
|
|
89
|
-
_context2.t0 = _context2["catch"](2);
|
|
90
|
-
return _context2.abrupt("return", "<code>".concat(text, "</code>"));
|
|
91
|
-
case 22:
|
|
92
|
-
case "end":
|
|
93
|
-
return _context2.stop();
|
|
94
|
-
}
|
|
95
|
-
}, _callee2, null, [[2, 19]]);
|
|
96
|
-
})));
|
|
97
|
-
}
|
|
37
|
+
}, _callee);
|
|
38
|
+
}));
|
|
39
|
+
return function initHighlighter() {
|
|
40
|
+
return _ref.apply(this, arguments);
|
|
98
41
|
};
|
|
99
|
-
}
|
|
42
|
+
}();
|
|
43
|
+
export var useHighlight = function useHighlight(text, language, isDarkMode) {
|
|
44
|
+
return useSWR([text, language, Number(isDarkMode)].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
45
|
+
var theme, lang, highlighter, html;
|
|
46
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
47
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
theme = isDarkMode ? 'dark' : 'light';
|
|
50
|
+
lang = language;
|
|
51
|
+
_context2.prev = 2;
|
|
52
|
+
_context2.next = 5;
|
|
53
|
+
return initHighlighter();
|
|
54
|
+
case 5:
|
|
55
|
+
highlighter = _context2.sent;
|
|
56
|
+
if (FALLBACK_LANGS.includes(lang)) {
|
|
57
|
+
_context2.next = 13;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
if (!languageMap.includes(lang)) {
|
|
61
|
+
_context2.next = 12;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
_context2.next = 10;
|
|
65
|
+
return highlighter === null || highlighter === void 0 ? void 0 : highlighter.loadLanguage(lang);
|
|
66
|
+
case 10:
|
|
67
|
+
_context2.next = 13;
|
|
68
|
+
break;
|
|
69
|
+
case 12:
|
|
70
|
+
lang = FALLBACK_LANG;
|
|
71
|
+
case 13:
|
|
72
|
+
_context2.next = 15;
|
|
73
|
+
return highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
|
|
74
|
+
lang: lang,
|
|
75
|
+
theme: theme
|
|
76
|
+
});
|
|
77
|
+
case 15:
|
|
78
|
+
html = _context2.sent;
|
|
79
|
+
return _context2.abrupt("return", html);
|
|
80
|
+
case 19:
|
|
81
|
+
_context2.prev = 19;
|
|
82
|
+
_context2.t0 = _context2["catch"](2);
|
|
83
|
+
return _context2.abrupt("return", "<code>".concat(text, "</code>"));
|
|
84
|
+
case 22:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context2.stop();
|
|
87
|
+
}
|
|
88
|
+
}, _callee2, null, [[2, 19]]);
|
|
89
|
+
})));
|
|
90
|
+
};
|
|
100
91
|
export { default as languageMap } from "./languageMap";
|