"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _editorForReact = require("@wangeditor/editor-for-react");
var _editor = require("@wangeditor/editor");
require("@wangeditor/editor/dist/css/style.css");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var RichEditor = function RichEditor(props, ref) {
  var editorConfig = props.editorConfig,
    defaultValue = props.defaultValue,
    style = props.style,
    __designMode = props.__designMode,
    language = props.language;
  var isDesignMode = __designMode === 'design';
  var _useState = (0, _react.useState)(null),
    editor = _useState[0],
    setEditor = _useState[1];
  // 编辑器内容
  var _useState2 = (0, _react.useState)(defaultValue),
    html = _useState2[0],
    setHtml = _useState2[1];

  // 工具栏配置
  var toolbarConfig = {};

  // 不支持动态刷新语言
  (0, _editor.i18nChangeLanguage)(language || 'zh-CN');

  // 及时销毁editor
  (0, _react.useEffect)(function () {
    return function () {
      if (editor === null) return;
      editor.destroy();
      setEditor(null);
    };
  }, [editor]);
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      editor: editor
    };
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    ref: ref,
    style: (0, _extends2["default"])({}, style || {})
  }, /*#__PURE__*/_react["default"].createElement(_editorForReact.Toolbar, {
    defaultConfig: toolbarConfig,
    mode: "default",
    editor: editor,
    style: {
      pointerEvents: isDesignMode ? 'none' : 'auto',
      borderBottom: '1px solid #ccc'
    }
  }), /*#__PURE__*/_react["default"].createElement(_editorForReact.Editor, {
    defaultConfig: editorConfig // 默认配置
    ,
    onCreated: setEditor,
    mode: "default",
    onChange: function onChange(domEditor) {
      return setHtml(domEditor.getHtml());
    },
    value: html,
    style: {
      pointerEvents: isDesignMode ? 'none' : 'auto'
    }
  }));
};
var RefRichEditor = /*#__PURE__*/(0, _react.forwardRef)(RichEditor);
RefRichEditor.displayName = 'RichEditor';
var _default = RefRichEditor;
exports["default"] = _default;