import { __require as requireApplyEntityToContentBlock } from './applyEntityToContentBlock.js';
import { __require as requireImmutable } from '../../../../immutable@3.7.6/node_modules/immutable/dist/immutable.js';

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 * 
 * @emails oncall+draft_js
 */

var applyEntityToContentState_1;
var hasRequiredApplyEntityToContentState;

function requireApplyEntityToContentState () {
	if (hasRequiredApplyEntityToContentState) return applyEntityToContentState_1;
	hasRequiredApplyEntityToContentState = 1;

	var applyEntityToContentBlock = requireApplyEntityToContentBlock();

	var Immutable = requireImmutable();

	function applyEntityToContentState(contentState, selectionState, entityKey) {
	  var blockMap = contentState.getBlockMap();
	  var startKey = selectionState.getStartKey();
	  var startOffset = selectionState.getStartOffset();
	  var endKey = selectionState.getEndKey();
	  var endOffset = selectionState.getEndOffset();
	  var newBlocks = blockMap.skipUntil(function (_, k) {
	    return k === startKey;
	  }).takeUntil(function (_, k) {
	    return k === endKey;
	  }).toOrderedMap().merge(Immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
	    var sliceStart = blockKey === startKey ? startOffset : 0;
	    var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
	    return applyEntityToContentBlock(block, sliceStart, sliceEnd, entityKey);
	  });
	  return contentState.merge({
	    blockMap: blockMap.merge(newBlocks),
	    selectionBefore: selectionState,
	    selectionAfter: selectionState
	  });
	}

	applyEntityToContentState_1 = applyEntityToContentState;
	return applyEntityToContentState_1;
}

export { requireApplyEntityToContentState as __require };
//# sourceMappingURL=applyEntityToContentState.js.map
