Skip to content

WIP: optimize react build ( not work ) #729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ava-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/ava-react",
"version": "3.1.9",
"version": "3.1.10-beta.0",
"description": "React components of AVA.",
"author": {
"name": "AntV",
Expand Down
44 changes: 26 additions & 18 deletions packages/ava-react/src/NarrativeTextVis/phrases/Phrase.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import React, { useState, useEffect } from 'react';

import { Tooltip, TooltipProps } from 'antd';
import { isTextPhrase, isEntityPhrase, isEscapePhrase, isFormulaPhrase } from '@antv/ava';
import { isFunction, kebabCase, isEmpty, isNil } from 'lodash';
import katex from 'katex';

import { NTV_PREFIX_CLS } from '../constants';
import { Entity, Bold, Italic, Underline, FormulaWrapper } from '../styled';
Expand All @@ -13,9 +12,32 @@ import { PhraseDescriptor, presetPluginManager } from '../chore/plugin';
import { getThemeColor } from '../theme';

import type { ReactNode } from 'react';
import type { PhraseSpec, EntityPhraseSpec, CustomPhraseSpec } from '@antv/ava';
import type { PhraseSpec, EntityPhraseSpec, CustomPhraseSpec, FormulaPhraseSpec } from '@antv/ava';
import type { ThemeStylesProps, ExtensionProps, PhraseEvents } from '../types';

const FormulaPhrase: React.FC<{
spec: FormulaPhraseSpec;
}> = ({ spec }) => {
const [katex, setKatex] = useState(null);
useEffect(() => {
import('katex').then(setKatex);
}, []);
return katex ? (
<FormulaWrapper
className={cx(spec.className, `${NTV_PREFIX_CLS}-formula`)}
style={spec.styles}
dangerouslySetInnerHTML={{
__html: katex.renderToString(spec.value, {
throwOnError: false,
displayMode: true,
strict: 'ignore',
fleqn: true,
}),
}}
/>
) : null;
};

type PhraseProps = ThemeStylesProps &
ExtensionProps &
PhraseEvents & {
Expand Down Expand Up @@ -160,21 +182,7 @@ export const Phrase: React.FC<PhraseProps> = ({

// use katex to render formula
// 使用 katex 渲染公式
if (isFormulaPhrase(phrase))
return (
<FormulaWrapper
className={cx(phrase.className, `${NTV_PREFIX_CLS}-formula`)}
style={phrase.styles}
dangerouslySetInnerHTML={{
__html: katex.renderToString(phrase.value, {
throwOnError: false,
displayMode: true,
strict: 'ignore',
fleqn: true,
}),
}}
/>
);
if (isFormulaPhrase(phrase)) return <FormulaPhrase spec={phrase} />;

const descriptor = pluginManager?.getPhraseDescriptorBySpec(phrase);
if (descriptor) {
Expand Down