├── .npmignore ├── .gitignore ├── example ├── assets │ ├── whoa.jpg │ ├── css │ │ ├── bundle.css.map │ │ ├── bundle.css │ │ └── example.css │ ├── app.js.map │ └── index.html ├── browser.js ├── config.js ├── draft │ ├── unstyled.js │ ├── header.js │ ├── index.js │ ├── resizeable-div2.js │ ├── resizeable-div.js │ ├── youtube.js │ └── data.js ├── index.js └── container.js ├── src ├── index.js ├── block-wrapper.js ├── editor.js └── create-plugins.js ├── gulpfile.js ├── .eslintrc ├── README.md ├── LICENSE └── package.json /.npmignore: -------------------------------------------------------------------------------- 1 | /dist/ 2 | /node_modules/ 3 | npm-debug.log 4 | /.idea -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /lib/ 2 | /node_modules/ 3 | npm-debug.log 4 | /.idea 5 | node_modules 6 | -------------------------------------------------------------------------------- /example/assets/whoa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bkniffler/draft-wysiwyg/HEAD/example/assets/whoa.jpg -------------------------------------------------------------------------------- /example/assets/css/bundle.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"css/bundle.css","sources":[],"mappings":"","sourceRoot":""} -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export EditorBlock from 'draft-js/lib/DraftEditorBlock.react'; 2 | export BlockWrapper from './block-wrapper'; 3 | export default from './editor'; 4 | -------------------------------------------------------------------------------- /example/assets/app.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.js","sources":["webpack:///app.js","webpack:///"],"mappings":"AAAA;ACyuJA;AA2vBA;AAsuHA;AA41GA;AAy3IA;AA+uIA;AAsqFA;AAg2FA;AAghEA;AAwlEA;AAg7GA;AA4nJA;AAyrIA;AAu3GA","sourceRoot":""} -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | 3 | gulp.task("build", function (callback) { 4 | global.DEBUG = false; 5 | 6 | require('wrappack/gulpfile')( 7 | require('./example/config.js')(), callback 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /example/browser.js: -------------------------------------------------------------------------------- 1 | import 'babel-polyfill'; 2 | import Example from './container'; 3 | import React from 'react'; 4 | import ReactDOM from 'react-dom'; 5 | 6 | ReactDOM.render( 7 | , 8 | document.getElementById('target') 9 | ); 10 | -------------------------------------------------------------------------------- /example/config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | module.exports = function(){ 4 | return { 5 | root: path.resolve(__dirname, '..'), 6 | app: path.resolve(__dirname, 'app.js'), 7 | cssModules: false, 8 | alias: { 9 | 'draft-wysiwyg': path.resolve(__dirname, '..', 'src'), 10 | } 11 | }; 12 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "plugins": [ "mocha" ], 4 | "env": { 5 | "browser": true, 6 | "mocha": true, 7 | "node": true 8 | }, 9 | "extends": "airbnb", 10 | "rules": { 11 | "max-len": 0, 12 | "comma-dangle": 0, 13 | "new-cap": 0, 14 | "react/prop-types": 0, 15 | "react/prefer-stateless-function": 0 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /example/draft/unstyled.js: -------------------------------------------------------------------------------- 1 | import React, {Component, PropTypes} from "react"; 2 | import DraftEditorBlock from 'draft-js/lib/DraftEditorBlock.react'; 3 | 4 | export default class Paragraph extends Component { 5 | render(){ 6 | return ( 7 |
8 | 9 |
10 | ) 11 | } 12 | } -------------------------------------------------------------------------------- /example/draft/header.js: -------------------------------------------------------------------------------- 1 | import React, {Component, PropTypes} from "react"; 2 | import DraftEditorBlock from 'draft-js/lib/DraftEditorBlock.react'; 3 | 4 | export default function(size){ 5 | return class Header extends Component { 6 | render(){ 7 | return React.createElement('h'+size, { className: 'header' }, ) 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/assets/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Draft 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/draft/index.js: -------------------------------------------------------------------------------- 1 | export Data from './data'; 2 | 3 | import Header from './header'; 4 | import Youtube from './youtube'; 5 | import ResizeableDiv from './resizeable-div'; 6 | import ResizeableDiv2 from './resizeable-div2'; 7 | /*import Columns2 from './columns2'; 8 | import Image from './image'; 9 | import Unstyled from './unstyled';*/ 10 | 11 | var blocks = { 12 | 'header-1': Header(1), 13 | 'header-2': Header(2), 14 | 'header-3': Header(3), 15 | 'header-4': Header(4), 16 | 'header-5': Header(5), 17 | youtube: Youtube, 18 | 'resizeable-div': ResizeableDiv, 19 | 'resizeable-div2': ResizeableDiv2, 20 | /* 21 | columns2: Columns2, 22 | image: Image, 23 | unstyled: Unstyled, 24 | */ 25 | } 26 | 27 | export const Blocks = blocks; 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # draft-wysiwyg 2 | A wysiwyg editor that mimics medium, build on top of https://github.com/facebook/draft-js and https://github.com/draft-js-plugins/draft-js-plugins. All the relevant behaviour comes from plugins, so this may serve as an example of using the plugin architecture and the different plugins. You can also install and use draft-wysiwyg right away. 3 | 4 | ## Demo 5 | https://draft-wysiwyg.herokuapp.com/ 6 | 7 | ## Features 8 | - Drag & Drop uploading 9 | - Inline toolbar for text 10 | - Block drag/drop 11 | - Block resizing (horizontal/vertical with absolute/relative sizes and aspect ratios) 12 | - Block toolbars 13 | - Block keydown handling to remove blocks (backspace) or move cursor to next/previous block 14 | - Tables (nested draft-js) 15 | - Links 16 | - Some more things 17 | 18 | ## Installation 19 | ``` 20 | npm install draft-wysiwyg 21 | or 22 | sudo npm install draft-wysiwyg 23 | ``` 24 | 25 | ## Usage 26 | WIP 27 | 28 | ## Contributing 29 | Pull requests are very welcome, feel free to commit your ideas! 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Benjamin Kniffler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /example/draft/resizeable-div2.js: -------------------------------------------------------------------------------- 1 | import React, {Component, PropTypes} from "react"; 2 | import { FocusDecorator } from 'draft-js-focus-plugin'; 3 | import { DraggableDecorator } from 'draft-js-dnd-plugin'; 4 | import { ToolbarDecorator } from 'draft-js-toolbar-plugin'; 5 | import { AlignmentDecorator } from 'draft-js-alignment-plugin'; 6 | import { ResizeableDecorator } from 'draft-js-resizeable-plugin'; 7 | 8 | class Div extends Component { 9 | render(){ 10 | const { style, className } = this.props; 11 | var styles = { 12 | backgroundColor: 'rgba(100, 100, 100, 1.0)', 13 | width: '100%', 14 | height: '100%', 15 | textAlign: 'center', 16 | color: 'white', 17 | zIndex: 1, 18 | position: 'relative', 19 | ...style 20 | }; 21 | return ( 22 |
23 | Horizontal only 24 | {/**/} 25 |
26 | ); 27 | } 28 | } 29 | export default ResizeableDecorator({ 30 | handles: true 31 | })( 32 | DraggableDecorator( 33 | FocusDecorator( 34 | AlignmentDecorator( 35 | ToolbarDecorator()( 36 | Div 37 | ) 38 | ) 39 | ) 40 | ) 41 | ); 42 | -------------------------------------------------------------------------------- /example/draft/resizeable-div.js: -------------------------------------------------------------------------------- 1 | import React, {Component, PropTypes} from "react"; 2 | import { FocusDecorator } from 'draft-js-focus-plugin'; 3 | import { DraggableDecorator } from 'draft-js-dnd-plugin'; 4 | import { ToolbarDecorator } from 'draft-js-toolbar-plugin'; 5 | import { AlignmentDecorator } from 'draft-js-alignment-plugin'; 6 | import { ResizeableDecorator } from 'draft-js-resizeable-plugin'; 7 | 8 | class Div extends Component { 9 | render(){ 10 | const { style, className } = this.props; 11 | var styles = { 12 | backgroundColor: 'rgba(98, 177, 254, 1.0)', 13 | width: '100%', 14 | height: '100%', 15 | textAlign: 'center', 16 | color: 'white', 17 | zIndex: 1, 18 | position: 'relative', 19 | ...style 20 | }; 21 | return ( 22 |
23 | Horizontal+Vertical 24 | {/**/} 25 |
26 | ); 27 | } 28 | } 29 | 30 | export default ResizeableDecorator({ 31 | resizeSteps: 10, 32 | caption: true, 33 | vertical: 'absolute' 34 | })( 35 | DraggableDecorator( 36 | FocusDecorator( 37 | AlignmentDecorator( 38 | ToolbarDecorator()( 39 | Div 40 | ) 41 | ) 42 | ) 43 | ) 44 | ); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "draft-wysiwyg", 3 | "version": "0.2.4", 4 | "author": "Benjamin Kniffler", 5 | "license": "MIT", 6 | "repository": "https://github.com/bkniffler/draft-wysiwyg", 7 | "main": "./lib", 8 | "engines": { 9 | "node": "5.x.x", 10 | "npm": "3.x.x" 11 | }, 12 | "keywords": [ 13 | "draftjs", 14 | "draft-js", 15 | "editor", 16 | "wysiwyg", 17 | "drag", 18 | "drop", 19 | "react", 20 | "richtext" 21 | ], 22 | "scripts": { 23 | "start": "node ./example", 24 | "build": "babel --presets es2015,stage-0,react src/ --out-dir lib/", 25 | "heroku": "git push heroku master", 26 | "start:production": "NODE_ENV=production node ./example", 27 | "build:example": "gulp build", 28 | "patch": "npm run build; npm version patch --force; npm publish" 29 | }, 30 | "dependencies": { 31 | "draft-js": "^0.7.0", 32 | "draft-js-alignment-plugin": "^1.0.3", 33 | "draft-js-cleanup-empty-plugin": "^1.0.2", 34 | "draft-js-dnd-plugin": "^1.0.7", 35 | "draft-js-entity-props-plugin": "^1.0.2", 36 | "draft-js-focus-plugin": "^1.0.12", 37 | "draft-js-image-plugin": "^1.0.3", 38 | "draft-js-plugins-editor-wysiwyg": "^1.0.3", 39 | "draft-js-resizeable-plugin": "^1.0.8", 40 | "draft-js-table-plugin": "^1.0.4", 41 | "draft-js-toolbar-plugin": "^1.0.5", 42 | "immutable": "^3.7.4" 43 | }, 44 | "devDependencies": { 45 | "express": "^4.13.1", 46 | "gulp": "^3.9.0", 47 | "multer": "^1.1.0", 48 | "react": "^15.0.2", 49 | "react-dom": "^15.0.2", 50 | "superagent": "^1.8.0", 51 | "wrappack": "^0.3.10" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/draft/youtube.js: -------------------------------------------------------------------------------- 1 | import React, {Component, PropTypes} from "react"; 2 | 3 | import { FocusDecorator } from 'draft-js-focus-plugin'; 4 | import { DraggableDecorator } from 'draft-js-dnd-plugin'; 5 | import { ToolbarDecorator } from 'draft-js-toolbar-plugin'; 6 | import { AlignmentDecorator } from 'draft-js-alignment-plugin'; 7 | import { ResizeableDecorator } from 'draft-js-resizeable-plugin'; 8 | 9 | var defaultVideo = 'https://www.youtube.com/embed/zalYJacOhpo'; 10 | class Div extends Component { 11 | setUrl(){ 12 | var url = window.prompt("URL", this.props.blockProps.url||defaultVideo); 13 | if(url){ 14 | const {setEntityData} = this.props.blockProps; 15 | setEntityData(this.props.block, {url}); 16 | } 17 | } 18 | render(){ 19 | const { style, className, ratioContentStyle, ratioContainerStyle, createRatioPlaceholder } = this.props; 20 | var action = { 21 | active: false, 22 | button: URL, 23 | toggle: ()=>this.setUrl(), 24 | label: 'URL' 25 | }; 26 | var styles = { 27 | width: '100%', 28 | height: '100%', 29 | position: 'relative', 30 | zIndex: 1, 31 | margin: '3px', 32 | ...style, 33 | ...ratioContainerStyle 34 | }; 35 | return ( 36 |
37 | {createRatioPlaceholder()} 38 |