UNPKG

@atlaskit/editor-common

Version:

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

28 lines (27 loc) 896 B
export var 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; };