itizawa 5 лет назад
Родитель
Сommit
91a0be5222
2 измененных файлов с 7 добавлено и 3 удалено
  1. 3 1
      src/client/js/components/PageEditor.jsx
  2. 4 2
      src/client/js/components/PageEditor/Preview.jsx

+ 3 - 1
src/client/js/components/PageEditor.jsx

@@ -21,6 +21,8 @@ class PageEditor extends React.Component {
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
 
 
+    this.previewElement = React.createRef();
+
     const config = this.props.appContainer.getConfig();
     const config = this.props.appContainer.getConfig();
     const isUploadable = config.upload.image || config.upload.file;
     const isUploadable = config.upload.image || config.upload.file;
     const isUploadableFile = config.upload.file;
     const isUploadableFile = config.upload.file;
@@ -309,7 +311,7 @@ class PageEditor extends React.Component {
           <Preview
           <Preview
             markdown={this.state.markdown}
             markdown={this.state.markdown}
             // eslint-disable-next-line no-return-assign
             // eslint-disable-next-line no-return-assign
-            inputRef={(el) => { return this.previewElement = el }}
+            innerRef={(el) => { return this.previewElement = el }}
             isMathJaxEnabled={this.state.isMathJaxEnabled}
             isMathJaxEnabled={this.state.isMathJaxEnabled}
             renderMathJaxOnInit={false}
             renderMathJaxOnInit={false}
             onScroll={this.onPreviewScroll}
             onScroll={this.onPreviewScroll}

+ 4 - 2
src/client/js/components/PageEditor/Preview.jsx

@@ -82,7 +82,9 @@ class Preview extends React.PureComponent {
             className="page-editor-preview-body"
             className="page-editor-preview-body"
             ref={(elm) => {
             ref={(elm) => {
                 this.previewElement = elm;
                 this.previewElement = elm;
-                this.props.inputRef(elm);
+                if (this.props.innerRef != null) {
+                  this.props.innerRef(elm);
+                }
               }}
               }}
             onScroll={(event) => {
             onScroll={(event) => {
                 if (this.props.onScroll != null) {
                 if (this.props.onScroll != null) {
@@ -112,7 +114,7 @@ Preview.propTypes = {
   appContainer: PropTypes.instanceOf(AppContainer).isRequired,
   appContainer: PropTypes.instanceOf(AppContainer).isRequired,
 
 
   markdown: PropTypes.string,
   markdown: PropTypes.string,
-  inputRef: PropTypes.func.isRequired, // for getting div element
+  innerRef: PropTypes.func,
   isMathJaxEnabled: PropTypes.bool,
   isMathJaxEnabled: PropTypes.bool,
   renderMathJaxOnInit: PropTypes.bool,
   renderMathJaxOnInit: PropTypes.bool,
   onScroll: PropTypes.func,
   onScroll: PropTypes.func,