1 | 'use strict';
|
2 |
|
3 | var _require = require('immutable'),
|
4 | List = _require.List;
|
5 |
|
6 | var isList = require('./isList');
|
7 | var getCurrentItem = require('./getCurrentItem');
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function getItemsAtRange(opts, value, range) {
|
19 | range = range || value.selection;
|
20 |
|
21 | if (!range.startKey) {
|
22 | return List();
|
23 | }
|
24 |
|
25 | var document = value.document;
|
26 |
|
27 |
|
28 | var startBlock = document.getClosestBlock(range.startKey);
|
29 | var endBlock = document.getClosestBlock(range.endKey);
|
30 |
|
31 | if (startBlock === endBlock) {
|
32 | var item = getCurrentItem(opts, value, startBlock);
|
33 | return item ? List([item]) : List();
|
34 | }
|
35 |
|
36 | var ancestor = document.getCommonAncestor(startBlock.key, endBlock.key);
|
37 |
|
38 | if (isList(opts, ancestor)) {
|
39 | var startPath = ancestor.getPath(startBlock.key);
|
40 | var endPath = ancestor.getPath(endBlock.key);
|
41 |
|
42 | return ancestor.nodes.slice(startPath[0], endPath[0] + 1);
|
43 | } else if (ancestor.type === opts.typeItem) {
|
44 |
|
45 | return List([ancestor]);
|
46 | } else {
|
47 |
|
48 | return List();
|
49 | }
|
50 | }
|
51 |
|
52 | module.exports = getItemsAtRange; |
\ | No newline at end of file |