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 {
|
export default class Selection {
|
||||||
|
|
||||||
constructor(selectors) {
|
constructor(target) {
|
||||||
this._stub = {
|
this._stub = {
|
||||||
type: 'Selection',
|
type: 'Selection',
|
||||||
body: [],
|
body: [],
|
||||||
target: {
|
target
|
||||||
selector: selectors
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a copy of this selection **/
|
/** Creates a copy of this selection **/
|
||||||
clone = opt_props => {
|
clone = opt_props => {
|
||||||
// Clone selector(s)
|
// Deep-clone target
|
||||||
const { selector } = this._stub.target;
|
const clonedTarget = JSON.parse(JSON.stringify(this._stub.target));
|
||||||
|
const cloned = new Selection(clonedTarget);
|
||||||
const clonedSelector = Array.isArray(selector) ?
|
|
||||||
selector.map(s => ({ ...s })) : { ...selector };
|
|
||||||
|
|
||||||
const cloned = new Selection(clonedSelector);
|
|
||||||
|
|
||||||
if (opt_props)
|
if (opt_props)
|
||||||
cloned._stub = { ...cloned._stub, ...opt_props };
|
cloned._stub = { ...cloned._stub, ...opt_props };
|
||||||
|
|
|
@ -37,14 +37,16 @@ export const rangeToSelection = (range, containerEl) => {
|
||||||
const quote = range.toString();
|
const quote = range.toString();
|
||||||
const start = rangeBefore.toString().length;
|
const start = rangeBefore.toString().length;
|
||||||
|
|
||||||
return new Selection([{
|
return new Selection({
|
||||||
type: 'TextQuoteSelector',
|
selector: [{
|
||||||
exact: quote
|
type: 'TextQuoteSelector',
|
||||||
}, {
|
exact: quote
|
||||||
type: 'TextPositionSelector',
|
}, {
|
||||||
start: start,
|
type: 'TextPositionSelector',
|
||||||
end: start + quote.length
|
start: start,
|
||||||
}]);
|
end: start + quote.length
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue