GithubHelp home page GithubHelp logo

jpuri / react-draft-wysiwyg Goto Github PK

View Code? Open in Web Editor NEW
6.4K 84.0 1.2K 43.93 MB

A Wysiwyg editor build on top of ReactJS and DraftJS. https://jpuri.github.io/react-draft-wysiwyg

License: MIT License

JavaScript 93.63% CSS 6.33% Shell 0.04%
wysiwyg-editor draft-js reactjs javascript

react-draft-wysiwyg's Introduction

React Draft Wysiwyg

A Wysiwyg editor built using ReactJS and DraftJS libraries. Demo Page.

Build Status

Features

  • Configurable toolbar with option to add/remove controls.
  • Option to change the order of the controls in the toolbar.
  • Option to add custom controls to the toolbar.
  • Option to change styles and icons in the toolbar.
  • Option to show toolbar only when editor is focused.
  • Support for inline styles: Bold, Italic, Underline, StrikeThrough, Code, Subscript, Superscript.
  • Support for block types: Paragraph, H1 - H6, Blockquote, Code.
  • Support for setting font-size and font-family.
  • Support for ordered / unordered lists and indenting.
  • Support for text-alignment.
  • Support for coloring text or background.
  • Support for adding / editing links
  • Choice of more than 150 emojis.
  • Support for mentions.
  • Support for hashtags.
  • Support for adding / uploading images.
  • Support for aligning images, setting height, width.
  • Support for Embedded links, flexibility to set height and width.
  • Option provided to remove added styling.
  • Option of undo and redo.
  • Configurable behavior for RTL and Spellcheck.
  • Support for placeholder.
  • Support for WAI-ARIA Support attributes
  • Using editor as controlled or un-controlled React component.
  • Support to convert Editor Content to HTML, JSON, Markdown.
  • Support to convert the HTML generated by the editor back to editor content.
  • Support for internationalization.

Installing

The package can be installed from npm react-draft-wysiwyg

$ npm install --save react-draft-wysiwyg draft-js

Getting started

Editor can be used as simple React Component:

import { Editor } from "react-draft-wysiwyg";
import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
<Editor
  editorState={editorState}
  toolbarClassName="toolbarClassName"
  wrapperClassName="wrapperClassName"
  editorClassName="editorClassName"
  onEditorStateChange={this.onEditorStateChange}
/>;

Docs

For more documentation check here.

Questions Discussions

For discussions join public channel #rd_wysiwyg in DraftJS Slack Organization.

Fund

You can fund project at Patreon.

Thanks

Original motivation and sponsorship for this work came from iPaoo. I am thankful to them for allowing the Editor to be open-sourced.

License

MIT.

react-draft-wysiwyg's People

Contributors

acidio avatar agerbens avatar alfaslash avatar amitom avatar bang88 avatar brod-dotdev avatar camwalker avatar cube-dan avatar dani-shopery avatar dependabot[bot] avatar dorarep avatar ferrao avatar jmavs avatar jmferreiratech avatar jpuri avatar lavoiedn avatar legrego avatar mguijarr avatar nlopin avatar paradoxxxzero avatar raphaelbadia avatar roelbarreto avatar roychoo avatar scbrady avatar seromenho avatar tammomueller avatar the1sky avatar vincentdesmares avatar weianan avatar zerocho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-draft-wysiwyg's Issues

Feature request: Embed

Hello, thanks for awesome repository! This is the most perfect react editor I've ever seen!

I'd really like to embed some cool stuffs in my post, such as YouTube or Codepen.
I will be happy if you implement this feature, and this repo will be perfect.

Options in dropdown overlapping

When options are in dropdown in multiple lines. Dropdown in first line when opened should not be behind dropdown in second line.

Image upload issue

Hi! When I click on "Image upload" button, then choose "URL" tab, then try to put a focus on "Enter url" input, it disappears and is replaced by "Drop the file or click to upload". Please, help. Thank you.

1.0

----------------------------- STABILIZING -------------------------------

  • #5
  • refactor npm dpeendencies
  • code cleanup
  • upgrade dependencies
  • folder structure changes
  • upgrade projects draftjs-utils and draftjs-to-html

----------------------------- BUGS -------------------------------

---------------------------- NEW FEATURES ------------------------------

---------------------------- TESTING -----------------------------

  • [ x] Testing all old and new features

---------------------------- DOCUMENTATION -----------------------------

  • enhanced docs
  • [x ] adding content to readme about using the lib
  • fixing documentation scripts

Prefix classes

Quick suggestion, if you are going to use classes to assign styles then you should probably add some sort of unique or definable prefix to the class names. Right now you are opening yourself up to a lot of unintentional collisions if someone were to use this in an existing project. Currently it would be difficult for others to keep in mind what all class names you've taken off the table.

Avoid 'undefined' class name

Be mindful of passing undefined values to className, because React interprets that as a class name of "undefined". When I inspect your editor, I see a lot of class="... undefined".

"convertFromHTML" not support tag "img" ? "draftToHtml" was not friendly to "img"?

Hello ~

Very thank you for your amazing writing component, thanks a lot!
But I found some problems in the process of use:

1:"convertFromHTML" method does not support img tags!
Ex:
ContentState createFromBlockArray (convertFromHTML ('<p>123<img src="http://image.mmzhuli.com/e0bd1b1a-8a8c-4cec-b42e-1e9605594353?hjw=50&hjh=50"/><br/>1111</p> '))
2, in the process of submitted data,"draftToHtml" method seems more parsing out a symbol
Ex:
qq20161026-0 2x

Thanks~ Really looking forward to receive your reply!

How to use spellcheck?

The spellcheck does not work annymore in your samples.
I tried to include "spellcheck={true}".
But that made no difference.

Usage Example

Hey @jpuri ,
I liked the text editor of demo page and I wanted to use similar kind of rich-text -editor in my project. But there is no information on How to use component after installation.
Great if you can provide some guide for the same.

Thanks

Loading HTML content into editor

Maybe is a basic question (actually I guess is not related with your current draft based editor), but I don't get at all how draftjs works. I've been trying to load some html using the demo as example and so far I've tried something like this:

import React from 'react'
import { Modal } from 'react-bootstrap'
import { Editor } from 'react-draft-wysiwyg';
import draftToHtml from 'draftjs-to-html';
import { convertFromHTML, ContentState, convertToRaw } from 'draft-js';


export default class EditDescriptionModal extends React.Component {

  constructor(props) {
    super(props);
    this.state = {editorContent: this._getInitialHTML()};
  }

  _getInitialHTML() {
    const contentBlocks = convertFromHTML('<p>Hello world</p>');
    const contentState = ContentState.createFromBlockArray(contentBlocks);
    return convertToRaw(contentState);
  }

  onEditorChange(editorContent) {
    console.log(draftToHtml(editorContent))
    this.setState({ editorContent });
  };

  render(){
    const { editorContent } = this.state;
    return(
      <Modal  show={this.props.showModal} onHide={this.props.onClose}
              bsSize="large" >
        <form className="form-horizontal" >
          <Modal.Header closeButton>
            <Modal.Title>Edit description</Modal.Title>
          </Modal.Header>
          <Modal.Body>
            <div className="demo-editorSection">
              <div className="demo-editorWrapper">
                <Editor
                  rawContentState={editorContent}
                  toolbarClassName="demo-toolbar"
                  wrapperClassName="demo-wrapper"
                  editorClassName="demo-editor"
                  onChange={this.onEditorChange.bind(this)}
                  toolbarAlwaysVisible
                />
              </div>
            </div>
          </Modal.Body>
          <Modal.Footer>
            <button type="submit" className="btn btn-info">Submit</button>
            <button type="button" className="btn"
                    onClick={this.props.onClose}>Close</button>
          </Modal.Footer>
        </form>
      </Modal>
    )
  }
}

So is supposed it should display that <p>Hello world</p> as initial editor content passing to the rawContentState of the Editor component, but I think I'm wrong.
In any case, if I add some text to the editor, is correctly converted to HTML in the onEditorChange function. What I'm doing wrong here?.
BTW, kudos for the great work done

> sign added when embed something.

I added youtube in your demo.
chrome_2016-11-25_06-35-22
In front of iframe, > sign is added, and this blocks rest of HTML from rendering normally.

also, can I change that 315px to other number?

Load Html and keep font-size and colors

Hello Jyoti.
I think your draft editor is great. I appreciate all your work!
You take the time to answer questions. What a service!

My question is about the possibility to load HTML into the editor.
It works fine. But things like font-size and colors are gone..

Think that you had some different font-sizes and font-colors in your
sampleEditorContent.js which is used in one of your samples here: initialContentState={sampleEditorContent}.
How could we keep/show them?

Image, Embed problem

@jpuri Thanks for the great editor!
When I embed url or add image url, img and iframe src is not the url I typed but [object Event]
<img src="[object Event]" role="presentation">
<iframe width="100%" height="315px" src="[object Event]" frameborder="0" allowfullscreen=""></iframe>
I found out that it is due to here and here
I think the order should be changed into this
const src = this.state.imgSrc || imgSrc;
also
const link = this.state.embeddedLink || embeddedLink;
I'm not sure what do those imgSrc and embeddedLink do. As an eventHandler callback, do we need second parameter?

Behavior on pressing enter

Hi,

Whenever you press enter and the content is too big to show without scrolling, whenever enter is pressed the editor scrolls to the end of the text. This might be a little annoying when writing news like paragraph. Is there any idea on how to solve this problem?

Congrats on the awesome job.

Hello. Some basic example?

Hello!

Based on what I've seen in the demos you provided, I like your implementation. I think it may be very good in production because of the practical way of grouping and arranging the design functions within it.

I want to test it in our projects.

But I think it might be helpful a basic usage guide, because I get this Warning: validateDOMNesting(...): < div> cannot appear as a descendant of < p>. See DraftEditorContents > p > ... > DraftEditorBlock > div.

Thank you for sharing your project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.