UNPKG

632 BJavaScriptView Raw
1'use strict';
2
3var getCurrentItem = require('./getCurrentItem');
4
5/**
6 * Get depth of current block in a document list
7 *
8 * @param {PluginOptions} opts
9 * @param {Slate.Value} value
10 * @param {Slate.Block} block?
11 * @return {Number}
12 */
13function getItemDepth(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 if (!currentItem) {
21 return 0;
22 }
23
24 var list = document.getParent(currentItem.key);
25
26 return 1 + getItemDepth(opts, value, list);
27}
28
29module.exports = getItemDepth;
\No newline at end of file