@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
32 lines • 1.17 kB
JavaScript
import { isListItemNode, isListNode } from '../utils';
import { getListItemAttributes } from './selection';
export var getCommonListAnalyticsAttributes = function getCommonListAnalyticsAttributes(tr) {
var _tr$selection = tr.selection,
$from = _tr$selection.$from,
$to = _tr$selection.$to;
var fromAttrs = getListItemAttributes($from);
var toAttrs = getListItemAttributes($to);
return {
itemIndexAtSelectionStart: fromAttrs.itemIndex,
itemIndexAtSelectionEnd: toAttrs.itemIndex,
indentLevelAtSelectionStart: fromAttrs.indentLevel,
indentLevelAtSelectionEnd: toAttrs.indentLevel,
itemsInSelection: countListItemsInSelection(tr)
};
};
export var countListItemsInSelection = function countListItemsInSelection(tr) {
var _tr$selection2 = tr.selection,
from = _tr$selection2.from,
to = _tr$selection2.to;
if (from === to) {
return 1;
}
var count = 0;
var listSlice = tr.doc.cut(from, to);
listSlice.content.nodesBetween(0, listSlice.content.size, function (node, pos, parent, index) {
if (parent && isListItemNode(parent) && !isListNode(node) && index === 0) {
count++;
}
});
return count;
};