DrawioViewerScript.tsx 1.2 KB

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