@lobehub/ui 2.15.3 → 2.15.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.
- package/es/CopyButton/CopyButton.js +6 -4
- package/es/CopyButton/type.d.ts +2 -2
- package/es/Highlighter/FullFeatured.js +96 -51
- package/es/Highlighter/Highlighter.js +44 -25
- package/es/Highlighter/SyntaxHighlighter/StaticRenderer.d.ts +17 -0
- package/es/Highlighter/SyntaxHighlighter/StaticRenderer.js +36 -0
- package/es/Highlighter/SyntaxHighlighter/StreamRenderer.d.ts +13 -0
- package/es/Highlighter/SyntaxHighlighter/StreamRenderer.js +147 -0
- package/es/Highlighter/SyntaxHighlighter/index.js +36 -139
- package/es/Highlighter/type.d.ts +1 -0
- package/es/Mermaid/FullFeatured.js +77 -45
- package/es/Mermaid/Mermaid.js +39 -20
- package/es/Mermaid/type.d.ts +1 -0
- package/es/hooks/useHighlight.d.ts +19 -3
- package/es/hooks/useHighlight.js +303 -35
- package/package.json +3 -1
- package/es/Highlighter/SyntaxHighlighter/Line.d.ts +0 -5
- package/es/Highlighter/SyntaxHighlighter/Line.js +0 -80
- package/es/Highlighter/SyntaxHighlighter/Span.d.ts +0 -5
- package/es/Highlighter/SyntaxHighlighter/Span.js +0 -16
|
@@ -1,108 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
4
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
-
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."); }
|
|
6
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
-
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."); }
|
|
10
|
-
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); }
|
|
11
|
-
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; }
|
|
12
|
-
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; } }
|
|
13
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
3
|
import { cva } from 'class-variance-authority';
|
|
15
|
-
import { memo,
|
|
16
|
-
import
|
|
17
|
-
import
|
|
4
|
+
import { memo, useMemo } from 'react';
|
|
5
|
+
import StaticRenderer from "./StaticRenderer";
|
|
6
|
+
import StreamRenderer from "./StreamRenderer";
|
|
18
7
|
import { useStyles } from "./style";
|
|
19
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
9
|
var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
|
|
21
|
-
var
|
|
10
|
+
var animated = _ref.animated,
|
|
22
11
|
children = _ref.children,
|
|
23
|
-
language = _ref.language,
|
|
24
12
|
className = _ref.className,
|
|
25
|
-
style = _ref.style,
|
|
26
13
|
enableTransformer = _ref.enableTransformer,
|
|
27
|
-
|
|
14
|
+
language = _ref.language,
|
|
15
|
+
style = _ref.style,
|
|
28
16
|
theme = _ref.theme,
|
|
29
|
-
|
|
17
|
+
_ref$variant = _ref.variant,
|
|
18
|
+
variant = _ref$variant === void 0 ? 'borderless' : _ref$variant;
|
|
30
19
|
var _useStyles = useStyles(),
|
|
31
20
|
styles = _useStyles.styles,
|
|
32
21
|
cx = _useStyles.cx;
|
|
33
22
|
var isDefaultTheme = theme === 'lobe-theme' || !theme;
|
|
34
23
|
var showBackground = !isDefaultTheme && variant === 'filled';
|
|
35
|
-
var
|
|
36
|
-
enableTransformer: enableTransformer,
|
|
37
|
-
language: language,
|
|
38
|
-
theme: isDefaultTheme ? undefined : theme
|
|
39
|
-
}),
|
|
40
|
-
data = _useHighlight.data;
|
|
41
|
-
var _useState = useState([]),
|
|
42
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
-
contentLines = _useState2[0],
|
|
44
|
-
setContentLines = _useState2[1];
|
|
45
|
-
var _useState3 = useState({}),
|
|
46
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
47
|
-
preStyle = _useState4[0],
|
|
48
|
-
setPreStyle = _useState4[1];
|
|
49
|
-
useEffect(function () {
|
|
50
|
-
if (data && typeof data === 'string') {
|
|
51
|
-
// Extract all lines from the HTML content
|
|
52
|
-
// We need to handle the structure from shiki which gives us HTML with a <pre><code> structure
|
|
53
|
-
var parser = new DOMParser();
|
|
54
|
-
var doc = parser.parseFromString(data, 'text/html');
|
|
55
|
-
var preElement = doc.querySelector('pre');
|
|
56
|
-
var _preStyle = preElement === null || preElement === void 0 ? void 0 : preElement.style;
|
|
57
|
-
if (_preStyle) {
|
|
58
|
-
setPreStyle({
|
|
59
|
-
backgroundColor: _preStyle === null || _preStyle === void 0 ? void 0 : _preStyle.backgroundColor,
|
|
60
|
-
color: _preStyle === null || _preStyle === void 0 ? void 0 : _preStyle.color
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
var codeElement = doc.querySelector('pre code');
|
|
64
|
-
if (codeElement) {
|
|
65
|
-
var spanLines = codeElement.querySelectorAll('.line');
|
|
66
|
-
var newLines = _toConsumableArray(spanLines).map(function (line) {
|
|
67
|
-
return line.outerHTML;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// Only update if the lines have changed
|
|
71
|
-
setContentLines(function (prevLines) {
|
|
72
|
-
if (prevLines.length !== newLines.length) return newLines;
|
|
73
|
-
var hasChanged = false;
|
|
74
|
-
var _iterator = _createForOfIteratorHelper(newLines.entries()),
|
|
75
|
-
_step;
|
|
76
|
-
try {
|
|
77
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
78
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
79
|
-
i = _step$value[0],
|
|
80
|
-
newLine = _step$value[1];
|
|
81
|
-
if (prevLines[i] !== newLine) {
|
|
82
|
-
hasChanged = true;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
} catch (err) {
|
|
87
|
-
_iterator.e(err);
|
|
88
|
-
} finally {
|
|
89
|
-
_iterator.f();
|
|
90
|
-
}
|
|
91
|
-
return hasChanged ? newLines : prevLines;
|
|
92
|
-
});
|
|
93
|
-
} else {
|
|
94
|
-
// Fallback if the structure is different
|
|
95
|
-
var htmlLines = data.split('\n').map(function (line) {
|
|
96
|
-
return "<span class=\"line\">".concat(line, "</span>");
|
|
97
|
-
});
|
|
98
|
-
setContentLines(htmlLines);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}, [data]);
|
|
24
|
+
var resolvedTheme = isDefaultTheme ? undefined : theme;
|
|
102
25
|
var variants = useMemo(function () {
|
|
103
26
|
return cva(styles.root, {
|
|
104
27
|
defaultVariants: {
|
|
105
|
-
shiki:
|
|
28
|
+
shiki: true,
|
|
106
29
|
showBackground: false,
|
|
107
30
|
variant: 'borderless'
|
|
108
31
|
},
|
|
@@ -125,61 +48,35 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
|
|
|
125
48
|
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
126
49
|
});
|
|
127
50
|
}, [styles]);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
showBackground: showBackground,
|
|
148
|
-
variant: variant
|
|
149
|
-
}), className),
|
|
150
|
-
dangerouslySetInnerHTML: {
|
|
151
|
-
__html: data || ''
|
|
152
|
-
},
|
|
153
|
-
dir: "ltr",
|
|
154
|
-
ref: ref,
|
|
155
|
-
style: style
|
|
51
|
+
var shikiClassName = cx(variants({
|
|
52
|
+
shiki: true,
|
|
53
|
+
showBackground: showBackground,
|
|
54
|
+
variant: variant
|
|
55
|
+
}), className);
|
|
56
|
+
var fallbackClassName = cx(variants({
|
|
57
|
+
shiki: false,
|
|
58
|
+
showBackground: showBackground,
|
|
59
|
+
variant: variant
|
|
60
|
+
}), className);
|
|
61
|
+
if (animated) {
|
|
62
|
+
return /*#__PURE__*/_jsx(StreamRenderer, {
|
|
63
|
+
className: shikiClassName,
|
|
64
|
+
enableTransformer: enableTransformer,
|
|
65
|
+
fallbackClassName: fallbackClassName,
|
|
66
|
+
language: language,
|
|
67
|
+
style: style,
|
|
68
|
+
theme: resolvedTheme,
|
|
69
|
+
children: children
|
|
156
70
|
});
|
|
157
71
|
}
|
|
158
|
-
return /*#__PURE__*/_jsx(
|
|
159
|
-
className:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}), className),
|
|
164
|
-
dir: "ltr",
|
|
165
|
-
ref: ref,
|
|
72
|
+
return /*#__PURE__*/_jsx(StaticRenderer, {
|
|
73
|
+
className: shikiClassName,
|
|
74
|
+
enableTransformer: enableTransformer,
|
|
75
|
+
fallbackClassName: fallbackClassName,
|
|
76
|
+
language: language,
|
|
166
77
|
style: style,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
style: preStyle,
|
|
170
|
-
tabIndex: 0,
|
|
171
|
-
children: /*#__PURE__*/_jsx("code", {
|
|
172
|
-
style: {
|
|
173
|
-
display: 'flex',
|
|
174
|
-
flexDirection: 'column'
|
|
175
|
-
},
|
|
176
|
-
children: contentLines.map(function (line, index) {
|
|
177
|
-
return /*#__PURE__*/_jsx(Line, {
|
|
178
|
-
children: line
|
|
179
|
-
}, index);
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
})
|
|
78
|
+
theme: resolvedTheme,
|
|
79
|
+
children: children
|
|
183
80
|
});
|
|
184
81
|
}, function (prevProps, nextProps) {
|
|
185
82
|
return prevProps.children === nextProps.children && prevProps.language === nextProps.language;
|
package/es/Highlighter/type.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface HighlighterProps extends Omit<FlexboxProps, 'children' | 'wrap'
|
|
|
17
17
|
actionsRender?: (props: {
|
|
18
18
|
actionIconSize: ActionIconProps['size'];
|
|
19
19
|
content: string;
|
|
20
|
+
getContent: () => string;
|
|
20
21
|
language: string;
|
|
21
22
|
originalNode: ReactNode;
|
|
22
23
|
}) => ReactNode;
|
|
@@ -17,7 +17,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
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
18
|
import { cva } from 'class-variance-authority';
|
|
19
19
|
import { ChevronDown, ChevronRight } from 'lucide-react';
|
|
20
|
-
import { memo, useMemo, useState } from 'react';
|
|
20
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
21
21
|
import { Flexbox } from 'react-layout-kit';
|
|
22
22
|
import ActionIcon from "../ActionIcon";
|
|
23
23
|
import CopyButton from "../CopyButton";
|
|
@@ -26,22 +26,49 @@ import MaterialFileTypeIcon from "../MaterialFileTypeIcon";
|
|
|
26
26
|
import Text from "../Text";
|
|
27
27
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
28
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
var MermaidHeaderLanguage = /*#__PURE__*/memo(function (_ref) {
|
|
30
|
+
var fileName = _ref.fileName,
|
|
31
|
+
language = _ref.language,
|
|
32
|
+
showLanguage = _ref.showLanguage;
|
|
33
|
+
if (!showLanguage) return null;
|
|
34
|
+
return /*#__PURE__*/_jsxs(Flexbox, {
|
|
35
|
+
align: 'center',
|
|
36
|
+
className: 'languageTitle',
|
|
37
|
+
flex: 1,
|
|
38
|
+
gap: 4,
|
|
39
|
+
horizontal: true,
|
|
40
|
+
justify: 'center',
|
|
41
|
+
children: [/*#__PURE__*/_jsx(MaterialFileTypeIcon, {
|
|
42
|
+
fallbackUnknownType: false,
|
|
43
|
+
filename: fileName || language,
|
|
44
|
+
size: 18,
|
|
45
|
+
type: 'file',
|
|
46
|
+
variant: 'raw'
|
|
47
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
48
|
+
ellipsis: true,
|
|
49
|
+
fontSize: 13,
|
|
50
|
+
children: fileName || 'Mermaid'
|
|
51
|
+
})]
|
|
52
|
+
});
|
|
53
|
+
}, function (prev, next) {
|
|
54
|
+
return prev.fileName === next.fileName && prev.language === next.language && prev.showLanguage === next.showLanguage;
|
|
55
|
+
});
|
|
56
|
+
export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref2) {
|
|
57
|
+
var showLanguage = _ref2.showLanguage,
|
|
58
|
+
content = _ref2.content,
|
|
59
|
+
children = _ref2.children,
|
|
60
|
+
className = _ref2.className,
|
|
61
|
+
copyable = _ref2.copyable,
|
|
62
|
+
actionsRender = _ref2.actionsRender,
|
|
63
|
+
style = _ref2.style,
|
|
64
|
+
variant = _ref2.variant,
|
|
65
|
+
shadow = _ref2.shadow,
|
|
66
|
+
_ref2$language = _ref2.language,
|
|
67
|
+
language = _ref2$language === void 0 ? 'mermaid' : _ref2$language,
|
|
68
|
+
fileName = _ref2.fileName,
|
|
69
|
+
_ref2$defaultExpand = _ref2.defaultExpand,
|
|
70
|
+
defaultExpand = _ref2$defaultExpand === void 0 ? true : _ref2$defaultExpand,
|
|
71
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
45
72
|
var _useState = useState(defaultExpand),
|
|
46
73
|
_useState2 = _slicedToArray(_useState, 2),
|
|
47
74
|
expand = _useState2[0],
|
|
@@ -49,6 +76,13 @@ export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
|
49
76
|
var _useStyles = useStyles('block'),
|
|
50
77
|
styles = _useStyles.styles,
|
|
51
78
|
cx = _useStyles.cx;
|
|
79
|
+
var contentRef = useRef(content);
|
|
80
|
+
useEffect(function () {
|
|
81
|
+
contentRef.current = content;
|
|
82
|
+
}, [content]);
|
|
83
|
+
var getContent = useCallback(function () {
|
|
84
|
+
return contentRef.current;
|
|
85
|
+
}, []);
|
|
52
86
|
var variants = useMemo(function () {
|
|
53
87
|
return cva(styles.root, {
|
|
54
88
|
defaultVariants: {
|
|
@@ -99,15 +133,27 @@ export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
|
99
133
|
}
|
|
100
134
|
});
|
|
101
135
|
}, [styles]);
|
|
102
|
-
var originalActions =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
136
|
+
var originalActions = useMemo(function () {
|
|
137
|
+
if (!copyable) return null;
|
|
138
|
+
return /*#__PURE__*/_jsx(CopyButton, {
|
|
139
|
+
content: getContent,
|
|
140
|
+
size: 'small'
|
|
141
|
+
});
|
|
142
|
+
}, [copyable, getContent]);
|
|
143
|
+
var actions = useMemo(function () {
|
|
144
|
+
if (!actionsRender) return originalActions;
|
|
145
|
+
return actionsRender({
|
|
146
|
+
actionIconSize: 'small',
|
|
147
|
+
content: content,
|
|
148
|
+
getContent: getContent,
|
|
149
|
+
originalNode: originalActions
|
|
150
|
+
});
|
|
151
|
+
}, [actionsRender, content, getContent, originalActions]);
|
|
152
|
+
var handleToggleExpand = useCallback(function () {
|
|
153
|
+
setExpand(function (prev) {
|
|
154
|
+
return !prev;
|
|
155
|
+
});
|
|
156
|
+
}, []);
|
|
111
157
|
return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
|
|
112
158
|
className: cx(variants({
|
|
113
159
|
shadow: shadow,
|
|
@@ -125,26 +171,12 @@ export var MermaidFullFeatured = /*#__PURE__*/memo(function (_ref) {
|
|
|
125
171
|
justify: 'space-between',
|
|
126
172
|
children: [/*#__PURE__*/_jsx(ActionIcon, {
|
|
127
173
|
icon: expand ? ChevronDown : ChevronRight,
|
|
128
|
-
onClick:
|
|
129
|
-
return setExpand(!expand);
|
|
130
|
-
},
|
|
174
|
+
onClick: handleToggleExpand,
|
|
131
175
|
size: 'small'
|
|
132
|
-
}),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
horizontal: true,
|
|
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
|
-
})]
|
|
176
|
+
}), /*#__PURE__*/_jsx(MermaidHeaderLanguage, {
|
|
177
|
+
fileName: fileName,
|
|
178
|
+
language: language,
|
|
179
|
+
showLanguage: showLanguage
|
|
148
180
|
}), /*#__PURE__*/_jsx(Flexbox, {
|
|
149
181
|
align: 'center',
|
|
150
182
|
flex: 'none',
|
package/es/Mermaid/Mermaid.js
CHANGED
|
@@ -10,7 +10,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
10
10
|
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
11
|
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
12
|
import { cva } from 'class-variance-authority';
|
|
13
|
-
import { memo, useMemo } from 'react';
|
|
13
|
+
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
14
14
|
import { Flexbox } from 'react-layout-kit';
|
|
15
15
|
import CopyButton from "../CopyButton";
|
|
16
16
|
import { useStyles } from "../Highlighter/style";
|
|
@@ -73,25 +73,44 @@ var Mermaid = /*#__PURE__*/memo(function (_ref) {
|
|
|
73
73
|
});
|
|
74
74
|
}, [styles]);
|
|
75
75
|
var tirmedChildren = children.trim();
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
var copyContentRef = useRef(tirmedChildren);
|
|
77
|
+
useEffect(function () {
|
|
78
|
+
copyContentRef.current = tirmedChildren;
|
|
79
|
+
}, [tirmedChildren]);
|
|
80
|
+
var getCopyContent = useCallback(function () {
|
|
81
|
+
return copyContentRef.current;
|
|
82
|
+
}, []);
|
|
83
|
+
var originalActions = useMemo(function () {
|
|
84
|
+
if (!copyable) return null;
|
|
85
|
+
return /*#__PURE__*/_jsx(CopyButton, {
|
|
86
|
+
content: getCopyContent,
|
|
87
|
+
size: actionIconSize
|
|
88
|
+
});
|
|
89
|
+
}, [actionIconSize, copyable, getCopyContent]);
|
|
90
|
+
var actions = useMemo(function () {
|
|
91
|
+
if (!actionsRender) return originalActions;
|
|
92
|
+
return actionsRender({
|
|
93
|
+
actionIconSize: actionIconSize,
|
|
94
|
+
content: tirmedChildren,
|
|
95
|
+
getContent: getCopyContent,
|
|
96
|
+
originalNode: originalActions
|
|
97
|
+
});
|
|
98
|
+
}, [actionIconSize, actionsRender, getCopyContent, originalActions, tirmedChildren]);
|
|
99
|
+
var defaultBody = useMemo(function () {
|
|
100
|
+
return /*#__PURE__*/_jsx(SyntaxMermaid, {
|
|
101
|
+
enablePanZoom: enablePanZoom,
|
|
102
|
+
theme: theme,
|
|
103
|
+
variant: variant,
|
|
104
|
+
children: tirmedChildren
|
|
105
|
+
});
|
|
106
|
+
}, [enablePanZoom, theme, tirmedChildren, variant]);
|
|
107
|
+
var body = useMemo(function () {
|
|
108
|
+
if (!bodyRender) return defaultBody;
|
|
109
|
+
return bodyRender({
|
|
110
|
+
content: tirmedChildren,
|
|
111
|
+
originalNode: defaultBody
|
|
112
|
+
});
|
|
113
|
+
}, [bodyRender, defaultBody, tirmedChildren]);
|
|
95
114
|
if (fullFeatured) return /*#__PURE__*/_jsx(FullFeatured, _objectSpread(_objectSpread({
|
|
96
115
|
actionsRender: actionsRender,
|
|
97
116
|
className: className,
|
package/es/Mermaid/type.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import type { BuiltinTheme, CodeToHastOptions, ThemedToken } from 'shiki';
|
|
2
3
|
import { SWRResponse } from 'swr';
|
|
3
4
|
declare const MD5_LENGTH_THRESHOLD = 10000;
|
|
5
|
+
type ColorReplacements = {
|
|
6
|
+
[themeName: string]: {
|
|
7
|
+
[color: string]: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type StreamingHighlightResult = {
|
|
11
|
+
colorReplacements?: Record<string, string>;
|
|
12
|
+
lines: ThemedToken[][];
|
|
13
|
+
preStyle?: CSSProperties;
|
|
14
|
+
};
|
|
15
|
+
type UseHighlightResponse = SWRResponse<string, Error> & {
|
|
16
|
+
colorReplacements?: ColorReplacements;
|
|
17
|
+
streaming?: StreamingHighlightResult;
|
|
18
|
+
};
|
|
4
19
|
type ICodeToHtml = (code: string, options: CodeToHastOptions) => Promise<string>;
|
|
5
20
|
declare const loadShiki: () => Promise<ICodeToHtml | null>;
|
|
6
21
|
declare const shikiPromise: Promise<ICodeToHtml | null>;
|
|
7
22
|
declare const escapeHtml: (str: string) => string;
|
|
8
|
-
export declare const useHighlight: (text: string, { language, enableTransformer, theme: builtinTheme, }: {
|
|
23
|
+
export declare const useHighlight: (text: string, { language, enableTransformer, theme: builtinTheme, streaming, }: {
|
|
9
24
|
enableTransformer?: boolean | undefined;
|
|
10
25
|
language: string;
|
|
26
|
+
streaming?: boolean | undefined;
|
|
11
27
|
theme?: import("shiki/dist/themes.mjs").BundledTheme | undefined;
|
|
12
|
-
}) =>
|
|
28
|
+
}) => UseHighlightResponse;
|
|
13
29
|
export { escapeHtml, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };
|