@lobehub/ui 2.10.1 → 2.10.3
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/Markdown/Markdown.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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 = ["ref", "children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "animated", "enableLatex", "enableMermaid", "enableImageGallery", "enableCustomFootnotes", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "showFootnotes", "variant", "reactMarkdownProps", "lineHeight", "rehypePlugins", "remarkPlugins", "remarkPluginsAhead", "components", "customRender", "citations"]
|
|
4
|
+
var _excluded = ["ref", "children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "animated", "enableLatex", "enableMermaid", "enableImageGallery", "enableCustomFootnotes", "enableGithubAlert", "enableStream", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "showFootnotes", "variant", "reactMarkdownProps", "lineHeight", "rehypePlugins", "remarkPlugins", "remarkPluginsAhead", "components", "customRender", "citations"],
|
|
5
|
+
_excluded2 = ["children"];
|
|
5
6
|
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
7
|
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
8
|
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; }
|
|
@@ -16,7 +17,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
16
17
|
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
18
|
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
19
|
import { cva } from 'class-variance-authority';
|
|
19
|
-
import { memo, useEffect, useMemo, useState } from 'react';
|
|
20
|
+
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
20
21
|
import { PreviewGroup } from "../Image";
|
|
21
22
|
import { MarkdownProvider } from "./components/MarkdownProvider";
|
|
22
23
|
import { MarkdownRender, StreamdownRender } from "./SyntaxMarkdown";
|
|
@@ -25,18 +26,19 @@ import { useStyles } from "./style";
|
|
|
25
26
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
27
|
var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
27
28
|
var ref = _ref.ref,
|
|
28
|
-
children = _ref.children,
|
|
29
|
+
_ref$children = _ref.children,
|
|
30
|
+
children = _ref$children === void 0 ? '' : _ref$children,
|
|
29
31
|
className = _ref.className,
|
|
30
32
|
style = _ref.style,
|
|
31
33
|
fullFeaturedCodeBlock = _ref.fullFeaturedCodeBlock,
|
|
32
34
|
onDoubleClick = _ref.onDoubleClick,
|
|
33
35
|
animated = _ref.animated,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_ref$enableMermaid = _ref.enableMermaid,
|
|
37
|
-
enableMermaid = _ref$enableMermaid === void 0 ? true : _ref$enableMermaid,
|
|
36
|
+
eLatex = _ref.enableLatex,
|
|
37
|
+
eMermaid = _ref.enableMermaid,
|
|
38
38
|
enableImageGallery = _ref.enableImageGallery,
|
|
39
39
|
enableCustomFootnotes = _ref.enableCustomFootnotes,
|
|
40
|
+
eGithubAlert = _ref.enableGithubAlert,
|
|
41
|
+
eStream = _ref.enableStream,
|
|
40
42
|
componentProps = _ref.componentProps,
|
|
41
43
|
allowHtml = _ref.allowHtml,
|
|
42
44
|
_ref$fontSize = _ref.fontSize,
|
|
@@ -61,11 +63,14 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
61
63
|
var _useStyles = useStyles(),
|
|
62
64
|
cx = _useStyles.cx,
|
|
63
65
|
styles = _useStyles.styles;
|
|
64
|
-
// Add state to track delayed animated value
|
|
65
66
|
var _useState = useState(animated),
|
|
66
67
|
_useState2 = _slicedToArray(_useState, 2),
|
|
67
68
|
delayedAnimated = _useState2[0],
|
|
68
69
|
setDelayedAnimated = _useState2[1];
|
|
70
|
+
var enableLatex = Boolean(typeof eLatex === 'boolean' && eLatex) || children.includes('$');
|
|
71
|
+
var enableMermaid = Boolean(typeof eMermaid === 'boolean' && eMermaid) || children.includes('```mermaid');
|
|
72
|
+
var enableGithubAlert = Boolean(typeof eGithubAlert === 'boolean' && eGithubAlert) || children.includes('> [!');
|
|
73
|
+
var enableStream = Boolean(typeof eStream === 'boolean' && eStream) || delayedAnimated || !children.includes('[^');
|
|
69
74
|
|
|
70
75
|
// Watch for changes in animated prop
|
|
71
76
|
useEffect(function () {
|
|
@@ -109,7 +114,15 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
109
114
|
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
110
115
|
});
|
|
111
116
|
}, [styles]);
|
|
112
|
-
var DefaultRender =
|
|
117
|
+
var DefaultRender = useCallback(function (_ref2) {
|
|
118
|
+
var children = _ref2.children,
|
|
119
|
+
reactMarkdownProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
120
|
+
return enableStream ? /*#__PURE__*/_jsx(StreamdownRender, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
|
|
121
|
+
children: children
|
|
122
|
+
})) : /*#__PURE__*/_jsx(MarkdownRender, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
|
|
123
|
+
children: children
|
|
124
|
+
}));
|
|
125
|
+
}, [enableStream]);
|
|
113
126
|
var defaultDOM = /*#__PURE__*/_jsx(DefaultRender, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
|
|
114
127
|
children: children
|
|
115
128
|
}));
|
|
@@ -138,6 +151,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
138
151
|
componentProps: componentProps,
|
|
139
152
|
components: components,
|
|
140
153
|
enableCustomFootnotes: enableCustomFootnotes,
|
|
154
|
+
enableGithubAlert: enableGithubAlert,
|
|
141
155
|
enableLatex: enableLatex,
|
|
142
156
|
enableMermaid: enableMermaid,
|
|
143
157
|
fullFeaturedCodeBlock: fullFeaturedCodeBlock,
|
|
@@ -148,7 +162,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
148
162
|
variant: variant
|
|
149
163
|
},
|
|
150
164
|
children: customRender ? customRender(defaultDOM, {
|
|
151
|
-
text: children
|
|
165
|
+
text: children
|
|
152
166
|
}) : defaultDOM
|
|
153
167
|
})
|
|
154
168
|
}))
|
|
@@ -15,6 +15,7 @@ import { memo, useId, useMemo } from 'react';
|
|
|
15
15
|
import { MarkdownHooks } from 'react-markdown';
|
|
16
16
|
import { useMarkdownComponents, useMarkdownContent, useMarkdownRehypePlugins, useMarkdownRemarkPlugins } from "../../hooks/useMarkdown";
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
import { createElement as _createElement } from "react";
|
|
18
19
|
var parseMarkdownIntoBlocks = function parseMarkdownIntoBlocks(markdown) {
|
|
19
20
|
var tokens = marked.lexer(markdown);
|
|
20
21
|
return tokens.map(function (token) {
|
|
@@ -44,13 +45,12 @@ export var StreamdownRender = /*#__PURE__*/memo(function (_ref2) {
|
|
|
44
45
|
}, [escapedContent]);
|
|
45
46
|
return /*#__PURE__*/_jsx("div", {
|
|
46
47
|
children: blocks.map(function (block, index) {
|
|
47
|
-
return /*#__PURE__*/
|
|
48
|
+
return /*#__PURE__*/_createElement(StreamdownBlock, _objectSpread(_objectSpread({}, rest), {}, {
|
|
48
49
|
components: components,
|
|
50
|
+
key: "".concat(generatedId, "-block_").concat(index),
|
|
49
51
|
rehypePlugins: rehypePluginsList,
|
|
50
52
|
remarkPlugins: remarkPluginsList
|
|
51
|
-
},
|
|
52
|
-
children: block
|
|
53
|
-
}), "".concat(generatedId, "-block_").concat(index));
|
|
53
|
+
}), block);
|
|
54
54
|
})
|
|
55
55
|
});
|
|
56
56
|
}, function (prevProps, nextProps) {
|
package/es/Markdown/type.d.ts
CHANGED
|
@@ -30,8 +30,10 @@ export interface SyntaxMarkdownProps {
|
|
|
30
30
|
};
|
|
31
31
|
components?: Components & Record<string, FC>;
|
|
32
32
|
enableCustomFootnotes?: boolean;
|
|
33
|
+
enableGithubAlert?: boolean;
|
|
33
34
|
enableLatex?: boolean;
|
|
34
35
|
enableMermaid?: boolean;
|
|
36
|
+
enableStream?: boolean;
|
|
35
37
|
fullFeaturedCodeBlock?: boolean;
|
|
36
38
|
reactMarkdownProps?: Omit<Readonly<ReactMarkdownOptions>, 'components' | 'rehypePlugins' | 'remarkPlugins'>;
|
|
37
39
|
rehypePlugins?: Pluggable[];
|
|
@@ -19,14 +19,15 @@ export var useMarkdownRehypePlugins = function useMarkdownRehypePlugins() {
|
|
|
19
19
|
animated = _useMarkdownContext.animated,
|
|
20
20
|
enableLatex = _useMarkdownContext.enableLatex,
|
|
21
21
|
enableCustomFootnotes = _useMarkdownContext.enableCustomFootnotes,
|
|
22
|
+
enableGithubAlert = _useMarkdownContext.enableGithubAlert,
|
|
22
23
|
allowHtml = _useMarkdownContext.allowHtml,
|
|
23
24
|
_useMarkdownContext$r = _useMarkdownContext.rehypePlugins,
|
|
24
25
|
rehypePlugins = _useMarkdownContext$r === void 0 ? [] : _useMarkdownContext$r,
|
|
25
26
|
_useMarkdownContext$r2 = _useMarkdownContext.rehypePluginsAhead,
|
|
26
27
|
rehypePluginsAhead = _useMarkdownContext$r2 === void 0 ? [] : _useMarkdownContext$r2;
|
|
27
28
|
var memoPlugins = useMemo(function () {
|
|
28
|
-
return [
|
|
29
|
-
}, [animated, enableLatex, enableCustomFootnotes, allowHtml]);
|
|
29
|
+
return [allowHtml && rehypeRaw, enableGithubAlert && rehypeGithubAlerts, enableLatex && rehypeKatex, enableLatex && rehypeKatexDir, enableCustomFootnotes && rehypeFootnoteLinks, animated && animatedPlugin].filter(Boolean);
|
|
30
|
+
}, [animated, enableLatex, enableGithubAlert, enableCustomFootnotes, allowHtml]);
|
|
30
31
|
return useMemo(function () {
|
|
31
32
|
return [].concat(_toConsumableArray(rehypePluginsAhead), _toConsumableArray(memoPlugins), _toConsumableArray(rehypePlugins));
|
|
32
33
|
}, [rehypePlugins, memoPlugins, rehypePluginsAhead]);
|