@lobehub/ui 1.153.13 → 1.153.14
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/useHighlight.d.ts +4 -5
- package/es/hooks/useHighlight.js +33 -17
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export declare const FALLBACK_LANG = "txt";
|
|
2
|
-
export declare const useHighlight: (text: string, lang: string, isDarkMode: boolean) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}>;
|
|
2
|
+
export declare const useHighlight: (text: string, lang: string, isDarkMode: boolean) => {
|
|
3
|
+
data: string;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
};
|
|
7
6
|
export { default as languageMap } from './languageMap';
|
package/es/hooks/useHighlight.js
CHANGED
|
@@ -1,37 +1,53 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
1
2
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
3
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
4
|
import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight } from '@shikijs/transformers';
|
|
5
|
+
import { useLayoutEffect, useState } from 'react';
|
|
4
6
|
import { codeToHtml } from 'shiki';
|
|
5
|
-
import useSWR from 'swr';
|
|
6
|
-
import { Md5 } from 'ts-md5';
|
|
7
7
|
import { themeConfig } from "../Highlighter/theme";
|
|
8
|
+
import languageMap from "./languageMap";
|
|
8
9
|
export var FALLBACK_LANG = 'txt';
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
var highlight = /*#__PURE__*/function () {
|
|
11
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(text, lang, isDarkMode) {
|
|
11
12
|
var language;
|
|
12
13
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
13
14
|
while (1) switch (_context.prev = _context.next) {
|
|
14
15
|
case 0:
|
|
15
|
-
_context.prev = 0;
|
|
16
16
|
language = lang.toLowerCase();
|
|
17
17
|
return _context.abrupt("return", codeToHtml(text, {
|
|
18
|
-
lang: language,
|
|
18
|
+
lang: languageMap.includes(language) ? language : FALLBACK_LANG,
|
|
19
19
|
theme: themeConfig(isDarkMode),
|
|
20
20
|
transformers: [transformerNotationDiff(), transformerNotationHighlight(), transformerNotationWordHighlight(), transformerNotationFocus(), transformerNotationErrorLevel()]
|
|
21
21
|
}));
|
|
22
|
-
case
|
|
23
|
-
_context.prev = 5;
|
|
24
|
-
_context.t0 = _context["catch"](0);
|
|
25
|
-
return _context.abrupt("return", text);
|
|
26
|
-
case 8:
|
|
22
|
+
case 2:
|
|
27
23
|
case "end":
|
|
28
24
|
return _context.stop();
|
|
29
25
|
}
|
|
30
|
-
}, _callee
|
|
31
|
-
}))
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
}, _callee);
|
|
27
|
+
}));
|
|
28
|
+
return function highlight(_x, _x2, _x3) {
|
|
29
|
+
return _ref.apply(this, arguments);
|
|
30
|
+
};
|
|
31
|
+
}();
|
|
32
|
+
export var useHighlight = function useHighlight(text, lang, isDarkMode) {
|
|
33
|
+
var _useState = useState(text),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
data = _useState2[0],
|
|
36
|
+
setData = _useState2[1];
|
|
37
|
+
var _useState3 = useState(true),
|
|
38
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
39
|
+
isLoading = _useState4[0],
|
|
40
|
+
setIsLoading = _useState4[1];
|
|
41
|
+
useLayoutEffect(function () {
|
|
42
|
+
setIsLoading(true);
|
|
43
|
+
highlight(text, lang, isDarkMode).then(function (date) {
|
|
44
|
+
setData(date);
|
|
45
|
+
setIsLoading(false);
|
|
46
|
+
});
|
|
47
|
+
}, [text, lang, isDarkMode]);
|
|
48
|
+
return {
|
|
49
|
+
data: data,
|
|
50
|
+
isLoading: isLoading
|
|
51
|
+
};
|
|
36
52
|
};
|
|
37
53
|
export { default as languageMap } from "./languageMap";
|