@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
41 lines (38 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.findNodePosByLocalIds = void 0;
/**
* Temporary file which extracts function from `editor-common`.
*
* Eventually we will deprecate and delete EditorActions. This is here to
* help decouple it from editor-common
*/
var findNodePosByLocalIds = exports.findNodePosByLocalIds = function findNodePosByLocalIds(state, ids) {
var _state$doc$attrs;
var option = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (ids.length === 0) {
return [];
}
var nodes = [];
var localIdSet = new Set(ids);
if (option.includeDocNode && localIdSet.has((_state$doc$attrs = state.doc.attrs) === null || _state$doc$attrs === void 0 ? void 0 : _state$doc$attrs.localId)) {
nodes.push({
node: state.doc,
pos: 0
});
}
state.doc.descendants(function (node, pos) {
var _node$attrs;
if (localIdSet.has((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId)) {
nodes.push({
node: node,
pos: pos
});
}
// stop traversing once we found all the nodes
return localIdSet.size !== nodes.length;
});
return nodes;
};