/**
 * Adds backspace support to stickers
 */ import { ContentBlock , EditorState , Modifier , SelectionState } from 'draft-js' ; const cleanupSticker = ( editorState , blockKey ) : EditorState => { const content = editorState . getCurrentContent ( ) ; const targetRange = new SelectionState ( { anchorKey : blockKey , anchorOffset : 0 , focusKey : blockKey , focusOffset : 0 , } ) ; const withoutSticker = Modifier . setBlockType ( content , targetRange , 'unstyled' ) ; const newState = EditorState . push ( editorState , withoutSticker , 'remove-range' ) ; return EditorState . forceSelection ( newState , withoutSticker . getSelectionAfter ( ) ) ; } ; export default ( editorState ) : EditorState => { let newEditorState = editorState ; editorState . getCurrentContent ( ) . get ( 'blockMap' ) . forEach ( ( block ) => { if ( block . get ( 'type' ) === 'sticker' && block . getEntityAt ( 0 ) === null ) { newEditorState = cleanupSticker ( editorState , block . get ( 'key' ) ) ; } } ) ; return newEditorState ; } ;