Skip to content

Commit 72da9f9

Browse files
committed
Add Image block compatible with draft-js-image-plugin
1 parent 4ef99a7 commit 72da9f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/modifiers/addImage.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { EditorState, AtomicBlockUtils } from 'draft-js';
2+
3+
export default (editorState, entityType, data = {}) => {
4+
const contentState = editorState.getCurrentContent();
5+
const contentStateWithEntity = contentState.createEntity(entityType, 'IMMUTABLE', data);
6+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
7+
8+
const newEditorState = AtomicBlockUtils.insertAtomicBlock(
9+
editorState,
10+
entityKey,
11+
' '
12+
);
13+
14+
return EditorState.forceSelection(
15+
newEditorState,
16+
newEditorState.getCurrentContent().getSelectionAfter()
17+
);
18+
};

0 commit comments

Comments
 (0)