var j = Object.defineProperty;
var T = (a, u, c) => u in a ? j(a, u, { enumerable: !0, configurable: !0, writable: !0, value: c }) : a[u] = c;
var r = (a, u, c) => T(a, typeof u != "symbol" ? u + "" : u, c);
import { defineComponent as $, shallowRef as R, ref as g, computed as q, inject as C, watch as p, nextTick as y, onBeforeUnmount as J, createElementBlock as P, openBlock as G, createVNode as S, unref as _, normalizeStyle as Q } from "vue";
import { Toolbar as W, Editor as X } from "@wangeditor/editor-for-vue";
import { Boot as w } from "@wangeditor/editor";
import { a as Y } from "./index-CpF1mzPx.mjs";
const Z = { class: "rich-text-editor" }, ee = /* @__PURE__ */ $({
  __name: "index",
  props: {
    name: { default: "" },
    modelValue: { default: "" },
    placeholder: { default: "Please input content..." },
    height: { default: "400px" },
    mode: { default: "default" },
    disabled: { type: Boolean, default: !1 },
    maxLength: { default: 1e4 },
    excludeKeys: { default: () => [] },
    includeKeys: { default: () => [] }
  },
  emits: ["update:modelValue", "change", "focus", "blur", "created", "upload-image", "upload-video"],
  setup(a, { expose: u, emit: c }) {
    const n = a, d = c, t = R(), i = g(""), I = q(() => typeof n.height == "number" ? `${n.height}px` : n.height), D = C("handleUpload", () => {
    }), m = C("fileUrl", null), E = C("chooseName", null), F = g(""), f = g(null), b = (e) => {
      if (!D) {
        console.warn("Upload: handleUpload function not provided by ancestor");
        return;
      }
      if (F.value = e, t.value)
        try {
          const o = t.value.selection;
          o && (f.value = {
            anchor: {
              path: [...o.anchor.path],
              offset: o.anchor.offset
            },
            focus: {
              path: [...o.focus.path],
              offset: o.focus.offset
            }
          });
        } catch (o) {
          console.warn("保存光标位置失败:", o);
        }
      const l = n.name + "_" + e;
      D(!0, l);
    };
    p(() => n.name, () => {
      m.value = null;
    }, { deep: !0, immediate: !0 }), p(
      () => [m == null ? void 0 : m.value],
      ([e]) => {
        const l = n.name + "_" + F.value;
        !e || !E.value || E.value !== l || t.value && y(() => {
          var o, h;
          if (t.value) {
            try {
              if (t.value.focus(), f.value)
                try {
                  t.value.select(f.value);
                } catch (s) {
                  console.warn("恢复光标位置失败，使用默认位置:", s);
                }
            } catch (s) {
              console.warn("聚焦编辑器失败:", s);
            }
            if (F.value === "img") {
              const v = `<img src="${e}" alt="图片" style="max-width: 100%;">`;
              (o = t.value) == null || o.dangerouslyInsertHtml(v);
            } else {
              const v = `<video src="${e}" controls style="max-width: 100%;"></video>`;
              (h = t.value) == null || h.dangerouslyInsertHtml(v);
            }
            f.value = null, F.value = "";
          }
        });
      },
      { immediate: !1 }
    );
    function H(e) {
      return class {
        constructor() {
          r(this, "title");
          r(this, "tag");
          r(this, "iconSvg");
          this.title = "上传图片", this.tag = "button", this.iconSvg = '<svg viewBox="0 0 1024 1024"><path d="M959.877 128l0.123 0.123v767.775l-0.123 0.122H64.102l-0.122-0.122V128.123l0.122-0.123h895.775zM960 64H64C28.795 64 0 92.795 0 128v768c0 35.205 28.795 64 64 64h896c35.205 0 64-28.795 64-64V128c0-35.205-28.795-64-64-64zM832 288.01c0 53.023-42.988 96.01-96.01 96.01s-96.01-42.987-96.01-96.01S682.967 192 735.99 192 832 234.988 832 288.01zM896 832H128V704l224.01-384 256 320h64l224.01-192z"></path></svg>';
        }
        isActive() {
          return !1;
        }
        getValue() {
          return "";
        }
        isDisabled() {
          return !1;
        }
        exec() {
          y(() => {
            console.log("点击了自定义上传图片菜单"), e("img");
          });
        }
      };
    }
    function k(e) {
      return class {
        constructor() {
          r(this, "title");
          r(this, "tag");
          r(this, "iconSvg");
          this.title = "上传视频", this.tag = "button", this.iconSvg = '<svg viewBox="0 0 1024 1024"><path d="M981.184 160.096C837.568 139.456 678.848 128 512 128S186.432 139.456 42.816 160.096C15.296 267.808 0 386.848 0 512s15.264 244.16 42.816 351.904C186.464 884.544 345.152 896 512 896s325.568-11.456 469.184-32.096C1008.704 756.192 1024 637.152 1024 512s-15.264-244.16-42.816-351.904zM384 704V320l320 192-320 192z"></path></svg>';
        }
        getValue() {
          return "";
        }
        isActive() {
          return !1;
        }
        isDisabled() {
          return !1;
        }
        exec() {
          y(() => {
            console.log("点击了自定义上传视频菜单"), e("video");
          });
        }
      };
    }
    const B = {
      toolbarKeys: [
        // 菜单 key
        "headerSelect",
        "bold",
        // 加粗
        "italic",
        // 斜体
        "through",
        // 删除线
        "underline",
        // 下划线
        "color",
        // 文字颜色
        "fontSize",
        // 字体大小
        "lineHeight",
        // 行高
        "delIndent",
        // 缩进
        "indent",
        // 增进
        "divider",
        // 分割线
        "insertTable",
        // 插入表格
        "justifyCenter",
        // 居中对齐
        "justifyJustify",
        // 两端对齐
        "justifyLeft",
        // 左对齐
        "justifyRight",
        // 右对齐
        "bulletedList",
        "numberedList",
        // 列表
        "undo",
        // 撤销
        "redo",
        // 重做
        "clearStyle",
        // 清除格式
        "codeBlock"
        //代码块
      ]
    }, x = [
      // 5个品牌默认颜色
      "#0032A0",
      "#FF0044",
      "#FF8200",
      "#001E60",
      "#E3E3E6",
      // wangEditor 默认颜色
      "#000000",
      "#262626",
      "#595959",
      "#8C8C8C",
      "#BFBFBF",
      "#D9D9D9",
      "#E8E8E8",
      "#F5F5F5",
      "#FFFFFF",
      "#F5222D",
      "#FA541C",
      "#FA8C16",
      "#FADB14",
      "#52C41A",
      "#13C2C2",
      "#1890FF",
      "#2F54EB",
      "#722ED1",
      "#EB2F96",
      "#FFE8E6",
      "#FFECE0",
      "#FFEFD1",
      "#FCFCCA",
      "#E4F7D2",
      "#D3F5F0",
      "#D4EEFC",
      "#DEE8FC",
      "#EFE1FA",
      "#FAE1EB",
      "#FFA39E",
      "#FFBB96",
      "#FFD591",
      "#FFFB8F",
      "#B7EB8F",
      "#87E8DE",
      "#91D5FF",
      "#ADC6FF",
      "#D3ADF7",
      "#FFADD2",
      "#FF4D4F",
      "#FF7A45",
      "#FFA940",
      "#FFEC3D",
      "#73D13D",
      "#36CFC9",
      "#40A9FF",
      "#597EF7",
      "#9254DE",
      "#F759AB",
      "#CF1322",
      "#D4380D",
      "#D46B08",
      "#D4B106",
      "#389E0D",
      "#08979C",
      "#096DD9",
      "#1D39C4",
      "#531DAB",
      "#C41D7F",
      "#820014",
      "#871400",
      "#873800",
      "#614700",
      "#135200",
      "#00474F",
      "#003A8C",
      "#061178",
      "#22075E",
      "#780650"
    ], z = {
      placeholder: n.placeholder,
      readOnly: n.disabled,
      maxLength: n.maxLength,
      MENU_CONF: {
        color: {
          colors: x
        },
        bgColor: {
          colors: x
        }
      },
      // --- 新增：自定义选中文字时的气泡菜单 ---
      hoverbarKeys: {
        // text 类型代表选中文字时弹出的菜单
        text: {
          // 通过配置来覆盖默认菜单
          // 我们重新定义 key 列表，排除掉 'color' (文字颜色) 和 'bgColor' (背景色)
          menuKeys: [
            "headerSelect",
            "insertLink",
            "bold",
            "italic",
            "underline",
            "through",
            // 'color',   <-- 去掉这两个
            // 'bgColor', <-- 去掉这两个
            "clearStyle"
          ]
        }
      }
    }, M = Math.random().toString(36).substring(2, 9), A = `CustomImageMenu_${M}`, V = `CustomVideoMenu_${M}`, K = (e) => {
      t.value = e;
      try {
        const l = H(b), o = k(b), h = {
          key: A,
          // 使用唯一的 key
          factory() {
            return new l();
          }
        }, s = {
          key: V,
          // 使用唯一的 key
          factory() {
            return new o();
          }
        };
        w.registerMenu(h), w.registerMenu(s);
      } catch (l) {
        console.warn("菜单注册失败:", l);
      }
      B.insertKeys = {
        index: 0,
        keys: [A, V]
      }, d("created", e);
    };
    J(() => {
      const e = t.value;
      e != null && e.destroy();
    }), p(
      () => n.modelValue,
      (e) => {
        e !== i.value && (i.value = e || "");
      },
      { immediate: !0 }
    );
    const L = (e) => {
      d("update:modelValue", i.value), d("change", e);
    }, N = () => {
      t.value = void 0;
    }, O = (e) => {
      d("focus", e);
    }, U = (e) => {
      d("blur", e);
    };
    return u({
      editor: t,
      getHtml: () => i.value,
      getText: () => {
        var e;
        return ((e = t.value) == null ? void 0 : e.getText()) || "";
      },
      isEmpty: () => {
        var e;
        return ((e = t.value) == null ? void 0 : e.isEmpty()) || !0;
      },
      clear: () => {
        var e;
        return (e = t.value) == null ? void 0 : e.clear();
      },
      focus: () => {
        var e;
        return (e = t.value) == null ? void 0 : e.focus();
      },
      blur: () => {
        var e;
        return (e = t.value) == null ? void 0 : e.blur();
      },
      disable: () => {
        var e;
        return (e = t.value) == null ? void 0 : e.disable();
      },
      enable: () => {
        var e;
        return (e = t.value) == null ? void 0 : e.enable();
      }
    }), (e, l) => (G(), P("div", Z, [
      S(_(W), {
        class: "editor-toolbar",
        editor: t.value,
        defaultConfig: B,
        mode: a.mode
      }, null, 8, ["editor", "mode"]),
      S(_(X), {
        class: "editor-content",
        style: Q({ height: I.value }),
        modelValue: i.value,
        "onUpdate:modelValue": l[0] || (l[0] = (o) => i.value = o),
        defaultConfig: z,
        mode: a.mode,
        onOnCreated: K,
        onOnChange: L,
        onOnDestroyed: N,
        onOnFocus: O,
        onOnBlur: U
      }, null, 8, ["style", "modelValue", "mode"])
    ]));
  }
}), re = /* @__PURE__ */ Y(ee, [["__scopeId", "data-v-e97d4bf7"]]);
export {
  re as default
};
