DrawioViewerScript.tsx 1.5 KB

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