diff --git a/frontend/components/Editor/components/BlockInsert.js b/frontend/components/Editor/components/BlockInsert.js index fdc7fb607..43df62813 100644 --- a/frontend/components/Editor/components/BlockInsert.js +++ b/frontend/components/Editor/components/BlockInsert.js @@ -90,12 +90,16 @@ export default class BlockInsert extends Component { this.left = Math.round(boxRect.left + window.scrollX - 20); }; - onClickBlock = ( + insertBlock = ( ev: SyntheticEvent, - type: string | Object, - wrapBlock?: string + options: { + type: string | Object, + wrapper?: string | Object, + append?: string | Object, + } ) => { ev.preventDefault(); + const { type, wrapper, append } = options; let { state } = this.props; let transform = state.transform(); const { document } = state; @@ -112,7 +116,8 @@ export default class BlockInsert extends Component { transform = transform.insertBlock(type); - if (wrapBlock) transform = transform.wrapBlock(wrapBlock); + if (wrapper) transform = transform.wrapBlock(wrapper); + if (append) transform = transform.insertBlock(append); state = transform.focus().apply(); this.props.onChange(state); @@ -134,6 +139,7 @@ export default class BlockInsert extends Component { render() { const style = { top: `${this.top}px`, left: `${this.left}px` }; const todo = { type: 'list-item', data: { checked: false } }; + const rule = { type: 'horizontal-rule', isVoid: true }; return ( @@ -148,9 +154,14 @@ export default class BlockInsert extends Component { label={} onPickImage={this.onPickImage} onInsertList={ev => - this.onClickBlock(ev, 'list-item', 'bulleted-list')} - onInsertTodoList={ev => this.onClickBlock(ev, todo, 'todo-list')} - onInsertBreak={ev => this.onClickBlock(ev, 'horizontal-rule')} + this.insertBlock(ev, { + type: 'list-item', + wrapper: 'bulleted-list', + })} + onInsertTodoList={ev => + this.insertBlock(ev, { type: todo, wrapper: 'todo-list' })} + onInsertBreak={ev => + this.insertBlock(ev, { type: rule, append: 'paragraph' })} onOpen={this.handleMenuOpen} onClose={this.handleMenuClose} /> diff --git a/frontend/components/Editor/components/HorizontalRule.js b/frontend/components/Editor/components/HorizontalRule.js new file mode 100644 index 000000000..375641eae --- /dev/null +++ b/frontend/components/Editor/components/HorizontalRule.js @@ -0,0 +1,17 @@ +// @flow +import React from 'react'; +import styled from 'styled-components'; +import type { Props } from '../types'; +import { color } from 'styles/constants'; + +function HorizontalRule(props: Props) { + const { state, node } = this.props; + const active = state.isFocused && state.selection.hasEdgeIn(node); + return ; +} + +const StyledHr = styled.hr` + border-bottom: 1px solid ${props => (props.active ? color.slate : color.slateLight)}; +`; + +export default HorizontalRule; diff --git a/frontend/components/Editor/plugins/MarkdownShortcuts.js b/frontend/components/Editor/plugins/MarkdownShortcuts.js index 0dd924156..de530b006 100644 --- a/frontend/components/Editor/plugins/MarkdownShortcuts.js +++ b/frontend/components/Editor/plugins/MarkdownShortcuts.js @@ -112,19 +112,17 @@ export default function MarkdownShortcuts() { if (chars === '--') { ev.preventDefault(); - const transform = state + return state .transform() .extendToStartOf(startBlock) .delete() .setBlock({ type: 'horizontal-rule', isVoid: true, - }); - state = transform + }) .collapseToStartOfNextBlock() .insertBlock('paragraph') .apply(); - return state; } }, diff --git a/frontend/components/Editor/schema.js b/frontend/components/Editor/schema.js index e915b636c..2010e4c22 100644 --- a/frontend/components/Editor/schema.js +++ b/frontend/components/Editor/schema.js @@ -1,6 +1,7 @@ // @flow import React from 'react'; import Code from './components/Code'; +import HorizontalRule from './components/HorizontalRule'; import InlineCode from './components/InlineCode'; import Image from './components/Image'; import Link from './components/Link'; @@ -33,7 +34,7 @@ const createSchema = () => { 'block-quote': (props: Props) => (
{props.children}
), - 'horizontal-rule': (props: Props) =>
, + 'horizontal-rule': HorizontalRule, 'bulleted-list': (props: Props) =>
    {props.children}
, 'ordered-list': (props: Props) =>
    {props.children}
, 'todo-list': (props: Props) => {props.children},