@lobehub/ui 2.8.4 → 2.8.6
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/Collapse/Collapse.js +2 -2
- package/es/Collapse/style.d.ts +1 -1
- package/es/Collapse/style.js +1 -1
- package/es/Highlighter/FullFeatured.d.ts +1 -0
- package/es/Highlighter/FullFeatured.js +29 -26
- package/es/Highlighter/Highlighter.js +21 -5
- package/es/Highlighter/LangSelect.d.ts +4 -0
- package/es/Highlighter/LangSelect.js +85 -0
- package/es/Highlighter/const.d.ts +4 -1
- package/es/Highlighter/const.js +37 -2
- package/es/Highlighter/style.js +2 -2
- package/es/Markdown/components/CodeBlock.js +1 -1
- package/es/Mermaid/FullFeatured.js +16 -5
- package/es/hooks/useHighlight.d.ts +0 -1
- package/es/hooks/useHighlight.js +2 -3
- package/es/mdx/mdxComponents/Pre.js +1 -1
- package/package.json +1 -1
package/es/Collapse/Collapse.js
CHANGED
|
@@ -114,8 +114,8 @@ var Collapse = /*#__PURE__*/memo(function (_ref) {
|
|
|
114
114
|
theme: {
|
|
115
115
|
components: {
|
|
116
116
|
Collapse: {
|
|
117
|
-
contentPadding: _typeof(padding) === 'object' ?
|
|
118
|
-
headerPadding: _typeof(padding) === 'object' ?
|
|
117
|
+
contentPadding: getPadding(_typeof(padding) === 'object' ? padding === null || padding === void 0 ? void 0 : padding.body : padding),
|
|
118
|
+
headerPadding: getPadding(_typeof(padding) === 'object' ? padding === null || padding === void 0 ? void 0 : padding.header : padding)
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
},
|
package/es/Collapse/style.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const DEFAULT_PADDING = "12px 16px";
|
|
2
|
-
export declare const getPadding: (padding?: number | string) => string
|
|
2
|
+
export declare const getPadding: (padding?: number | string) => string;
|
|
3
3
|
export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
|
|
4
4
|
borderless: import("antd-style").SerializedStyles;
|
|
5
5
|
desc: import("antd-style").SerializedStyles;
|
package/es/Collapse/style.js
CHANGED
|
@@ -3,7 +3,7 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
|
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
4
|
export var DEFAULT_PADDING = '12px 16px';
|
|
5
5
|
export var getPadding = function getPadding(padding) {
|
|
6
|
-
return !padding && padding !== 0 ? DEFAULT_PADDING : padding;
|
|
6
|
+
return !padding && padding !== 0 ? DEFAULT_PADDING : "".concat(typeof padding === 'string' ? padding : "".concat(padding, "px"), " !important");
|
|
7
7
|
};
|
|
8
8
|
export var useStyles = createStyles(function (_ref) {
|
|
9
9
|
var css = _ref.css,
|
|
@@ -2,6 +2,7 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
import { HighlighterProps } from './type';
|
|
3
3
|
interface HighlighterFullFeaturedProps extends Omit<HighlighterProps, 'children' | 'bodyRender' | 'enableTransformer'> {
|
|
4
4
|
content: string;
|
|
5
|
+
setLanguage?: (language: string) => void;
|
|
5
6
|
}
|
|
6
7
|
export declare const HighlighterFullFeatured: import("react").NamedExoticComponent<HighlighterFullFeaturedProps & {
|
|
7
8
|
children: ReactNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
var _excluded = ["content", "language", "showLanguage", "className", "style", "allowChangeLanguage", "fileName", "icon", "actionsRender", "copyable", "variant", "shadow", "wrap", "defaultExpand", "children"];
|
|
4
|
+
var _excluded = ["content", "language", "setLanguage", "showLanguage", "className", "style", "allowChangeLanguage", "fileName", "icon", "actionsRender", "copyable", "variant", "shadow", "wrap", "defaultExpand", "children"];
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
7
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -15,26 +15,23 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
15
15
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
16
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
17
17
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
18
|
-
import { Select } from 'antd';
|
|
19
18
|
import { cva } from 'class-variance-authority';
|
|
20
19
|
import { ChevronDown, ChevronRight } from 'lucide-react';
|
|
21
20
|
import { memo, useMemo, useState } from 'react';
|
|
22
21
|
import { Flexbox } from 'react-layout-kit';
|
|
23
22
|
import ActionIcon from "../ActionIcon";
|
|
24
23
|
import CopyButton from "../CopyButton";
|
|
25
|
-
import {
|
|
24
|
+
import { getCodeLanguageDisplayName, getCodeLanguageFilename } from "./const";
|
|
25
|
+
import MaterialFileTypeIcon from "../MaterialFileTypeIcon";
|
|
26
|
+
import Text from "../Text";
|
|
27
|
+
import LangSelect from "./LangSelect";
|
|
26
28
|
import { useStyles } from "./style";
|
|
27
29
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
30
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
|
-
var options = languages.map(function (item) {
|
|
30
|
-
return {
|
|
31
|
-
label: item,
|
|
32
|
-
value: item.toLowerCase()
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
31
|
export var HighlighterFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
36
32
|
var content = _ref.content,
|
|
37
33
|
language = _ref.language,
|
|
34
|
+
setLanguage = _ref.setLanguage,
|
|
38
35
|
showLanguage = _ref.showLanguage,
|
|
39
36
|
className = _ref.className,
|
|
40
37
|
style = _ref.style,
|
|
@@ -55,10 +52,6 @@ export var HighlighterFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
|
55
52
|
_useState2 = _slicedToArray(_useState, 2),
|
|
56
53
|
expand = _useState2[0],
|
|
57
54
|
setExpand = _useState2[1];
|
|
58
|
-
var _useState3 = useState(language),
|
|
59
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
60
|
-
lang = _useState4[0],
|
|
61
|
-
setLang = _useState4[1];
|
|
62
55
|
var _useStyles = useStyles(),
|
|
63
56
|
styles = _useStyles.styles,
|
|
64
57
|
cx = _useStyles.cx;
|
|
@@ -127,6 +120,14 @@ export var HighlighterFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
|
127
120
|
language: language,
|
|
128
121
|
originalNode: originalActions
|
|
129
122
|
}) : originalActions;
|
|
123
|
+
var displayName = useMemo(function () {
|
|
124
|
+
if (fileName) return fileName;
|
|
125
|
+
return getCodeLanguageDisplayName(language);
|
|
126
|
+
}, [fileName, language]);
|
|
127
|
+
var filetype = useMemo(function () {
|
|
128
|
+
if (fileName) return fileName;
|
|
129
|
+
return getCodeLanguageFilename(language);
|
|
130
|
+
}, [fileName, language]);
|
|
130
131
|
return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
|
|
131
132
|
className: cx(variants({
|
|
132
133
|
shadow: shadow,
|
|
@@ -149,22 +150,24 @@ export var HighlighterFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
|
149
150
|
return setExpand(!expand);
|
|
150
151
|
},
|
|
151
152
|
size: 'small'
|
|
152
|
-
}), allowChangeLanguage && !fileName ? showLanguage && /*#__PURE__*/_jsx(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
options: options,
|
|
156
|
-
size: 'small',
|
|
157
|
-
suffixIcon: false,
|
|
158
|
-
value: lang.toLowerCase(),
|
|
159
|
-
variant: 'borderless'
|
|
153
|
+
}), allowChangeLanguage && !fileName ? showLanguage && /*#__PURE__*/_jsx(LangSelect, {
|
|
154
|
+
onSelect: setLanguage,
|
|
155
|
+
value: language.toLowerCase()
|
|
160
156
|
}) : /*#__PURE__*/_jsxs(Flexbox, {
|
|
161
157
|
align: 'center',
|
|
162
|
-
className:
|
|
163
|
-
gap:
|
|
158
|
+
className: 'languageTitle',
|
|
159
|
+
gap: 4,
|
|
164
160
|
horizontal: true,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
children: [icon || /*#__PURE__*/_jsx(MaterialFileTypeIcon, {
|
|
162
|
+
fallbackUnknownType: false,
|
|
163
|
+
filename: filetype,
|
|
164
|
+
size: 18,
|
|
165
|
+
type: 'file',
|
|
166
|
+
variant: 'raw'
|
|
167
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
168
|
+
ellipsis: true,
|
|
169
|
+
fontSize: 13,
|
|
170
|
+
children: displayName
|
|
168
171
|
})]
|
|
169
172
|
}), /*#__PURE__*/_jsx(Flexbox, {
|
|
170
173
|
align: 'center',
|
|
@@ -7,12 +7,19 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
7
7
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
9
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
10
16
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
11
17
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
18
|
import { cva } from 'class-variance-authority';
|
|
13
|
-
import { memo, useMemo } from 'react';
|
|
19
|
+
import { memo, useMemo, useState } from 'react';
|
|
14
20
|
import { Flexbox } from 'react-layout-kit';
|
|
15
21
|
import CopyButton from "../CopyButton";
|
|
22
|
+
import { getCodeLanguageDisplayName } from "./const";
|
|
16
23
|
import Tag from "../Tag";
|
|
17
24
|
import FullFeatured from "./FullFeatured";
|
|
18
25
|
import SyntaxHighlighter from "./SyntaxHighlighter";
|
|
@@ -48,6 +55,10 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
48
55
|
var _useStyles = useStyles(),
|
|
49
56
|
styles = _useStyles.styles,
|
|
50
57
|
cx = _useStyles.cx;
|
|
58
|
+
var _useState = useState(language),
|
|
59
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
60
|
+
lang = _useState2[0],
|
|
61
|
+
setLang = _useState2[1];
|
|
51
62
|
var variants = useMemo(function () {
|
|
52
63
|
return cva(styles.root, {
|
|
53
64
|
defaultVariants: {
|
|
@@ -83,20 +94,24 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
83
94
|
var actions = actionsRender ? actionsRender({
|
|
84
95
|
actionIconSize: actionIconSize,
|
|
85
96
|
content: tirmedChildren,
|
|
86
|
-
language:
|
|
97
|
+
language: lang,
|
|
87
98
|
originalNode: originalActions
|
|
88
99
|
}) : originalActions;
|
|
89
100
|
var originalBody = /*#__PURE__*/_jsx(SyntaxHighlighter, {
|
|
90
101
|
animated: animated,
|
|
91
102
|
enableTransformer: enableTransformer,
|
|
92
|
-
language:
|
|
103
|
+
language: lang === null || lang === void 0 ? void 0 : lang.toLowerCase(),
|
|
93
104
|
theme: theme,
|
|
94
105
|
variant: variant,
|
|
95
106
|
children: tirmedChildren
|
|
96
107
|
});
|
|
108
|
+
var displayName = useMemo(function () {
|
|
109
|
+
if (fileName) return fileName;
|
|
110
|
+
return getCodeLanguageDisplayName(language);
|
|
111
|
+
}, [fileName, language]);
|
|
97
112
|
var body = bodyRender ? bodyRender({
|
|
98
113
|
content: tirmedChildren,
|
|
99
|
-
language:
|
|
114
|
+
language: lang,
|
|
100
115
|
originalNode: originalBody
|
|
101
116
|
}) : originalBody;
|
|
102
117
|
if (fullFeatured) return /*#__PURE__*/_jsx(FullFeatured, _objectSpread(_objectSpread({
|
|
@@ -109,6 +124,7 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
109
124
|
fileName: fileName,
|
|
110
125
|
icon: icon,
|
|
111
126
|
language: language,
|
|
127
|
+
setLanguage: setLang,
|
|
112
128
|
shadow: shadow,
|
|
113
129
|
showLanguage: showLanguage,
|
|
114
130
|
variant: variant,
|
|
@@ -133,7 +149,7 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
133
149
|
children: actions
|
|
134
150
|
}), showLanguage && language && /*#__PURE__*/_jsx(Tag, {
|
|
135
151
|
className: styles.lang,
|
|
136
|
-
children:
|
|
152
|
+
children: displayName
|
|
137
153
|
}), body]
|
|
138
154
|
}));
|
|
139
155
|
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
+
function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
|
|
16
|
+
import { Select } from 'antd';
|
|
17
|
+
import { memo, useMemo } from 'react';
|
|
18
|
+
import { Flexbox } from 'react-layout-kit';
|
|
19
|
+
import { bundledLanguagesInfo } from 'shiki';
|
|
20
|
+
import MaterialFileTypeIcon from "../MaterialFileTypeIcon";
|
|
21
|
+
import Text from "../Text";
|
|
22
|
+
import { useStyles } from "./style";
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
25
|
+
export var LangSelect = /*#__PURE__*/memo(function (_ref) {
|
|
26
|
+
var rest = Object.assign({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
27
|
+
var _useStyles = useStyles(),
|
|
28
|
+
styles = _useStyles.styles;
|
|
29
|
+
var options = useMemo(function () {
|
|
30
|
+
return [{
|
|
31
|
+
aliases: ['text', 'txt'],
|
|
32
|
+
label: /*#__PURE__*/_jsxs(Flexbox, {
|
|
33
|
+
align: 'center',
|
|
34
|
+
gap: 4,
|
|
35
|
+
horizontal: true,
|
|
36
|
+
children: [/*#__PURE__*/_jsx(MaterialFileTypeIcon, {
|
|
37
|
+
fallbackUnknownType: false,
|
|
38
|
+
filename: "*.txt",
|
|
39
|
+
size: 18,
|
|
40
|
+
type: 'file',
|
|
41
|
+
variant: 'raw'
|
|
42
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
43
|
+
ellipsis: true,
|
|
44
|
+
fontSize: 13,
|
|
45
|
+
children: "Plaintext"
|
|
46
|
+
})]
|
|
47
|
+
}),
|
|
48
|
+
value: 'plaintext'
|
|
49
|
+
}].concat(_toConsumableArray(bundledLanguagesInfo.map(function (item) {
|
|
50
|
+
var _item$aliases;
|
|
51
|
+
return {
|
|
52
|
+
aliases: item.aliases,
|
|
53
|
+
label: /*#__PURE__*/_jsxs(Flexbox, {
|
|
54
|
+
align: 'center',
|
|
55
|
+
gap: 4,
|
|
56
|
+
horizontal: true,
|
|
57
|
+
children: [/*#__PURE__*/_jsx(MaterialFileTypeIcon, {
|
|
58
|
+
fallbackUnknownType: false,
|
|
59
|
+
filename: "*.".concat((item === null || item === void 0 || (_item$aliases = item.aliases) === null || _item$aliases === void 0 ? void 0 : _item$aliases[0]) || item.id),
|
|
60
|
+
size: 18,
|
|
61
|
+
type: 'file',
|
|
62
|
+
variant: 'raw'
|
|
63
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
64
|
+
ellipsis: true,
|
|
65
|
+
fontSize: 13,
|
|
66
|
+
children: item.name
|
|
67
|
+
})]
|
|
68
|
+
}),
|
|
69
|
+
title: (item.aliases || [item.id]).filter(Boolean).map(function (item) {
|
|
70
|
+
return "*.".concat(item);
|
|
71
|
+
}).join(','),
|
|
72
|
+
value: item.id
|
|
73
|
+
};
|
|
74
|
+
})));
|
|
75
|
+
}, []);
|
|
76
|
+
return /*#__PURE__*/_jsx(Select, _objectSpread({
|
|
77
|
+
className: styles.select,
|
|
78
|
+
options: options,
|
|
79
|
+
showSearch: true,
|
|
80
|
+
size: 'small',
|
|
81
|
+
suffixIcon: false,
|
|
82
|
+
variant: 'borderless'
|
|
83
|
+
}, rest));
|
|
84
|
+
});
|
|
85
|
+
export default LangSelect;
|
|
@@ -3,5 +3,8 @@ interface HighlighterThemeItem {
|
|
|
3
3
|
id: string;
|
|
4
4
|
}
|
|
5
5
|
export declare const highlighterThemes: HighlighterThemeItem[];
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const FALLBACK_LANG = "plaintext";
|
|
7
|
+
export declare const getCodeLanguageByInput: (input: string) => string;
|
|
8
|
+
export declare const getCodeLanguageFilename: (input: string) => string;
|
|
9
|
+
export declare const getCodeLanguageDisplayName: (input: string) => string;
|
|
7
10
|
export {};
|
package/es/Highlighter/const.js
CHANGED
|
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
5
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
-
import { bundledThemesInfo } from 'shiki';
|
|
7
|
+
import { bundledLanguagesInfo, bundledThemesInfo } from 'shiki';
|
|
8
8
|
export var highlighterThemes = [{
|
|
9
9
|
displayName: 'Lobe Theme',
|
|
10
10
|
id: 'lobe-theme'
|
|
@@ -14,4 +14,39 @@ export var highlighterThemes = [{
|
|
|
14
14
|
id: item.id
|
|
15
15
|
};
|
|
16
16
|
})));
|
|
17
|
-
export var
|
|
17
|
+
export var FALLBACK_LANG = 'plaintext';
|
|
18
|
+
export var getCodeLanguageByInput = function getCodeLanguageByInput(input) {
|
|
19
|
+
if (!input) {
|
|
20
|
+
return 'plaintext';
|
|
21
|
+
}
|
|
22
|
+
var inputLang = input.toLocaleLowerCase();
|
|
23
|
+
var matchLang = bundledLanguagesInfo.find(function (lang) {
|
|
24
|
+
var _lang$aliases;
|
|
25
|
+
return lang.id === inputLang || ((_lang$aliases = lang.aliases) === null || _lang$aliases === void 0 ? void 0 : _lang$aliases.includes(inputLang));
|
|
26
|
+
});
|
|
27
|
+
return (matchLang === null || matchLang === void 0 ? void 0 : matchLang.id) || 'plaintext';
|
|
28
|
+
};
|
|
29
|
+
export var getCodeLanguageFilename = function getCodeLanguageFilename(input) {
|
|
30
|
+
var _matchLang$aliases;
|
|
31
|
+
if (!input) {
|
|
32
|
+
return 'Plaintext';
|
|
33
|
+
}
|
|
34
|
+
var inputLang = input.toLocaleLowerCase();
|
|
35
|
+
var matchLang = bundledLanguagesInfo.find(function (lang) {
|
|
36
|
+
var _lang$aliases2;
|
|
37
|
+
return lang.id === inputLang || ((_lang$aliases2 = lang.aliases) === null || _lang$aliases2 === void 0 ? void 0 : _lang$aliases2.includes(inputLang));
|
|
38
|
+
});
|
|
39
|
+
var type = (matchLang === null || matchLang === void 0 || (_matchLang$aliases = matchLang.aliases) === null || _matchLang$aliases === void 0 ? void 0 : _matchLang$aliases[0]) || (matchLang === null || matchLang === void 0 ? void 0 : matchLang.id) || 'txt';
|
|
40
|
+
return "*.".concat(type);
|
|
41
|
+
};
|
|
42
|
+
export var getCodeLanguageDisplayName = function getCodeLanguageDisplayName(input) {
|
|
43
|
+
if (!input) {
|
|
44
|
+
return 'Plaintext';
|
|
45
|
+
}
|
|
46
|
+
var inputLang = input.toLocaleLowerCase();
|
|
47
|
+
var matchLang = bundledLanguagesInfo.find(function (lang) {
|
|
48
|
+
var _lang$aliases3;
|
|
49
|
+
return lang.id === inputLang || ((_lang$aliases3 = lang.aliases) === null || _lang$aliases3 === void 0 ? void 0 : _lang$aliases3.includes(inputLang));
|
|
50
|
+
});
|
|
51
|
+
return (matchLang === null || matchLang === void 0 ? void 0 : matchLang.name) || 'Plaintext';
|
|
52
|
+
};
|
package/es/Highlighter/style.js
CHANGED
|
@@ -21,8 +21,8 @@ export var useStyles = createStyles(function (_ref) {
|
|
|
21
21
|
headerBorderless: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n padding-inline: 0;\n "]))),
|
|
22
22
|
headerFilled: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n background: ", ";\n "])), token.colorFillQuaternary),
|
|
23
23
|
headerOutlined: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n & + .", " {\n border-block-start: 1px solid ", ";\n }\n "])), expandCls, token.colorFillQuaternary),
|
|
24
|
-
headerRoot: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n position: relative;\n padding: 4px;\n "]))),
|
|
25
|
-
lang: cx(langHoverCls, stylish.blur, css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-end: 8px;\n inset-inline-end:
|
|
24
|
+
headerRoot: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n position: relative;\n padding: 4px;\n\n .languageTitle {\n opacity: 0.5;\n transition: opacity 0.2s ", ";\n }\n\n &:hover {\n .languageTitle {\n opacity: 1;\n }\n }\n "])), token.motionEaseInOut),
|
|
25
|
+
lang: cx(langHoverCls, stylish.blur, css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 2;\n inset-block-end: 8px;\n inset-inline-end: 8px;\n\n font-family: ", ";\n color: ", ";\n\n opacity: 0;\n background: ", ";\n\n transition: opacity 0.1s;\n "])), token.fontFamilyCode, token.colorTextSecondary, token.colorFillQuaternary)),
|
|
26
26
|
nowrap: css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n pre,\n code {\n text-wrap: nowrap;\n }\n "]))),
|
|
27
27
|
outlined: stylish.variantOutlinedWithoutHover,
|
|
28
28
|
root: cx(prefix, css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n position: relative;\n\n overflow: hidden;\n\n width: 100%;\n border-radius: ", "px;\n\n transition: background-color 100ms ", ";\n\n &:hover {\n .", " {\n opacity: 1;\n }\n\n .", " {\n opacity: 1;\n }\n }\n\n code {\n background: transparent !important;\n }\n "])), token.borderRadius, token.motionEaseOut, actionsHoverCls, langHoverCls)),
|
|
@@ -7,7 +7,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
|
-
import { FALLBACK_LANG } from "../../
|
|
10
|
+
import { FALLBACK_LANG } from "../../Highlighter/const";
|
|
11
11
|
import Pre, { PreMermaid, PreSingleLine } from "../../mdx/mdxComponents/Pre";
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
var countLines = function countLines(str) {
|
|
@@ -22,6 +22,8 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
22
22
|
import ActionIcon from "../ActionIcon";
|
|
23
23
|
import CopyButton from "../CopyButton";
|
|
24
24
|
import { useStyles } from "../Highlighter/style";
|
|
25
|
+
import MaterialFileTypeIcon from "../MaterialFileTypeIcon";
|
|
26
|
+
import Text from "../Text";
|
|
25
27
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
28
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
27
29
|
export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
@@ -127,13 +129,22 @@ export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
|
127
129
|
return setExpand(!expand);
|
|
128
130
|
},
|
|
129
131
|
size: 'small'
|
|
130
|
-
}), showLanguage && /*#__PURE__*/
|
|
132
|
+
}), showLanguage && /*#__PURE__*/_jsxs(Flexbox, {
|
|
131
133
|
align: 'center',
|
|
132
|
-
className:
|
|
133
|
-
gap:
|
|
134
|
+
className: 'languageTitle',
|
|
135
|
+
gap: 4,
|
|
134
136
|
horizontal: true,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
children: [/*#__PURE__*/_jsx(MaterialFileTypeIcon, {
|
|
138
|
+
fallbackUnknownType: false,
|
|
139
|
+
filename: fileName || language,
|
|
140
|
+
size: 18,
|
|
141
|
+
type: 'file',
|
|
142
|
+
variant: 'raw'
|
|
143
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
144
|
+
ellipsis: true,
|
|
145
|
+
fontSize: 13,
|
|
146
|
+
children: fileName || 'Mermaid'
|
|
147
|
+
})]
|
|
137
148
|
}), /*#__PURE__*/_jsx(Flexbox, {
|
|
138
149
|
align: 'center',
|
|
139
150
|
flex: 'none',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { BuiltinTheme, CodeToHastOptions } from 'shiki';
|
|
2
2
|
import { SWRResponse } from 'swr';
|
|
3
|
-
export declare const FALLBACK_LANG = "txt";
|
|
4
3
|
declare const MD5_LENGTH_THRESHOLD = 10000;
|
|
5
4
|
type ICodeToHtml = (code: string, options: CodeToHastOptions) => Promise<string>;
|
|
6
5
|
declare const loadShiki: () => Promise<ICodeToHtml | null>;
|
package/es/hooks/useHighlight.js
CHANGED
|
@@ -9,8 +9,7 @@ import { useTheme, useThemeMode } from 'antd-style';
|
|
|
9
9
|
import { useMemo } from 'react';
|
|
10
10
|
import useSWR from 'swr';
|
|
11
11
|
import { Md5 } from 'ts-md5';
|
|
12
|
-
import {
|
|
13
|
-
export var FALLBACK_LANG = 'txt';
|
|
12
|
+
import { getCodeLanguageByInput } from "../Highlighter/const";
|
|
14
13
|
|
|
15
14
|
// Application-level cache to avoid repeated calculations
|
|
16
15
|
var MD5_LENGTH_THRESHOLD = 10000; // Use async MD5 for text exceeding this length
|
|
@@ -43,7 +42,7 @@ export var useHighlight = function useHighlight(text, _ref) {
|
|
|
43
42
|
|
|
44
43
|
// Match supported languages
|
|
45
44
|
var matchedLanguage = useMemo(function () {
|
|
46
|
-
return
|
|
45
|
+
return getCodeLanguageByInput(lang);
|
|
47
46
|
}, [lang]);
|
|
48
47
|
|
|
49
48
|
// Optimize transformer creation
|
|
@@ -15,9 +15,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
15
15
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
16
16
|
import { createStyles } from 'antd-style';
|
|
17
17
|
import Highlighter from "../../Highlighter";
|
|
18
|
+
import { FALLBACK_LANG } from "../../Highlighter/const";
|
|
18
19
|
import Mermaid from "../../Mermaid";
|
|
19
20
|
import Snippet from "../../Snippet";
|
|
20
|
-
import { FALLBACK_LANG } from "../../hooks/useHighlight";
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
22
|
var useStyles = createStyles(function (_ref) {
|
|
23
23
|
var css = _ref.css;
|