coderly / teamplaybook-ember

0 stars 0 forks source link

Editor feature #24

Open begedin opened 9 years ago

begedin commented 9 years ago

Moving this here from the gist, so we can have it more easily accessible

Options

Ember.js Wysiwyg Component with Summernote

begedin commented 9 years ago

List of editors from SO

http://stackoverflow.com/questions/6756407/what-contenteditable-editors-are-there

joshsmith commented 9 years ago

Very solid research on this @begedin.

I lean very heavily in the direction of a Medium-like front-end. Not full WYSIWYG, but something drastically simplified. I'm pretty sour on Markdown because it's kind of painful to write, and even more painful to read and edit. It's okay for small amounts of documentation like a README, but anything larger and longer than that, or that has to be edited often, and it becomes arduous for me.

I'd be very interested in the document/editing structure and architecture that Medium uses. The front-end work around the editor seems hard but achievable, but the document structure itself is a black box to me.

joshsmith commented 9 years ago

After much searching, I found it: https://medium.com/medium-eng/why-contenteditable-is-terrible-122d8a40e480

joshsmith commented 9 years ago

@idelahoz and I have had a long conversation in Slack about this. Did some deep reverse engineering and really like their approach.

begedin commented 9 years ago

I took a look at some editors that support "inline" editing. I didn't completely understand from the discussion if we want to try to implement something of our own, or repurpose something existing, but here's what I found:

Aloha Editor 2 (in alpha)

Etch

CKEditor

FreshEditor

Hallo

Mercury

TinyMCE

MediumJS

Redactor

Thoughts

Out of these above, I'm leaning strongest towards Aloha based on UI alone, though it doesn't have all the features we'd want yet. For instance, image drag and drop doesn't work yet. Outside of that, i'd probably go with Redactor or Mercury, followed by MediumJS, in order of preference.

begedin commented 9 years ago

Copied from https://gist.github.com/begedin/8aaecc4fe5681b1ea5af

Options for image uploading with medium-editor

What's supported and what isn't.

At the moment, medium-editor allows dropping an image into the editor area in order to add it to the document. However, this works via base64 image embedding, which isn't optimal and I'm guessing we don't wont.

This feature also does not work when pasting image files (file path is pasted instead), or image clipboard data (nothing happens).

What can we do

For UI-based image uploads

medium-editor does support extensions.

You can define a simple button extension which modifies the selection automatically, or a form extension, which first shows a form and then does something based on our interaction with the form.

What we could do is define our own form extension. The extension allows us to browse for an image and upload it. Upon upload, it replaces the selection with an image tag containing an url to the image. The obvious problem here is that the medium-editor toolbar is selection-based, meaning we still need to select a piece of text to insert the image, which is a bit unintuitive. Even the default image button already present in the editor, works by simply wrapping a selection into an image tag, meaning it also needs a selection to work with.

There are probably ways around it, but nothing satisfyingly straightforward enough.

For dropping from the file system into the editor

We need to somehow override the default behavior of embedding the image as base64. Since image-dragging is already an extension, we should be able to write our own, so I'm not expecting this to be too hard. We could reuse the uploading logic we implement in the image upload button.

For pasting from the file system

I don't think this is possible due to browser security limitations. At least, I wasn't able to find a method of doing it.

GitHub doesn't support this either, nor do a bunch of other services I tried out.

For pasting image data from clipboard

We can again implement our own paste plugin which overrides the default paste extension provided by medium-editor.

Once we do that, we will have access to the editedPaste event, where we can do the following:

It may even be possible to insert some placeholder text while the upload is being performed, similar to how github does it.

Future-proofing

medium-editor does this thing where it maps some default dom events onto custom events specific to this library. For instance, paste gets wrapped into editablePaste, etc.

This means all of our extension stuff will be bound to this specific library instead of working in a more general manner.

I could look into hooking into these events directly and handle image stuff through the component instead of through the medium-editor library and then just make lightweight extension wrappers for the editor itself, which encapsulats this general behavior. That way, when we make the switch to something else, which we likely will eventually, it's easier to keep the behavior.

I'm not sure how viable that is, though. It might proove too difficult.