77 CompositeDecorator ,
88 Editor ,
99 EditorState ,
10- Entity ,
1110 RichUtils ,
1211} from 'draft-js' ;
1312
@@ -62,7 +61,7 @@ class DraftJSEditor extends Component {
6261 this . confirmBlock = this . _confirmBlock . bind ( this ) ;
6362 this . onBlockInputKeyDown = this . _onBlockInputKeyDown . bind ( this ) ;
6463 this . onBlockDataChange = this . _onBlockDataChange . bind ( this ) ;
65- this . renderBlock = this . _renderBlock . bind ( this ) ;
64+ this . renderBlock = this . _renderBlock . bind ( this , editorState . getCurrentContent ( ) ) ;
6665 }
6766
6867 componentWillReceiveProps ( newProps ) {
@@ -140,10 +139,11 @@ class DraftJSEditor extends Component {
140139
141140 _confirmLink ( ) {
142141 const { editorState, urlValue } = this . state ;
143- const entityKey = Entity . create ( 'LINK' , 'MUTABLE' , {
142+ const contentState = editorState . getCurrentContent ( ) . createEntity ( 'LINK' , 'MUTABLE' , {
144143 target : this . props . linkTarget ,
145144 url : urlValue ,
146145 } ) ;
146+ const entityKey = contentState . getLastCreatedEntityKey ( ) ;
147147
148148 this . onChange (
149149 RichUtils . toggleLink ( editorState , editorState . getSelection ( ) , entityKey )
@@ -186,7 +186,7 @@ class DraftJSEditor extends Component {
186186 this . onChange ( RichUtils . toggleLink ( editorState , selection , null ) ) ;
187187 }
188188
189- _confirmBlock ( e , data ) {
189+ _confirmBlock ( data ) {
190190 this . setState (
191191 {
192192 customBlockData : { } ,
@@ -199,6 +199,8 @@ class DraftJSEditor extends Component {
199199 showCustomBlockInput : false ,
200200 } ,
201201 ( ) => {
202+ const contentState = this . state . editorState . getCurrentContent ( ) ;
203+ this . props . onChange ( convertToRaw ( contentState ) ) ;
202204 setTimeout ( ( ) => this . focus ( ) , 0 ) ;
203205 }
204206 ) ;
@@ -215,7 +217,8 @@ class DraftJSEditor extends Component {
215217 }
216218
217219 _insertCustomBlock ( editorState , type , data ) {
218- const entityKey = Entity . create ( type , 'IMMUTABLE' , data ) ;
220+ const contentState = editorState . getCurrentContent ( ) . createEntity ( type , 'IMMUTABLE' , data ) ;
221+ const entityKey = contentState . getLastCreatedEntityKey ( ) ;
219222
220223 // if you use an empty string for the block content here Draft will die
221224 return AtomicBlockUtils . insertAtomicBlock ( editorState , entityKey , ' ' ) ;
@@ -240,9 +243,9 @@ class DraftJSEditor extends Component {
240243 }
241244 }
242245
243- _renderBlock ( block ) {
246+ _renderBlock ( contentState , block ) {
244247 if ( block . getType ( ) === 'atomic' ) {
245- const entityType = Entity . get ( block . getEntityAt ( 0 ) ) . getType ( ) ;
248+ const entityType = contentState . getEntity ( block . getEntityAt ( 0 ) ) . getType ( ) ;
246249
247250 return this . props . customBlocks [ entityType ]
248251 ? this . props . customBlocks [ entityType ] . getBlockRenderer ( )
0 commit comments