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