Skip to content

Commit 71b8dfb

Browse files
committed
Merge pull request draft-js-plugins#35 from nikgraf/creation
Add createWithContent and createWithText
2 parents 983961d + 83f7da9 commit 71b8dfb

File tree

7 files changed

+43
-12
lines changed

7 files changed

+43
-12
lines changed

site/components/UnicornEditor/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import Editor, { createEmpty } from 'draft-js-plugin-editor';
2+
import Editor, { createWithText } from 'draft-js-plugin-editor';
33
import hashtagPlugin from 'draft-js-hashtag-plugin';
44
import stickerPlugin from 'draft-js-sticker-plugin';
55
import linkifyPlugin from 'draft-js-linkify-plugin';
@@ -23,7 +23,7 @@ const plugins = List([
2323
export default class UnicornEditor extends Component {
2424

2525
state = {
26-
editorState: createEmpty(plugins),
26+
editorState: createWithText('Hello World!', plugins),
2727
readOnly: false,
2828
showState: false,
2929
};

src/PluginEditor/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import createEmptyFn from './createEmpty';
1+
import createEmptyFn from './utils/createEmpty';
2+
import createWithContentFn from './utils/createWithContent';
3+
import createWithTextFn from './utils/createWithText';
24

35
export default from './Editor';
6+
export const createWithContent = createWithContentFn;
7+
export const createWithText = createWithTextFn;
48
export const createEmpty = createEmptyFn;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { CompositeDecorator } from 'draft-js';
2+
3+
export default (plugins) => {
4+
const decorators = plugins
5+
.filter((plugin) => plugin.compositeDecorator !== undefined)
6+
.map((plugin) => plugin.compositeDecorator);
7+
return new CompositeDecorator(decorators.toJS());
8+
};

src/PluginEditor/utils/createEmpty.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { EditorState } from 'draft-js';
2+
import createCompositeDecorator from './createCompositeDecorator';
3+
4+
export default (plugins) => {
5+
const compositeDecorator = createCompositeDecorator(plugins);
6+
return EditorState.createEmpty(compositeDecorator);
7+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { EditorState, convertFromRaw, ContentState } from 'draft-js';
2+
import createCompositeDecorator from './createCompositeDecorator';
3+
4+
export default (rawContent, plugins) => {
5+
const compositeDecorator = createCompositeDecorator(plugins);
6+
const blocks = convertFromRaw(rawContent);
7+
return EditorState.createWithContent(
8+
ContentState.createFromBlockArray(blocks),
9+
compositeDecorator,
10+
);
11+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { EditorState, ContentState } from 'draft-js';
2+
import createCompositeDecorator from './createCompositeDecorator';
3+
4+
export default (text, plugins) => {
5+
const compositeDecorator = createCompositeDecorator(plugins);
6+
return EditorState.createWithContent(
7+
ContentState.createFromText(text),
8+
compositeDecorator,
9+
);
10+
};

src/pluginEditor/createEmpty.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)