Editor fixes
This commit is contained in:
@ -96,10 +96,8 @@ class DropToImport extends Component {
|
|||||||
multiple
|
multiple
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<span>
|
{this.state.isImporting && <LoadingIndicator />}
|
||||||
{this.state.isImporting && <LoadingIndicator />}
|
{this.props.children}
|
||||||
{this.props.children}
|
|
||||||
</span>
|
|
||||||
</Dropzone>
|
</Dropzone>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,13 @@ import { observer } from 'mobx-react';
|
|||||||
import { Editor, Plain } from 'slate';
|
import { Editor, Plain } from 'slate';
|
||||||
import classnames from 'classnames/bind';
|
import classnames from 'classnames/bind';
|
||||||
import type { Document, State, Editor as EditorType } from './types';
|
import type { Document, State, Editor as EditorType } from './types';
|
||||||
|
import Flex from 'components/Flex';
|
||||||
import ClickablePadding from './components/ClickablePadding';
|
import ClickablePadding from './components/ClickablePadding';
|
||||||
import Toolbar from './components/Toolbar';
|
import Toolbar from './components/Toolbar';
|
||||||
import Markdown from './serializer';
|
import Markdown from './serializer';
|
||||||
import createSchema from './schema';
|
import createSchema from './schema';
|
||||||
import createPlugins from './plugins';
|
import createPlugins from './plugins';
|
||||||
|
import styled from 'styled-components';
|
||||||
import styles from './Editor.scss';
|
import styles from './Editor.scss';
|
||||||
|
|
||||||
const cx = classnames.bind(styles);
|
const cx = classnames.bind(styles);
|
||||||
@ -25,6 +27,7 @@ type Props = {
|
|||||||
onImageUploadStop: Function,
|
onImageUploadStop: Function,
|
||||||
starred: boolean,
|
starred: boolean,
|
||||||
readOnly: boolean,
|
readOnly: boolean,
|
||||||
|
heading?: ?React.Element<*>,
|
||||||
};
|
};
|
||||||
|
|
||||||
type KeyData = {
|
type KeyData = {
|
||||||
@ -116,7 +119,13 @@ type KeyData = {
|
|||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Container auto column>
|
||||||
|
<HeaderContainer
|
||||||
|
onClick={this.focusAtStart}
|
||||||
|
readOnly={this.props.readOnly}
|
||||||
|
>
|
||||||
|
{this.props.heading}
|
||||||
|
</HeaderContainer>
|
||||||
<Toolbar state={this.state.state} onChange={this.onChange} />
|
<Toolbar state={this.state.state} onChange={this.onChange} />
|
||||||
<Editor
|
<Editor
|
||||||
key={this.props.starred}
|
key={this.props.starred}
|
||||||
@ -134,7 +143,7 @@ type KeyData = {
|
|||||||
/>
|
/>
|
||||||
{!this.props.readOnly &&
|
{!this.props.readOnly &&
|
||||||
<ClickablePadding onClick={this.focusAtEnd} grow />}
|
<ClickablePadding onClick={this.focusAtEnd} grow />}
|
||||||
</div>
|
</Container>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -143,4 +152,15 @@ MarkdownEditor.childContextTypes = {
|
|||||||
starred: PropTypes.bool,
|
starred: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Container = styled(Flex)`
|
||||||
|
height: 100%;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const HeaderContainer = styled(Flex).attrs({
|
||||||
|
align: 'flex-end',
|
||||||
|
})`
|
||||||
|
height: 100px;
|
||||||
|
${({ readOnly }) => !readOnly && 'cursor: text;'}
|
||||||
|
`;
|
||||||
|
|
||||||
export default MarkdownEditor;
|
export default MarkdownEditor;
|
||||||
|
@ -6,6 +6,7 @@ import { observer, inject } from 'mobx-react';
|
|||||||
import { withRouter, Prompt } from 'react-router';
|
import { withRouter, Prompt } from 'react-router';
|
||||||
import Flex from 'components/Flex';
|
import Flex from 'components/Flex';
|
||||||
import { layout } from 'styles/constants';
|
import { layout } from 'styles/constants';
|
||||||
|
import invariant from 'invariant';
|
||||||
|
|
||||||
import Document from 'models/Document';
|
import Document from 'models/Document';
|
||||||
import UiStore from 'stores/UiStore';
|
import UiStore from 'stores/UiStore';
|
||||||
@ -135,6 +136,21 @@ type Props = {
|
|||||||
this.setState({ isDragging: false });
|
this.setState({ isDragging: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderHeading(isEditing: boolean) {
|
||||||
|
invariant(this.document, 'document not available');
|
||||||
|
return (
|
||||||
|
<InfoWrapper visible={!isEditing}>
|
||||||
|
<PublishingInfo
|
||||||
|
collaborators={this.document.collaborators}
|
||||||
|
createdAt={this.document.createdAt}
|
||||||
|
createdBy={this.document.createdBy}
|
||||||
|
updatedAt={this.document.updatedAt}
|
||||||
|
updatedBy={this.document.updatedBy}
|
||||||
|
/>
|
||||||
|
</InfoWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const isNew = this.props.newDocument;
|
const isNew = this.props.newDocument;
|
||||||
const isEditing = this.props.match.params.edit || isNew;
|
const isEditing = this.props.match.params.edit || isNew;
|
||||||
@ -161,37 +177,28 @@ type Props = {
|
|||||||
onDragEnter={this.onStartDragging}
|
onDragEnter={this.onStartDragging}
|
||||||
onDragLeave={this.onStopDragging}
|
onDragLeave={this.onStopDragging}
|
||||||
onDrop={this.onStopDragging}
|
onDrop={this.onStopDragging}
|
||||||
|
style={{ display: 'flex', flex: 1 }}
|
||||||
>
|
>
|
||||||
<PagePadding justify="center" auto>
|
<Flex justify="center" auto>
|
||||||
<Prompt
|
<Prompt
|
||||||
when={this.document.hasPendingChanges}
|
when={this.document.hasPendingChanges}
|
||||||
message={DISCARD_CHANGES}
|
message={DISCARD_CHANGES}
|
||||||
/>
|
/>
|
||||||
<DocumentContainer>
|
<DocumentContainer>
|
||||||
<InfoWrapper visible={!isEditing}>
|
<Editor
|
||||||
<PublishingInfo
|
key={this.document.id}
|
||||||
collaborators={this.document.collaborators}
|
text={this.document.text}
|
||||||
createdAt={this.document.createdAt}
|
onImageUploadStart={this.onImageUploadStart}
|
||||||
createdBy={this.document.createdBy}
|
onImageUploadStop={this.onImageUploadStop}
|
||||||
updatedAt={this.document.updatedAt}
|
onChange={this.onChange}
|
||||||
updatedBy={this.document.updatedBy}
|
onSave={this.onSave}
|
||||||
/>
|
onCancel={this.onCancel}
|
||||||
</InfoWrapper>
|
onStar={this.document.star}
|
||||||
<Content>
|
onUnstar={this.document.unstar}
|
||||||
<Editor
|
starred={this.document.starred}
|
||||||
key={this.document.id}
|
heading={this.renderHeading(!!isEditing)}
|
||||||
text={this.document.text}
|
readOnly={!isEditing}
|
||||||
onImageUploadStart={this.onImageUploadStart}
|
/>
|
||||||
onImageUploadStop={this.onImageUploadStop}
|
|
||||||
onChange={this.onChange}
|
|
||||||
onSave={this.onSave}
|
|
||||||
onCancel={this.onCancel}
|
|
||||||
onStar={this.document.star}
|
|
||||||
onUnstar={this.document.unstar}
|
|
||||||
starred={this.document.starred}
|
|
||||||
readOnly={!isEditing}
|
|
||||||
/>
|
|
||||||
</Content>
|
|
||||||
</DocumentContainer>
|
</DocumentContainer>
|
||||||
<Meta align="center" justify="flex-end" readOnly={!isEditing}>
|
<Meta align="center" justify="flex-end" readOnly={!isEditing}>
|
||||||
<Flex align="center">
|
<Flex align="center">
|
||||||
@ -207,7 +214,7 @@ type Props = {
|
|||||||
{!isEditing && <Menu document={this.document} />}
|
{!isEditing && <Menu document={this.document} />}
|
||||||
</Flex>
|
</Flex>
|
||||||
</Meta>
|
</Meta>
|
||||||
</PagePadding>
|
</Flex>
|
||||||
</DropToImport>}
|
</DropToImport>}
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
@ -228,22 +235,18 @@ const DropHere = styled(Flex)`
|
|||||||
|
|
||||||
const Meta = styled(Flex)`
|
const Meta = styled(Flex)`
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
width: 100%;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
right: 0;
|
||||||
padding: ${layout.padding};
|
padding: ${layout.padding};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Content = styled(Flex)`
|
|
||||||
margin-bottom: 20px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const InfoWrapper = styled(Flex)`
|
const InfoWrapper = styled(Flex)`
|
||||||
opacity: ${({ visible }) => (visible ? '1' : '0')};
|
opacity: ${({ visible }) => (visible ? '1' : '0')};
|
||||||
transition: all 100ms ease-in-out;
|
transition: all 100ms ease-in-out;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled(Flex)`
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
`;
|
`;
|
||||||
@ -252,11 +255,6 @@ const LoadingState = styled(PreviewLoading)`
|
|||||||
margin: 80px 20px;
|
margin: 80px 20px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const PagePadding = styled(Flex)`
|
|
||||||
padding: 80px 20px;
|
|
||||||
position: relative;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const DocumentContainer = styled.div`
|
const DocumentContainer = styled.div`
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
|
Reference in New Issue
Block a user