import { __require as requireContentBlock } from './ContentBlock.js';
import { __require as requireContentBlockNode } from './ContentBlockNode.js';
import { __require as requireConvertFromHTMLToContentBlocks } from './convertFromHTMLToContentBlocks.js';
import { __require as requireGenerateRandomKey } from './generateRandomKey.js';
import { __require as requireGetSafeBodyFromHTML } from './getSafeBodyFromHTML.js';
import { __require as requireGkx } from './gkx.js';
import { __require as requireImmutable } from '../../../../immutable@3.7.6/node_modules/immutable/dist/immutable.js';
import { __require as requireSanitizeDraftText } from './sanitizeDraftText.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 DraftPasteProcessor_1;
var hasRequiredDraftPasteProcessor;

function requireDraftPasteProcessor () {
	if (hasRequiredDraftPasteProcessor) return DraftPasteProcessor_1;
	hasRequiredDraftPasteProcessor = 1;

	function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

	function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

	var ContentBlock = requireContentBlock();

	var ContentBlockNode = requireContentBlockNode();

	var convertFromHTMLToContentBlocks = requireConvertFromHTMLToContentBlocks();

	var generateRandomKey = requireGenerateRandomKey();

	var getSafeBodyFromHTML = requireGetSafeBodyFromHTML();

	var gkx = requireGkx();

	var Immutable = requireImmutable();

	var sanitizeDraftText = requireSanitizeDraftText();

	var List = Immutable.List,
	    Repeat = Immutable.Repeat;
	var experimentalTreeDataSupport = gkx('draft_tree_data_support');
	var ContentBlockRecord = experimentalTreeDataSupport ? ContentBlockNode : ContentBlock;
	var DraftPasteProcessor = {
	  processHTML: function processHTML(html, blockRenderMap) {
	    return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML, blockRenderMap);
	  },
	  processText: function processText(textBlocks, character, type) {
	    return textBlocks.reduce(function (acc, textLine, index) {
	      textLine = sanitizeDraftText(textLine);
	      var key = generateRandomKey();
	      var blockNodeConfig = {
	        key: key,
	        type: type,
	        text: textLine,
	        characterList: List(Repeat(character, textLine.length))
	      }; // next block updates previous block

	      if (experimentalTreeDataSupport && index !== 0) {
	        var prevSiblingIndex = index - 1; // update previous block

	        var previousBlock = acc[prevSiblingIndex] = acc[prevSiblingIndex].merge({
	          nextSibling: key
	        });
	        blockNodeConfig = _objectSpread({}, blockNodeConfig, {
	          prevSibling: previousBlock.getKey()
	        });
	      }

	      acc.push(new ContentBlockRecord(blockNodeConfig));
	      return acc;
	    }, []);
	  }
	};
	DraftPasteProcessor_1 = DraftPasteProcessor;
	return DraftPasteProcessor_1;
}

export { requireDraftPasteProcessor as __require };
//# sourceMappingURL=DraftPasteProcessor.js.map
