openannotation/annotator — pull request #374 by csillag (2014-05-05 15:41:17+00:00)
Title: Split the adder plugin to 3 parts

1.

Generalizing adder button: data format

When we detect a selection, we store some data, which is later
used when the adder button is clicked.

Before this change, we stored the list of ranges, and then when the
adder button was clicked, we created an annotation out of it.

To make this more generic, I moved the code responsible for creating
the annotation from the list of ranges from the adder button click
to the earlier phase (after detecting a selection).

So now the skeleton for the annotation is created right away, when
a selection is detected, and when the adder button is clicked,
we simply use this skeleton to create the real animation.

(This way, we can decouple the analysis of the selection from the adder
button.)

2.

Decomposing the Adder plugin: TextSelector + LegacyRange + Adder

This Separating text selection, and the adder button

This change cuts the Adder plugin into three parts:

* The `TextSelector` plugin is responsible for detecting the
selection of text (using the mouse), and filtering out various
unwanted elements.
* The `LegacyRanges` plugin contains the legacy implementation
to describe these ranges with (serializable) XPath ranges.
* The core adder button functionality remains in the `Adder` plugin.

The goal is to make it possible to introduce alternate methods
for describing the target of the annotation (for example, using
targets and selectors, as done in the Hypothes.is fork), and also
to use the adder button with different kinds of selections.

Communication between the plugins:

* The `TextSelector` plugin emits a `rawSelection` event, which
carries the list of raw `NormalizedRange` objects.
* The `LegacyRanges` plugin reacts to this event by describing
the ranges with XPath ranges, serializing them, creating the
annotation skeleton from them, and emitting the `selection` event,
which carries this skeleton.
* The `Adder` plugin reacts to this event by displaying
the adder button.

Since all three plugins are core plugins, they are all automatically
installed by default, so end users don't need to care about this change.

* * *

This PR supersedes https://github.com/openannotation/annotator/pull/369 and https://github.com/hypothesis/annotator/pull/62.

I believe I have addressed all the comments. (This is now against the master branch, there is full test coverage, and I have removed the spurious `failedSelection` event; now there is only selection.