"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.withMask = exports.buildLayoutFromMarkup = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _mask = _interopRequireDefault(require("./mask"));

var _componentize2 = _interopRequireDefault(require("./componentize"));

var _serialization = require("./serialization");

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var buildLayoutFromMarkup = function buildLayoutFromMarkup(markup, type) {
  var _componentize = (0, _componentize2["default"])(markup, type),
      processed = _componentize.markup;

  var value = (0, _serialization.deserialize)(processed);
  return value.document;
};

exports.buildLayoutFromMarkup = buildLayoutFromMarkup;

var withMask = function withMask(type, renderChildren) {
  var _class;

  return _class = /*#__PURE__*/function (_React$Component) {
    (0, _inherits2["default"])(WithMask, _React$Component);

    var _super = _createSuper(WithMask);

    function WithMask() {
      (0, _classCallCheck2["default"])(this, WithMask);
      return _super.apply(this, arguments);
    }

    (0, _createClass2["default"])(WithMask, [{
      key: "render",
      value: function render() {
        var _this$props = this.props,
            markup = _this$props.markup,
            layout = _this$props.layout,
            value = _this$props.value,
            onChange = _this$props.onChange;
        var maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
        return /*#__PURE__*/_react["default"].createElement(_mask["default"], {
          layout: maskLayout,
          value: value,
          onChange: onChange,
          renderChildren: renderChildren(this.props)
        });
      }
    }]);
    return WithMask;
  }(_react["default"].Component), (0, _defineProperty2["default"])(_class, "propTypes", {
    /**
     * At the start we'll probably work with markup
     */
    markup: _propTypes["default"].string,

    /**
     * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.
     */
    layout: _propTypes["default"].object,
    value: _propTypes["default"].object,
    onChange: _propTypes["default"].func
  }), _class;
};

exports.withMask = withMask;
//# sourceMappingURL=with-mask.js.map