acsi-core 0.9.1 → 0.9.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.
@@ -7,8 +7,13 @@ import { useDispatch, useSelector } from 'react-redux';
7
7
  import { Link } from 'react-router-dom';
8
8
  import { FormGroup, Input, Label, Modal, ModalHeader, ModalBody, ModalFooter, Tooltip, Row, Col, Button, Pagination, PaginationItem, PaginationLink } from 'reactstrap';
9
9
  import ReactSelect, { components } from 'react-select';
10
+ import ReactMarkdown from 'react-markdown';
11
+ import remarkMath from 'remark-math';
12
+ import remarkGfm from 'remark-gfm';
13
+ import rehypeKatex from 'rehype-katex';
14
+ import remarkRehype from 'remark-rehype';
15
+ import rehypeRaw from 'rehype-raw';
10
16
  import 'katex/dist/katex.min.css';
11
- import renderMathInElement from 'katex/contrib/auto-render';
12
17
  import Cookies from 'js-cookie';
13
18
  export { default as Cookies } from 'js-cookie';
14
19
  import moment from 'moment';
@@ -1662,68 +1667,71 @@ var CoreTooltip = function CoreTooltip(_ref) {
1662
1667
  }, content));
1663
1668
  };
1664
1669
 
1670
+ var LatexExtractor = /*#__PURE__*/function () {
1671
+ function LatexExtractor() {}
1672
+ LatexExtractor.extractMultiLineFormulas = function extractMultiLineFormulas(content) {
1673
+ var formulas = content.split(/\\\\/);
1674
+ var isMathFormula = function isMathFormula(text) {
1675
+ return !!text && (text.includes('=') || text.includes('\\') || text.includes('^{') || text.includes('_{') || !!text.match(/[a-zA-Z]\s*[=+\-*/]\s*[a-zA-Z0-9]/));
1676
+ };
1677
+ return formulas.map(function (formula) {
1678
+ return formula.trim().replace(/\.$/, '');
1679
+ }).filter(function (formula) {
1680
+ return formula.length > 0 && isMathFormula(formula);
1681
+ });
1682
+ };
1683
+ LatexExtractor.extractInlineMath = function extractInlineMath(content) {
1684
+ var inlineMathRegex = /\$[^$]+\$|\\\([^)]+\\\)/g;
1685
+ var matches = content.match(inlineMathRegex) || [];
1686
+ return matches.map(function (match) {
1687
+ return match.trim();
1688
+ });
1689
+ };
1690
+ LatexExtractor.extractDisplayMath = function extractDisplayMath(content) {
1691
+ var displayMathRegex = /\\\[[^\]]+\\\]/g;
1692
+ var matches = content.match(displayMathRegex) || [];
1693
+ return matches.map(function (match) {
1694
+ return match.trim();
1695
+ });
1696
+ };
1697
+ return LatexExtractor;
1698
+ }();
1699
+
1700
+ var _excluded$3 = ["node"];
1665
1701
  var MarkdownLatexRender = function MarkdownLatexRender(_ref) {
1666
1702
  var content = _ref.content;
1667
- var displayRef = React.useRef(null);
1668
- var processedText = content.replace(/(.*)(?:\s*(.*))?(?=\n\n|$)/, function (_match, prefix, equation) {
1669
- if (equation) {
1670
- var trimmedEquation = equation.trim();
1671
- if (trimmedEquation.startsWith("\\(") && trimmedEquation.endsWith("\\)")) {
1672
- return "" + prefix + equation;
1673
- } else {
1674
- return prefix + "\n\\(" + equation + "\\)";
1675
- }
1676
- } else {
1677
- var latexStart = -1;
1678
- if (content.includes("_")) {
1679
- latexStart = content.search(/[a-zA-Z]_/);
1680
- } else if (content.includes("^")) {
1681
- latexStart = content.search(/[a-zA-Z]\^/);
1682
- } else if (content.includes("\\")) {
1683
- latexStart = content.search(/\\/);
1684
- }
1685
- if (latexStart !== -1) {
1686
- var _prefix = content.substring(0, latexStart);
1687
- var _equation = content.substring(latexStart);
1688
- return _prefix + "\\(" + _equation + "\\)";
1689
- } else {
1690
- return content;
1691
- }
1692
- }
1693
- });
1694
- useEffect(function () {
1695
- if (displayRef.current) {
1696
- try {
1697
- displayRef.current.innerHTML = processedText;
1698
- renderMathInElement(displayRef.current, {
1699
- delimiters: [{
1700
- left: "$$",
1701
- right: "$$",
1702
- display: true
1703
- }, {
1704
- left: "$$$$",
1705
- right: "$$$$",
1706
- display: true
1707
- }, {
1708
- left: "\\(",
1709
- right: "\\)",
1710
- display: false
1711
- }, {
1712
- left: "\\[",
1713
- right: "\\]",
1714
- display: true
1715
- }]
1716
- });
1717
- } catch (error) {
1718
- console.error("Error rendering math:", error);
1703
+ var updatedMarkdown = formatContent(content);
1704
+ return React.createElement("span", null, React.createElement(ReactMarkdown, {
1705
+ remarkPlugins: [remarkMath, remarkGfm, remarkRehype],
1706
+ rehypePlugins: [rehypeKatex, rehypeRaw],
1707
+ components: {
1708
+ p: function p(_ref2) {
1709
+ var props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
1710
+ return React.createElement("span", Object.assign({}, props));
1719
1711
  }
1720
1712
  }
1721
- }, [content]);
1722
- return React.createElement("span", null, React.createElement("div", {
1723
- ref: displayRef,
1724
- className: "equation-support"
1725
- }));
1713
+ }, updatedMarkdown));
1726
1714
  };
1715
+ function formatContent(content) {
1716
+ var lines = content.split("\n");
1717
+ var result = [];
1718
+ var i = 0;
1719
+ while (i < lines.length) {
1720
+ var line = lines[i];
1721
+ var results = LatexExtractor.extractMultiLineFormulas(line);
1722
+ var newline = line.replace(results[0], function (match) {
1723
+ return "$$" + match + "$$";
1724
+ });
1725
+ if (newline !== line) {
1726
+ result.push(newline);
1727
+ i++;
1728
+ continue;
1729
+ }
1730
+ result.push(line);
1731
+ i++;
1732
+ }
1733
+ return result.join("\n");
1734
+ }
1727
1735
 
1728
1736
  var CookieService = /*#__PURE__*/function () {
1729
1737
  function CookieService() {}
@@ -3320,7 +3328,7 @@ var CustomOption = function CustomOption(props) {
3320
3328
  }, props.data.label));
3321
3329
  };
3322
3330
 
3323
- var _excluded$3 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3331
+ var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3324
3332
  var CustomSelect = function CustomSelect(_ref) {
3325
3333
  var isDefault = _ref.isDefault,
3326
3334
  options = _ref.options,
@@ -3328,7 +3336,7 @@ var CustomSelect = function CustomSelect(_ref) {
3328
3336
  scrollBottom = _ref.scrollBottom,
3329
3337
  value = _ref.value,
3330
3338
  isMulti = _ref.isMulti,
3331
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
3339
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3332
3340
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3333
3341
  return value.includes(i.value);
3334
3342
  }) : isMulti ? options === null || options === void 0 ? void 0 : options.filter(function (i) {
@@ -3355,7 +3363,7 @@ var CustomSelect = function CustomSelect(_ref) {
3355
3363
  }, rest));
3356
3364
  };
3357
3365
 
3358
- var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3366
+ var _excluded$5 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3359
3367
  var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3360
3368
  var isDefault = _ref.isDefault,
3361
3369
  options = _ref.options,
@@ -3363,7 +3371,7 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3363
3371
  scrollBottom = _ref.scrollBottom,
3364
3372
  value = _ref.value,
3365
3373
  isMulti = _ref.isMulti,
3366
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3374
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3367
3375
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3368
3376
  return value.includes(i.value);
3369
3377
  }) : isMulti ? options.filter(function (i) {
@@ -3390,14 +3398,14 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3390
3398
  }, rest));
3391
3399
  };
3392
3400
 
3393
- var _excluded$5 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3401
+ var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3394
3402
  var CustomCreatable = function CustomCreatable(_ref) {
3395
3403
  var options = _ref.options,
3396
3404
  isDisabled = _ref.isDisabled,
3397
3405
  scrollBottom = _ref.scrollBottom,
3398
3406
  value = _ref.value,
3399
3407
  isMulti = _ref.isMulti,
3400
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3408
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3401
3409
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3402
3410
  return value.includes(i.value);
3403
3411
  }) : isMulti ? options.filter(function (i) {
@@ -3424,7 +3432,7 @@ var CustomCreatable = function CustomCreatable(_ref) {
3424
3432
  }, rest));
3425
3433
  };
3426
3434
 
3427
- var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3435
+ var _excluded$7 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3428
3436
  var CustomSelectOption = function CustomSelectOption(_ref) {
3429
3437
  var defaultValue = _ref.defaultValue,
3430
3438
  options = _ref.options,
@@ -3432,7 +3440,7 @@ var CustomSelectOption = function CustomSelectOption(_ref) {
3432
3440
  scrollBottom = _ref.scrollBottom,
3433
3441
  value = _ref.value,
3434
3442
  isMulti = _ref.isMulti,
3435
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3443
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
3436
3444
  var initialValues = defaultValue !== null && typeof defaultValue !== "undefined" ? options.find(function (option) {
3437
3445
  return option.value === defaultValue;
3438
3446
  }) || null : null;