@@ -7,65 +7,78 @@ import handleBlockType from './modifiers/handleBlockType';
77import handleInlineStyle from './modifiers/handleInlineStyle' ;
88import handleNewCodeBlock from './modifiers/handleNewCodeBlock' ;
99import insertEmptyBlock from './modifiers/insertEmptyBlock' ;
10+ import handleLink from './modifiers/handleLink' ;
11+ import createLinkDecorator from './decorators/link' ;
1012
11- const createMarkdownShortcutsPlugin = ( ) => ( {
12- blockRenderMap,
13- handleReturn ( ev , { setEditorState, getEditorState } ) {
14- const editorState = getEditorState ( ) ;
15- let newEditorState = handleNewCodeBlock ( editorState ) ;
16- if ( editorState === newEditorState && ( ev . ctrlKey || ev . shiftKey || ev . metaKey || ev . altKey ) ) {
17- newEditorState = insertEmptyBlock ( editorState ) ;
18- }
19- if ( editorState !== newEditorState ) {
20- setEditorState ( newEditorState ) ;
21- return 'handled' ;
22- }
23- return 'not-handled' ;
24- } ,
25- blockStyleFn ( block ) {
26- if ( block . getType ( ) === CHECKABLE_LIST_ITEM ) {
27- return CHECKABLE_LIST_ITEM ;
28- }
29- return null ;
30- } ,
31- blockRendererFn ( block , { setEditorState, getEditorState } ) {
32- if ( block . getType ( ) === CHECKABLE_LIST_ITEM ) {
33- return {
34- component : CheckableListItem ,
35- props : {
36- onChangeChecked : ( ) => setEditorState (
37- CheckableListItemUtils . toggleChecked ( getEditorState ( ) , block )
38- ) ,
39- checked : ! ! block . getData ( ) . get ( 'checked' ) ,
40- } ,
41- } ;
42- }
43- return null ;
44- } ,
45- onTab ( ev , { getEditorState, setEditorState } ) {
46- const editorState = getEditorState ( ) ;
47- const newEditorState = adjustBlockDepth ( editorState , ev ) ;
48- if ( newEditorState !== editorState ) {
49- setEditorState ( newEditorState ) ;
50- return 'handled' ;
51- }
52- return 'not-handled' ;
53- } ,
54- handleBeforeInput ( character , { getEditorState, setEditorState } ) {
55- if ( character !== ' ' ) {
13+ const createMarkdownShortcutsPlugin = ( config = { } ) => {
14+ const store = { } ;
15+ return {
16+ blockRenderMap,
17+ decorators : [ createLinkDecorator ( config , store ) ] ,
18+ initialize ( { setEditorState, getEditorState } ) {
19+ store . setEditorState = setEditorState ;
20+ store . getEditorState = getEditorState ;
21+ } ,
22+ handleReturn ( ev , { setEditorState, getEditorState } ) {
23+ const editorState = getEditorState ( ) ;
24+ let newEditorState = handleNewCodeBlock ( editorState ) ;
25+ if ( editorState === newEditorState && ( ev . ctrlKey || ev . shiftKey || ev . metaKey || ev . altKey ) ) {
26+ newEditorState = insertEmptyBlock ( editorState ) ;
27+ }
28+ if ( editorState !== newEditorState ) {
29+ setEditorState ( newEditorState ) ;
30+ return 'handled' ;
31+ }
32+ return 'not-handled' ;
33+ } ,
34+ blockStyleFn ( block ) {
35+ if ( block . getType ( ) === CHECKABLE_LIST_ITEM ) {
36+ return CHECKABLE_LIST_ITEM ;
37+ }
38+ return null ;
39+ } ,
40+ blockRendererFn ( block , { setEditorState, getEditorState } ) {
41+ if ( block . getType ( ) === CHECKABLE_LIST_ITEM ) {
42+ return {
43+ component : CheckableListItem ,
44+ props : {
45+ onChangeChecked : ( ) => setEditorState (
46+ CheckableListItemUtils . toggleChecked ( getEditorState ( ) , block )
47+ ) ,
48+ checked : ! ! block . getData ( ) . get ( 'checked' ) ,
49+ } ,
50+ } ;
51+ }
52+ return null ;
53+ } ,
54+ onTab ( ev , { getEditorState, setEditorState } ) {
55+ const editorState = getEditorState ( ) ;
56+ const newEditorState = adjustBlockDepth ( editorState , ev ) ;
57+ if ( newEditorState !== editorState ) {
58+ setEditorState ( newEditorState ) ;
59+ return 'handled' ;
60+ }
61+ return 'not-handled' ;
62+ } ,
63+ handleBeforeInput ( character , { getEditorState, setEditorState } ) {
64+ if ( character !== ' ' ) {
65+ return 'not-handled' ;
66+ }
67+ const editorState = getEditorState ( ) ;
68+ let newEditorState = handleBlockType ( editorState , character ) ;
69+ if ( editorState === newEditorState ) {
70+ newEditorState = handleInlineStyle ( editorState , character ) ;
71+ }
72+ if ( editorState === newEditorState ) {
73+ newEditorState = handleLink ( editorState , character ) ;
74+ }
75+ if ( editorState !== newEditorState ) {
76+ setEditorState ( newEditorState ) ;
77+ return 'handled' ;
78+ }
5679 return 'not-handled' ;
5780 }
58- const editorState = getEditorState ( ) ;
59- let newEditorState = handleBlockType ( editorState , character ) ;
60- if ( editorState === newEditorState ) {
61- newEditorState = handleInlineStyle ( editorState , character ) ;
62- }
63- if ( editorState !== newEditorState ) {
64- setEditorState ( newEditorState ) ;
65- return 'handled' ;
66- }
67- return 'not-handled' ;
68- }
69- } ) ;
81+ }
82+ } ;
7083
7184export default createMarkdownShortcutsPlugin ;
0 commit comments