Skip to content

Add createWithContent and createWithText #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions site/components/UnicornEditor/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import Editor, { createEmpty } from 'draft-js-plugin-editor';
import Editor, { createWithText } from 'draft-js-plugin-editor';
import hashtagPlugin from 'draft-js-hashtag-plugin';
import stickerPlugin from 'draft-js-sticker-plugin';
import linkifyPlugin from 'draft-js-linkify-plugin';
Expand All @@ -23,7 +23,7 @@ const plugins = List([
export default class UnicornEditor extends Component {

state = {
editorState: createEmpty(plugins),
editorState: createWithText('Hello World!', plugins),
readOnly: false,
showState: false,
};
Expand Down
6 changes: 5 additions & 1 deletion src/PluginEditor/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import createEmptyFn from './createEmpty';
import createEmptyFn from './utils/createEmpty';
import createWithContentFn from './utils/createWithContent';
import createWithTextFn from './utils/createWithText';

export default from './Editor';
export const createWithContent = createWithContentFn;
export const createWithText = createWithTextFn;
export const createEmpty = createEmptyFn;
8 changes: 8 additions & 0 deletions src/PluginEditor/utils/createCompositeDecorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CompositeDecorator } from 'draft-js';

export default (plugins) => {
const decorators = plugins
.filter((plugin) => plugin.compositeDecorator !== undefined)
.map((plugin) => plugin.compositeDecorator);
return new CompositeDecorator(decorators.toJS());
};
7 changes: 7 additions & 0 deletions src/PluginEditor/utils/createEmpty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { EditorState } from 'draft-js';
import createCompositeDecorator from './createCompositeDecorator';

export default (plugins) => {
const compositeDecorator = createCompositeDecorator(plugins);
return EditorState.createEmpty(compositeDecorator);
};
11 changes: 11 additions & 0 deletions src/PluginEditor/utils/createWithContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { EditorState, convertFromRaw, ContentState } from 'draft-js';
import createCompositeDecorator from './createCompositeDecorator';

export default (rawContent, plugins) => {
const compositeDecorator = createCompositeDecorator(plugins);
const blocks = convertFromRaw(rawContent);
return EditorState.createWithContent(
ContentState.createFromBlockArray(blocks),
compositeDecorator,
);
};
10 changes: 10 additions & 0 deletions src/PluginEditor/utils/createWithText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { EditorState, ContentState } from 'draft-js';
import createCompositeDecorator from './createCompositeDecorator';

export default (text, plugins) => {
const compositeDecorator = createCompositeDecorator(plugins);
return EditorState.createWithContent(
ContentState.createFromText(text),
compositeDecorator,
);
};
9 changes: 0 additions & 9 deletions src/pluginEditor/createEmpty.js

This file was deleted.