API change: selections now take target as arg, not selectors
This commit is contained in:
parent
9f11f88fa6
commit
1508ed1207
|
@ -8,25 +8,19 @@ import uuid from 'uuid/v1';
|
|||
*/
|
||||
export default class Selection {
|
||||
|
||||
constructor(selectors) {
|
||||
constructor(target) {
|
||||
this._stub = {
|
||||
type: 'Selection',
|
||||
body: [],
|
||||
target: {
|
||||
selector: selectors
|
||||
}
|
||||
target
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a copy of this selection **/
|
||||
clone = opt_props => {
|
||||
// Clone selector(s)
|
||||
const { selector } = this._stub.target;
|
||||
|
||||
const clonedSelector = Array.isArray(selector) ?
|
||||
selector.map(s => ({ ...s })) : { ...selector };
|
||||
|
||||
const cloned = new Selection(clonedSelector);
|
||||
// Deep-clone target
|
||||
const clonedTarget = JSON.parse(JSON.stringify(this._stub.target));
|
||||
const cloned = new Selection(clonedTarget);
|
||||
|
||||
if (opt_props)
|
||||
cloned._stub = { ...cloned._stub, ...opt_props };
|
||||
|
|
|
@ -37,14 +37,16 @@ export const rangeToSelection = (range, containerEl) => {
|
|||
const quote = range.toString();
|
||||
const start = rangeBefore.toString().length;
|
||||
|
||||
return new Selection([{
|
||||
type: 'TextQuoteSelector',
|
||||
exact: quote
|
||||
}, {
|
||||
type: 'TextPositionSelector',
|
||||
start: start,
|
||||
end: start + quote.length
|
||||
}]);
|
||||
return new Selection({
|
||||
selector: [{
|
||||
type: 'TextQuoteSelector',
|
||||
exact: quote
|
||||
}, {
|
||||
type: 'TextPositionSelector',
|
||||
start: start,
|
||||
end: start + quote.length
|
||||
}]
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue