|
@@ -11,11 +11,12 @@
|
|
|
* specific language governing permissions and limitations under the License.
|
|
|
*/
|
|
|
|
|
|
-import React, { lazy, useMemo } from "react";
|
|
|
+import React, { lazy, useMemo, Suspense } from "react";
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
import Tooltip from "@mui/material/Tooltip";
|
|
|
|
|
|
import { formatWSValue } from "../../utils";
|
|
|
+import { getSuffixedClassNames } from "./utils";
|
|
|
import { useClassNames, useDynamicProperty, useFormatConfig } from "../../utils/hooks";
|
|
|
import { TaipyBaseProps, TaipyHoverProps, getCssSize } from "./utils";
|
|
|
import { getComponentClassName } from "./TaipyStyle";
|
|
@@ -33,6 +34,23 @@ interface TaipyFieldProps extends TaipyBaseProps, TaipyHoverProps {
|
|
|
const unsetWeightSx = { fontWeight: "unset" };
|
|
|
|
|
|
const Markdown = lazy(() => import("react-markdown"));
|
|
|
+const MathJax = lazy(() => import("better-react-mathjax").then((module) => ({ default: module.MathJax })));
|
|
|
+const MathJaxContext = lazy(() =>
|
|
|
+ import("better-react-mathjax").then((module) => ({ default: module.MathJaxContext }))
|
|
|
+);
|
|
|
+
|
|
|
+const mathJaxConfig = {
|
|
|
+ tex: {
|
|
|
+ inlineMath: [
|
|
|
+ ["$", "$"],
|
|
|
+ ["\\(", "\\)"],
|
|
|
+ ],
|
|
|
+ displayMath: [
|
|
|
+ ["$$", "$$"],
|
|
|
+ ["\\[", "\\]"],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+};
|
|
|
|
|
|
const Field = (props: TaipyFieldProps) => {
|
|
|
const { id, dataType, format, defaultValue, raw } = props;
|
|
@@ -68,18 +86,55 @@ const Field = (props: TaipyFieldProps) => {
|
|
|
<Tooltip title={hover || ""}>
|
|
|
<>
|
|
|
{mode == "pre" ? (
|
|
|
- <pre className={`${className} ${getComponentClassName(props.children)}`} id={id} style={style}>
|
|
|
+ <pre
|
|
|
+ className={`${className} ${getSuffixedClassNames(className, "-pre")} ${getComponentClassName(
|
|
|
+ props.children
|
|
|
+ )}`}
|
|
|
+ id={id}
|
|
|
+ style={style}
|
|
|
+ >
|
|
|
{value}
|
|
|
</pre>
|
|
|
) : mode == "markdown" || mode == "md" ? (
|
|
|
- <Markdown className={`${className} ${getComponentClassName(props.children)}`}>{value}</Markdown>
|
|
|
+ <Suspense fallback={<div>Loading Markdown...</div>}>
|
|
|
+ <Markdown
|
|
|
+ className={`${className} ${getSuffixedClassNames(
|
|
|
+ className,
|
|
|
+ "-markdown"
|
|
|
+ )} ${getComponentClassName(props.children)}`}
|
|
|
+ >
|
|
|
+ {value}
|
|
|
+ </Markdown>
|
|
|
+ </Suspense>
|
|
|
) : raw || mode == "raw" ? (
|
|
|
- <span className={className} id={id} style={style}>
|
|
|
+ <span
|
|
|
+ className={`${className} ${getSuffixedClassNames(className, "-raw")} ${getComponentClassName(
|
|
|
+ props.children
|
|
|
+ )}`}
|
|
|
+ id={id}
|
|
|
+ style={style}
|
|
|
+ >
|
|
|
{value}
|
|
|
</span>
|
|
|
+ ) : mode == "latex" ? (
|
|
|
+ <Suspense fallback={<div>Loading LaTex...</div>}>
|
|
|
+ <MathJaxContext config={mathJaxConfig}>
|
|
|
+ <MathJax
|
|
|
+ className={`${className} ${getSuffixedClassNames(
|
|
|
+ className,
|
|
|
+ "-latex"
|
|
|
+ )} ${getComponentClassName(props.children)}`}
|
|
|
+ id={id}
|
|
|
+ >
|
|
|
+ {value}
|
|
|
+ </MathJax>
|
|
|
+ </MathJaxContext>
|
|
|
+ </Suspense>
|
|
|
) : (
|
|
|
<Typography
|
|
|
- className={`${className} ${getComponentClassName(props.children)}`}
|
|
|
+ className={`${className} ${
|
|
|
+ mode ? getSuffixedClassNames(className, "-" + mode) : ""
|
|
|
+ } ${getComponentClassName(props.children)}`}
|
|
|
id={id}
|
|
|
component="span"
|
|
|
sx={typoSx}
|