guardian / scribe

DEPRECATED: A rich text editor framework for the web platform
http://guardian.github.io/scribe/
Apache License 2.0
3.51k stars 245 forks source link

Paste: Unify clipboard types data types #405

Closed rrees closed 9 years ago

rrees commented 9 years ago

Combines @alexygolev 's advice with my own desire to hit everything with the Immutable hammer.

Should finally solve #401

An illustration of the unification: https://jsfiddle.net/heopbyo3/3/

regiskuckaertz commented 9 years ago

:+1:

regiskuckaertz commented 9 years ago

One never gets back from Immutableland :-)

alexeygolev commented 9 years ago

@rrees Maybe a bit too late, but I checked the implementation of the Immutable.List constructor and figured that you can actually just use var types = Immutable.List(event.clipboardData.types); It's possible because to create a List it goes through a sequence of checks, one of which is isArrayLike. In all the browsers our type thingy is an array like as far as Immutable concerned (it has a length method on its prototype) so Immutable calls the ArraySeq constructor as a result. That doesn't solve our problem on it's own because we just basically packed our array-like into a ArraySeq container. However, the only method we need is .includes which doesn't care about the kind of iterable you feed it as long as it can iterate over it using a for loop. I didn't think about it because I completely forgot that we already have a dependency on Immutable.

rrees commented 9 years ago

@alexeygolev Thanks for looking for this. I tried this but it failed for me on Firefox because the DOMStringList couldn't be tickled into the a Seq. If you're certain it works I would much prefer to use this as the solution.

alexeygolev commented 9 years ago

@rrees weird... it shouldn't even depend on the FF version. Does this work for you in FF? https://jsfiddle.net/heopbyo3/4/

rrees commented 9 years ago

That does appear to work, how odd that I thought it didn't. I'll try and release this (nicer) version soon.

rrees commented 9 years ago

@alexeygolev unless you want to put in a PR?

alexeygolev commented 9 years ago

@rrees will do it now