'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var editorForVue = require('@wangeditor/editor-for-vue');

"use strict";
const _hoisted_1 = { class: "me-wang-editor" };
const __default__ = vue.defineComponent({
  name: "me-wang-editor"
});
var script = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: /* @__PURE__ */ vue.mergeModels({
    headers: { type: Object, required: false, default: () => ({}) },
    url: { type: String, required: false, default: "#" },
    uploadImageConfig: { type: Object, required: false },
    uploadVideoConfig: { type: Object, required: false }
  }, {
    "modelValue": {},
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props) {
    const props = __props;
    const valueHtml = vue.useModel(__props, "modelValue");
    const editorRef = vue.shallowRef();
    const mode = vue.ref("default");
    const handleCreated = (editor) => {
      editorRef.value = editor;
    };
    const visible = vue.ref(false);
    let title = "\u56FE\u7247";
    let cursorPosition = "";
    const insetMedia = async (res) => {
      const mediaUrl = res[0].url;
      let mediaHtml = title === "\u4E0A\u4F20\u56FE\u7247" ? `<img src='${mediaUrl}' style="width:100%; vertical-align: middle" alt="\u56FE\u7247\u63CF\u8FF0" />` : `<p style="width:100%;"><video style="width:100%;" src="${mediaUrl}" controls="true"></video></p>`;
      editorRef.value.select(cursorPosition);
      editorRef.value.dangerouslyInsertHtml(mediaHtml);
      visible.value = false;
    };
    const toolbarConfig = {
      excludeKeys: ["fullScreen"]
    };
    const editorConfig = {
      placeholder: "\u8BF7\u8F93\u5165\u5185\u5BB9...",
      MENU_CONF: {
        // uploadImage: props.uploadImageConfig,
        // uploadVideo: props.uploadVideoConfig,
        uploadImage: props.uploadImageConfig,
        uploadVideo: props.uploadVideoConfig
      }
    };
    vue.onBeforeUnmount(() => {
      const editor = editorRef.value;
      if (editor) editor.destroy();
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.createVNode(vue.unref(editorForVue.Toolbar), {
          style: { "border-bottom": "1px solid #ccc" },
          editor: editorRef.value,
          defaultConfig: toolbarConfig,
          mode: mode.value
        }, null, 8, ["editor", "mode"]),
        vue.createVNode(vue.unref(editorForVue.Editor), vue.mergeProps({
          modelValue: valueHtml.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => valueHtml.value = $event),
          style: { "overflow-y": "hidden", "flex": "1" },
          defaultConfig: editorConfig,
          mode: mode.value
        }, _ctx.$attrs, { onOnCreated: handleCreated }), null, 16, ["modelValue", "mode"])
      ]);
    };
  }
});

exports.default = script;
//# sourceMappingURL=wang-editor.vue2.js.map
