@lobehub/ui 1.94.0 → 1.94.2
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/README.md +2 -24
- package/es/Highlighter/SyntaxHighlighter/index.d.ts +0 -2
- package/es/Highlighter/SyntaxHighlighter/index.js +21 -12
- package/es/Markdown/index.d.ts +0 -1
- package/es/Markdown/index.js +0 -1
- package/es/ThemeProvider/index.js +4 -0
- package/es/hooks/languageMap.d.ts +2 -0
- package/es/hooks/languageMap.js +1 -0
- package/es/hooks/useHighlight.d.ts +2 -26
- package/es/hooks/useHighlight.js +11 -60
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -108,30 +108,7 @@ $ pnpm start
|
|
|
108
108
|
|
|
109
109
|
## 🤝 Contributing
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
> 📊 Total: <kbd>**6**</kbd>
|
|
114
|
-
|
|
115
|
-
<a href="https://github.com/canisminor1990" title="canisminor1990">
|
|
116
|
-
<img src="https://avatars.githubusercontent.com/u/17870709?v=4" width="50" />
|
|
117
|
-
</a>
|
|
118
|
-
<a href="https://github.com/arvinxx" title="arvinxx">
|
|
119
|
-
<img src="https://avatars.githubusercontent.com/u/28616219?v=4" width="50" />
|
|
120
|
-
</a>
|
|
121
|
-
<a href="https://github.com/apps/dependabot" title="dependabot[bot]">
|
|
122
|
-
<img src="https://avatars.githubusercontent.com/in/29110?v=4" width="50" />
|
|
123
|
-
</a>
|
|
124
|
-
<a href="https://github.com/actions-user" title="actions-user">
|
|
125
|
-
<img src="https://avatars.githubusercontent.com/u/65916846?v=4" width="50" />
|
|
126
|
-
</a>
|
|
127
|
-
<a href="https://github.com/Wxh16144" title="Wxh16144">
|
|
128
|
-
<img src="https://avatars.githubusercontent.com/u/32004925?v=4" width="50" />
|
|
129
|
-
</a>
|
|
130
|
-
<a href="https://github.com/meganjohnson96" title="meganjohnson96">
|
|
131
|
-
<img src="https://avatars.githubusercontent.com/u/136729222?v=4" width="50" />
|
|
132
|
-
</a>
|
|
133
|
-
|
|
134
|
-
<!-- CONTRIBUTION END -->
|
|
111
|
+
[![][contributors-contrib]][contributors-url]
|
|
135
112
|
|
|
136
113
|
<div align="right">
|
|
137
114
|
|
|
@@ -166,6 +143,7 @@ This project is [MIT](./LICENSE) licensed.
|
|
|
166
143
|
[ci-release-url]: https://github.com/lobehub/lobe-ui/actions?query=workflow%3ARelease%20CI
|
|
167
144
|
[ci-test-shield]: https://github.com/lobehub/lobe-ui/workflows/Test%20CI/badge.svg
|
|
168
145
|
[ci-test-url]: https://github.com/lobehub/lobe-ui/actions?query=workflow%3ATest%20CI
|
|
146
|
+
[contributors-contrib]: https://contrib.rocks/image?repo=lobehub/lobe-ui
|
|
169
147
|
[contributors-shield]: https://img.shields.io/github/contributors/lobehub/lobe-ui.svg?style=flat
|
|
170
148
|
[contributors-url]: https://github.com/lobehub/lobe-ui/graphs/contributors
|
|
171
149
|
[forks-shield]: https://img.shields.io/github/forks/lobehub/lobe-ui.svg?style=flat
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { type HighlighterCoreOptions } from 'shikiji';
|
|
3
2
|
import { DivProps } from "../../types";
|
|
4
3
|
export interface SyntaxHighlighterProps extends DivProps {
|
|
5
4
|
children: string;
|
|
6
5
|
language: string;
|
|
7
|
-
options?: HighlighterCoreOptions;
|
|
8
6
|
}
|
|
9
7
|
declare const SyntaxHighlighter: import("react").NamedExoticComponent<SyntaxHighlighterProps>;
|
|
10
8
|
export default SyntaxHighlighter;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import { useThemeMode } from 'antd-style';
|
|
3
3
|
import { Loader2 } from 'lucide-react';
|
|
4
|
-
import { memo, useEffect } from 'react';
|
|
4
|
+
import { memo, useEffect, useState } from 'react';
|
|
5
5
|
import { Center } from 'react-layout-kit';
|
|
6
|
+
import { codeToHtml } from 'shikiji';
|
|
7
|
+
import { themeConfig } from "../theme";
|
|
6
8
|
import Icon from "../../Icon";
|
|
7
|
-
import { useHighlight } from "../../hooks/useHighlight";
|
|
8
9
|
import { useStyles } from "./style";
|
|
9
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
11
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -12,7 +13,6 @@ import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
12
13
|
var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
|
|
13
14
|
var children = _ref.children,
|
|
14
15
|
language = _ref.language,
|
|
15
|
-
options = _ref.options,
|
|
16
16
|
className = _ref.className,
|
|
17
17
|
style = _ref.style;
|
|
18
18
|
var _useStyles = useStyles(),
|
|
@@ -20,15 +20,24 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
20
20
|
cx = _useStyles.cx;
|
|
21
21
|
var _useThemeMode = useThemeMode(),
|
|
22
22
|
isDarkMode = _useThemeMode.isDarkMode;
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
var _useState = useState(true),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
isLoading = _useState2[0],
|
|
26
|
+
setIsLoading = _useState2[1];
|
|
27
|
+
var _useState3 = useState(''),
|
|
28
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
29
|
+
data = _useState4[0],
|
|
30
|
+
setData = _useState4[1];
|
|
29
31
|
useEffect(function () {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
setIsLoading(true);
|
|
33
|
+
codeToHtml(children.trim(), {
|
|
34
|
+
lang: language,
|
|
35
|
+
theme: themeConfig(isDarkMode)
|
|
36
|
+
}).then(function (code) {
|
|
37
|
+
setData(code);
|
|
38
|
+
});
|
|
39
|
+
setIsLoading(false);
|
|
40
|
+
}, [children, language, isDarkMode]);
|
|
32
41
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
33
42
|
children: [isLoading ? /*#__PURE__*/_jsx("code", {
|
|
34
43
|
className: className,
|
|
@@ -37,7 +46,7 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
37
46
|
}) : /*#__PURE__*/_jsx("div", {
|
|
38
47
|
className: cx(styles.shiki, className),
|
|
39
48
|
dangerouslySetInnerHTML: {
|
|
40
|
-
__html:
|
|
49
|
+
__html: data
|
|
41
50
|
},
|
|
42
51
|
style: style
|
|
43
52
|
}), isLoading && /*#__PURE__*/_jsxs(Center, {
|
package/es/Markdown/index.d.ts
CHANGED
package/es/Markdown/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock"];
|
|
|
4
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
import { Collapse, Divider, Image, Typography } from 'antd';
|
|
7
|
-
import 'katex/dist/katex.min.css';
|
|
8
7
|
import { memo } from 'react';
|
|
9
8
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
9
|
import ReactMarkdown from 'react-markdown';
|
|
@@ -32,6 +32,10 @@ var ThemeProvider = /*#__PURE__*/memo(function (_ref) {
|
|
|
32
32
|
path: 'css/index.css',
|
|
33
33
|
pkg: '@lobehub/webfont-harmony-sans-sc',
|
|
34
34
|
version: '1.0.0'
|
|
35
|
+
}), genCdnUrl({
|
|
36
|
+
path: 'dist/katex.min.css',
|
|
37
|
+
pkg: 'katex',
|
|
38
|
+
version: '0.16.8'
|
|
35
39
|
})] : _ref$webfonts;
|
|
36
40
|
useEffect(function () {
|
|
37
41
|
setupStyled({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default ['abap', 'actionscript-3', 'ada', 'apache', 'apex', 'apl', 'applescript', 'ara', 'asm', 'astro', 'awk', 'ballerina', 'bat', 'beancount', 'berry', 'bibtex', 'bicep', 'blade', 'c', 'cadence', 'clarity', 'clojure', 'cmake', 'cobol', 'codeql', 'coffee', 'cpp', 'crystal', 'csharp', 'css', 'cue', 'cypher', 'd', 'dart', 'dax', 'diff', 'docker', 'dream-maker', 'elixir', 'elm', 'erb', 'erlang', 'fish', 'fsharp', 'gdresource', 'gdscript', 'gdshader', 'gherkin', 'git-commit', 'git-rebase', 'glimmer-js', 'glimmer-ts', 'glsl', 'gnuplot', 'go', 'graphql', 'groovy', 'hack', 'haml', 'handlebars', 'haskell', 'hcl', 'hjson', 'hlsl', 'html', 'http', 'imba', 'ini', 'java', 'javascript', 'jinja-html', 'jison', 'json', 'json5', 'jsonc', 'jsonl', 'jsonnet', 'jssm', 'jsx', 'julia', 'kotlin', 'kusto', 'latex', 'less', 'liquid', 'lisp', 'logo', 'lua', 'make', 'markdown', 'marko', 'matlab', 'mdc', 'mdx', 'mermaid', 'mojo', 'narrat', 'nextflow', 'nginx', 'nim', 'nix', 'objective-c', 'objective-cpp', 'ocaml', 'pascal', 'perl', 'php', 'plsql', 'postcss', 'powerquery', 'powershell', 'prisma', 'prolog', 'proto', 'pug', 'puppet', 'purescript', 'python', 'r', 'raku', 'razor', 'reg', 'rel', 'riscv', 'rst', 'ruby', 'rust', 'sas', 'sass', 'scala', 'scheme', 'scss', 'shaderlab', 'shellscript', 'shellsession', 'smalltalk', 'solidity', 'sparql', 'splunk', 'sql', 'ssh-config', 'stata', 'stylus', 'svelte', 'swift', 'system-verilog', 'tasl', 'tcl', 'tex', 'toml', 'tsx', 'turtle', 'twig', 'typescript', 'v', 'vb', 'verilog', 'vhdl', 'viml', 'vue', 'vue-html', 'vyper', 'wasm', 'wenyan', 'wgsl', 'wolfram', 'xml', 'xsl', 'yaml', 'zenscript', 'zig', 'bash', 'batch', 'be', 'c#', 'cdc', 'clj', 'cmd', 'console', 'cql', 'cs', 'dockerfile', 'erl', 'f#', 'fs', 'fsl', 'gjs', 'gts', 'hbs', 'hs', 'jade', 'js', 'kql', 'makefile', 'md', 'nar', 'nf', 'objc', 'perl6', 'properties', 'ps', 'ps1', 'py', 'ql', 'rb', 'rs', 'sh', 'shader', 'shell', 'spl', 'styl', 'ts', 'vim', 'vimscript', 'vy', 'yml', 'zsh', '文言'];
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
/**
|
|
4
|
-
* @title 代码高亮的存储对象
|
|
5
|
-
*/
|
|
6
|
-
interface Store {
|
|
7
|
-
/**
|
|
8
|
-
* @title Convert code to HTML string
|
|
9
|
-
* @param text - The code text
|
|
10
|
-
* @param language - The language of the code
|
|
11
|
-
* @param isDarkMode - Whether it's in dark mode or not
|
|
12
|
-
* @returns HTML string
|
|
13
|
-
*/
|
|
14
|
-
codeToHtml: (text: string, language: string, isDarkMode: boolean) => string;
|
|
15
|
-
/**
|
|
16
|
-
* @title Highlighter object
|
|
17
|
-
*/
|
|
18
|
-
highlighter?: Highlighter;
|
|
19
|
-
/**
|
|
20
|
-
* @title Initialize the highlighter object
|
|
21
|
-
* @returns Initialization promise object
|
|
22
|
-
*/
|
|
23
|
-
initHighlighter: (options?: HighlighterCoreOptions) => Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
export declare const useHighlight: import("zustand/traditional").UseBoundStoreWithEqualityFn<import("zustand/vanilla").StoreApi<Store>>;
|
|
26
|
-
export {};
|
|
1
|
+
export declare const useHighlight: (text: string, language: string, isDarkMode: boolean) => import("swr/_internal").SWRResponse<string, any, any>;
|
|
2
|
+
export { default as languageMap } from './languageMap';
|
package/es/hooks/useHighlight.js
CHANGED
|
@@ -1,61 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { bundledLanguages, getHighlighter } from 'shikiji';
|
|
4
|
-
import { shallow } from 'zustand/shallow';
|
|
5
|
-
import { createWithEqualityFn } from 'zustand/traditional';
|
|
1
|
+
import { codeToHtml } from 'shikiji';
|
|
2
|
+
import useSWR from 'swr';
|
|
6
3
|
import { themeConfig } from "../Highlighter/theme";
|
|
7
|
-
export var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _get = get(),
|
|
17
|
-
highlighter = _get.highlighter;
|
|
18
|
-
if (!highlighter) return '';
|
|
19
|
-
try {
|
|
20
|
-
return highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
|
|
21
|
-
lang: language,
|
|
22
|
-
theme: isDarkMode ? 'dark' : 'light'
|
|
23
|
-
});
|
|
24
|
-
} catch (_unused) {
|
|
25
|
-
return text;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
highlighter: undefined,
|
|
29
|
-
initHighlighter: function () {
|
|
30
|
-
var _initHighlighter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
|
31
|
-
var highlighter;
|
|
32
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
|
-
while (1) switch (_context.prev = _context.next) {
|
|
34
|
-
case 0:
|
|
35
|
-
if (get().highlighter) {
|
|
36
|
-
_context.next = 5;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
_context.next = 3;
|
|
40
|
-
return getHighlighter({
|
|
41
|
-
langs: (options === null || options === void 0 ? void 0 : options.langs) || languageMap,
|
|
42
|
-
themes: (options === null || options === void 0 ? void 0 : options.themes) || [themeConfig(true), themeConfig(false)]
|
|
43
|
-
});
|
|
44
|
-
case 3:
|
|
45
|
-
highlighter = _context.sent;
|
|
46
|
-
set({
|
|
47
|
-
highlighter: highlighter
|
|
48
|
-
});
|
|
49
|
-
case 5:
|
|
50
|
-
case "end":
|
|
51
|
-
return _context.stop();
|
|
52
|
-
}
|
|
53
|
-
}, _callee);
|
|
54
|
-
}));
|
|
55
|
-
function initHighlighter(_x) {
|
|
56
|
-
return _initHighlighter.apply(this, arguments);
|
|
57
|
-
}
|
|
58
|
-
return initHighlighter;
|
|
59
|
-
}()
|
|
60
|
-
};
|
|
61
|
-
}, shallow);
|
|
4
|
+
export var useHighlight = function useHighlight(text, language, isDarkMode) {
|
|
5
|
+
return useSWR([text, language, String(isDarkMode)].join('-'), function () {
|
|
6
|
+
return codeToHtml(text, {
|
|
7
|
+
lang: language,
|
|
8
|
+
theme: themeConfig(isDarkMode)
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export { default as languageMap } from "./languageMap";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/ui",
|
|
3
|
-
"version": "1.94.
|
|
3
|
+
"version": "1.94.2",
|
|
4
4
|
"description": "Lobe UI is an open-source UI component library for building AIGC web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -88,7 +88,6 @@
|
|
|
88
88
|
"emoji-regex": "^10",
|
|
89
89
|
"fast-deep-equal": "^3",
|
|
90
90
|
"immer": "^10",
|
|
91
|
-
"katex": "^0.16",
|
|
92
91
|
"leva": "^0",
|
|
93
92
|
"lodash-es": "^4",
|
|
94
93
|
"lucide-react": "latest",
|
|
@@ -107,6 +106,7 @@
|
|
|
107
106
|
"remark-math": "^5",
|
|
108
107
|
"shikiji": "^0",
|
|
109
108
|
"styled-components": "^6",
|
|
109
|
+
"swr": "^2",
|
|
110
110
|
"three": "^0.150",
|
|
111
111
|
"ts-md5": "^1",
|
|
112
112
|
"use-merge-value": "^1",
|