diff --git a/.babelrc b/.babelrc index 027c9bee..49568cfd 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,8 @@ { - "presets": ["react", "env"], + "presets": [ + "react", + "env" + ], "plugins": [ "lodash", "styled-components", @@ -7,11 +10,14 @@ "transform-es2015-destructuring", "transform-object-rest-spread", "transform-regenerator", - "transform-class-properties" + "transform-class-properties", + "syntax-dynamic-import" ], "env": { "development": { - "presets": ["react-hmre"] + "presets": [ + "react-hmre" + ] } } -} +} \ No newline at end of file diff --git a/app/components/Editor/Editor.js b/app/components/Editor/Editor.js index 41d5627f..c09a1417 100644 --- a/app/components/Editor/Editor.js +++ b/app/components/Editor/Editor.js @@ -24,12 +24,12 @@ import styled from 'styled-components'; type Props = { text: string, onChange: Change => *, - onSave: (redirect?: boolean) => *, - onCancel: () => void, - onImageUploadStart: () => void, - onImageUploadStop: () => void, - emoji?: string, - readOnly: boolean, + onSave: (redirect?: boolean) => *, + onCancel: () => void, + onImageUploadStart: () => void, + onImageUploadStop: () => void, + emoji ?: string, + readOnly: boolean, }; @observer @@ -216,13 +216,13 @@ class MarkdownEditor extends Component { }; } -const MaxWidth = styled(Flex)` +const MaxWidth = styled(Flex) ` margin: 0 60px; max-width: 46em; height: 100%; `; -const Header = styled(Flex)` +const Header = styled(Flex) ` height: 60px; flex-shrink: 0; align-items: flex-end; @@ -233,7 +233,7 @@ const Header = styled(Flex)` } `; -const StyledEditor = styled(Editor)` +const StyledEditor = styled(Editor) ` font-weight: 400; font-size: 1em; line-height: 1.7em; diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index 1cb0de0c..eea6bcf2 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -25,8 +25,8 @@ import DocumentsStore from 'stores/DocumentsStore'; import CollectionsStore from 'stores/CollectionsStore'; import DocumentMenu from 'menus/DocumentMenu'; import SaveAction from './components/SaveAction'; +import type EditorType from 'components/Editor'; import LoadingPlaceholder from 'components/LoadingPlaceholder'; -import Editor from 'components/Editor'; import LoadingIndicator from 'components/LoadingIndicator'; import Collaborators from 'components/Collaborators'; import CenteredContent from 'components/CenteredContent'; @@ -56,6 +56,7 @@ class DocumentScene extends Component { props: Props; savedTimeout: number; + @observable editorComponent; @observable editCache: ?string; @observable newDocument: ?Document; @observable isLoading = false; @@ -65,6 +66,7 @@ class DocumentScene extends Component { componentDidMount() { this.loadDocument(this.props); + this.loadEditor(); } componentWillReceiveProps(nextProps) { @@ -128,6 +130,11 @@ class DocumentScene extends Component { } }; + loadEditor = async () => { + const EditorImport = await import('components/Editor'); + this.editorComponent = EditorImport.default; + }; + get isEditing() { return ( this.props.match.path === matchDocumentEdit || this.props.newDocument @@ -208,6 +215,7 @@ class DocumentScene extends Component { } render() { + const Editor = this.editorComponent; const isNew = this.props.newDocument; const isMoving = this.props.match.path === matchDocumentMove; const document = this.document; @@ -225,82 +233,82 @@ class DocumentScene extends Component { {isMoving && document && } {titleText && } {(this.isLoading || this.isSaving) && } - {!document ? ( + {!document || !Editor ? ( ) : ( - - {this.isEditing && ( - - )} - - - {!isNew && - !this.isEditing && } - - {this.isEditing ? ( - - ) : ( - Edit - )} - + {this.isEditing && ( - - Discard - + )} - {!this.isEditing && ( + + + {!isNew && + !this.isEditing && } - + {this.isEditing ? ( + + ) : ( + Edit + )} - )} - {!this.isEditing && } - - {!this.isEditing && ( - - - + {this.isEditing && ( + + Discard + )} - - - - )} + {!this.isEditing && ( + + + + )} + {!this.isEditing && } + + {!this.isEditing && ( + + + + )} + + + + )} ); } } -const Container = styled(Flex)` +const Container = styled(Flex) ` position: relative; `; -const LoadingState = styled(LoadingPlaceholder)` +const LoadingState = styled(LoadingPlaceholder) ` margin: 90px 0; `; diff --git a/package.json b/package.json index fbac1f2c..351032bb 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "babel-loader": "^7.1.2", "babel-plugin-lodash": "^3.2.11", "babel-plugin-styled-components": "^1.1.7", + "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-decorators-legacy": "1.3.4", "babel-plugin-transform-es2015-destructuring": "^6.23.0", diff --git a/yarn.lock b/yarn.lock index e4c511a8..43ce308c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -697,6 +697,10 @@ babel-plugin-syntax-decorators@^6.1.18: version "6.13.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz#312563b4dbde3cc806cee3e416cceeaddd11ac0b" +babel-plugin-syntax-dynamic-import@^6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-dynamic-import/-/babel-plugin-syntax-dynamic-import-6.18.0.tgz#8d6a26229c83745a9982a441051572caa179b1da" + babel-plugin-syntax-exponentiation-operator@^6.8.0: version "6.13.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de"