@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
34 lines (32 loc) • 973 B
JavaScript
/**
* 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
*/
export const findNodePosByLocalIds = (state, ids, option = {}) => {
var _state$doc$attrs;
if (ids.length === 0) {
return [];
}
const nodes = [];
const 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((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,
pos
});
}
// stop traversing once we found all the nodes
return localIdSet.size !== nodes.length;
});
return nodes;
};