var T = Object.defineProperty;
var $ = (u, s, i) => s in u ? T(u, s, { enumerable: !0, configurable: !0, writable: !0, value: i }) : u[s] = i;
var c = (u, s, i) => $(u, typeof s != "symbol" ? s + "" : s, i);
import { defineComponent as R, shallowRef as q, ref as C, computed as J, inject as p, watch as y, nextTick as D, onBeforeUnmount as G, createElementBlock as P, openBlock as Q, createVNode as _, unref as w, normalizeStyle as W } from "vue";
import { Toolbar as X, Editor as Y } from "@wangeditor/editor-for-vue";
import { Boot as I } from "@wangeditor/editor";
import { a as Z } from "./index-DhFzQ0t1.mjs";
const ee = { class: "rich-text-editor" }, te = /* @__PURE__ */ R({
  __name: "index",
  props: {
    name: { default: "" },
    modelValue: { default: "" },
    placeholder: { default: t("placeholder.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(u, { expose: s, emit: i }) {
    const a = u, m = i, o = q(), d = C(""), H = J(() => typeof a.height == "number" ? `${a.height}px` : a.height), E = p("handleUpload", () => {
    }), F = p("fileUrl", null), b = p("chooseName", null), f = C(""), h = C(null), B = (e) => {
      if (!E) {
        console.warn("Upload: handleUpload function not provided by ancestor");
        return;
      }
      if (f.value = e, o.value)
        try {
          const l = o.value.selection;
          l && (h.value = {
            anchor: {
              path: [...l.anchor.path],
              offset: l.anchor.offset
            },
            focus: {
              path: [...l.focus.path],
              offset: l.focus.offset
            }
          });
        } catch (l) {
          console.warn("保存光标位置失败:", l);
        }
      const n = a.name + "_" + e;
      E(!0, n);
    };
    y(() => a.name, () => {
      F.value = null;
    }, { deep: !0, immediate: !0 }), y(
      () => [F == null ? void 0 : F.value],
      ([e]) => {
        const n = a.name + "_" + f.value;
        !e || !b.value || b.value !== n || o.value && D(() => {
          var l, v;
          if (o.value) {
            try {
              if (o.value.focus(), h.value)
                try {
                  o.value.select(h.value);
                } catch (r) {
                  console.warn("恢复光标位置失败，使用默认位置:", r);
                }
            } catch (r) {
              console.warn("聚焦编辑器失败:", r);
            }
            if (f.value === "img") {
              const g = `<img src="${e}" alt="图片" style="max-width: 100%;">`;
              (l = o.value) == null || l.dangerouslyInsertHtml(g);
            } else {
              const g = `<video src="${e}" controls style="max-width: 100%;"></video>`;
              (v = o.value) == null || v.dangerouslyInsertHtml(g);
            }
            h.value = null, f.value = "";
          }
        });
      },
      { immediate: !1 }
    );
    function k(e) {
      return class {
        constructor() {
          c(this, "title");
          c(this, "tag");
          c(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() {
          D(() => {
            console.log("点击了自定义上传图片菜单"), e("img");
          });
        }
      };
    }
    function z(e) {
      return class {
        constructor() {
          c(this, "title");
          c(this, "tag");
          c(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() {
          D(() => {
            console.log("点击了自定义上传视频菜单"), e("video");
          });
        }
      };
    }
    const x = {
      toolbarKeys: [
        // 菜单 key
        "headerSelect",
        "bold",
        // 加粗
        "italic",
        // 斜体
        "through",
        // 删除线
        "underline",
        // 下划线
        "color",
        // 文字颜色
        "fontSize",
        // 字体大小
        "lineHeight",
        // 行高
        "delIndent",
        // 缩进
        "indent",
        // 增进
        "divider",
        // 分割线
        "insertTable",
        // 插入表格
        "justifyCenter",
        // 居中对齐
        "justifyJustify",
        // 两端对齐
        "justifyLeft",
        // 左对齐
        "justifyRight",
        // 右对齐
        "bulletedList",
        "numberedList",
        // 列表
        "undo",
        // 撤销
        "redo",
        // 重做
        "clearStyle",
        // 清除格式
        "codeBlock"
        //代码块
      ]
    }, M = [
      // 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"
    ], K = {
      placeholder: a.placeholder,
      readOnly: a.disabled,
      maxLength: a.maxLength,
      MENU_CONF: {
        color: {
          colors: M
        },
        bgColor: {
          colors: M
        }
      },
      // --- 新增：自定义选中文字时的气泡菜单 ---
      hoverbarKeys: {
        // text 类型代表选中文字时弹出的菜单
        text: {
          // 通过配置来覆盖默认菜单
          // 我们重新定义 key 列表，排除掉 'color' (文字颜色) 和 'bgColor' (背景色)
          menuKeys: [
            "headerSelect",
            "insertLink",
            "bold",
            "italic",
            "underline",
            "through",
            // 'color',   <-- 去掉这两个
            // 'bgColor', <-- 去掉这两个
            "clearStyle"
          ]
        }
      }
    }, A = Math.random().toString(36).substring(2, 9), V = `CustomImageMenu_${A}`, S = `CustomVideoMenu_${A}`, L = (e) => {
      o.value = e;
      try {
        const n = k(B), l = z(B), v = {
          key: V,
          // 使用唯一的 key
          factory() {
            return new n();
          }
        }, r = {
          key: S,
          // 使用唯一的 key
          factory() {
            return new l();
          }
        };
        I.registerMenu(v), I.registerMenu(r);
      } catch (n) {
        console.warn("菜单注册失败:", n);
      }
      x.insertKeys = {
        index: 0,
        keys: [V, S]
      }, m("created", e);
    };
    G(() => {
      const e = o.value;
      e != null && e.destroy();
    }), y(
      () => a.modelValue,
      (e) => {
        e !== d.value && (d.value = e || "");
      },
      { immediate: !0 }
    );
    const N = (e) => {
      m("update:modelValue", d.value), m("change", e);
    }, O = () => {
      o.value = void 0;
    }, U = (e) => {
      m("focus", e);
    }, j = (e) => {
      m("blur", e);
    };
    return s({
      editor: o,
      getHtml: () => d.value,
      getText: () => {
        var e;
        return ((e = o.value) == null ? void 0 : e.getText()) || "";
      },
      isEmpty: () => {
        var e;
        return ((e = o.value) == null ? void 0 : e.isEmpty()) || !0;
      },
      clear: () => {
        var e;
        return (e = o.value) == null ? void 0 : e.clear();
      },
      focus: () => {
        var e;
        return (e = o.value) == null ? void 0 : e.focus();
      },
      blur: () => {
        var e;
        return (e = o.value) == null ? void 0 : e.blur();
      },
      disable: () => {
        var e;
        return (e = o.value) == null ? void 0 : e.disable();
      },
      enable: () => {
        var e;
        return (e = o.value) == null ? void 0 : e.enable();
      }
    }), (e, n) => (Q(), P("div", ee, [
      _(w(X), {
        class: "editor-toolbar",
        editor: o.value,
        defaultConfig: x,
        mode: u.mode
      }, null, 8, ["editor", "mode"]),
      _(w(Y), {
        class: "editor-content",
        style: W({ height: H.value }),
        modelValue: d.value,
        "onUpdate:modelValue": n[0] || (n[0] = (l) => d.value = l),
        defaultConfig: K,
        mode: u.mode,
        onOnCreated: L,
        onOnChange: N,
        onOnDestroyed: O,
        onOnFocus: U,
        onOnBlur: j
      }, null, 8, ["style", "modelValue", "mode"])
    ]));
  }
}), ce = /* @__PURE__ */ Z(te, [["__scopeId", "data-v-c3852efa"]]);
export {
  ce as default
};
