|
@@ -23,12 +23,14 @@ export type DrawioViewerProps = {
|
|
|
bol?: number,
|
|
bol?: number,
|
|
|
eol?: number,
|
|
eol?: number,
|
|
|
children?: ReactNode,
|
|
children?: ReactNode,
|
|
|
|
|
+ onRenderingStart?: () => void,
|
|
|
onRenderingUpdated?: (hasError: boolean) => void,
|
|
onRenderingUpdated?: (hasError: boolean) => void,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const DrawioViewer = React.memo((props: DrawioViewerProps): JSX.Element => {
|
|
export const DrawioViewer = React.memo((props: DrawioViewerProps): JSX.Element => {
|
|
|
const {
|
|
const {
|
|
|
diagramIndex, bol, eol, children,
|
|
diagramIndex, bol, eol, children,
|
|
|
|
|
+ onRenderingStart, onRenderingUpdated,
|
|
|
} = props;
|
|
} = props;
|
|
|
|
|
|
|
|
const drawioContainerRef = useRef<HTMLDivElement>(null);
|
|
const drawioContainerRef = useRef<HTMLDivElement>(null);
|
|
@@ -60,15 +62,17 @@ export const DrawioViewer = React.memo((props: DrawioViewerProps): JSX.Element =
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
setError(err);
|
|
setError(err);
|
|
|
|
|
+ onRenderingUpdated?.(true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }, [drawioContainerRef]);
|
|
|
|
|
|
|
+ }, [onRenderingUpdated]);
|
|
|
|
|
|
|
|
const renderDrawioWithDebounce = useMemo(() => debounce(200, renderDrawio), [renderDrawio]);
|
|
const renderDrawioWithDebounce = useMemo(() => debounce(200, renderDrawio), [renderDrawio]);
|
|
|
|
|
|
|
|
const mxgraphHtml = useMemo(() => {
|
|
const mxgraphHtml = useMemo(() => {
|
|
|
setError(undefined);
|
|
setError(undefined);
|
|
|
|
|
+ onRenderingStart?.();
|
|
|
|
|
|
|
|
if (children == null) {
|
|
if (children == null) {
|
|
|
return '';
|
|
return '';
|
|
@@ -81,13 +85,15 @@ export const DrawioViewer = React.memo((props: DrawioViewerProps): JSX.Element =
|
|
|
let mxgraphData;
|
|
let mxgraphData;
|
|
|
try {
|
|
try {
|
|
|
mxgraphData = generateMxgraphData(code);
|
|
mxgraphData = generateMxgraphData(code);
|
|
|
|
|
+ onRenderingUpdated?.(false);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
setError(err);
|
|
setError(err);
|
|
|
|
|
+ onRenderingUpdated?.(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return `<div class="mxgraph" data-mxgraph="${mxgraphData}"></div>`;
|
|
return `<div class="mxgraph" data-mxgraph="${mxgraphData}"></div>`;
|
|
|
- }, [children]);
|
|
|
|
|
|
|
+ }, [children, onRenderingStart, onRenderingUpdated]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (mxgraphHtml.length > 0) {
|
|
if (mxgraphHtml.length > 0) {
|