@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
34 lines (32 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.findNodePosByFragmentLocalIds = void 0;
var findNodePosByFragmentLocalIds = exports.findNodePosByFragmentLocalIds = function findNodePosByFragmentLocalIds(state, ids) {
if (ids.length === 0) {
return [];
}
var nodes = [];
var localIdSet = new Set(ids);
state.doc.descendants(function (node, pos) {
var _node$marks;
var fragmentLocalIdList = (_node$marks = node.marks) === null || _node$marks === void 0 ? void 0 : _node$marks.filter(function (m) {
return m.type.name === 'fragment';
}).map(function (m) {
var _m$attrs;
return (_m$attrs = m.attrs) === null || _m$attrs === void 0 ? void 0 : _m$attrs.localId;
}).filter(function (id) {
return id && localIdSet.has(id);
});
if (fragmentLocalIdList.length > 0) {
nodes.push({
node: node,
pos: pos
});
}
// stop traversing once we found all the nodes
return localIdSet.size !== nodes.length;
});
return nodes;
};