"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=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb2RlL21hc2stbWFya3VwL3dpdGgtbWFzay5qc3giXSwibmFtZXMiOlsiYnVpbGRMYXlvdXRGcm9tTWFya3VwIiwibWFya3VwIiwidHlwZSIsInByb2Nlc3NlZCIsInZhbHVlIiwiZG9jdW1lbnQiLCJ3aXRoTWFzayIsInJlbmRlckNoaWxkcmVuIiwicHJvcHMiLCJsYXlvdXQiLCJvbkNoYW5nZSIsIm1hc2tMYXlvdXQiLCJSZWFjdCIsIkNvbXBvbmVudCIsIlByb3BUeXBlcyIsInN0cmluZyIsIm9iamVjdCIsImZ1bmMiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBOztBQUNBOztBQUNBOztBQUNBOztBQUNBOzs7Ozs7QUFFTyxJQUFNQSxxQkFBcUIsR0FBRyxTQUF4QkEscUJBQXdCLENBQUNDLE1BQUQsRUFBU0MsSUFBVCxFQ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