Просмотр исходного кода

Merge pull request #3077 from kaishuu0123/fix/gc-4383-responsive-for-drawio

refs GC-4383: If the figure of drawio is too big, it will be out of view.
Yuki Takei 5 лет назад
Родитель
Сommit
535e99c280
2 измененных файлов с 21 добавлено и 2 удалено
  1. 18 0
      src/client/js/components/Drawio.jsx
  2. 3 2
      src/server/views/widget/headers/drawio.html

+ 18 - 0
src/client/js/components/Drawio.jsx

@@ -1,6 +1,8 @@
 import React from 'react';
 import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 
 
+import { debounce } from 'throttle-debounce';
+
 import { withTranslation } from 'react-i18next';
 import { withTranslation } from 'react-i18next';
 
 
 import AppContainer from '../services/AppContainer';
 import AppContainer from '../services/AppContainer';
@@ -26,6 +28,9 @@ class Drawio extends React.Component {
     this.drawioContent = this.props.drawioContent;
     this.drawioContent = this.props.drawioContent;
 
 
     this.onEdit = this.onEdit.bind(this);
     this.onEdit = this.onEdit.bind(this);
+
+    // create debounced method for rendering Drawio
+    this.renderDrawioWithDebounce = debounce(200, this.renderDrawio);
   }
   }
 
 
   onEdit() {
   onEdit() {
@@ -35,6 +40,16 @@ class Drawio extends React.Component {
   }
   }
 
 
   componentDidMount() {
   componentDidMount() {
+    const DrawioViewer = window.GraphViewer;
+    if (DrawioViewer != null) {
+      this.renderDrawio();
+    }
+    else {
+      this.renderDrawioWithDebounce();
+    }
+  }
+
+  renderDrawio() {
     const DrawioViewer = window.GraphViewer;
     const DrawioViewer = window.GraphViewer;
     if (DrawioViewer != null) {
     if (DrawioViewer != null) {
       const mxgraphs = this.drawioContainer.getElementsByClassName('mxgraph');
       const mxgraphs = this.drawioContainer.getElementsByClassName('mxgraph');
@@ -48,6 +63,9 @@ class Drawio extends React.Component {
         }
         }
       }
       }
     }
     }
+    else {
+      this.renderDrawioWithDebounce();
+    }
   }
   }
 
 
   renderContents() {
   renderContents() {

+ 3 - 2
src/server/views/widget/headers/drawio.html

@@ -24,8 +24,9 @@
       DrawioViewer.useResizeSensor = false;
       DrawioViewer.useResizeSensor = false;
       DrawioViewer.prototype.checkVisibleState = false;
       DrawioViewer.prototype.checkVisibleState = false;
 
 
-      // initialize
-      DrawioViewer.processElements();
+      // Set responsive option.
+      // refs: https://github.com/jgraph/drawio/blob/v13.9.1/src/main/webapp/js/diagramly/GraphViewer.js#L89-L95
+      DrawioViewer.prototype.responsive = true;
     }
     }
   };
   };
 </script>
 </script>