UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

38 lines (37 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCommonListAnalyticsAttributes = exports.countListItemsInSelection = void 0; var _utils = require("../utils"); var _selection = require("./selection"); var getCommonListAnalyticsAttributes = exports.getCommonListAnalyticsAttributes = function getCommonListAnalyticsAttributes(tr) { var _tr$selection = tr.selection, $from = _tr$selection.$from, $to = _tr$selection.$to; var fromAttrs = (0, _selection.getListItemAttributes)($from); var toAttrs = (0, _selection.getListItemAttributes)($to); return { itemIndexAtSelectionStart: fromAttrs.itemIndex, itemIndexAtSelectionEnd: toAttrs.itemIndex, indentLevelAtSelectionStart: fromAttrs.indentLevel, indentLevelAtSelectionEnd: toAttrs.indentLevel, itemsInSelection: countListItemsInSelection(tr) }; }; var countListItemsInSelection = exports.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 && (0, _utils.isListItemNode)(parent) && !(0, _utils.isListNode)(node) && index === 0) { count++; } }); return count; };