UNPKG

772 BJavaScriptView Raw
1'use strict';
2
3var getCurrentItem = require('./getCurrentItem');
4
5/**
6 * Return the previous item, from current selection or from a node.
7 *
8 * @param {PluginOptions} opts
9 * @param {Slate.Value} value
10 * @param {Slate.Block} block?
11 * @return {Slate.Block || Void}
12 */
13function getPreviousItem(opts, value, block) {
14 var document = value.document,
15 startBlock = value.startBlock;
16
17 block = block || startBlock;
18
19 var currentItem = getCurrentItem(opts, value, block);
20
21 var previousSibling = document.getPreviousSibling(currentItem.key);
22
23 if (!previousSibling) {
24 return null;
25 } else if (previousSibling.type === opts.typeItem) {
26 return previousSibling;
27 } else {
28 return null;
29 }
30}
31
32module.exports = getPreviousItem;
\No newline at end of file