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/app/scenes/Document/components/plugins.js
2019-10-27 18:04:45 -07:00

39 lines
1.2 KiB
JavaScript

// @flow
import { Node, Editor } from 'slate';
import Placeholder from 'rich-markdown-editor/lib/plugins/Placeholder';
import isModKey from 'rich-markdown-editor/lib/lib/isModKey';
export default [
Placeholder({
placeholder: 'Start with a title…',
when: (editor: Editor, node: Node) => {
if (editor.readOnly) return false;
if (node.object !== 'block') return false;
if (node.type !== 'heading1') return false;
if (node.text !== '') return false;
if (editor.value.document.nodes.first() !== node) return false;
return true;
},
}),
Placeholder({
placeholder: '…the rest is your canvas',
when: (editor: Editor, node: Node) => {
if (editor.readOnly) return false;
if (node.object !== 'block') return false;
if (node.type !== 'paragraph') return false;
if (node.text !== '') return false;
if (editor.value.document.getDepth(node.key) !== 1) return false;
return true;
},
}),
{
onKeyDown(ev: SyntheticKeyboardEvent<>, editor: Editor, next: Function) {
if (ev.key === 'p' && ev.shiftKey && isModKey(ev)) {
return editor.props.onPublish(ev);
}
return next();
},
},
];