acsi-core 0.9.2 → 0.9.4

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,77 @@ var CoreTooltip = function CoreTooltip(_ref) {
1663
1668
  }, content));
1664
1669
  };
1665
1670
 
1666
- var MarkdownLatexRender = function MarkdownLatexRender(_ref) {
1667
- 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;
1671
+ var LatexExtractor = /*#__PURE__*/function () {
1672
+ function LatexExtractor() {}
1673
+ LatexExtractor.ApplyLatexFormat = function ApplyLatexFormat(content) {
1674
+ var allComponents = LatexExtractor.extractAllLatexUltimate(content);
1675
+ var multiLineFormulas = LatexExtractor.extractMultiLineFormulas(content);
1676
+ var foundLatexStr = multiLineFormulas[0] || "";
1677
+ if (foundLatexStr && foundLatexStr !== "" && content.includes(foundLatexStr)) {
1678
+ var firstPosition = content.indexOf(allComponents[0]);
1679
+ if (firstPosition > 0) {
1680
+ var textPart = content.slice(0, firstPosition).trim();
1681
+ var latexPart = content.slice(firstPosition).trim();
1682
+ return textPart + (" $$" + latexPart + "$$");
1692
1683
  }
1693
1684
  }
1685
+ return content.replace(foundLatexStr, "$$" + foundLatexStr + "$$");
1686
+ };
1687
+ return LatexExtractor;
1688
+ }();
1689
+ LatexExtractor.extractAllLatexUltimate = function (content) {
1690
+ var latexRegex = /(\\[a-zA-Z]+\s*\{[^}]*\}(?:\s*\{[^}]*\})*|\\[a-zA-Z]+|\\[a-zA-Z]+\s*[^\\\s\{]+|[a-zA-Z]+\^{[^}]*}|[a-zA-Z]+\_{[^}]*}|\$[^$]+\$|\\\([^)]+\\\)|\\\[[^\]]+\\\]|\\[a-zA-Z]+\d*|(?:\\[a-zA-Z]+\s*)+[^\\]*(?=\\\\|\.|$))/g;
1691
+ var matches = content.match(latexRegex) || [];
1692
+ return matches.map(function (match) {
1693
+ return match.trim();
1694
+ }).filter(function (match) {
1695
+ return match.length > 1 && !match.match(/^[,\s\.]*$/) && (match.includes("\\") || match.includes("^{") || match.includes("_{") || match.includes("$") || !!match.match(/[a-zA-Z]\s*[=+\-*/]\s*[a-zA-Z0-9]/));
1694
1696
  });
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);
1697
+ };
1698
+ LatexExtractor.extractMultiLineFormulas = function (content) {
1699
+ var formulas = content.split(/\\\\/);
1700
+ return formulas.map(function (formula) {
1701
+ return formula.trim().replace(/\.$/, "");
1702
+ }).filter(function (formula) {
1703
+ return formula.length > 0 && LatexExtractor.isMathFormula(formula);
1704
+ });
1705
+ };
1706
+ LatexExtractor.isMathFormula = function (text) {
1707
+ return !!text && (text.includes("=") || text.includes("\\") || text.includes("^{") || text.includes("_{") || !!text.match(/[a-zA-Z]\s*[=+\-*/]\s*[a-zA-Z0-9]/));
1708
+ };
1709
+
1710
+ var _excluded$3 = ["node"];
1711
+ var MarkdownLatexRender = function MarkdownLatexRender(_ref) {
1712
+ var content = _ref.content;
1713
+ var updatedMarkdown = formatContent(content);
1714
+ return React__default.createElement("span", null, React__default.createElement(ReactMarkdown, {
1715
+ remarkPlugins: [remarkMath, remarkGfm, remarkRehype],
1716
+ rehypePlugins: [rehypeKatex, rehypeRaw],
1717
+ components: {
1718
+ p: function p(_ref2) {
1719
+ var props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
1720
+ return React__default.createElement("span", Object.assign({}, props));
1724
1721
  }
1725
1722
  }
1726
- }, [content]);
1727
- return React__default.createElement("div", {
1728
- ref: displayRef,
1729
- className: "equation-support"
1730
- });
1723
+ }, updatedMarkdown));
1731
1724
  };
1725
+ function formatContent(content) {
1726
+ var lines = content.split("\n");
1727
+ var result = [];
1728
+ var i = 0;
1729
+ while (i < lines.length) {
1730
+ var line = lines[i];
1731
+ var appliedLatexFormat = LatexExtractor.ApplyLatexFormat(line);
1732
+ if (appliedLatexFormat !== line) {
1733
+ result.push(appliedLatexFormat);
1734
+ i++;
1735
+ continue;
1736
+ }
1737
+ result.push(line);
1738
+ i++;
1739
+ }
1740
+ return result.join("\n");
1741
+ }
1732
1742
 
1733
1743
  var CookieService = /*#__PURE__*/function () {
1734
1744
  function CookieService() {}
@@ -3322,7 +3332,7 @@ var CustomOption = function CustomOption(props) {
3322
3332
  }, props.data.label));
3323
3333
  };
3324
3334
 
3325
- var _excluded$3 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3335
+ var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3326
3336
  var CustomSelect = function CustomSelect(_ref) {
3327
3337
  var isDefault = _ref.isDefault,
3328
3338
  options = _ref.options,
@@ -3330,7 +3340,7 @@ var CustomSelect = function CustomSelect(_ref) {
3330
3340
  scrollBottom = _ref.scrollBottom,
3331
3341
  value = _ref.value,
3332
3342
  isMulti = _ref.isMulti,
3333
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
3343
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3334
3344
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3335
3345
  return value.includes(i.value);
3336
3346
  }) : isMulti ? options === null || options === void 0 ? void 0 : options.filter(function (i) {
@@ -3357,7 +3367,7 @@ var CustomSelect = function CustomSelect(_ref) {
3357
3367
  }, rest));
3358
3368
  };
3359
3369
 
3360
- var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3370
+ var _excluded$5 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3361
3371
  var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3362
3372
  var isDefault = _ref.isDefault,
3363
3373
  options = _ref.options,
@@ -3365,7 +3375,7 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3365
3375
  scrollBottom = _ref.scrollBottom,
3366
3376
  value = _ref.value,
3367
3377
  isMulti = _ref.isMulti,
3368
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3378
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3369
3379
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3370
3380
  return value.includes(i.value);
3371
3381
  }) : isMulti ? options.filter(function (i) {
@@ -3392,14 +3402,14 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3392
3402
  }, rest));
3393
3403
  };
3394
3404
 
3395
- var _excluded$5 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3405
+ var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3396
3406
  var CustomCreatable = function CustomCreatable(_ref) {
3397
3407
  var options = _ref.options,
3398
3408
  isDisabled = _ref.isDisabled,
3399
3409
  scrollBottom = _ref.scrollBottom,
3400
3410
  value = _ref.value,
3401
3411
  isMulti = _ref.isMulti,
3402
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3412
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3403
3413
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3404
3414
  return value.includes(i.value);
3405
3415
  }) : isMulti ? options.filter(function (i) {
@@ -3426,7 +3436,7 @@ var CustomCreatable = function CustomCreatable(_ref) {
3426
3436
  }, rest));
3427
3437
  };
3428
3438
 
3429
- var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3439
+ var _excluded$7 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3430
3440
  var CustomSelectOption = function CustomSelectOption(_ref) {
3431
3441
  var defaultValue = _ref.defaultValue,
3432
3442
  options = _ref.options,
@@ -3434,7 +3444,7 @@ var CustomSelectOption = function CustomSelectOption(_ref) {
3434
3444
  scrollBottom = _ref.scrollBottom,
3435
3445
  value = _ref.value,
3436
3446
  isMulti = _ref.isMulti,
3437
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3447
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
3438
3448
  var initialValues = defaultValue !== null && typeof defaultValue !== "undefined" ? options.find(function (option) {
3439
3449
  return option.value === defaultValue;
3440
3450
  }) || null : null;