File tree Expand file tree Collapse file tree 10 files changed +134
-104
lines changed
Expand file tree Collapse file tree 10 files changed +134
-104
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ import { isUrl, isImageUrl } from '../lib/util'
1111
1212import theme from './theme'
1313
14- import NodesPlugin from '../plugins/nodes '
15- import MarksPlugin from '../plugins/marks'
14+ import MarkdownPlugin from '../plugins/markdown '
15+
1616import CodePlugin from '../plugins/code'
1717import LiveJSXPlugin from '../plugins/live-jsx'
1818import TablePlugin from '../plugins/table'
@@ -24,8 +24,7 @@ import MarkdownShortcutsPlugin from '../plugins/markdown-shortcuts'
2424
2525const plugins = [
2626 SoftBreak ( { shift : true } ) ,
27- NodesPlugin ( ) ,
28- MarksPlugin ( ) ,
27+ MarkdownPlugin ( ) ,
2928 CodePlugin ( ) ,
3029 LiveJSXPlugin ( ) ,
3130 TablePlugin ( ) ,
Original file line number Diff line number Diff line change 1+ const DEFAULT_BLOCK = 'paragraph'
2+
3+ const toggleBold = editor => {
4+ editor . toggleMark ( 'bold' ) . focus ( )
5+ }
6+
7+ const toggleItalic = editor => {
8+ editor . toggleMark ( 'italic' ) . focus ( )
9+ }
10+
11+ const toggleBlock = ( editor , type ) => {
12+ if ( editor . hasBlock ( type ) ) {
13+ editor . setBlocks ( DEFAULT_BLOCK )
14+ } else {
15+ editor . setBlocks ( type )
16+ }
17+ }
18+
19+ const toggleHeadingOne = editor => toggleBlock ( editor , 'heading-one' )
20+ const toggleHeadingTwo = editor => toggleBlock ( editor , 'heading-two' )
21+
22+ export default {
23+ toggleBold,
24+ toggleItalic,
25+ toggleBlock,
26+ toggleHeadingOne,
27+ toggleHeadingTwo
28+ }
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+
3+ import queries from './queries'
4+ import commands from './commands'
5+ import renderMark from './renderMark'
6+ import renderNode from './renderNode'
7+ import onKeyDown from './onKeyDown'
8+
9+ export default ( opts = { } ) => ( {
10+ queries,
11+ commands,
12+ renderMark,
13+ renderNode,
14+ onKeyDown
15+ } )
Original file line number Diff line number Diff line change 1+ import { keyboardEvent } from '@slate-editor/utils'
2+
3+ export default ( event , editor , next ) => {
4+ if ( ! keyboardEvent . isMod ( event ) ) return next ( )
5+ switch ( event . key ) {
6+ case 'b' :
7+ editor . toggleBold ( )
8+ break
9+ case 'i' :
10+ editor . toggleItalic ( )
11+ break
12+ default :
13+ next ( )
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ const hasBlock = ( editor , type ) => {
2+ return editor . value . blocks . some ( node => node . type === type )
3+ }
4+
5+ export default {
6+ hasBlock
7+ }
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import { Styled } from 'theme-ui'
3+
4+ export default ( props , editor , next ) => {
5+ const { mark, attributes, children } = props
6+
7+ switch ( mark . type ) {
8+ case 'bold' :
9+ return < Styled . strong { ...attributes } > { children } </ Styled . strong >
10+ case 'code' :
11+ return < Styled . inlineCode { ...attributes } > { children } </ Styled . inlineCode >
12+ case 'italic' :
13+ return < Styled . em { ...attributes } > { children } </ Styled . em >
14+ case 'underlined' :
15+ return < u { ...attributes } > { children } </ u >
16+ case 'strikethrough' :
17+ return < s { ...attributes } > { children } </ s >
18+ default :
19+ return next ( )
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import { Styled } from 'theme-ui'
3+
4+ export default ( props , editor , next ) => {
5+ const { node, attributes, children } = props
6+
7+ switch ( node . type ) {
8+ case 'block-quote' :
9+ return < Styled . blockquote { ...attributes } > { children } </ Styled . blockquote >
10+ case 'bulleted-list' :
11+ return < Styled . ul { ...attributes } > { children } </ Styled . ul >
12+ case 'numbered-list' :
13+ return < Styled . ol { ...attributes } > { children } </ Styled . ol >
14+ case 'list-item' :
15+ return < Styled . li { ...attributes } > { children } </ Styled . li >
16+ case 'list-item-child' :
17+ return < Styled . p { ...attributes } > { children } </ Styled . p >
18+ case 'heading-one' :
19+ return < Styled . h1 { ...attributes } > { children } </ Styled . h1 >
20+ case 'heading-two' :
21+ return < Styled . h2 { ...attributes } > { children } </ Styled . h2 >
22+ case 'heading-three' :
23+ return < Styled . h3 { ...attributes } > { children } </ Styled . h3 >
24+ case 'heading-four' :
25+ return < Styled . h4 { ...attributes } > { children } </ Styled . h4 >
26+ case 'heading-five' :
27+ return < Styled . h5 { ...attributes } > { children } </ Styled . h5 >
28+ case 'heading-six' :
29+ return < Styled . h6 { ...attributes } > { children } </ Styled . h6 >
30+ case 'list-item' :
31+ return < Styled . li { ...attributes } > { children } </ Styled . li >
32+ case 'paragraph' :
33+ return < Styled . p { ...attributes } > { children } </ Styled . p >
34+ case 'hr' :
35+ return < Styled . hr { ...attributes } />
36+ case 'link' :
37+ return (
38+ < Styled . a { ...attributes } href = { node . data . get ( 'href' ) } >
39+ { children }
40+ </ Styled . a >
41+ )
42+ default :
43+ return next ( )
44+ }
45+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -44,8 +44,6 @@ const toggleBlockQuote = editor => {
4444 }
4545}
4646
47- const toggleHeadingOne = editor => toggleBlock ( editor , 'heading-one' )
48- const toggleHeadingTwo = editor => toggleBlock ( editor , 'heading-two' )
4947const toggleJSX = editor => toggleBlock ( editor , 'jsx' )
5048const togglePre = editor => toggleBlock ( editor , 'pre' )
5149
@@ -83,8 +81,6 @@ export default (opts = {}) => ({
8381 commands : {
8482 toggleBlock,
8583 toggleBlockQuote,
86- toggleHeadingOne,
87- toggleHeadingTwo,
8884 toggleBulletedList,
8985 toggleJSX,
9086 togglePre
You can’t perform that action at this time.
0 commit comments