Git Product home page Git Product logo

react-rte's Introduction

Deprecated

This repository is long ourdated and even Draft.js (on which this editor is built) is long outdated and has been superceded by Lexical.

I don't recommend you use this in your project. There are many great alternatives such as TipTap.

React Rich Text Editor

This is a UI component built completely in React that is meant to be a full-featured textarea replacement similar to CKEditor, TinyMCE and other rich text "WYSIWYG" editors. It's based on the excellent, open source Draft.js from Facebook which is performant and production-tested.

Demo

Try the editor here: react-rte.org/demo

Screenshot 1

Getting Started

$ npm install --save react-rte

RichTextEditor is the main editor component. It is comprised of the Draft.js <Editor>, some UI components (e.g. toolbar) and some helpful abstractions around getting and setting content with HTML/Markdown.

RichTextEditor is designed to be used like a textarea except that instead of value being a string, it is an object with toString on it. Creating a value from a string is also easy using createValueFromString(markup, 'html').

Browser Compatibility

The scripts are transpiled by Babel to ES6. Additionally, at least one of this package's dependencies does not support IE. So, for IE and back-plat support you will need to include some polyfill in your HTML (#74, #196, #203): <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=String.prototype.startsWith,Array.from,Array.prototype.fill,Array.prototype.keys,Array.prototype.findIndex,Number.isInteger&flags=gated"></script>

Required Webpack configuration

If you are not using Webpack, you can skip this section. Webpack is required for isomorphic/server-side rendering support in a Node.js environment.

'react-rte' contains a bundle that is already built (with CSS) using webpack and is not intended to be consumed again by webpack. So, if you are using webpack you must import RichTextEditor from react-rte/lib/RichTextEditor in order to get the un-bundled script which webpack can bundle with your app.

If you are using webpack you must add a css loader or else your webpack build will fail. For example:

  {
    test: /\.css$/,
    loaders: [
      'style-loader',
      'css-loader?modules'
    ]
  },

Example Usage:

This example uses newer JavaScript and JSX. For an example in old JavaScript, see below.

import React, {Component, PropTypes} from 'react';
import RichTextEditor from 'react-rte';

class MyStatefulEditor extends Component {
  static propTypes = {
    onChange: PropTypes.func
  };

  state = {
    value: RichTextEditor.createEmptyValue()
  }

  onChange = (value) => {
    this.setState({value});
    if (this.props.onChange) {
      // Send the changes up to the parent component as an HTML string.
      // This is here to demonstrate using `.toString()` but in a real app it
      // would be better to avoid generating a string on each change.
      this.props.onChange(
        value.toString('html')
      );
    }
  };

  render () {
    return (
      <RichTextEditor
        value={this.state.value}
        onChange={this.onChange}
      />
    );
  }
}

Toolbar Customization

render() {
  // The toolbarConfig object allows you to specify custom buttons, reorder buttons and to add custom css classes.
  // Supported inline styles: https://github.com/facebook/draft-js/blob/master/docs/Advanced-Topics-Inline-Styles.md
  // Supported block types: https://github.com/facebook/draft-js/blob/master/docs/Advanced-Topics-Custom-Block-Render.md#draft-default-block-render-map
  const toolbarConfig = {
    // Optionally specify the groups to display (displayed in the order listed).
    display: ['INLINE_STYLE_BUTTONS', 'BLOCK_TYPE_BUTTONS', 'LINK_BUTTONS', 'BLOCK_TYPE_DROPDOWN', 'HISTORY_BUTTONS'],
    INLINE_STYLE_BUTTONS: [
      {label: 'Bold', style: 'BOLD', className: 'custom-css-class'},
      {label: 'Italic', style: 'ITALIC'},
      {label: 'Underline', style: 'UNDERLINE'}
    ],
    BLOCK_TYPE_DROPDOWN: [
      {label: 'Normal', style: 'unstyled'},
      {label: 'Heading Large', style: 'header-one'},
      {label: 'Heading Medium', style: 'header-two'},
      {label: 'Heading Small', style: 'header-three'}
    ],
    BLOCK_TYPE_BUTTONS: [
      {label: 'UL', style: 'unordered-list-item'},
      {label: 'OL', style: 'ordered-list-item'}
    ]
  };
  return (
    <RichTextEditor toolbarConfig={toolbarConfig} />
  );
}

Motivation

In short, this is a modern approach to rich text editing built on a battle-hardened open-source framework and, importantly, we do not store document state in the DOM, eliminating entire classes of common "WYSIWYG" problems.

This editor is built on Draft.js from Facebook. Draft.js is more of a low-level framework (contentEditable abstraction), however this component is intended to be a fully polished UI component that you can reach for when you need to replace a <textarea/> in your application to support bold, italic, links, lists, etc.

The data model in Draft.js allows us to represent the document in a way that is mostly agnostic to the view/render layer or the textual representation (html/markdown) you choose. This data model encapsulates the content/state of the editor and is based on Immutable.js to be both performant and easy to reason about.

Features

  • Pure React and fully declarative
  • Supported formats: HTML and Markdown (coming soon: extensible support for custom formats)
  • Document Model represents your document in a sane way that will deterministically convert to clean markup regardless of your format choice
  • Takes full advantage of Immutable.js and the excellent performance characteristics that come with it.
  • Reliable undo/redo without a large memory footprint
  • Modern browser support

Deterministic Output

Unlike typical rich text editors (such as CKEditor and TinyMCE) we keep our content state in a well-architected data model instead of in the view. One important advantage of separating our data model from our view is deterministic output.

Say, for instance, you select some text and add bold style. Then you add italic style. Or what if you add italic first and then bold. The result should be the same either way: the text range has both bold and italic style. But in the browser's view (Document Object Model) is this represented with a <strong> inside of an <em> or vice versa? Does it depend on the order in which you added the styles? In many web-based editors the HTML output does depend on the order of your actions. That means your output is non-deterministic. Two documents that look exactly the same in the editor will have different, sometimes unpredictable, HTML representations.

In this editor we use a pure, deterministic function to convert document state to HTML output. No matter how you arrived at the state, the output will be predictable. This makes everything easier to reason about. In our case, the <strong> will go inside the <em> every time.

API

Required Props

  • value: Used to represent the content/state of the editor. Initially you will probably want to create an instance using a provided helper such as RichTextEditor.createEmptyValue() or RichTextEditor.createValueFromString(markup, 'html').
  • onChange: A function that will be called with the "value" of the editor whenever it is changed. The value has a toString method which accepts a single format argument (either 'html' or 'markdown').

Other Props

All the props you can pass to Draft.js Editor can be passed to RichTextEditor (with the exception of editorState which will be generated internally based on the value prop).

  • autoFocus: Setting this to true will automatically focus input into the editor when the component is mounted
  • placeholder: A string to use as placeholder text for the RichTextEditor.
  • readOnly: A boolean that determines if the RichTextEditor should render static html.
  • enableSoftNewLineByDefault: Set this to true if you wish to use soft line breaks when only pressing the return key. By default, if you press the return/enter key it will create a new text block. If you don't set this value to true, the user may use one of several designated keys while pressing the return key to create a soft new line.

EditorValue Class

In Draft.js EditorState contains not only the document contents but the entire state of the editor including cursor position and selection. This is helpful for many reasons including undo/redo. To make things easier for you, we have wrapped the state of the editor in an EditorValue instance with helpful methods to convert to/from a HTML or Markdown. An instance of this class should be passed to RichTextEditor in the value prop.

The EditorValue class has certain optimizations built in. So let's say you are showing the HTML of the editor contents in your view. If you change your cursor position, that will trigger an onChange event (because, remember, cursor position is part of EditorState) and you will need to call toString() to render your view. However, EditorValue is smart enough to know that the content didn't actually change since last toString() so it will return a cached version of the HTML.

Optimization tip: Try to call editorValue.toString() only when you actually need to convert it to a string. If you can keep passing around the editorValue without calling toString it will be very performant.

Example with ES5 and no JSX

var React = require('react');
var RichTextEditor = require('react-rte');

React.createClass({
  propTypes: {
    onChange: React.PropTypes.func
  },

  getInitialState: function() {
    return {
      value: RichTextEditor.createEmptyValue()
    };
  },

  render: function() {
    return React.createElement(RichTextEditor, {
      value: this.state.value,
      onChange: this.onChange
    });
  },

  onChange: function(value) {
    this.setState({value: value});
    if (this.props.onChange) {
      // Send the changes up to the parent component as an HTML string.
      // This is here to demonstrate using `.toString()` but in a real app it
      // would be better to avoid generating a string on each change.
      this.props.onChange(
        value.toString('html')
      );
    }
  }

});

TODO

  • Support images
  • Better test coverage
  • Documentation for using this editor in your projects
  • Fix some issues with Markdown parsing (migrate to remark parser)
  • Internationalization
  • Better icons and overall design

Known Limitations

Currently the biggest limitation is that images are not supported. There is a plan to support inline images (using decorators) and eventually Medium-style block-level images (using a custom block renderer).

Other limitations include missing features such as: text-alignment and text color. These are coming soon.

React prior v15 will log the following superfluous warning:

A component is contentEditable and contains children managed by React. It is now your responsibility to guarantee that none of those nodes are unexpectedly modified or duplicated. This is probably not intentional.

As all nodes are managed internally by Draft, this is not a problem and this warning can be safely ignored. You can suppress this warning's display completely by duck-punching console.error before instantiating your component:

console.error = (function(_error) {
  return function(message) {
    if (typeof message !== 'string' || message.indexOf('component is `contentEditable`') === -1) {
      _error.apply(console, arguments);
    }
  };
})(console.error);

Contribute

I'm happy to take pull requests for bug-fixes and improvements (and tests). If you have a feature you want to implement it's probably a good idea to open an issue first to see if it's already being worked on. Please match the code style of the rest of the project (ESLint should enforce this) and please include tests. Thanks!

Run the Demo

Clone this project. Run npm install. Run npm run build-dist then point the server of your choice (like serv) to /demo.html.

License

This software is ISC Licensed.

react-rte's People

Contributors

andschdk avatar benjy avatar bherila avatar bliheris avatar brakmic avatar cmdrdats avatar forbeslindesay avatar gauravchl avatar gpittarelli avatar jide avatar jono avatar jtraub avatar kamioftea avatar kcraw avatar kiwka avatar machineghost avatar mjlescano avatar moimael avatar mplis avatar mvanlonden avatar peterzernia avatar ralphschindler avatar ric9176 avatar rotoglup avatar simpixelated avatar skolmer avatar sstur avatar ubermouse avatar zackify 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

react-rte's Issues

nodeName of undefined in IE 11?

screen shot 2016-05-31 at 4 18 53 pm

This happens when loading in the editor. It doesn't show up. Not sure if this is a problem due to draftjs itself or due to react-rte. Only happens on IE 11 like I said. Can't stand IE....

npm run build-demo command not working

In this commit, the build-demo script was removed from the package.json file.

Adding the line "build-demo": "webpack", to the package.json file solved the issue for me. Perhaps the readme should be updated or the script should be added back.

Markdown: Fix Parsing bugs / Use `remark`

The current Markdown parser is based on chjj/marked but it has been modified a lot (to parse to a synthetic DOM rather than a string). However, the more tests I write, the more markdown parsing bugs I'm noticing, so I am considering a move to wooorm/remark.

Additional Documentation or example?

I'm looking around, and I don't see any additional documentation besides the project's README, so I'm having issues figuring out how to integrate this.

I have so many integration questions like:
How do I set options, such as disabling certain buttons?
How do I set up the onChange function? Currently, the editor isn't behaving like a contentEditable div. It's not editable?
etc

Is anyone able to point me to additional documentation, or an example that isn't as long as demo.js (38,000 lines @_@....)

Thanks for any assistance you folks can offer!

Feature request: value prop as string

It would be nice if value prop is just a string and format is provided via props. This would make it easier to combine react-rte with libraries like redux-form.

<RichTextEditor
    value={'<p>some text</p>'}
    format={'html'}
    onChange={() => { // do something }}
 />

Making a Rich Text Editor flex-ible/full screen

I am attempting to make make use of flexbox in order to build a full screen-ish modal that allows the editing experience to happen in a popup, but also allows the RTE instance to fill a flex column. Unfortunately, I am not finding a good way to, through the modular css, be able to inject the necessary css in order to achieve the result I am looking for.

(Currently, it appears .public-DraftEditor-content is hardcoded to 110px. But aside from that, it appears I need to modify styles__richTextEditor___2Dl6A RichTextEditor__root___2QXK- which I can't see a way to do.)

Prototype of what I am trying to achieve: https://jsfiddle.net/av0v2540/

Since there is a build process at place that puts a _[hash] in css names, I can't depend on overriding the css inline as it will change from release to release. What I need to make it achieve the above is the ability to use display: flex along with various flex: 1, flex: 2, and flex-direction: column directives. Any insight how I can achieve this with react-rte is appreciated.

Thanks in advance.

Strange NPM errors with Meteor

Hi, I am using Meteor 1.3 with React. I installed react-rte and everything works wonderfully. Great job with this RTE!

However, I am having this annoying error being logged to my server's console:

Unable to resolve some modules:

"!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./Button.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js(web.browser)

"!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./ButtonWrap.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

"!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./IconButton.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

"!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./ButtonGroup.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

"!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./InputPopover.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

"!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./Dropdown.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

"!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./EditorToolbar.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

"!!./../node_modules/raw-loader/index.js!./Draft.global.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

"!!./../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./RichTextEditor.css" in ~/MeteorProject/node_modules/react-rte/dist/react-rte.js (web.browser)

If you notice problems related to these missing modules, consider running:

  meteor npm install --save !!.

I tried npm install css-loader both locally and globally to no avail.

I repeat, It works, but I would love to make this error go away. Any ideas?

Editing a link URL

Is there a way to edit the URL in a link? I think I would expect that when:

  1. I position the cursor within an existing link text in the editor (or select an existing link text).
  2. I click the link button in the toolbar.

Then

  1. The textbox in the link widget would be populated with the existing link.
  2. Editing the contents of the link textbox and clicking the submit button would update the link text.

Move Importer/Exporter into own installable module

Howdy!

I'm reading your repo since I'm running into the storage conundrum where I have services that need to consume what draft has produced. Originally I thought about just storing the JSON object representation of it and then pulling that back out but some of these services don't want to have a conversion step for working with the data.

Consequently, I've been looking at deserializing/serializing it and started writing a basic importer exporter. Which is when I stumbled upon how yours is working. Honestly, I'd just use this component but we need to be able to make ours a little more flexible and support lots of different entities for mentions, tagging, etc.

I really like how your stateFromHTML/element works. I was thinking this almost makes sense to pull outside of rte since it's not rte specific and it could be expanded to support plenty of other types by the community. For instance, xml. Some of your TODOs already mention moving pieces into their own modules, but I'm assuming that's referring to modules inside this repo.

Any thoughts on making a separate dependency for that? I'd be happy to volunteer time to working on it as your approach is the best I've seen in looking around the last couple of days. Someone else had started a repo called DraftExporter but yours is far more robust.

Thanks for your time!

Support Text Align at Block Level

Have you figured out how to do text align? I've been struggling to implement that. Your repo is the most complete example I've found. Curious how you're solving left right center and justify.

document API with expected properties, usage, etc.

Something like:

From my limited knowledge, I could get this started with:

RichTextEditor

Main editor component, with draft-js <Editor> and custom toolbar.

Properties

  • value: used to populate the initial content of the editor; if no previous value is available, should be populated with RichTextEditor.createEmptyValue()
  • onChange: function that will be passed the value of the editor whenever it is changed. The value object passed to this function has a toString method which accepts a string of either 'html' or 'markdown'

Example usage:

import RichTextEditor from 'react-rte';

class MyCustomEditor extends Component {

  static propTypes = {
    onChange: PropTypes.func.isRequired
  };

  state = {
    value: RichTextEditor.createEmptyValue()
  }

  handleChange = value => {
    this.setState({ value });
    // send the changes up to the parent component as an HTML string
    this.props.onChange(value.toString('html'));
  };

  render () {
    return (
      <RichTextEditor
        value={this.state.value}
        onChange={this.handleChange}
      />
    );
  }
}

Installing into project using react_webpack_rails fails

The were a bunch of dependencies that could not be met. I did an npm update and got the same result.

$ npm install --save react-rte
npm ERR! Darwin 15.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "--save" "react-rte"
npm ERR! node v0.10.36
npm ERR! npm  v2.3.0
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package react does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.0 || ^15.0.0-rc
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.8
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.8
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.0
npm ERR! peerinvalid Peer [email protected] wants react@^15.0.1

Server Side Rendering Problem

I use server-side-rendering with react and webpack based on react-webpack-node.
Does react-rte use jquery? Or, is it draft-js that use jquery?
I don't use jquery in my project but after I installed react-rte,
console shows me an error message that

var $ = window.jQuery || window.Zepto;
              ^
TypeError: cannot find property 'jQuery' of undefined

So, I think this is because nodejs server doesn't know window object...
Is there possible solution for this??

Peer Dependencies not satisfied

Seems like the upgrade to 0.6.0 draft-js broke the package, since the export/import-ers uses 0.5.0 as the draft-js peer dependency.

Unable to load soft newlines with createValueFromString

I'm having trouble figuring out how to load a soft newline. When I type in the editor:

Hi
there

It spits out the html <p>Hi<br/>\nthere</p>. In my case, I'm exporting this html and saving it in a database. When they come back to the editor, I call createValueFromString to repopulate the text but the newline is gone... we get <p>Hi<br/> there</p>, instead. The newline is now a space.

I tracked this down to the collapseWhitespace function in draft-js-import-element. I assume there's a good reason to strip out the whitespace so I'm not sure the best way to go about fixing this is.

You can easily repro the issue by appending this block to EditorDemo.js:

<div className="row">
  <RichTextEditor
     value={RichTextEditor.createValueFromString(value.toString(format), format)}
     placeholder="Tell a story"
   />
</div>

Then fire up the demo page, and type some text with a soft newline (Shift-Enter) in the top editor.

CSS Reset

We should include a targeted set of CSS reset styles to avoid cascading effects from other stylesheets on the page that do things like p { line-height: 50px }

Webpack style- and css- loaders in dist build

Thanks for the great work! ^______^

I get errors (v0.1.13) when I try to import react-rte using browserify:

events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./Button.css' 
from '/../my-project-path/node_modules/react-rte/dist'

Is there a way to exclude webpack loaders in dist build? (I even found module.hot mentions in dist.js source code).

I downgraded to v.0.1.10 and errors are gone (however Editor has no styles at all). I suppose something went wrong with #10

Edit Link

When the cursor is in a link entity, clicking the link button should pre-fill with the current href value.

Cannot run locally: 404 page for /demo

After trying node versions 5.10, 4.2, 0.12, I cannot run react-rte locally.

steps to reproduce

npm i
npm run build-demo <- outdated (does not work) and i saw that all the builds were happening anyways
npm i -g serv
serv

I hacked my way to a solution by modifying the webpack config and creating a server.js file like in https://github.com/gaearon/react-hot-boilerplate.

Is there something simple I'm missing? Thanks for the awesome work though!

is height of EDITOR not enough?

.editor :global(.public-DraftEditor-content) {
  height: 110px;
  overflow: auto;
}

as it is the height which is set to 110px, but not min-height, is it too low or not grow-able?
any suggested way to modify this outside your module?
sorry if with bad English grammer.

Currently unusable with browserify

It seems that react-rte is 100% reliant on webpack to work, which is a bit unfortunate since a fair number of people use other solutions for bundling.

Here's the stack trace if you try to use it with browserify/babelify

Error2: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./IconButton.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Finished building JS. buildJS: 496.802ms Error2: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./ButtonWrap.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Error2: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./Button.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Error2: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./InputPopover.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Error2: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./ButtonGroup.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Error2: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./Dropdown.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Error2: Cannot find module '!!./../../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./EditorToolbar.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Error2: Cannot find module '!!./../node_modules/raw-loader/index.js!./Draft.global.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist' Error2: Cannot find module '!!./../node_modules/css-loader/index.js?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!./RichTextEditor.css' from '/home/cvoege/mimirhq/lms/node_modules/react-rte/dist'

Isomorphic Support

Thanks for writing this.

In an isomorphic app, this library fails when rendering on server with


                var $ = window.jQuery || window.Zepto;
                              ^
                TypeError: Cannot read property 'jQuery' of undefined

Modifying Element(s) before `toString()`

Is there a way that I can add target="blank" to all tags before calling toString('html')? It would be cool if there was an easy way to modify tags being outputted.

Support for onBlur

I was wondering if React-RTE supported onBlur?

passing in my onBlur function as a prop doesn't seem to work, and I was hoping to run a save function onBlur. Any ideas?

Thanks!

Editor not editable

Hi there,

I'm trying to bring onboard react-rte, but I'm having difficulties. I see the editor perfectly rendered on my screen, but the textbox is not recognizing my inputs. My onChange function is getting triggered, though. Would anyone be able to point out what I did wrong?

My changes are:

  1. My component's getInitialState returns:
    format: "markdown", value: Editor.createEmptyValue()
  2. An onChange function:
    _onChange: function(value) { this.setState({value: value}); }
  3. Rendering it:
    <Editor value={this.state.value} onChange={this._onChange} placeholder="My name is Rain" />

The onChange function is triggering, so it's detecting my text input, but it doesn't display any of my text input. I get the feeling the problem is in my onChange function, but I could use some guidance in how to fix it.

Note - I am not using flow. I see that the demo is, and is importing an EditorValue type, that is used in the demo's onChange function. I'm hoping that isn't necessary.

Thanks!

Dependencies require older version of draft-js

react-rte needs draft-js 0.7.0. But...

npm WARN [email protected] requires a peer of draft-js@^0.5.0 but none was installed.
npm WARN [email protected] requires a peer of draft-js@^0.5.0 but none was installed.
npm WARN [email protected] requires a peer of draft-js@^0.5.0 but none was installed.
npm WARN [email protected] requires a peer of draft-js@^0.5.0 but none was installed.
npm WARN [email protected] requires a peer of draft-js@^0.5.0 but none was installed.
npm WARN [email protected] requires a peer of draft-js@^0.5.0 but none was installed.

Great component, BTW. Thanks!

Using react-rte with formsy.

How to use this component with formsy-react? Here is how I tried it.

...
class FormsyRichTextEditor extends React.Component {

  state = {
    value: RichTextEditor.createEmptyValue()
  };

  static propTypes = {
     ...
  }

  __handleChange__ = (value) => {
    this.setState({ value });
    this.props.setValue(value.toString('markdown'));
  }

  render() {
    let className = ' ';
    className += this.props.showRequired() ? 'required' : '';
    className += this.props.showError() ? 'error' : '';

    let errorMessage = this.props.getErrorMessage();

    return (
      <div className={'text-left form-group' + className }>
        <label htmlFor={this.props.id}>{this.props.title}</label>
        <RichTextEditor
          id={this.props.id}
          name={this.props.name}
          value={this.state.value}
          onChange={this.__handleChange__} />
        <span className='error-message'>{errorMessage}</span>
      </div>
    );
  }
}

export default HOC(FormsyRichTextEditor);

I get the following issue

Warning: A component is `contentEditable` and contains `children` managed by React. It is now your responsibility to guarantee that none of those nodes are unexpectedly modified or duplicated. This is probably not intentional.

Some digging into the issue shows people creating rte are facing this issue and there is a way to suppress this warning. Is there any way to suppress it with react-rte?
Really unsure as to what this warning means and why it is there?

Localization support

Is localization suppport possible? I was thinking about passing an array of label strings for the tooltips and Header dropdown:

Example for German:

const labels: {
  bold: 'Fett',
  italic: 'Kursiv',
  strikethrough: 'Durchgestrichen',
  monospace: 'Monospace',
  ul: 'Liste',
  ol: 'Aufzählung',
  bockquote: 'Zitat',
  link: 'Link',
  removeLink: 'Link entfernen',
  normal: 'Normal',
  headingLarge: 'Überschrift groß',
  headingMedium: 'Überschrift mittel',
  headingSmall: 'Überschrift klein',
  codeBlock: 'Code Block',
  undo: 'Rückgängig',
  redo: 'Wiederherstellen'
};

return <RichTextEditor labels={labels} {...props} />;

Support Images

I'm curious about including markdown image syntax ![](), noticed the demo doesn't have it yet.

Awesome project. I knew someone would do the commonmark/markdown <---> draftjs soon, very glad you made this so seamless. 💃

Pressing enter*2 while in a list should end it

On every wysiwyg I know, if you have a bulleted list and do enter (add an empty bullet) and enter again it will remove the empty bullet and break out of the list.

In react-rte, it keeps adding more bullets.

Code and quoted markdown is lost

All code and quoted blocks are lost when importing markdown. As an example, in the demo at https://react-rte.org/demo:

  • Set the mode radio button to Markdown
  • Type some text and mark it as a quote or code in the RTE top editor. MD in bottom textarea looks OK.
  • Type anything in the MD textarea, which updates the RTE editor, and all quotes and code blocks are lost (quotes become unstyled text, code block content just plain disappears altogether)

Use CSS Modules

This will avoid naming collisions and unintentional cascading effects and a bunch of related problems.

Feature request: add disabled alias

The standard way to disable a form element is by using the disabled property. I think you have readOnly .. Consider using <RichTextEditor disabled={loading} /> to make this consistent.

emoji support

Would be great to see this lib have emoji support - any suggestions as to how this might be implemented?

readOnly support

If you set readOnly={true} the text input is disabled, toolbar controls are only styled disabled but still clickable. Best would be to hide toolbar completely if readOnly is set, what do you think?

Links are not clickable

I noticed in the demo that while creating a link in the editor produces an href, complete with the default stylings, it isn't clickable.

I was wondering if this was intentional or a bug?

distribution build

So I started working on this and managed to get it loaded into my app, but I keep getting the duplicate versions of React error:
mui/material-ui#2818
https://gist.github.com/jimfb/4faa6cbfb1ef476bd105

I'm importing it using babel + webpack, so I think it has to do with the way webpack loads dependencies, but I'm not sure. Ideally, it would be great if react-rte had a distribution build available after npm install react-rte that includes draft-js, immutable.js, but not react/react-dom.

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.