|
@@ -27,7 +27,7 @@ type Props = {
|
|
|
children?: ReactNode,
|
|
children?: ReactNode,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export const DrawioViewer = (props: Props): JSX.Element => {
|
|
|
|
|
|
|
+export const DrawioViewer = React.memo((props: Props): JSX.Element => {
|
|
|
const {
|
|
const {
|
|
|
diagramIndex, bol, eol, children,
|
|
diagramIndex, bol, eol, children,
|
|
|
} = props;
|
|
} = props;
|
|
@@ -60,22 +60,26 @@ export const DrawioViewer = (props: Props): JSX.Element => {
|
|
|
|
|
|
|
|
const renderDrawioWithDebounce = useMemo(() => debounce(200, renderDrawio), [renderDrawio]);
|
|
const renderDrawioWithDebounce = useMemo(() => debounce(200, renderDrawio), [renderDrawio]);
|
|
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- renderDrawioWithDebounce();
|
|
|
|
|
- }, [renderDrawioWithDebounce]);
|
|
|
|
|
|
|
+ const mxgraphHtml = useMemo(() => {
|
|
|
|
|
+ if (children == null) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ const code = children instanceof Array
|
|
|
|
|
+ ? children.map(e => e?.toString()).join('')
|
|
|
|
|
+ : children.toString();
|
|
|
|
|
|
|
|
- if (children == null) {
|
|
|
|
|
- return <></>;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const mxgraphData = generateMxgraphData(code, diagramIndex);
|
|
|
|
|
|
|
|
- const code = children instanceof Array
|
|
|
|
|
- ? children.map(e => e?.toString()).join('')
|
|
|
|
|
- : children.toString();
|
|
|
|
|
|
|
+ return `<div class="mxgraph" data-mxgraph="${mxgraphData}"></div>`;
|
|
|
|
|
|
|
|
- const mxgraphData = generateMxgraphData(code, diagramIndex);
|
|
|
|
|
|
|
+ }, [children, diagramIndex]);
|
|
|
|
|
|
|
|
- const mxgraphHtml = `<div class="mxgraph" data-mxgraph="${mxgraphData}"></div>`;
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (mxgraphHtml.length > 0) {
|
|
|
|
|
+ renderDrawioWithDebounce();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [mxgraphHtml.length, renderDrawioWithDebounce]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div
|
|
<div
|
|
@@ -89,4 +93,5 @@ export const DrawioViewer = (props: Props): JSX.Element => {
|
|
|
<div dangerouslySetInnerHTML={{ __html: mxgraphHtml }} />
|
|
<div dangerouslySetInnerHTML={{ __html: mxgraphHtml }} />
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
-};
|
|
|
|
|
|
|
+});
|
|
|
|
|
+DrawioViewer.displayName = 'DrawioViewer';
|