@lobehub/ui 2.0.15 → 2.0.17

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.
@@ -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 = ["fullFeatured", "actionIconSize", "children", "language", "className", "copyable", "showLanguage", "variant", "shadow", "wrap", "bodyRender", "actionsRender", "enableTransformer", "theme"];
4
+ var _excluded = ["animated", "fullFeatured", "actionIconSize", "children", "language", "className", "copyable", "showLanguage", "variant", "shadow", "wrap", "bodyRender", "actionsRender", "enableTransformer", "theme"];
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; }
@@ -20,7 +20,8 @@ import { useStyles } from "./style";
20
20
  import { jsx as _jsx } from "react/jsx-runtime";
21
21
  import { jsxs as _jsxs } from "react/jsx-runtime";
22
22
  export var Highlighter = /*#__PURE__*/memo(function (_ref) {
23
- var fullFeatured = _ref.fullFeatured,
23
+ var animated = _ref.animated,
24
+ fullFeatured = _ref.fullFeatured,
24
25
  actionIconSize = _ref.actionIconSize,
25
26
  children = _ref.children,
26
27
  _ref$language = _ref.language,
@@ -81,6 +82,7 @@ export var Highlighter = /*#__PURE__*/memo(function (_ref) {
81
82
  originalNode: originalActions
82
83
  }) : originalActions;
83
84
  var originalBody = /*#__PURE__*/_jsx(SyntaxHighlighter, {
85
+ animated: animated,
84
86
  enableTransformer: enableTransformer,
85
87
  language: language === null || language === void 0 ? void 0 : language.toLowerCase(),
86
88
  theme: theme,
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ declare const Line: import("react").NamedExoticComponent<{
3
+ children?: string | undefined;
4
+ }>;
5
+ export default Line;
@@ -0,0 +1,78 @@
1
+ 'use client';
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
+ import { memo, useEffect, useState } from 'react';
15
+ import Span from "./Span";
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ var Line = /*#__PURE__*/memo(function (_ref) {
18
+ var children = _ref.children;
19
+ var _useState = useState([]),
20
+ _useState2 = _slicedToArray(_useState, 2),
21
+ contents = _useState2[0],
22
+ setContents = _useState2[1];
23
+ useEffect(function () {
24
+ if (children && typeof children === 'string') {
25
+ // Extract all lines from the HTML content
26
+ // We need to handle the structure from shiki which gives us HTML with a <pre><code> structure
27
+ var parser = new DOMParser();
28
+ var doc = parser.parseFromString(children, 'text/html');
29
+ var codeElement = doc.querySelector('span.line');
30
+ if (codeElement) {
31
+ var spanLines = codeElement.querySelectorAll('span');
32
+ var newLines = _toConsumableArray(spanLines).map(function (line) {
33
+ return line.outerHTML;
34
+ });
35
+ setContents(function (prevLines) {
36
+ if (prevLines.length !== newLines.length) return newLines;
37
+ var hasChanged = false;
38
+ var _iterator = _createForOfIteratorHelper(newLines.entries()),
39
+ _step;
40
+ try {
41
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
+ var _step$value = _slicedToArray(_step.value, 2),
43
+ i = _step$value[0],
44
+ newLine = _step$value[1];
45
+ if (prevLines[i] !== newLine) {
46
+ hasChanged = true;
47
+ break;
48
+ }
49
+ }
50
+ } catch (err) {
51
+ _iterator.e(err);
52
+ } finally {
53
+ _iterator.f();
54
+ }
55
+ return hasChanged ? newLines : prevLines;
56
+ });
57
+ } else {
58
+ // Fallback if the structure is different
59
+ var htmlLines = children.split('\n').map(function (line) {
60
+ return "<span>".concat(line, "</span>");
61
+ });
62
+ setContents(htmlLines);
63
+ }
64
+ }
65
+ }, [children]);
66
+ return /*#__PURE__*/_jsx("span", {
67
+ className: 'line',
68
+ children: contents && contents.length > 0 ? contents.map(function (span, index) {
69
+ return /*#__PURE__*/_jsx(Span, {
70
+ children: span
71
+ }, index);
72
+ }) : /*#__PURE__*/_jsx("span", {
73
+ children: " "
74
+ })
75
+ });
76
+ });
77
+ Line.displayName = 'HighlighterLine';
78
+ export default Line;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ declare const Span: import("react").NamedExoticComponent<{
3
+ children?: string | undefined;
4
+ }>;
5
+ export default Span;
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+
3
+ import { memo } from 'react';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ var Span = /*#__PURE__*/memo(function (_ref) {
6
+ var children = _ref.children;
7
+ return /*#__PURE__*/_jsx("span", {
8
+ dangerouslySetInnerHTML: {
9
+ __html: children || ''
10
+ }
11
+ });
12
+ });
13
+ Span.displayName = 'HighlighterSpan';
14
+ export default Span;
@@ -14,66 +14,19 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
  import { cva } from 'class-variance-authority';
15
15
  import { memo, useEffect, useMemo, useState } from 'react';
16
16
  import { useHighlight } from "../../hooks/useHighlight";
17
+ import Line from "./Line";
17
18
  import { useStyles } from "./style";
18
19
  import { jsx as _jsx } from "react/jsx-runtime";
19
- var Span = /*#__PURE__*/memo(function (_ref) {
20
- var data = _ref.data;
21
- return /*#__PURE__*/_jsx("span", {
22
- dangerouslySetInnerHTML: {
23
- __html: data
24
- }
25
- });
26
- });
27
- var Line = /*#__PURE__*/memo(function (_ref2) {
28
- var data = _ref2.data;
29
- var _useState = useState([]),
30
- _useState2 = _slicedToArray(_useState, 2),
31
- contents = _useState2[0],
32
- setContents = _useState2[1];
33
- useEffect(function () {
34
- if (data && typeof data === 'string') {
35
- // Extract all lines from the HTML content
36
- // We need to handle the structure from shiki which gives us HTML with a <pre><code> structure
37
- var parser = new DOMParser();
38
- var doc = parser.parseFromString(data, 'text/html');
39
- var codeElement = doc.querySelector('span.line');
40
- if (codeElement) {
41
- var spanLines = codeElement.querySelectorAll('span');
42
- var newLines = _toConsumableArray(spanLines).map(function (line) {
43
- return line.outerHTML;
44
- });
45
- setContents(newLines);
46
- } else {
47
- // Fallback if the structure is different
48
- var htmlLines = data.split('\n').map(function (line) {
49
- return "<span>".concat(line, "</span>");
50
- });
51
- setContents(htmlLines);
52
- }
53
- }
54
- }, [data]);
55
- return /*#__PURE__*/_jsx("span", {
56
- className: 'line',
57
- children: contents && contents.length > 0 ? contents.map(function (span, index) {
58
- return /*#__PURE__*/_jsx(Span, {
59
- data: span || ' '
60
- }, index);
61
- }) : /*#__PURE__*/_jsx("span", {
62
- children: " "
63
- })
64
- });
65
- });
66
- Line.displayName = 'HighlighterLine';
67
- Span.displayName = 'HighlighterSpan';
68
- var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref3) {
69
- var ref = _ref3.ref,
70
- children = _ref3.children,
71
- language = _ref3.language,
72
- className = _ref3.className,
73
- style = _ref3.style,
74
- enableTransformer = _ref3.enableTransformer,
75
- variant = _ref3.variant,
76
- theme = _ref3.theme;
20
+ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref) {
21
+ var ref = _ref.ref,
22
+ children = _ref.children,
23
+ language = _ref.language,
24
+ className = _ref.className,
25
+ style = _ref.style,
26
+ enableTransformer = _ref.enableTransformer,
27
+ variant = _ref.variant,
28
+ theme = _ref.theme,
29
+ animated = _ref.animated;
77
30
  var _useStyles = useStyles(),
78
31
  styles = _useStyles.styles,
79
32
  cx = _useStyles.cx;
@@ -85,16 +38,28 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref3) {
85
38
  theme: isDefaultTheme ? undefined : theme
86
39
  }),
87
40
  data = _useHighlight.data;
88
- var _useState3 = useState([]),
41
+ var _useState = useState([]),
42
+ _useState2 = _slicedToArray(_useState, 2),
43
+ contentLines = _useState2[0],
44
+ setContentLines = _useState2[1];
45
+ var _useState3 = useState({}),
89
46
  _useState4 = _slicedToArray(_useState3, 2),
90
- contentLines = _useState4[0],
91
- setContentLines = _useState4[1];
47
+ preStyle = _useState4[0],
48
+ setPreStyle = _useState4[1];
92
49
  useEffect(function () {
93
50
  if (data && typeof data === 'string') {
94
51
  // Extract all lines from the HTML content
95
52
  // We need to handle the structure from shiki which gives us HTML with a <pre><code> structure
96
53
  var parser = new DOMParser();
97
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
+ }
98
63
  var codeElement = doc.querySelector('pre code');
99
64
  if (codeElement) {
100
65
  var spanLines = codeElement.querySelectorAll('.line');
@@ -175,6 +140,21 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref3) {
175
140
  })
176
141
  })
177
142
  });
143
+ if (!animated) {
144
+ return /*#__PURE__*/_jsx("div", {
145
+ className: cx(variants({
146
+ shiki: true,
147
+ showBackground: showBackground,
148
+ variant: variant
149
+ }), className),
150
+ dangerouslySetInnerHTML: {
151
+ __html: data || ''
152
+ },
153
+ dir: "ltr",
154
+ ref: ref,
155
+ style: style
156
+ });
157
+ }
178
158
  return /*#__PURE__*/_jsx("div", {
179
159
  className: cx(variants({
180
160
  shiki: true,
@@ -185,11 +165,17 @@ var SyntaxHighlighter = /*#__PURE__*/memo(function (_ref3) {
185
165
  ref: ref,
186
166
  style: style,
187
167
  children: /*#__PURE__*/_jsx("pre", {
188
- className: "shiki",
168
+ className: cx('shiki', isDefaultTheme ? undefined : theme),
169
+ style: preStyle,
170
+ tabIndex: 0,
189
171
  children: /*#__PURE__*/_jsx("code", {
172
+ style: {
173
+ display: 'flex',
174
+ flexDirection: 'column'
175
+ },
190
176
  children: contentLines.map(function (line, index) {
191
177
  return /*#__PURE__*/_jsx(Line, {
192
- data: line
178
+ children: line
193
179
  }, index);
194
180
  })
195
181
  })
@@ -11,7 +11,7 @@ export var useStyles = createStyles(function (_ref) {
11
11
  noPadding: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n pre {\n padding: 0;\n }\n "]))),
12
12
  padding: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n pre {\n padding: 16px;\n }\n "]))),
13
13
  root: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n direction: ltr;\n margin: 0;\n padding: 0;\n text-align: start;\n\n pre {\n overflow-x: auto;\n margin: 0;\n padding: 0;\n }\n "]))),
14
- shiki: cx("".concat(prefixCls, "-highlighter-shiki"), css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n pre {\n code {\n display: block;\n\n .line {\n display: block;\n\n width: calc(100% + 32px);\n margin-block: 0;\n margin-inline: -16px;\n padding-block: 0;\n padding-inline: 16px;\n }\n }\n\n &.has-focused {\n .line:not(.focused) {\n opacity: 0.5;\n }\n }\n\n .highlighted {\n background: ", ";\n\n &.warning {\n background: ", ";\n }\n\n &.error {\n background: ", ";\n }\n }\n\n .highlighted-word {\n padding-block: 0.1em;\n padding-inline: 0.2em;\n\n background: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n }\n\n .diff {\n &.remove {\n background: ", ";\n\n &::before {\n content: '-';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n\n &.add {\n background: ", ";\n\n &::before {\n content: '+';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n }\n }\n "])), token.colorFillTertiary, token.colorWarningBg, token.colorErrorBg, token.colorFillTertiary, token.colorBorderSecondary, token.borderRadius, token.colorErrorBg, token.colorErrorText, token.colorSuccessBg, token.colorSuccessText)),
14
+ shiki: cx("".concat(prefixCls, "-highlighter-shiki"), css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n pre {\n code {\n display: block;\n\n .line {\n display: inline-block;\n\n width: calc(100% + 32px);\n margin-block: 0;\n margin-inline: -16px;\n padding-block: 0;\n padding-inline: 16px;\n }\n }\n\n &.has-focused {\n .line:not(.focused) {\n opacity: 0.5;\n }\n }\n\n .highlighted {\n background: ", ";\n\n &.warning {\n background: ", ";\n }\n\n &.error {\n background: ", ";\n }\n }\n\n .highlighted-word {\n padding-block: 0.1em;\n padding-inline: 0.2em;\n border: 1px solid ", ";\n border-radius: ", "px;\n\n background: ", ";\n }\n\n .diff {\n &.remove {\n background: ", ";\n\n &::before {\n content: '-';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n\n &.add {\n background: ", ";\n\n &::before {\n content: '+';\n\n position: absolute;\n inset-inline-start: 4px;\n\n display: inline-block;\n\n color: ", ";\n }\n }\n }\n }\n "])), token.colorFillTertiary, token.colorWarningBg, token.colorErrorBg, token.colorBorderSecondary, token.borderRadius, token.colorFillTertiary, token.colorErrorBg, token.colorErrorText, token.colorSuccessBg, token.colorSuccessText)),
15
15
  unshiki: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n color: ", ";\n "])), token.colorTextDescription)
16
16
  };
17
17
  });
@@ -4,6 +4,7 @@ import type { BuiltinTheme } from 'shiki';
4
4
  import type { ActionIconProps } from "../ActionIcon";
5
5
  import { DivProps } from "../types";
6
6
  export interface SyntaxHighlighterProps extends DivProps {
7
+ animated?: boolean;
7
8
  children: string;
8
9
  enableTransformer?: HighlighterProps['enableTransformer'];
9
10
  language: HighlighterProps['language'];
@@ -20,6 +21,7 @@ export interface HighlighterProps extends Omit<FlexboxProps, 'children' | 'wrap'
20
21
  originalNode: ReactNode;
21
22
  }) => ReactNode;
22
23
  allowChangeLanguage?: boolean;
24
+ animated?: boolean;
23
25
  bodyRender?: (props: {
24
26
  content: string;
25
27
  language: string;
@@ -7,10 +7,16 @@ 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, useEffect, useMemo, useState } from 'react';
14
20
  import SyntaxMarkdown from "./SyntaxMarkdown";
15
21
  import Typography from "./Typography";
16
22
  import { useStyles } from "./style";
@@ -55,6 +61,27 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
55
61
  var _useStyles = useStyles(),
56
62
  cx = _useStyles.cx,
57
63
  styles = _useStyles.styles;
64
+ // Add state to track delayed animated value
65
+ var _useState = useState(animated),
66
+ _useState2 = _slicedToArray(_useState, 2),
67
+ delayedAnimated = _useState2[0],
68
+ setDelayedAnimated = _useState2[1];
69
+
70
+ // Watch for changes in animated prop
71
+ useEffect(function () {
72
+ // If animated changes from true to false, delay the update by 1 second
73
+ if (animated === false && delayedAnimated === true) {
74
+ var timer = setTimeout(function () {
75
+ setDelayedAnimated(false);
76
+ }, 1000);
77
+ return function () {
78
+ return clearTimeout(timer);
79
+ };
80
+ } else {
81
+ // For any other changes, update immediately
82
+ setDelayedAnimated(animated);
83
+ }
84
+ }, [animated, delayedAnimated]);
58
85
 
59
86
  // Style variant handling
60
87
  var variants = useMemo(function () {
@@ -84,7 +111,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
84
111
  }, [styles]);
85
112
  return /*#__PURE__*/_jsx(Typography, _objectSpread(_objectSpread({
86
113
  className: cx(variants({
87
- animated: animated,
114
+ animated: delayedAnimated,
88
115
  enableLatex: enableLatex,
89
116
  variant: variant
90
117
  }), className),
@@ -99,7 +126,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
99
126
  }, rest), {}, {
100
127
  children: /*#__PURE__*/_jsx(SyntaxMarkdown, {
101
128
  allowHtml: allowHtml,
102
- animated: animated,
129
+ animated: delayedAnimated,
103
130
  citations: citations,
104
131
  componentProps: componentProps,
105
132
  components: components,
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import 'katex/dist/contrib/mhchem';
2
3
  import { SyntaxMarkdownProps } from '../type';
3
4
  declare const SyntaxMarkdown: import("react").NamedExoticComponent<SyntaxMarkdownProps>;
4
5
  export default SyntaxMarkdown;
@@ -6,40 +6,66 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
6
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
7
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
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
+ import 'katex/dist/contrib/mhchem';
9
10
  import { memo, useMemo } from 'react';
10
11
  import ReactMarkdown from 'react-markdown';
11
12
  import { PreviewGroup } from "../../Image";
12
- import { useMarkdown } from "../../hooks/useMarkdown";
13
+ import { useMarkdown, useMarkdownContent } from "../../hooks/useMarkdown";
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
- var SyntaxMarkdown = /*#__PURE__*/memo(function (_ref) {
15
- var children = _ref.children,
16
- fullFeaturedCodeBlock = _ref.fullFeaturedCodeBlock,
17
- animated = _ref.animated,
18
- _ref$enableLatex = _ref.enableLatex,
19
- enableLatex = _ref$enableLatex === void 0 ? true : _ref$enableLatex,
20
- _ref$enableMermaid = _ref.enableMermaid,
21
- enableMermaid = _ref$enableMermaid === void 0 ? true : _ref$enableMermaid,
22
- _ref$enableImageGalle = _ref.enableImageGallery,
23
- enableImageGallery = _ref$enableImageGalle === void 0 ? true : _ref$enableImageGalle,
24
- enableCustomFootnotes = _ref.enableCustomFootnotes,
25
- componentProps = _ref.componentProps,
26
- allowHtml = _ref.allowHtml,
27
- showFootnotes = _ref.showFootnotes,
28
- _ref$variant = _ref.variant,
29
- variant = _ref$variant === void 0 ? 'default' : _ref$variant,
15
+ // Create a pure component that only renders ReactMarkdown
16
+ // This helps prevent unnecessary rerenders of ReactMarkdown
17
+ var MarkdownRenderer = /*#__PURE__*/memo(function (_ref) {
18
+ var escapedContent = _ref.escapedContent,
19
+ memoComponents = _ref.memoComponents,
20
+ rehypePluginsList = _ref.rehypePluginsList,
21
+ remarkPluginsList = _ref.remarkPluginsList,
30
22
  reactMarkdownProps = _ref.reactMarkdownProps,
31
- rehypePlugins = _ref.rehypePlugins,
32
- remarkPlugins = _ref.remarkPlugins,
33
- remarkPluginsAhead = _ref.remarkPluginsAhead,
34
- _ref$components = _ref.components,
35
- components = _ref$components === void 0 ? {} : _ref$components,
36
- customRender = _ref.customRender,
37
- citations = _ref.citations;
38
- // Use our new hook to handle Markdown processing
23
+ enableImageGallery = _ref.enableImageGallery;
24
+ return /*#__PURE__*/_jsx(PreviewGroup, {
25
+ enable: enableImageGallery,
26
+ children: /*#__PURE__*/_jsx(ReactMarkdown, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
27
+ components: memoComponents,
28
+ rehypePlugins: rehypePluginsList,
29
+ remarkPlugins: remarkPluginsList,
30
+ children: escapedContent || ''
31
+ }))
32
+ });
33
+ });
34
+ MarkdownRenderer.displayName = 'MarkdownRenderer';
35
+ var SyntaxMarkdown = /*#__PURE__*/memo(function (_ref2) {
36
+ var children = _ref2.children,
37
+ fullFeaturedCodeBlock = _ref2.fullFeaturedCodeBlock,
38
+ animated = _ref2.animated,
39
+ _ref2$enableLatex = _ref2.enableLatex,
40
+ enableLatex = _ref2$enableLatex === void 0 ? true : _ref2$enableLatex,
41
+ _ref2$enableMermaid = _ref2.enableMermaid,
42
+ enableMermaid = _ref2$enableMermaid === void 0 ? true : _ref2$enableMermaid,
43
+ _ref2$enableImageGall = _ref2.enableImageGallery,
44
+ enableImageGallery = _ref2$enableImageGall === void 0 ? true : _ref2$enableImageGall,
45
+ enableCustomFootnotes = _ref2.enableCustomFootnotes,
46
+ componentProps = _ref2.componentProps,
47
+ allowHtml = _ref2.allowHtml,
48
+ showFootnotes = _ref2.showFootnotes,
49
+ _ref2$variant = _ref2.variant,
50
+ variant = _ref2$variant === void 0 ? 'default' : _ref2$variant,
51
+ reactMarkdownProps = _ref2.reactMarkdownProps,
52
+ rehypePlugins = _ref2.rehypePlugins,
53
+ remarkPlugins = _ref2.remarkPlugins,
54
+ remarkPluginsAhead = _ref2.remarkPluginsAhead,
55
+ _ref2$components = _ref2.components,
56
+ components = _ref2$components === void 0 ? {} : _ref2$components,
57
+ customRender = _ref2.customRender,
58
+ citations = _ref2.citations;
59
+ var escapedContent = useMarkdownContent({
60
+ animated: animated,
61
+ children: children,
62
+ citations: citations,
63
+ enableCustomFootnotes: enableCustomFootnotes,
64
+ enableLatex: enableLatex
65
+ });
39
66
  var _useMarkdown = useMarkdown({
40
67
  allowHtml: allowHtml,
41
68
  animated: animated,
42
- children: children,
43
69
  citations: citations,
44
70
  componentProps: componentProps,
45
71
  components: components,
@@ -54,29 +80,32 @@ var SyntaxMarkdown = /*#__PURE__*/memo(function (_ref) {
54
80
  showFootnotes: showFootnotes,
55
81
  variant: variant
56
82
  }),
57
- escapedContent = _useMarkdown.escapedContent,
58
83
  memoComponents = _useMarkdown.memoComponents,
59
84
  rehypePluginsList = _useMarkdown.rehypePluginsList,
60
85
  remarkPluginsList = _useMarkdown.remarkPluginsList;
61
86
 
62
- // 渲染默认内容
87
+ // Memoize the renderer configuration to prevent unnecessary re-renders
88
+ var rendererProps = useMemo(function () {
89
+ return {
90
+ enableImageGallery: enableImageGallery,
91
+ memoComponents: memoComponents,
92
+ reactMarkdownProps: reactMarkdownProps,
93
+ rehypePluginsList: rehypePluginsList,
94
+ remarkPluginsList: remarkPluginsList
95
+ };
96
+ }, [memoComponents, rehypePluginsList, remarkPluginsList, enableImageGallery, reactMarkdownProps]);
97
+
98
+ // Render default content using memoized MarkdownRenderer
63
99
  var defaultDOM = useMemo(function () {
64
- return /*#__PURE__*/_jsx(PreviewGroup, {
65
- enable: enableImageGallery,
66
- children: /*#__PURE__*/_jsx(ReactMarkdown, _objectSpread(_objectSpread({}, reactMarkdownProps), {}, {
67
- components: memoComponents,
68
- rehypePlugins: rehypePluginsList,
69
- remarkPlugins: remarkPluginsList,
70
- children: escapedContent
71
- }))
72
- });
73
- }, [escapedContent, memoComponents, rehypePluginsList, remarkPluginsList, enableImageGallery, reactMarkdownProps]);
100
+ return /*#__PURE__*/_jsx(MarkdownRenderer, _objectSpread({
101
+ escapedContent: escapedContent
102
+ }, rendererProps));
103
+ }, [rendererProps, escapedContent]);
74
104
 
75
- // 应用自定义渲染
76
- var markdownContent = customRender ? customRender(defaultDOM, {
105
+ // Apply custom rendering if needed
106
+ return customRender ? customRender(defaultDOM, {
77
107
  text: escapedContent || ''
78
108
  }) : defaultDOM;
79
- return markdownContent;
80
109
  });
81
110
  SyntaxMarkdown.displayName = 'SyntaxMarkdown';
82
111
  export default SyntaxMarkdown;
@@ -7,12 +7,12 @@ export declare const useCode: (raw: any) => {
7
7
  lang: any;
8
8
  } | undefined;
9
9
  interface CodeBlockProps {
10
+ animated?: boolean;
10
11
  children: any;
11
12
  enableMermaid?: boolean;
12
13
  fullFeatured?: boolean;
13
14
  highlight?: HighlighterProps;
14
15
  mermaid?: MermaidProps;
15
16
  }
16
- export declare const CodeLite: FC<CodeBlockProps>;
17
- export declare const CodeFullFeatured: FC<CodeBlockProps>;
17
+ export declare const CodeBlock: FC<CodeBlockProps>;
18
18
  export {};
@@ -1,5 +1,5 @@
1
1
  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); }
2
- var _excluded = ["fullFeatured", "enableMermaid", "highlight", "mermaid", "children"];
2
+ var _excluded = ["fullFeatured", "enableMermaid", "highlight", "mermaid", "children", "animated"];
3
3
  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; }
4
4
  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; }
5
5
  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; }
@@ -30,12 +30,13 @@ export var useCode = function useCode(raw) {
30
30
  lang: lang
31
31
  };
32
32
  };
33
- var CodeBlock = function CodeBlock(_ref) {
33
+ export var CodeBlock = function CodeBlock(_ref) {
34
34
  var fullFeatured = _ref.fullFeatured,
35
35
  enableMermaid = _ref.enableMermaid,
36
36
  highlight = _ref.highlight,
37
37
  mermaid = _ref.mermaid,
38
38
  children = _ref.children,
39
+ animated = _ref.animated,
39
40
  rest = _objectWithoutProperties(_ref, _excluded);
40
41
  var code = useCode(children);
41
42
  if (!code) return;
@@ -49,17 +50,10 @@ var CodeBlock = function CodeBlock(_ref) {
49
50
  children: code.content
50
51
  });
51
52
  return /*#__PURE__*/_jsx(Pre, _objectSpread(_objectSpread(_objectSpread({
53
+ animated: animated,
52
54
  fullFeatured: fullFeatured,
53
55
  language: code.lang
54
56
  }, highlight), rest), {}, {
55
57
  children: code.content
56
58
  }));
57
- };
58
- export var CodeLite = function CodeLite(props) {
59
- return /*#__PURE__*/_jsx(CodeBlock, _objectSpread({}, props));
60
- };
61
- export var CodeFullFeatured = function CodeFullFeatured(props) {
62
- return /*#__PURE__*/_jsx(CodeBlock, _objectSpread({
63
- fullFeatured: true
64
- }, props));
65
59
  };