@lobehub/ui 2.10.1 → 2.10.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/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";
|
|
@@ -31,12 +32,12 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
31
32
|
fullFeaturedCodeBlock = _ref.fullFeaturedCodeBlock,
|
|
32
33
|
onDoubleClick = _ref.onDoubleClick,
|
|
33
34
|
animated = _ref.animated,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_ref$enableMermaid = _ref.enableMermaid,
|
|
37
|
-
enableMermaid = _ref$enableMermaid === void 0 ? true : _ref$enableMermaid,
|
|
35
|
+
eLatex = _ref.enableLatex,
|
|
36
|
+
eMermaid = _ref.enableMermaid,
|
|
38
37
|
enableImageGallery = _ref.enableImageGallery,
|
|
39
38
|
enableCustomFootnotes = _ref.enableCustomFootnotes,
|
|
39
|
+
eGithubAlert = _ref.enableGithubAlert,
|
|
40
|
+
eStream = _ref.enableStream,
|
|
40
41
|
componentProps = _ref.componentProps,
|
|
41
42
|
allowHtml = _ref.allowHtml,
|
|
42
43
|
_ref$fontSize = _ref.fontSize,
|
|
@@ -61,11 +62,14 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
61
62
|
var _useStyles = useStyles(),
|
|
62
63
|
cx = _useStyles.cx,
|
|
63
64
|
styles = _useStyles.styles;
|
|
64
|
-
// Add state to track delayed animated value
|
|
65
65
|
var _useState = useState(animated),
|
|
66
66
|
_useState2 = _slicedToArray(_useState, 2),
|
|
67
67
|
delayedAnimated = _useState2[0],
|
|
68
68
|
setDelayedAnimated = _useState2[1];
|
|
69
|
+
var enableLatex = Boolean(typeof eLatex === 'boolean' && eLatex) || children.includes('$');
|
|
70
|
+
var enableMermaid = Boolean(typeof eMermaid === 'boolean' && eMermaid) || children.includes('```mermaid');
|
|
71
|
+
var enableGithubAlert = Boolean(typeof eGithubAlert === 'boolean' && eGithubAlert) || children.includes('> [!');
|
|
72
|
+
var enableStream = Boolean(typeof eStream === 'boolean' && eStream) || delayedAnimated || !children.includes('[^');
|
|
69
73
|
|
|
70
74
|
// Watch for changes in animated prop
|
|
71
75
|
useEffect(function () {
|
|
@@ -109,7 +113,15 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
109
113
|
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
110
114
|
});
|
|
111
115
|
}, [styles]);
|
|
112
|
-
var DefaultRender =
|
|
116
|
+
var DefaultRender = useCallback(function (_ref2) {
|
|
117
|
+
var children = _ref2.children,
|
|
118
|
+
reactMarkdownProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
119
|
+
return enableStream ? /*#__PURE__*/_jsx(StreamdownRender, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
|
|
120
|
+
children: children
|
|
121
|
+
})) : /*#__PURE__*/_jsx(MarkdownRender, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
|
|
122
|
+
children: children
|
|
123
|
+
}));
|
|
124
|
+
}, [enableStream]);
|
|
113
125
|
var defaultDOM = /*#__PURE__*/_jsx(DefaultRender, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
|
|
114
126
|
children: children
|
|
115
127
|
}));
|
|
@@ -138,6 +150,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
138
150
|
componentProps: componentProps,
|
|
139
151
|
components: components,
|
|
140
152
|
enableCustomFootnotes: enableCustomFootnotes,
|
|
153
|
+
enableGithubAlert: enableGithubAlert,
|
|
141
154
|
enableLatex: enableLatex,
|
|
142
155
|
enableMermaid: enableMermaid,
|
|
143
156
|
fullFeaturedCodeBlock: fullFeaturedCodeBlock,
|
|
@@ -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]);
|