"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.withDeprecations = withDeprecations;
var _element = require("@wordpress/element");
var _blocks = require("@wordpress/blocks");
var _richText = require("@wordpress/rich-text");
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
var _multiline = _interopRequireDefault(require("./multiline"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function withDeprecations(Component) {
  return (0, _element.forwardRef)((props, ref) => {
    let value = props.value;
    let onChange = props.onChange;

    // Handle deprecated format.
    if (Array.isArray(value)) {
      (0, _deprecated.default)('wp.blockEditor.RichText value prop as children type', {
        since: '6.1',
        version: '6.3',
        alternative: 'value prop as string',
        link: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/'
      });
      value = _blocks.children.toHTML(props.value);
      onChange = newValue => props.onChange(_blocks.children.fromDOM((0, _richText.__unstableCreateElement)(document, newValue).childNodes));
    }
    const NewComponent = props.multiline ? _multiline.default : Component;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(NewComponent, {
      ...props,
      value: value,
      onChange: onChange,
      ref: ref
    });
  });
}
//# sourceMappingURL=with-deprecations.js.map