text: /**
   * Copyright (c) 2013-present, Facebook, Inc.
   * All rights reserved.
   *
   * This source code is licensed under the BSD-style license found in the
   * LICENSE file in the root directory of this source tree. An additional grant
   * of patent rights can be found in the PATENTS file in the same directory.
   *
   * @providesModule ContentState
   * @typechecks
   * 
   */
  
  'use strict';
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  
  var BlockMapBuilder = require('./BlockMapBuilder');
  var CharacterMetadata = require('./CharacterMetadata');
  var ContentBlock = require('./ContentBlock');
  var Immutable = require('immutable');
  var SelectionState = require('./SelectionState');
  
  var generateRandomKey = require('./generateRandomKey');
  var sanitizeDraftText = require('./sanitizeDraftText');
  
  var List = Immutable.List;
  var Record = Immutable.Record;
  var Repeat = Immutable.Repeat;
  
  
  var defaultRecord = {
    blockMap: null,
    selectionBefore: null,
    selectionAfter: null
  };
  
  var ContentStateRecord = Record(defaultRecord);
  
  var ContentState = function (_ContentStateRecord) {
    _inherits(ContentState, _ContentStateRecord);
  
    function ContentState() {
      _classCallCheck(this, ContentState);
  
      return _possibleConstructorReturn(this, _ContentStateRecord.apply(this, arguments));
    }
  
    ContentState.prototype.getBlockMap = function getBlockMap() {
      return this.get('blockMap');
    };
  
    ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
      return this.get('selectionBefore');
    };
  
    ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
      return this.get('selectionAfter');
    };
  
    ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
      var block = this.getBlockMap().get(key);
      return block;
    };
  
    ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
      return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
        return v === key;
      }).skip(1).first();
    };
  
    ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
      return this.getBlockMap().keySeq().skipUntil(function (v) {
        return v === key;
      }).skip(1).first();
    };
  
    ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
      return this.getBlockMap().skipUntil(function (_, k) {
        return k === key;
      }).skip(1).first();
    };
  
    ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
      return this.getBlockMap().reverse().skipUntil(function (_, k) {
        return k === key;
      }).skip(1).first();
    };
  
    ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
      return this.getBlockMap().toArray();
    };
  
    ContentState.prototype.getFirstBlock = function getFirstBlock() {
      return this.getBlockMap().first();
    };
  
    ContentState.prototype.getLastBlock = function getLastBlock() {
      return this.getBlockMap().last();
    };
  
    ContentState.prototype.getPlainText = function getPlainText(delimiter) {
      return this.getBlockMap().map(function (block) {
        return block ? block.getText() : '';
      }).join(delimiter || '\n');
    };
  
    ContentState.prototype.hasText = function hasText() {
      var blockMap = this.getBlockMap();
      return blockMap.size > 1 || blockMap.first().getLength() > 0;
    };
  
    ContentState.createFromBlockArray = function createFromBlockArray(blocks) {
      var blockMap = BlockMapBuilder.createFromArray(blocks);
      var selectionState = SelectionState.createEmpty(blockMap.first().getKey());
      return new ContentState({
        blockMap: blockMap,
        selectionBefore: selectionState,
        selectionAfter: selectionState
      });
    };
  
    ContentState.createFromText = function createFromText(text) {
      var delimiter = arguments.length <= 1 || arguments[1] === undefined ? /\r\n?|\n/g : arguments[1];
  
      var strings = text.split(delimiter);
      var blocks = strings.map(function (block) {
        block = sanitizeDraftText(block);
        return new ContentBlock({
          key: generateRandomKey(),
          text: block,
          type: 'unstyled',
          characterList: List(Repeat(CharacterMetadata.EMPTY, block.length))
        });
      });
      return ContentState.createFromBlockArray(blocks);
    };
  
    return ContentState;
  }(ContentStateRecord);
  
  module.exports = ContentState;