@wix/design-system
Version:
@wix/design-system
46 lines (36 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
/**
* Returns an array of all `ContentBlock` instances within two block keys
*
* @param {object} contentState A draft.js `ContentState` instance
* @param {string} anchorKey The block key to start searching from
* @param {string} focusKey The block key until which to search
*
* @return {array} An array containing the found content blocks
*/
var _default = function _default(contentState, anchorKey, focusKey) {
var isSameBlock = anchorKey === focusKey;
var startingBlock = contentState.getBlockForKey(anchorKey);
if (!startingBlock) {
return [];
}
var selectedBlocks = [startingBlock];
if (!isSameBlock) {
var blockKey = anchorKey;
while (blockKey !== focusKey) {
var nextBlock = contentState.getBlockAfter(blockKey);
if (!nextBlock) {
selectedBlocks = [];
break;
}
selectedBlocks.push(nextBlock);
blockKey = nextBlock.getKey();
}
}
return selectedBlocks;
};
exports["default"] = _default;