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.
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,68 +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
- renderMathInElement(displayRef.current, {
1700
- delimiters: [{
1701
- left: "$$",
1702
- right: "$$",
1703
- display: true
1704
- }, {
1705
- left: "$$$$",
1706
- right: "$$$$",
1707
- display: true
1708
- }, {
1709
- left: "\\(",
1710
- right: "\\)",
1711
- display: false
1712
- }, {
1713
- left: "\\[",
1714
- right: "\\]",
1715
- display: true
1716
- }]
1717
- });
1718
- } catch (error) {
1719
- 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));
1720
1712
  }
1721
1713
  }
1722
- }, [content]);
1723
- return React__default.createElement("span", null, React__default.createElement("div", {
1724
- ref: displayRef,
1725
- className: "equation-support"
1726
- }));
1714
+ }, updatedMarkdown));
1727
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
+ }
1728
1736
 
1729
1737
  var CookieService = /*#__PURE__*/function () {
1730
1738
  function CookieService() {}
@@ -3318,7 +3326,7 @@ var CustomOption = function CustomOption(props) {
3318
3326
  }, props.data.label));
3319
3327
  };
3320
3328
 
3321
- var _excluded$3 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3329
+ var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3322
3330
  var CustomSelect = function CustomSelect(_ref) {
3323
3331
  var isDefault = _ref.isDefault,
3324
3332
  options = _ref.options,
@@ -3326,7 +3334,7 @@ var CustomSelect = function CustomSelect(_ref) {
3326
3334
  scrollBottom = _ref.scrollBottom,
3327
3335
  value = _ref.value,
3328
3336
  isMulti = _ref.isMulti,
3329
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
3337
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3330
3338
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3331
3339
  return value.includes(i.value);
3332
3340
  }) : isMulti ? options === null || options === void 0 ? void 0 : options.filter(function (i) {
@@ -3353,7 +3361,7 @@ var CustomSelect = function CustomSelect(_ref) {
3353
3361
  }, rest));
3354
3362
  };
3355
3363
 
3356
- var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3364
+ var _excluded$5 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3357
3365
  var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3358
3366
  var isDefault = _ref.isDefault,
3359
3367
  options = _ref.options,
@@ -3361,7 +3369,7 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3361
3369
  scrollBottom = _ref.scrollBottom,
3362
3370
  value = _ref.value,
3363
3371
  isMulti = _ref.isMulti,
3364
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3372
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3365
3373
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3366
3374
  return value.includes(i.value);
3367
3375
  }) : isMulti ? options.filter(function (i) {
@@ -3388,14 +3396,14 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3388
3396
  }, rest));
3389
3397
  };
3390
3398
 
3391
- var _excluded$5 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3399
+ var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3392
3400
  var CustomCreatable = function CustomCreatable(_ref) {
3393
3401
  var options = _ref.options,
3394
3402
  isDisabled = _ref.isDisabled,
3395
3403
  scrollBottom = _ref.scrollBottom,
3396
3404
  value = _ref.value,
3397
3405
  isMulti = _ref.isMulti,
3398
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3406
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3399
3407
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3400
3408
  return value.includes(i.value);
3401
3409
  }) : isMulti ? options.filter(function (i) {
@@ -3422,7 +3430,7 @@ var CustomCreatable = function CustomCreatable(_ref) {
3422
3430
  }, rest));
3423
3431
  };
3424
3432
 
3425
- var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3433
+ var _excluded$7 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3426
3434
  var CustomSelectOption = function CustomSelectOption(_ref) {
3427
3435
  var defaultValue = _ref.defaultValue,
3428
3436
  options = _ref.options,
@@ -3430,7 +3438,7 @@ var CustomSelectOption = function CustomSelectOption(_ref) {
3430
3438
  scrollBottom = _ref.scrollBottom,
3431
3439
  value = _ref.value,
3432
3440
  isMulti = _ref.isMulti,
3433
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3441
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
3434
3442
  var initialValues = defaultValue !== null && typeof defaultValue !== "undefined" ? options.find(function (option) {
3435
3443
  return option.value === defaultValue;
3436
3444
  }) || null : null;