diff --git a/conf/storybook/webpack.config.js b/conf/storybook/webpack.config.js index 370d4ab..7dde8c8 100644 --- a/conf/storybook/webpack.config.js +++ b/conf/storybook/webpack.config.js @@ -6,5 +6,15 @@ module.exports = { path.resolve( './src' ), ], }, + module: { + loaders: [ + { + test: /plugin\.css$/, + loaders: [ + 'style', 'css', + ], + }, + ], + } }; diff --git a/package.json b/package.json index b2e0338..28a8823 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,11 @@ "babel-runtime": "^6.5.0", "css-loader": "^0.23.1", "debug": "^2.2.0", - "draft-js": "0.9.0", - "draft-js-mention-plugin": "1.1.0", - "draft-js-plugins-editor": "1.1.0", + "draft-js": "0.9.1", + "draft-js-linkify-plugin": "^2.0.0-beta5", + "draft-js-mention-plugin": "2.0.0-beta5", + "draft-js-plugins-editor": "2.0.0-beta5", + "draft-js-undo-plugin": "^2.0.0-beta5", "enzyme": "^2.4.1", "express": "^4.13.4", "falcor": "^0.1.16", diff --git a/src/components/comfy-editor/index.js b/src/components/comfy-editor/index.js new file mode 100644 index 0000000..508dac0 --- /dev/null +++ b/src/components/comfy-editor/index.js @@ -0,0 +1,65 @@ +import React, { PropTypes } from 'react'; +import reactStamp from 'react-stamp'; +import { fromJS, List, Repeat } from 'immutable'; + +import EditorFactory from 'components/editor'; + +import createMentionPlugin, { defaultSuggestionsFilter } from 'draft-js-mention-plugin'; +import createUndoPlugin from 'draft-js-undo-plugin'; +import createLinkifyPlugin from 'draft-js-linkify-plugin'; + +import 'draft-js-mention-plugin/lib/plugin.css'; +import 'draft-js-undo-plugin/lib/plugin.css'; +import 'draft-js-linkify-plugin/lib/plugin.css'; + +import { cyan700, green700 } from 'material-ui/lib/styles/colors'; + +const Editor = EditorFactory(React); + +const MentionComponent = ({ entityKey, mention, className, mentionPrefix, decoratedText, children }) => ( + + {mentionPrefix}{children} + +); + +const mentionPlugin = createMentionPlugin({ mentionComponent: MentionComponent }); +const undoPlugin = createUndoPlugin(); +const linkifyPlugin = createLinkifyPlugin(); + +const { MentionSuggestions } = mentionPlugin; + +export default (React, ...behaviours) => reactStamp(React).compose({ + propTypes: { + onSearchChange: PropTypes.func, + searchSuggestions: PropTypes.arrayOf(PropTypes.shape({ + type: PropTypes.oneOf(['character', 'element']).isRequired, + _id: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + link: PropTypes.string.isRequired, + avatar: PropTypes.string.isRequired, + })).isRequired, + }, + + render() { + const { onSearchChange, searchSuggestions, plugins = [], ...rest } = this.props; + return ( +
+ + +
+ ); + }, +}); diff --git a/src/components/comfy-editor/story.js b/src/components/comfy-editor/story.js new file mode 100644 index 0000000..89ed564 --- /dev/null +++ b/src/components/comfy-editor/story.js @@ -0,0 +1,44 @@ +import React from 'react'; +import { storiesOf, action } from '@kadira/storybook'; + +import EditorFactory from './'; + +const Editor = EditorFactory(React); + +import { + EditorState, + ContentState, + ContentBlock, + CharacterMetadata, + convertToRaw, + convertFromRaw, + genKey, +} from 'draft-js'; +import { is, fromJS, List, Repeat } from 'immutable'; + +const genContent = (text) => { + const contentState = ContentState.createFromBlockArray([ + new ContentBlock({ + key: 'abc', + type: 'unstyled', + text, + characterList: List(Repeat(CharacterMetadata.EMPTY, text.length)) + }), + ]); + return convertToRaw(contentState); +}; + +storiesOf('Comfy editor', module) + .add('default', () => { + const initialContent = genContent('Here we go'); + return ( + + ); + });