News for hackers. Stuff that matters.
Re:Draft.js – Rich Text Editor Framework for React by leeoniya on Monday February 22, 2016 @03:05PM (#11153840)
Is there a specific benefit to having this built on top of React rather than just wrapping an existing editor's API [1][2][3]? Is it cross-usability for React-native or just NIH syndrome?

I'm not sure how I feel about re-implementing all the things and introducing a React dependency to everything. The lock-in seems okay if React really is the final word in UI frameworks (though it is very large and currently very slow). I am certainly not in this camp, however.

[1] https://github.com/neilj/Squire

[2] https://github.com/quilljs/quill

[3] https://github.com/zenoamaro/react-quill

Re:Draft.js – Rich Text Editor Framework for React by spicyj on Monday February 22, 2016 @03:17PM (#11153935)
(Biased React dev here.)

The key insight in Draft.js is that it's incredibly difficult to keep your model in sync with the browser's contenteditable behavior unless you intercept many of the behaviors and perform them entirely in the model, then change the DOM accordingly. Medium found the same thing when building their editor:

https://medium.com/medium-eng/why-contenteditable-is-terribl...

In order to build high-quality text editors, you need to be in control of what's happening in the DOM. There's obviously many ways to control the DOM. React is a solid base for this, as are many other libraries. Facebook uses React extensively so it made sense to use as a base for Draft to avoid needing to essentially rewrite React and to make it even easier to integrate with existing React apps. Of course, you can also use Draft easily inside a non-React app.

The entire Draft model is also separate code decoupled from the UI and you're free to use the model and implement the views yourself if you're allergic to React or aren't targeting the DOM. The Facebook Groups app uses Draft's model but implements custom views for it in React Native.

Re:Draft.js – Rich Text Editor Framework for React by jhchen on Monday February 22, 2016 @04:07PM (#11154297)
(Biased Quill author here)

Most modern rich text editors have or are moving towards having a document model that maps to the DOM, ideally also producing compact and canonical output. Quill's new document model Parchment takes this approach as well though I admit I borrowed the idea from the Etherpad guys, and some design ideas from React as well [1]. I have not had the time to dig into Draft.js in depth but Facebook has made many high quality contributions to open source and looking forward to borrowing more ideas.

[1] http://quilljs.com/blog/the-road-to-1-0/

Re:Draft.js – Rich Text Editor Framework for React by almost on Monday February 22, 2016 @03:23PM (#11153981)
Any chance that react native view code will be released at any point? Would be so useful!
Re:Draft.js – Rich Text Editor Framework for React by spicyj on Monday February 22, 2016 @03:25PM (#11153996)
Good idea. It's based off of an older version of the Draft code so it might not work out of the box. If we don't get a chance, hopefully it won't be hard for people to build out a solid implementation on RN.
Re:Draft.js – Rich Text Editor Framework for React by stemuk on Monday February 22, 2016 @03:41PM (#11154120)
I am extesively using the polymer webcomponents framework, do I need to install react in the background or can I use draft.js independently?
Re:Draft.js – Rich Text Editor Framework for React by yrezgui on Wednesday February 24, 2016 @02:19PM (#11169394)
You'll have to use ReactJS as it's needed to have the control over the DOM.
Re:Draft.js – Rich Text Editor Framework for React by underwater on Monday February 22, 2016 @03:18PM (#11153945)
In most rich text editors the DOM is the source of truth and the editor reads and attempts to sanitize HTML when you're done.

Draft.JS is a controlled input. The view is completely derived from the model. This eliminates whole classes of browser and editor bugs.

It's also makes the editor really easy to extend. You can add new object types and complex styling without having to worry about all the nuances of text editing.

For example you could highlight hashtags by giving the editor a regex to match and then tell it which styles your hashtag should be decorated with. Draft.js handles creating and removing tags as you type, drag and drop, copy, paste, etc.

Re:Draft.js – Rich Text Editor Framework for React by ridiculous_fish on Monday February 22, 2016 @03:31PM (#11154037)
Unfortunately this approach also introduces new classes of bugs, when the browser's editing facilities collide with those provided by the component. For example, on OS X, type any letter and then choose Edit->Undo; nothing will happen. This sort of thing is generally impossible to fix since there's no undo event in HTML.
Re:Draft.js – Rich Text Editor Framework for React by danabramov on Monday February 22, 2016 @03:33PM (#11154061)
I just tried that in http://facebook.github.io/draft-js/, and Edit -> Undo worked for me.
Re:Draft.js – Rich Text Editor Framework for React by ridiculous_fish on Monday February 22, 2016 @03:47PM (#11154176)
Hmm, what were your steps where it worked?

Undo and other text editing facilities aren't completely nonfunctional, they just become broken and unpredictable. For example, these steps:

1. Load http://facebook.github.io/draft-js/ 2. Click in the text box 3. Type 'hello' on the keyboard 4. Using the mouse, choose Edit -> Undo

The text box will show "h" instead of being empty. Do you see this too?

Note that cmd-Z won't reproduce this since the page tries to handle that itself to work around these bugs.

Re:Draft.js – Rich Text Editor Framework for React by danabramov on Monday February 22, 2016 @04:13PM (#11154343)
Good catch. Maybe worth filing an issue?
Re:Draft.js – Rich Text Editor Framework for React by the_mitsuhiko on Monday February 22, 2016 @07:20PM (#11155455)
Against what? Html5? ;)
Re:Draft.js – Rich Text Editor Framework for React by Reinmar on Tuesday February 23, 2016 @07:37AM (#11158443)
Well... yes :D [1] (AFAIR this case is covered by [2]).

The Editing Task Force is working on opening necessary APIs so editor implementors could integrate with all the native features. I wrote an article about the effort [3]. It's a bit outdated now, but explains what are the goals.

[1] https://github.com/w3c/editing/issues

[2] https://github.com/w3c/editing/issues/79

[3] https://medium.com/content-uneditable/fixing-contenteditable...

Re:Draft.js – Rich Text Editor Framework for React by eloisant on Monday February 22, 2016 @04:43PM (#11154516)
It surely does, because it's a crucial feature for a text editor, but the developers had to implement and undo/redo stack in their lib.

Anyway this approach is the only good one if you don't want to produce crappy HTML that will end up on your site. TinyMCE and the rest are obsolete, and editors like DraftJS or mobiledoc-kit are the only viable solutions until browsers offer a new, not broken alternative to content-editable.

Re:Draft.js – Rich Text Editor Framework for React by underwater on Monday February 22, 2016 @04:30PM (#11154450)
Yes, you're right. No solution is perfect.

I was involved in a project that used contentEditable DOM as the source of truth before I had a chance to work with Draft, and I believe that Draft's model is the best compromise.

Draft does a lot to handle the edge cases where it's possible. IME and spellcheck are two of the big ones.

Re:Draft.js – Rich Text Editor Framework for React by gabriele on Monday February 22, 2016 @03:26PM (#11154004)
maybe this is a hint that they're going to introduce rich text for posting soon

(disclaimer: I've been out of Facebook for a while so they may have introduced that feature already)

Re:Draft.js – Rich Text Editor Framework for React by calvin on Monday February 22, 2016 @03:29PM (#11154018)
In the livestream video, they show using draft.js features for @-mentions in normal posts, and for rich text features in their Notes feature.
Re:Draft.js – Rich Text Editor Framework for React by juretriglav on Monday February 22, 2016 @04:40PM (#11154495)
Substance (http://substance.io/) also wraps their editor in a React Component (https://github.com/substance/lens/blob/master/ReactLensWrite...) and it works great. (I'm a very minor contributor.)
Re:Draft.js – Rich Text Editor Framework for React by jonknee on Monday February 22, 2016 @03:09PM (#11153878)
On the other hand it's perfect if you have a React project and need rich text editing.
Re:Draft.js – Rich Text Editor Framework for React by leeoniya on Monday February 22, 2016 @03:12PM (#11153894)
Is it more perfect than e.g. https://github.com/zenoamaro/react-quill ?

My point is, if you can have a truly reusable component with an API that can be integrated into anywhere (including a React wrapper), what do you gain by making a component that can only live in React and have no other re-usability to speak of?

There are many drawbacks, but React-native is the only benefit as far as I can see, which requires a firm React commitment.

Re:Draft.js – Rich Text Editor Framework for React by terda12 on Monday February 22, 2016 @03:19PM (#11153950)
Yes, it's much simpler to have a natively React text editor, that way you can plug in the state of the <Draft> component into your other React components. See http://facebook.github.io/draft-js/docs/overview.html#conten..., everything is nice and neat.

I'm not sure about 3rd party js text editors, but I'm guessing it could be a pain to work with state and props in that context.