This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/frontend/scenes/Document/components/Menu.js
Jori Lallo ff17047791 Slate editor (#38)
* WIP: Slate editor

* WIP

* Focus at start / end working

* ah ha

* Super basic floating toolbar

* Nested list editing

* Pulling more logic into plugins

* inline code markdown

* Backspace at end of code block should remove mark

* Ensure there is always an empty line at editor end

* Add keyboard shortcuts for bold, italic, underline

* Add strikethrough shortcode and toolbar

* Toolbar to declarative
Fixed paragraph styling
Removed unused stuffs

* Super basic link editing

* Split Toolbar, now possible to edit and remove links

* Add new link to selection from toolbar working

* Ensure toolbar doesn't extend off screen

* Fix minor js issues, disable formatting of document title

* Boom, icons

* Remove codemirror, fix MD parsing issues

* CMD+S now saves inplace

* Add --- shortcut for horizontal rule

* Improved styling for link editor

* Add header anchors in readOnly

* More readable core text color

* Restored image file uploading 🎉

* Add support for inline md syntax, ** __ etc

* Centered

* Flooooow

* Checklist support

* Upgrade edit list plugin

* Finally. Allow keydown within rich textarea

* Update Markdown serializer

* Cleanup, remove async editor loading

* Editor > MarkdownEditor
Fixed unsaved changes warning triggered when all changes are saved

* MOAR typing

* Combine edit and view

* Fixed checkboxes still editable in readOnly

* wip

* Breadcrumb
Restored scroll

* Move document scene actions to menu

* Added: Support for code blocks, syntax highlighting

* Cleanup

*  > styled component

* Prevent CMD+Enter from adding linebreak

* Show image uploading in layout activity indicator

* Upgrade editor deps

* Improve link toolbar. Only one scenario where it's not working now
2017-05-17 19:36:31 -07:00

79 lines
2.2 KiB
JavaScript

// @flow
import React, { Component } from 'react';
import invariant from 'invariant';
import get from 'lodash/get';
import { browserHistory } from 'react-router';
import { observer } from 'mobx-react';
import type { Document as DocumentType } from 'types';
import DropdownMenu, { MenuItem, MoreIcon } from 'components/DropdownMenu';
import DocumentStore from '../DocumentStore';
type Props = {
document: DocumentType,
collectionTree: ?Object,
store: DocumentStore,
};
@observer class Menu extends Component {
props: Props;
onCreateDocument = () => {
invariant(this.props.collectionTree, 'collectionTree is not available');
browserHistory.push(`${this.props.collectionTree.url}/new`);
};
onCreateChild = () => {
invariant(this.props.document, 'Document is not available');
browserHistory.push(`${this.props.document.url}/new`);
};
onDelete = () => {
let msg;
if (get(this.props, 'document.collection.type') === 'atlas') {
msg =
"Are you sure you want to delete this document and all it's child documents (if any)?";
} else {
msg = 'Are you sure you want to delete this document?';
}
if (confirm(msg)) {
this.props.store.deleteDocument();
}
};
onExport = () => {
const doc = this.props.document;
if (doc) {
const a = document.createElement('a');
a.textContent = 'download';
a.download = `${doc.title}.md`;
a.href = `data:text/markdown;charset=UTF-8,${encodeURIComponent(doc.text)}`;
a.click();
}
};
render() {
const document = get(this.props, 'document');
const collection = get(document, 'collection.type') === 'atlas';
const allowDelete =
collection &&
document.id !== get(document, 'collection.navigationTree.id');
return (
<DropdownMenu label={<MoreIcon />}>
{collection &&
<div>
<MenuItem onClick={this.onCreateDocument}>
New document
</MenuItem>
<MenuItem onClick={this.onCreateChild}>New child</MenuItem>
</div>}
<MenuItem onClick={this.onExport}>Export</MenuItem>
{allowDelete && <MenuItem onClick={this.onDelete}>Delete</MenuItem>}
</DropdownMenu>
);
}
}
export default Menu;