Files
outline/app/scenes/Document/components/Editor.js
Tom Moor d0606a72c3 feat: Improved table of contents (#1223)
* feat: New table of contents

* fix: Hide TOC in edit mode

* feat: Highlight follows scroll position

* scroll tracking

* UI

* fix: Unrelated css fix with long doc titles

* Improve responsiveness

* feat: Add keyboard shortcut access to TOC

* fix: Headings should reflect content correctly when viewing old document revision

* flow

* fix: Persist TOC choice between sessions
2020-04-05 12:22:26 -07:00

52 lines
1.0 KiB
JavaScript

// @flow
import * as React from 'react';
import Editor from 'components/Editor';
import ClickablePadding from 'components/ClickablePadding';
import plugins from './plugins';
type Props = {|
defaultValue?: string,
readOnly?: boolean,
|};
class DocumentEditor extends React.Component<Props> {
editor: ?Editor;
componentDidMount() {
if (!this.props.defaultValue) {
setImmediate(this.focusAtStart);
}
}
focusAtStart = () => {
if (this.editor) {
this.editor.focusAtStart();
}
};
focusAtEnd = () => {
if (this.editor) {
this.editor.focusAtEnd();
}
};
render() {
const { readOnly } = this.props;
return (
<React.Fragment>
<Editor
ref={ref => (this.editor = ref)}
autoFocus={!this.props.defaultValue}
plugins={plugins}
grow
{...this.props}
/>
{!readOnly && <ClickablePadding onClick={this.focusAtEnd} grow />}
</React.Fragment>
);
}
}
export default DocumentEditor;