@lobehub/ui 1.153.9 → 1.153.11
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 +2 -0
- package/es/hooks/useHighlight.js +20 -61
- package/package.json +11 -11
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const FALLBACK_LANG = "txt";
|
|
2
2
|
export declare const useHighlight: (text: string, lang: string, isDarkMode: boolean) => import("swr/dist/_internal").SWRResponse<string, any, {
|
|
3
|
+
refreshWhenOffline: false;
|
|
3
4
|
revalidateOnFocus: false;
|
|
5
|
+
revalidateOnReconnect: false;
|
|
4
6
|
}>;
|
|
5
7
|
export { default as languageMap } from './languageMap';
|
package/es/hooks/useHighlight.js
CHANGED
|
@@ -1,78 +1,37 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
3
|
import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight } from '@shikijs/transformers';
|
|
4
|
-
import {
|
|
4
|
+
import { codeToHtml } from 'shiki';
|
|
5
5
|
import useSWR from 'swr';
|
|
6
|
+
import { Md5 } from 'ts-md5';
|
|
6
7
|
import { themeConfig } from "../Highlighter/theme";
|
|
7
|
-
import languageMap from "./languageMap";
|
|
8
8
|
export var FALLBACK_LANG = 'txt';
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(lang) {
|
|
13
|
-
var highlighter, language;
|
|
9
|
+
export var useHighlight = function useHighlight(text, lang, isDarkMode) {
|
|
10
|
+
return useSWR(Md5.hashStr([lang.toLowerCase(), isDarkMode ? 'd' : 'l', text].join('-')), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
11
|
+
var language;
|
|
14
12
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
15
13
|
while (1) switch (_context.prev = _context.next) {
|
|
16
14
|
case 0:
|
|
17
|
-
|
|
18
|
-
language = lang.toLowerCase();
|
|
19
|
-
if (!(highlighter && FALLBACK_LANGS.includes(language))) {
|
|
20
|
-
_context.next = 4;
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
return _context.abrupt("return", highlighter);
|
|
24
|
-
case 4:
|
|
25
|
-
if (languageMap.includes(language) && !FALLBACK_LANGS.includes(language)) {
|
|
26
|
-
FALLBACK_LANGS.push(language);
|
|
27
|
-
}
|
|
28
|
-
_context.next = 7;
|
|
29
|
-
return getHighlighter({
|
|
30
|
-
langs: FALLBACK_LANGS,
|
|
31
|
-
themes: [themeConfig(true), themeConfig(false)]
|
|
32
|
-
});
|
|
33
|
-
case 7:
|
|
34
|
-
highlighter = _context.sent;
|
|
35
|
-
cacheHighlighter = highlighter;
|
|
36
|
-
return _context.abrupt("return", highlighter);
|
|
37
|
-
case 10:
|
|
38
|
-
case "end":
|
|
39
|
-
return _context.stop();
|
|
40
|
-
}
|
|
41
|
-
}, _callee);
|
|
42
|
-
}));
|
|
43
|
-
return function initHighlighter(_x) {
|
|
44
|
-
return _ref.apply(this, arguments);
|
|
45
|
-
};
|
|
46
|
-
}();
|
|
47
|
-
export var useHighlight = function useHighlight(text, lang, isDarkMode) {
|
|
48
|
-
return useSWR([lang.toLowerCase(), isDarkMode ? 'dark' : 'light', text].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
49
|
-
var language, highlighter, html;
|
|
50
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
51
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
52
|
-
case 0:
|
|
53
|
-
_context2.prev = 0;
|
|
15
|
+
_context.prev = 0;
|
|
54
16
|
language = lang.toLowerCase();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
highlighter = _context2.sent;
|
|
59
|
-
html = highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
|
|
60
|
-
lang: languageMap.includes(language) ? language : FALLBACK_LANG,
|
|
61
|
-
theme: isDarkMode ? 'dark' : 'light',
|
|
17
|
+
return _context.abrupt("return", codeToHtml(text, {
|
|
18
|
+
lang: language,
|
|
19
|
+
theme: themeConfig(isDarkMode),
|
|
62
20
|
transformers: [transformerNotationDiff(), transformerNotationHighlight(), transformerNotationWordHighlight(), transformerNotationFocus(), transformerNotationErrorLevel()]
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
case 12:
|
|
21
|
+
}));
|
|
22
|
+
case 5:
|
|
23
|
+
_context.prev = 5;
|
|
24
|
+
_context.t0 = _context["catch"](0);
|
|
25
|
+
return _context.abrupt("return", text);
|
|
26
|
+
case 8:
|
|
70
27
|
case "end":
|
|
71
|
-
return
|
|
28
|
+
return _context.stop();
|
|
72
29
|
}
|
|
73
|
-
},
|
|
30
|
+
}, _callee, null, [[0, 5]]);
|
|
74
31
|
})), {
|
|
75
|
-
|
|
32
|
+
refreshWhenOffline: false,
|
|
33
|
+
revalidateOnFocus: false,
|
|
34
|
+
revalidateOnReconnect: false
|
|
76
35
|
});
|
|
77
36
|
};
|
|
78
37
|
export { default as languageMap } from "./languageMap";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/ui",
|
|
3
|
-
"version": "1.153.
|
|
3
|
+
"version": "1.153.11",
|
|
4
4
|
"description": "Lobe UI is an open-source UI component library for building AIGC web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -76,8 +76,9 @@
|
|
|
76
76
|
]
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
+
"@ant-design/cssinjs": "^1.22.1",
|
|
79
80
|
"@babel/runtime": "^7.26.0",
|
|
80
|
-
"@dnd-kit/core": "^6.
|
|
81
|
+
"@dnd-kit/core": "^6.3.1",
|
|
81
82
|
"@dnd-kit/modifiers": "^8.0.0",
|
|
82
83
|
"@dnd-kit/sortable": "^9.0.0",
|
|
83
84
|
"@dnd-kit/utilities": "^3.2.2",
|
|
@@ -85,9 +86,11 @@
|
|
|
85
86
|
"@emoji-mart/react": "^1.1.1",
|
|
86
87
|
"@floating-ui/react": "^0.26.28",
|
|
87
88
|
"@giscus/react": "^3.0.0",
|
|
89
|
+
"@lobehub/fluent-emoji": "^1.0.1",
|
|
88
90
|
"@react-spring/web": "^9.7.5",
|
|
89
91
|
"@shikijs/transformers": "^1.24.0",
|
|
90
92
|
"@splinetool/runtime": "^0.9.526",
|
|
93
|
+
"ahooks": "^3.8.4",
|
|
91
94
|
"chroma-js": "^3.1.2",
|
|
92
95
|
"dayjs": "^1.11.13",
|
|
93
96
|
"emoji-mart": "^5.6.0",
|
|
@@ -104,7 +107,7 @@
|
|
|
104
107
|
"re-resizable": "^6.10.1",
|
|
105
108
|
"react-avatar-editor": "^13.0.2",
|
|
106
109
|
"react-error-boundary": "^4.1.2",
|
|
107
|
-
"react-layout-kit": "^1.9.
|
|
110
|
+
"react-layout-kit": "^1.9.1",
|
|
108
111
|
"react-markdown": "^8.0.7",
|
|
109
112
|
"react-merge-refs": "^2.1.1",
|
|
110
113
|
"react-rnd": "^10.4.13",
|
|
@@ -117,6 +120,7 @@
|
|
|
117
120
|
"shiki": "^1.24.0",
|
|
118
121
|
"swr": "^2.2.5",
|
|
119
122
|
"ts-md5": "^1.3.1",
|
|
123
|
+
"unified": "^10.1.2",
|
|
120
124
|
"url-join": "^5.0.0",
|
|
121
125
|
"use-merge-value": "^1.2.0",
|
|
122
126
|
"uuid": "^11.0.3"
|
|
@@ -132,9 +136,9 @@
|
|
|
132
136
|
"@types/numeral": "^2.0.5",
|
|
133
137
|
"@types/pangu": "^4.0.2",
|
|
134
138
|
"@types/query-string": "^6.3.0",
|
|
135
|
-
"@types/react": "^18.3.
|
|
139
|
+
"@types/react": "^18.3.14",
|
|
136
140
|
"@types/react-avatar-editor": "^13.0.3",
|
|
137
|
-
"@types/react-dom": "^18.3.
|
|
141
|
+
"@types/react-dom": "^18.3.2",
|
|
138
142
|
"@types/unist": "^3.0.3",
|
|
139
143
|
"@types/uuid": "^10.0.0",
|
|
140
144
|
"@vitest/coverage-v8": "~1.2.2",
|
|
@@ -150,7 +154,7 @@
|
|
|
150
154
|
"husky": "^9.1.7",
|
|
151
155
|
"jsdom": "^25.0.1",
|
|
152
156
|
"lint-staged": "^15.2.10",
|
|
153
|
-
"prettier": "^3.4.
|
|
157
|
+
"prettier": "^3.4.2",
|
|
154
158
|
"react": "^18.3.1",
|
|
155
159
|
"react-dom": "^18.3.1",
|
|
156
160
|
"remark": "^14.0.3",
|
|
@@ -163,15 +167,11 @@
|
|
|
163
167
|
"vitest": "~1.2.2"
|
|
164
168
|
},
|
|
165
169
|
"peerDependencies": {
|
|
166
|
-
"@ant-design/cssinjs": ">=1",
|
|
167
|
-
"@lobehub/fluent-emoji": ">=1",
|
|
168
|
-
"ahooks": ">=3",
|
|
169
170
|
"antd": ">=5.13.0",
|
|
170
171
|
"antd-style": ">=3",
|
|
171
172
|
"lucide-react": ">=0.396.0",
|
|
172
173
|
"react": ">=18",
|
|
173
|
-
"react-dom": ">=18"
|
|
174
|
-
"unified": ">=10"
|
|
174
|
+
"react-dom": ">=18"
|
|
175
175
|
},
|
|
176
176
|
"publishConfig": {
|
|
177
177
|
"access": "public",
|