text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = void 0;
  
  var React = _interopRequireWildcard(require("react"));
  
  var _KeyCode = _interopRequireDefault(require("rc-util/lib/KeyCode"));
  
  var _reactLifecyclesCompat = require("react-lifecycles-compat");
  
  var _icon = _interopRequireDefault(require("../icon"));
  
  var _TextArea = _interopRequireDefault(require("../input/TextArea"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
  
  function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  
  var Editable =
  /*#__PURE__*/
  function (_React$Component) {
    _inherits(Editable, _React$Component);
  
    function Editable() {
      var _this;
  
      _classCallCheck(this, Editable);
  
      _this = _possibleConstructorReturn(this, _getPrototypeOf(Editable).apply(this, arguments));
      _this.inComposition = false;
      _this.state = {
        current: ''
      };
  
      _this.onChange = function (_ref) {
        var value = _ref.target.value;
  
        _this.setState({
          current: value.replace(/[\r\n]/g, '')
        });
      };
  
      _this.onCompositionStart = function () {
        _this.inComposition = true;
      };
  
      _this.onCompositionEnd = function () {
        _this.inComposition = false;
      };
  
      _this.onKeyDown = function (_ref2) {
        var keyCode = _ref2.keyCode;
        // We don't record keyCode when IME is using
        if (_this.inComposition) return;
        _this.lastKeyCode = keyCode;
      };
  
      _this.onKeyUp = function (_ref3) {
        var keyCode = _ref3.keyCode,
            ctrlKey = _ref3.ctrlKey,
            altKey = _ref3.altKey,
            metaKey = _ref3.metaKey,
            shiftKey = _ref3.shiftKey;
        var onCancel = _this.props.onCancel; // Check if it's a real key
  
        if (_this.lastKeyCode === keyCode && !_this.inComposition && !ctrlKey && !altKey && !metaKey && !shiftKey) {
          if (keyCode === _KeyCode["default"].ENTER) {
            _this.confirmChange();
          } else if (keyCode === _KeyCode["default"].ESC) {
            onCancel();
          }
        }
      };
  
      _this.onBlur = function () {
        _this.confirmChange();
      };
  
      _this.confirmChange = function () {
        var current = _this.state.current;
        var onSave = _this.props.onSave;
        onSave(current.trim());
      };
  
      _this.setTextarea = function (textarea) {
        _this.textarea = textarea;
      };
  
      return _this;
    }
  
    _createClass(Editable, [{
      key: "componentDidMount",
      value: function componentDidMount() {
        if (this.textarea) {
          this.textarea.focus();
        }
      }
    }, {
      key: "render",
      value: function render() {
        var current = this.state.current;
        var _this$props = this.props,
            prefixCls = _this$props.prefixCls,
            ariaLabel = _this$props['aria-label'],
            className = _this$props.className,
            style = _this$props.style;
        return React.createElement("div", {
          className: "".concat(prefixCls, " ").concat(prefixCls, "-edit-content ").concat(className),
          style: style
        }, React.createElement(_TextArea["default"], {
          ref: this.setTextarea,
          value: current,
          onChange: this.onChange,
          onKeyDown: this.onKeyDown,
          onKeyUp: this.onKeyUp,
          onCompositionStart: this.onCompositionStart,
          onCompositionEnd: this.onCompositionEnd,
          onBlur: this.onBlur,
          "aria-label": ariaLabel,
          autosize: true
        }), React.createElement(_icon["default"], {
          type: "enter",
          className: "".concat(prefixCls, "-edit-content-confirm")
        }));
      }
    }], [{
      key: "getDerivedStateFromProps",
      value: function getDerivedStateFromProps(nextProps, prevState) {
        var prevValue = prevState.prevValue;
        var value = nextProps.value;
        var newState = {
          prevValue: value
        };
  
        if (prevValue !== value) {
          newState.current = value;
        }
  
        return newState;
      }
    }]);
  
    return Editable;
  }(React.Component);
  
  (0, _reactLifecyclesCompat.polyfill)(Editable);
  var _default = Editable;
  exports["default"] = _default;
  module.exports = exports.default;