File tree Expand file tree Collapse file tree 4 files changed +50
-4
lines changed
draft-js-placeholder-plugin Expand file tree Collapse file tree 4 files changed +50
-4
lines changed Original file line number Diff line number Diff line change 1
- # DraftJS Divider Plugin
1
+ # DraftJS placeholder Plugin
2
2
3
3
* This is a plugin for the ` draft-js-plugins-editor ` .*
4
+
5
+ ## Usage
6
+
7
+ ``` js
8
+ import createPlaceholderPlugin from ' draft-js-placeholder-plugin' ;
9
+
10
+ const placeholderPlugin = createPlaceholderPlugin ();
11
+
12
+ ```
13
+
14
+ ## Default Config
15
+
16
+ ``` js
17
+ {
18
+ dataKey = ' placeholder' ,
19
+ component = DefaultPlaceholder,
20
+ }
21
+
22
+ ```
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " draft-js-placeholder-plugin" ,
3
- "version" : " 0.1.0 " ,
3
+ "version" : " 0.1.1 " ,
4
4
"description" : " Placeholder Plugin for DraftJS" ,
5
5
"author" : {
6
6
"name" : " Ilkwon Sim" ,
Original file line number Diff line number Diff line change @@ -2,14 +2,16 @@ import { EditorState } from 'draft-js';
2
2
3
3
import DefaultPlaceholder from './components/DefaultPlaceholder' ;
4
4
5
- const placeholderPlugin = ( { dataKey = 'placeholder' } = { } ) => {
5
+ const placeholderPlugin = (
6
+ { dataKey = 'placeholder' , component = DefaultPlaceholder } = { }
7
+ ) => {
6
8
return {
7
9
blockRendererFn : block => {
8
10
const placeholder = block . getData ( ) . get ( dataKey ) ;
9
11
10
12
if ( placeholder ) {
11
13
return {
12
- component : DefaultPlaceholder ,
14
+ component,
13
15
props : {
14
16
placeholder,
15
17
} ,
Original file line number Diff line number Diff line change
1
+ const addPlaceholder = editorState => {
2
+ const contentState = editorState . getCurrentContent ( ) ;
3
+ const selectionState = editorState . getSelection ( ) ;
4
+ const currentBlock = getCurrentBlock ( editorState ) ;
5
+
6
+ if ( isEmptyBlock ( currentBlock ) ) {
7
+ const newContentState = Modifier . setBlockData (
8
+ contentState ,
9
+ selectionState ,
10
+ {
11
+ placeholder : 'This is placeholder' ,
12
+ }
13
+ ) ;
14
+
15
+ setEditorState (
16
+ EditorState . push ( editorState , newContentState , 'change-block-data' )
17
+ ) ;
18
+ // setEditorState(RichUtils.toggleBlockType(editorState, 'placeholder'));
19
+ // setEditorState(
20
+ // Modifier.insertText(contentState, selectionState, 'attach youtube')
21
+ // );
22
+ }
23
+ } ;
24
+
25
+ export default addPlaceholder ;
You can’t perform that action at this time.
0 commit comments