DrawioViewerScript.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { useCallback } from 'react';
  2. import type { IGraphViewerGlobal } from '@growi/remark-drawio';
  3. import Head from 'next/head';
  4. import { useViewerMinJsUrl } from './use-viewer-min-js-url';
  5. declare global {
  6. // eslint-disable-next-line vars-on-top, no-var
  7. var GraphViewer: IGraphViewerGlobal;
  8. }
  9. type Props = {
  10. drawioUri: string;
  11. }
  12. export const DrawioViewerScript = ({ drawioUri }: Props): JSX.Element => {
  13. const viewerMinJsSrc = useViewerMinJsUrl(drawioUri);
  14. const loadedHandler = useCallback(() => {
  15. // disable useResizeSensor and checkVisibleState
  16. // for preventing resize event by viewer.min.js
  17. GraphViewer.useResizeSensor = false;
  18. GraphViewer.prototype.checkVisibleState = false;
  19. // Set responsive option.
  20. // refs: https://github.com/jgraph/drawio/blob/v13.9.1/src/main/webapp/js/diagramly/GraphViewer.js#L89-L95
  21. // GraphViewer.prototype.responsive = true;
  22. // Set z-index ($zindex-dropdown + 200) for lightbox.
  23. // 'lightbox' is like a modal dialog that appears when click on a drawio diagram.
  24. // z-index refs: https://github.com/twbs/bootstrap/blob/v4.6.2/scss/_variables.scss#L681
  25. GraphViewer.prototype.lightboxZIndex = 1200;
  26. GraphViewer.prototype.toolbarZIndex = 1200;
  27. GraphViewer.processElements();
  28. }, []);
  29. return (
  30. <Head>
  31. <script
  32. type="text/javascript"
  33. async
  34. src={viewerMinJsSrc}
  35. onLoad={loadedHandler}
  36. />
  37. </Head>
  38. );
  39. };