UNPKG

@imengyu/vue3-context-menu

Version:
1,584 lines 57.8 kB
import { defineComponent as te, toRefs as ce, ref as W, computed as Be, reactive as Ne, onMounted as be, nextTick as ie, onBeforeUnmount as we, openBlock as b, createElementBlock as P, normalizeClass as oe, normalizeStyle as Me, createElementVNode as D, renderSlot as j, unref as l, createCommentVNode as N, inject as z, provide as G, mergeProps as ke, createBlock as T, createVNode as re, toDisplayString as _e, resolveComponent as et, watch as $e, Teleport as tt, Transition as ft, withCtx as pe, withDirectives as vt, Fragment as Pe, renderList as Ae, createSlots as nt, vShow as ht, useSlots as ot, h as Se, normalizeProps as mt, guardReactiveProps as pt, render as Ke } from "vue"; let le = null; function gt() { return le !== null; } function bt(e) { le && lt(), le = e; } function Ye(e) { e === le && (le = null); } function lt() { le && (le.closeMenu(), le = null); } const ee = { defaultDirection: "br", defaultMinWidth: 100, defaultMaxWidth: 600, defaultZindex: 100, defaultZoom: 1, defaultAdjustPadding: { x: 0, y: 10 } }; function se(e, o) { let s = e.offsetTop; return e.offsetParent != null && e.offsetParent != o && (s -= e.offsetParent.scrollTop, s += se(e.offsetParent, o)), s; } function ue(e, o) { let s = e.offsetLeft; return e.offsetParent != null && e.offsetParent != o && (s -= e.offsetParent.scrollLeft, s += ue(e.offsetParent, o)), s; } function Ct(e, o, s, u) { return { x: ue(e, u) + o, y: se(e, u) + s }; } const Re = "mx-menu-default-container", yt = "mx-menu-container-"; let xt = 0; function st(e) { const { getContainer: o, zIndex: s } = e; if (o) { const v = typeof o == "function" ? o() : o; if (v) { let n = v.getAttribute("id"); return n || (n = yt + xt++, v.setAttribute("id", n)), { eleId: n, container: v, isNew: !1 }; } } let u = document.getElementById(Re); return u || (u = document.createElement("div"), u.setAttribute("id", Re), u.setAttribute("class", "mx-menu-ghost-host fullscreen"), document.body.appendChild(u)), u.style.zIndex = (s == null ? void 0 : s.toString()) || ee.defaultZindex.toString(), { eleId: Re, container: u, isNew: !0 }; } function Mt(e) { let o = 0; for (let s = 0; s < e.length; s++) { const u = e.charCodeAt(s); o = (o << 5) - o + u, o |= 0; } return o; } function Ve(e) { return typeof e == "number" ? `${e}px` : e; } const q = te({ props: { /** * Can be VNode or (data: unknown) => VNode */ vnode: { type: null }, /** * If vnode is a callback, this data will be passed to the callback first parameter. * @default null */ data: { type: null, default: null } }, setup(e) { const { vnode: o, data: s } = ce(e); return () => typeof o.value == "function" ? o.value(s.value) : o.value; } }); function kt(e, o) { const s = { ...e }; return delete s[o], s; } var St = Object.defineProperty, wt = (e, o, s) => o in e ? St(e, o, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[o] = s, Ue = (e, o, s) => wt(e, typeof o != "symbol" ? o + "" : o, s); class Xe { constructor(o, s) { Ue(this, "x", 0), Ue(this, "y", 0), this.x = o || 0, this.y = s || 0; } set(o, s) { this.x = o, this.y = s; } substract(o) { this.x -= o.x, this.y -= o.y; } } function Ze(e) { const { onDown: o, onMove: s, onUp: u } = e, v = new Xe(), n = new Xe(); let O; function d(m) { m.stopPropagation(), n.set(m.x, m.y), n.substract(v), s(v, n, m, O); } function g(m) { u(m, O), v.set(0, 0), document.removeEventListener("mousemove", d), document.removeEventListener("mouseup", g); } return (m, x) => o(m, x) ? (O = x, v.set(m.x, m.y), document.addEventListener("mousemove", d), document.addEventListener("mouseup", g), m.stopPropagation(), !0) : !1; } function It(e, o) { let s = 0; return { start() { s > 0 && clearInterval(s), s = setInterval(() => { s = 0, o(); }, e); }, stop() { s > 0 && (clearInterval(s), s = 0); } }; } const me = [], Ge = It(100, () => { for (const e of me) e(); }); function Wt(e, o, s, u) { let v = 0, n = 0; function O() { e.value && (o && v !== e.value.offsetWidth && o(e.value.offsetWidth), s && n !== e.value.offsetHeight && s(e.value.offsetHeight), u && (v !== e.value.offsetWidth || n !== e.value.offsetHeight) && u(e.value.offsetWidth, e.value.offsetHeight), v = e.value.offsetWidth, n = e.value.offsetHeight); } return { startResizeChecker() { Ge.start(), me.push(O); }, stopResizeChecker() { const d = me.indexOf(O); d >= 0 && me.splice(d, 1), me.length === 0 && Ge.stop(); } }; } const Je = 140, Ot = 70, Ht = /* @__PURE__ */ te({ __name: "ScrollRect", props: { /** * Scroll direction * * * both : Scroll in both directions * * vertical : Scroll only in vertical direction * * horizontal : Scroll only in horizontal direction * * none : Disable scroll * * @default both */ scroll: { type: String, default: "both" }, /** * Show scroll bar always, otherwise show scroll bar when mouse over * @default false */ scrollBarAlwaysShow: { type: Boolean, default: !1 }, /** * Is able to click scroll bar background to set scroll position? (When `scrollBarAlwaysShow` is true) * @default true */ scrollBarBackgroundClickable: { type: Boolean, default: !1 }, height: { type: Number, default: void 0 }, width: { type: Number, default: void 0 }, /** * */ maxHeight: { type: Number, default: void 0 }, maxWidth: { type: Number, default: void 0 }, /** * CSS class of inner container */ containerClass: { type: String, default: "" }, /** * Container style */ containerStyle: { type: null } }, emits: ["scroll", "resized"], setup(e, { expose: o, emit: s }) { const u = e, v = s, n = W(), O = W(), d = W(), g = W(), m = W(), x = W(), H = W(!1), E = Be(() => u.scroll === "horizontal" || u.scroll === "both"), _ = Be(() => u.scroll === "vertical" || u.scroll === "both"), h = Ne({ show: !1, size: 0, sizeRaw: 0, pos: 0 }), M = Ne({ show: !1, size: 0, sizeRaw: 0, pos: 0 }); let B = 0, f = 0, i = 0, C = 0, y = null; const k = { attributes: !0, childList: !0 }; function S() { if (n.value) { if (h.show) { const t = n.value.offsetWidth / n.value.scrollWidth; h.sizeRaw = t * n.value.offsetWidth, h.size = t * 100, h.pos = n.value.scrollLeft / (n.value.scrollWidth - n.value.offsetWidth) * (100 - h.size), t >= 1 && (h.show = !1); } if (M.show) { const t = n.value.offsetHeight / n.value.scrollHeight; M.sizeRaw = t * n.value.offsetHeight, M.size = t * 100, M.pos = n.value.scrollTop / (n.value.scrollHeight - n.value.offsetHeight) * (100 - M.size), t >= 1 && (M.show = !1); } v("scroll", n.value.scrollLeft, n.value.scrollTop); } } function r(t = !1) { if (!n.value) return; let c = E.value, p = _.value; const a = c && (B !== n.value.scrollWidth || i !== n.value.offsetWidth), ae = _ && (f !== n.value.scrollHeight || C !== n.value.offsetHeight); if (!t && !a && !ae) return; const Y = window.getComputedStyle(n.value); (Y.overflow === "hidden" || Y.overflowX === "hidden") && (c = !1), (Y.overflow === "hidden" || Y.overflowY === "hidden") && (p = !1), h.show = c, M.show = p, S(), i = n.value.offsetWidth, C = n.value.offsetHeight, B = n.value.scrollWidth, f = n.value.scrollHeight, v("resized", B, f); } function A(t) { var c; u.scroll == "horizontal" && (t.deltaMode == 0 && ((c = n.value) == null || c.scrollTo({ left: n.value.scrollLeft + (t.deltaY > 0 ? Je : -140), behavior: "smooth" })), t.preventDefault(), t.stopPropagation()); } function R(t) { var c; t.deltaMode == 0 && ((c = n.value) == null || c.scrollTo({ left: n.value.scrollLeft + (t.deltaY > 0 ? Je : -140), behavior: "smooth" }), t.preventDefault(), t.stopPropagation()); } function F(t) { var c; t.deltaMode == 0 && ((c = n.value) == null || c.scrollTo({ top: n.value.scrollTop + (t.deltaY > 0 ? Ot : -70), behavior: "smooth" }), t.preventDefault(), t.stopPropagation()); } let U = 0, X = 0, L = 0, w = 0; const $ = Ze({ onDown(t) { return !d.value || !m.value ? !1 : (U = t.offsetX, X = t.x - t.offsetX - m.value.offsetLeft, t.preventDefault(), H.value = !0, !0); }, onMove(t, c, p) { n.value && d.value && (J(p.x - U - X), p.preventDefault(), p.stopPropagation()); }, onUp() { H.value = !1; } }), K = Ze({ onDown(t) { return !g.value || !x.value ? !1 : (L = t.offsetY, w = t.y - t.offsetY - x.value.offsetTop, t.preventDefault(), H.value = !0, !0); }, onMove(t, c, p) { n.value && g.value && (ne(p.y - L - w), p.preventDefault(), p.stopPropagation()); }, onUp() { H.value = !1; } }); function V(t) { n.value && (n.value.scrollLeft = t / 100 * (n.value.scrollWidth - n.value.offsetWidth)); } function Z(t) { n.value && (n.value.scrollLeft = t / 100 * (n.value.scrollHeight - n.value.offsetHeight)); } function J(t) { n.value && (n.value.scrollLeft = t / (n.value.offsetWidth - h.sizeRaw) * (n.value.scrollWidth - n.value.offsetWidth)); } function ne(t) { n.value && (n.value.scrollTop = t / (n.value.offsetHeight - M.sizeRaw) * (n.value.scrollHeight - n.value.offsetHeight)); } function I(t) { u.scrollBarBackgroundClickable && J(t.offsetX - h.sizeRaw / 2); } function de(t) { u.scrollBarBackgroundClickable && ne(t.offsetY - M.sizeRaw / 2); } const { startResizeChecker: Te, stopResizeChecker: Ce } = Wt( n, () => r(), () => r() ); return be(() => { ie(() => { setTimeout(() => r(!0), 200), r(!0), Te(), y = new MutationObserver(() => r()), y.observe(n.value, k); }); }), we(() => { Ce(), y && (y.disconnect(), y = null); }), o({ refreshScrollState() { r(!0); }, getScrollContainer() { return n.value; }, scrollTo(t, c) { var p; (p = n.value) == null || p.scrollTo(t, c); }, scrollToTop() { var t; (t = n.value) == null || t.scrollTo(0, 0); }, scrollToBottom() { var t; (t = n.value) == null || t.scrollTo(n.value.scrollWidth, n.value.scrollHeight); } }), (t, c) => (b(), P("div", { ref_key: "scrollrect", ref: O, class: oe([ "vue-scroll-rect", e.scrollBarAlwaysShow ? "always-show-scrollbar" : "", e.scrollBarBackgroundClickable ? "background-clickable" : "", H.value ? "dragging" : "" ]), style: Me({ width: e.width ? `${e.width}px` : void 0, height: e.height ? `${e.height}px` : void 0 }), onWheel: A }, [ D("div", { ref_key: "container", ref: n, class: oe(["scroll-content", e.scroll, e.containerClass]), style: Me({ maxWidth: e.maxWidth ? `${e.maxWidth}px` : void 0, maxHeight: e.maxHeight ? `${e.maxHeight}px` : void 0, ...e.containerStyle }), onScroll: S }, [ j(t.$slots, "default") ], 38), h.show ? j(t.$slots, "scrollBarX", { key: 0, scrollBarValue: h, onScroll: V }, () => [ D("div", { ref_key: "scrollBarRefX", ref: d, class: "scrollbar horizontal", onClick: I, onWheel: R }, [ D("div", { class: "thumb", ref_key: "scrollBarThumbRefX", ref: m, style: Me({ left: `${h.pos}%`, width: `${h.size}%` }), onMousedown: c[0] || (c[0] = //@ts-ignore (...p) => l($) && l($)(...p)), onWheel: R }, null, 36) ], 544) ]) : N("", !0), M.show ? j(t.$slots, "scrollBarY", { key: 1, scrollBarValue: M, onScroll: Z }, () => [ M.show ? (b(), P("div", { key: 0, ref_key: "scrollBarRefY", ref: g, class: "scrollbar vertical", onClick: de, onWheel: F }, [ D("div", { class: "thumb", ref_key: "scrollBarThumbRefY", ref: x, style: Me({ top: `${M.pos}%`, height: `${M.size}%` }), onMousedown: c[1] || (c[1] = //@ts-ignore (...p) => l(K) && l(K)(...p)), onWheel: F }, null, 36) ], 544)) : N("", !0) ]) : N("", !0) ], 38)); } }), Ie = (e, o) => { const s = e.__vccOpts || e; for (const [u, v] of o) s[u] = v; return s; }, Rt = {}, Bt = { class: "mx-checked-mark", "aria-hidden": "true", viewBox: "0 0 1024 1024" }, _t = /* @__PURE__ */ D("path", { d: "M129.3,428.6L52,512l345,372.5l575-620.8l-69.5-75L400.4,718.2L129.3,428.6z" }, null, -1), Pt = [ _t ]; function $t(e, o) { return b(), P("svg", Bt, Pt); } const At = /* @__PURE__ */ Ie(Rt, [["render", $t]]), Ft = {}, Lt = { class: "mx-right-arrow", "aria-hidden": "true", viewBox: "0 0 1024 1024" }, Tt = /* @__PURE__ */ D("path", { d: "M307.018 49.445c11.517 0 23.032 4.394 31.819 13.18L756.404 480.18c8.439 8.438 13.181 19.885 13.181 31.82s-4.741 23.38-13.181 31.82L338.838 961.376c-17.574 17.573-46.065 17.573-63.64-0.001-17.573-17.573-17.573-46.065 0.001-63.64L660.944 512 275.198 126.265c-17.574-17.573-17.574-46.066-0.001-63.64C283.985 53.839 295.501 49.445 307.018 49.445z" }, null, -1), Et = [ Tt ]; function zt(e, o) { return b(), P("svg", Lt, Et); } const jt = /* @__PURE__ */ Ie(Ft, [["render", zt]]), Dt = { class: "mx-item-row" }, Nt = ["xlink:href"], Kt = { key: 1, class: "label" }, Yt = { class: "mx-item-row" }, Vt = { class: "mx-shortcut" }, Fe = /* @__PURE__ */ te({ __name: "ContextMenuItem", props: { /** * Is this menu disabled? */ disabled: { type: Boolean, default: !1 }, /** * Is this menu hidden? */ hidden: { type: Boolean, default: !1 }, customRender: { type: Function, default: null }, /** * Custom css class for submenu */ customClass: { type: String, default: "" }, clickHandler: { type: Function, default: null }, /** * Menu label */ label: { type: [String, Object, Function], default: "" }, /** * Menu icon (for icon class) */ icon: { type: [String, Object, Function], default: "" }, /** * Custom icon library font class name. * * Only for css font icon, If you use the svg icon, you do not need to use this. */ iconFontClass: { type: String, default: "iconfont" }, /** * Is this menu item checked? * * The check mark are displayed on the left side of the icon, so it is not recommended to display the icon at the same time. */ checked: { type: Boolean, default: !1 }, /** * Shortcut key text display on the right. * * The shortcut keys here are only for display. You need to handle the key events by yourself. */ shortcut: { type: String, default: "" }, /** * Display icons use svg symbol (`<use xlink:href="#icon-symbol-name">`) , only valid when icon attribute is empty. */ svgIcon: { type: String, default: "" }, /** * The user-defined attribute of the svg tag, which is valid when using `svgIcon`. */ svgProps: { type: Object, default: null }, /** * Should a fixed-width icon area be reserved for menu items without icon. (this item) * * Default is true . * * The width of icon area can be override with css var `--mx-menu-placeholder-width`. */ preserveIconWidth: { type: Boolean, default: !0 }, /** * Show right arrow on this menu? */ showRightArrow: { type: Boolean, default: !1 }, hasChildren: { type: Boolean, default: !1 }, /** * Should close menu when Click this menu item ? */ clickClose: { type: Boolean, default: !0 }, /** * When there are subitems in this item, is it allowed to trigger its own click event? Default is false */ clickableWhenHasChildren: { type: Boolean, default: !1 }, rawMenuItem: { type: Object, default: void 0 } }, emits: [ "click", "subMenuOpen", "subMenuClose" ], setup(e, { expose: o, emit: s }) { const u = e, v = s, { clickHandler: n, clickClose: O, clickableWhenHasChildren: d, disabled: g, hidden: m, label: x, icon: H, iconFontClass: E, showRightArrow: _, shortcut: h, hasChildren: M } = ce(u), B = W(!1), f = W(!1), i = W(), C = z("globalOptions"), y = z("globalHasSlot"), k = z("globalRenderSlot"), S = z("globalCloseMenu"), r = z("menuContext"), A = Be(() => typeof x.value == "string" ? x.value : typeof x.value == "function" ? Mt(x.value.toString()) : "MenuItem[unknow]"); G("MenuItemName", A); const R = { getSubMenuInstance: () => { }, showSubMenu: () => B.value ? (r.markActiveMenuItem(R, !0), !0) : M.value ? (U(), !0) : !1, hideSubMenu: () => { r.closeOtherSubMenu(); }, isDisabledOrHidden: () => g.value || m.value, getElement: () => i.value, focus: () => f.value = !0, blur: () => f.value = !1, click: F }; G("menuItemInstance", R), be(() => { r.isMenuItemDataCollectedFlag() ? ie(() => { let w = 0; const $ = r.getElement(); if ($) { let K = 0; for (let V = 0; V < $.children.length; V++) { const Z = $.children[V]; if (Z.getAttribute("data-type") === "ContextMenuItem") { if (Z === i.value) { w = K; break; } K++; } } } r.addChildMenuItem(R, w); }) : r.addChildMenuItem(R); }), we(() => { r.removeChildMenuItem(R); }); function F(w) { if (!g.value) { if (w) { const $ = w.target; if ($.classList.contains("mx-context-no-clickable") || C.value.ignoreClickClassName && $.classList.contains(C.value.ignoreClickClassName)) return; if (C.value.clickCloseClassName && $.classList.contains(C.value.clickCloseClassName)) { w.stopPropagation(), S(u.rawMenuItem); return; } } M.value ? d.value ? (typeof n.value == "function" && n.value(w), v("click", w)) : B.value || U() : (typeof n.value == "function" && n.value(w), v("click", w), O.value && S(u.rawMenuItem)); } } function U(w) { f.value = !1, r.checkCloseOtherSubMenuTimeOut() || r.closeOtherSubMenu(), g.value || (r.markActiveMenuItem(R), M.value && (w || r.markThisOpenedByKeyBoard(), r.addOpenedSubMenu(X), B.value = !0, ie(() => v("subMenuOpen", R)))); } function X() { f.value = !1, B.value = !1, v("subMenuClose", R); } function L() { return { disabled: g.value, label: x.value, icon: H.value, iconFontClass: E.value, showRightArrow: _.value, clickClose: O.value, clickableWhenHasChildren: d.value, shortcut: h.value, theme: C.value.theme, isOpen: B, hasChildren: M, onClick: F, onMouseEnter: U, closeMenu: S }; } return o(R), (w, $) => { var K; return l(m) ? N("", !0) : (b(), P("div", ke({ key: 0, class: "mx-context-menu-item-wrapper", ref_key: "menuItemRef", ref: i, "data-type": "ContextMenuItem" }, { ...w.$attrs, ...((K = e.rawMenuItem) == null ? void 0 : K.attrs) || {} }), [ l(y)("itemRender") ? (b(), T(l(q), { key: 0, vnode: () => l(k)("itemRender", L()) }, null, 8, ["vnode"])) : e.customRender ? (b(), T(l(q), { key: 1, vnode: e.customRender, data: L() }, null, 8, ["vnode", "data"])) : (b(), P("div", { key: 2, class: oe([ "mx-context-menu-item", l(g) ? "disabled" : "", f.value ? "keyboard-focus" : "", e.customClass ? " " + e.customClass : "", B.value ? "open" : "" ]), onClick: F, onMouseenter: U }, [ j(w.$slots, "default", {}, () => [ D("div", Dt, [ D("div", { class: oe([ "mx-icon-placeholder", e.preserveIconWidth ? "preserve-width" : "" ]) }, [ j(w.$slots, "icon", {}, () => [ l(y)("itemIconRender") ? (b(), T(l(q), { key: 0, vnode: () => l(k)("itemIconRender", L()) }, null, 8, ["vnode"])) : typeof e.svgIcon == "string" && e.svgIcon ? (b(), P("svg", ke({ key: 1, class: "icon svg" }, e.svgProps), [ D("use", { "xlink:href": e.svgIcon }, null, 8, Nt) ], 16)) : typeof l(H) != "string" ? (b(), T(l(q), { key: 2, vnode: l(H), data: l(H) }, null, 8, ["vnode", "data"])) : typeof l(H) == "string" && l(H) !== "" ? (b(), P("i", { key: 3, class: oe(l(H) + " icon " + l(E) + " " + l(C).iconFontClass) }, null, 2)) : N("", !0) ]), e.checked ? j(w.$slots, "check", { key: 0 }, () => [ l(y)("itemCheckRender") ? (b(), T(l(q), { key: 0, vnode: () => l(k)("itemCheckRender", L()) }, null, 8, ["vnode"])) : N("", !0), re(At) ]) : N("", !0) ], 2), j(w.$slots, "label", {}, () => [ l(y)("itemLabelRender") ? (b(), T(l(q), { key: 0, vnode: () => l(k)("itemLabelRender", L()) }, null, 8, ["vnode"])) : typeof l(x) == "string" ? (b(), P("span", Kt, _e(l(x)), 1)) : (b(), T(l(q), { key: 2, vnode: l(x), data: l(x) }, null, 8, ["vnode", "data"])) ]) ]), D("div", Yt, [ l(h) || w.$slots.shortcut ? j(w.$slots, "shortcut", { key: 0 }, () => [ l(y)("itemShortcutRender") ? (b(), T(l(q), { key: 0, vnode: () => l(k)("itemShortcutRender", L()) }, null, 8, ["vnode"])) : N("", !0), D("span", Vt, _e(l(h)), 1) ]) : N("", !0), l(_) ? j(w.$slots, "rightArrow", { key: 1 }, () => [ l(y)("itemRightArrowRender") ? (b(), T(l(q), { key: 0, vnode: () => l(k)("itemRightArrowRender", L()) }, null, 8, ["vnode"])) : N("", !0), re(jt) ]) : N("", !0) ]) ]) ], 34)), j(w.$slots, "submenu", { context: R, show: B.value }) ], 16)); }; } }), Ut = te({ name: "ContextMenuSperator", components: { VNodeRender: q }, setup() { const e = z("globalHasSlot"), o = z("globalRenderSlot"); return { globalHasSlot: e, globalRenderSlot: o }; } }), Xt = { key: 1, class: "mx-context-menu-item-sperator mx-context-no-clickable" }; function Zt(e, o, s, u, v, n) { const O = et("VNodeRender"); return e.globalHasSlot("separatorRender") ? (b(), T(O, { key: 0, vnode: () => e.globalRenderSlot("separatorRender", {}) }, null, 8, ["vnode"])) : (b(), P("div", Xt)); } const ge = /* @__PURE__ */ Ie(Ut, [["render", Zt]]), Le = /* @__PURE__ */ te({ __name: "ContextSubMenu", props: { /** * Items from options */ items: { type: Object, default: null }, /** * Show */ show: { type: Boolean, default: !1 }, /** * Should the menu be destroyed when it is closed? */ destroyOnClose: { type: Boolean, default: !0 }, /** * Max height for this submenu */ maxHeight: { type: Number, default: 0 }, /** * Max width for this submenu */ maxWidth: { type: [String, Number], default: 0 }, /** * Min width for this submenu */ minWidth: { type: [String, Number], default: 0 }, /** * Specifies should submenu adjust it position * when the menu exceeds the screen. The default is true */ adjustPosition: { type: Boolean, default: !0 }, /** * Menu direction */ direction: { type: String, default: "br" }, parentMenuItemContext: { type: Object, default: null } }, emits: ["closeAnimFinished"], setup(e, { expose: o, emit: s }) { const u = e, v = s, n = W(!1), O = z("globalGetMenuHostId", ""), d = z("menuContext"), g = z("globalOptions"); z("globalHasSlot"), z("globalRenderSlot"); const m = W("UnknowOrRoot"), x = z("MenuItemName", m), { zIndex: H, getParentWidth: E, getParentHeight: _, getZoom: h } = d, { adjustPosition: M } = ce(u), B = W(), f = W(), i = W(), C = [], y = z("globalSetCurrentSubMenu"), k = []; let S = null, r = 0; function A() { S && S.blur(); } function R(t, c) { if (t) { for (let p = c !== void 0 ? c : 0; p < k.length; p++) if (!k[p].isDisabledOrHidden()) { F(p); break; } } else for (let p = c !== void 0 ? c : k.length - 1; p >= 0; p--) if (!k[p].isDisabledOrHidden()) { F(p); break; } } function F(t) { if (S && A(), t !== void 0 && (S = k[Math.max(0, Math.min(t, k.length - 1))]), !S) return; S.focus(); const c = S.getElement(); c && c.scrollIntoView({ behavior: "auto", block: "nearest", inline: "nearest" }); } function U() { y(X); } const X = { el: i, name: x, isTopLevel: () => d.getParentContext() === null, closeSelfAndActiveParent: () => { const t = $.getParentContext(); if (t) { t.closeOtherSubMenu(); const c = t.getSubMenuInstanceContext(); if (c) return c.focusCurrentItem(), !0; } return !1; }, closeCurrentSubMenu: () => { var t; return (t = $.getParentContext()) == null ? void 0 : t.closeOtherSubMenu(); }, moveCurrentItemFirst: () => R(!0), moveCurrentItemLast: () => R(!1), moveCurrentItemDown: () => R(!0, S ? k.indexOf(S) + 1 : 0), moveCurrentItemUp: () => R(!1, S ? k.indexOf(S) - 1 : 0), focusCurrentItem: () => F(), openCurrentItemSubMenu: () => S ? S == null ? void 0 : S.showSubMenu() : !1, triggerCurrentItemClick: (t) => S == null ? void 0 : S.click(t) }; let L = !1, w = !1; const $ = { zIndex: H + 1, container: d.container, adjustPadding: g.value.adjustPadding || ee.defaultAdjustPadding, getParentWidth: () => { var t; return ((t = i.value) == null ? void 0 : t.offsetWidth) || 0; }, getParentHeight: () => { var t; return ((t = i.value) == null ? void 0 : t.offsetHeight) || 0; }, getPositon: () => [I.value.x, I.value.y], getZoom: () => g.value.zoom || ee.defaultZoom, addOpenedSubMenu(t) { C.push(t); }, closeOtherSubMenu() { C.forEach((t) => t()), C.splice(0, C.length), y(X); }, checkCloseOtherSubMenuTimeOut() { return r ? (clearTimeout(r), r = 0, !0) : !1; }, closeOtherSubMenuWithTimeOut() { r = setTimeout(() => { r = 0, this.closeOtherSubMenu(); }, 200); }, addChildMenuItem: (t, c) => { c === void 0 ? k.push(t) : k.splice(c, 0, t); }, removeChildMenuItem: (t) => { k.splice(k.indexOf(t), 1), t.getSubMenuInstance = () => { }; }, markActiveMenuItem: (t, c = !1) => { A(), S = t, c && F(); }, markThisOpenedByKeyBoard: () => { L = !0; }, isOpenedByKeyBoardFlag: () => L ? (L = !1, !0) : !1, isMenuItemDataCollectedFlag: () => w, getElement: () => i.value || null, getParentContext: () => d, getSubMenuInstanceContext: () => X }; G("menuContext", $); const K = { getChildItem: (t) => k[t], getMenuDimensions: () => f.value ? { width: f.value.offsetWidth, height: f.value.offsetHeight } : { width: 0, height: 0 }, getSubmenuRoot: () => f.value, getMenu: () => i.value, getScrollValue: () => { var t, c; return ((c = (t = B.value) == null ? void 0 : t.getScrollContainer()) == null ? void 0 : c.scrollTop) || 0; }, setScrollValue: (t) => { var c; return (c = B.value) == null ? void 0 : c.scrollTo(0, t); }, getScrollHeight: () => Z.value, adjustPosition: () => { de(); }, getMaxHeight: () => J.value, getPosition: () => I.value, setPosition: (t, c) => { I.value.x = t, I.value.y = c; } }, V = z("menuItemInstance", void 0); V && (V.getSubMenuInstance = () => K); const Z = W(0), J = W(0), ne = W(!1), I = W({ x: 0, y: 0 }); function de() { ie(() => { var p; const t = i.value, c = f.value; if (t && c && B.value) { const { container: a } = d, ae = (E == null ? void 0 : E()) ?? 0, Y = (_ == null ? void 0 : _()) ?? 0, Q = getComputedStyle(c), ye = parseFloat(Q.paddingLeft), xe = parseFloat(Q.paddingTop), We = Y > 0 ? xe : 0, at = document.documentElement.scrollHeight / h(), it = document.documentElement.scrollWidth / h(), rt = Math.min(it, a.offsetWidth), Ee = Math.min(at, a.offsetHeight); let Oe = ue(t, a), He = se(t, a); if (u.direction.includes("l") ? I.value.x -= t.offsetWidth + ye : u.direction.includes("r") ? I.value.x += ae + ye : (I.value.x += ae / 2, I.value.x -= (t.offsetWidth + ye) / 2), u.direction.includes("t")) { const fe = (p = u.parentMenuItemContext) == null ? void 0 : p.getElement(); fe && (I.value.y += fe.offsetHeight), I.value.y -= (t.offsetHeight + xe) / h(); } else u.direction.includes("b") ? I.value.y -= xe / h() : I.value.y -= t.offsetHeight / 2 / h(); ie(() => { var je, De; Oe = ue(t, a), He = se(t, a); const fe = ((De = (je = B.value) == null ? void 0 : je.getScrollContainer()) == null ? void 0 : De.scrollHeight) || 0, ct = u.maxHeight; Z.value = u.maxHeight ? Math.min(fe, u.maxHeight) : fe; const dt = Oe + t.offsetWidth - rt, ze = He + Z.value + We * 2 - Ee; if (ne.value = ze > 0, M.value && dt > 0) { const ve = ae + t.offsetWidth - ye, he = Oe; ve > he ? I.value.x -= he : I.value.x -= ve; } if (ne.value) { if (M.value) { const ve = ze, he = He; ve > he ? I.value.y -= he - We : I.value.y -= ve - We; } J.value = Ee - (I.value.y + xe); } else J.value = ct || 0; }); } }); } function Te() { } function Ce() { var c; const t = (c = u.parentMenuItemContext) == null ? void 0 : c.getElement(); if (t) { const p = ue(t, d.container), a = se(t, d.container); I.value.x = p, I.value.y = a; } else { const [p, a] = d.getPositon(); I.value.x = p, I.value.y = a; } ie(() => { var p; y(X), (p = i.value) == null || p.focus({ preventScroll: !0 }), d.isOpenedByKeyBoardFlag() && ie(() => R(!0)), w = !0; }), de(); } return $e(() => u.show, (t) => { t ? Ce() : void 0; }), be(() => { n.value = !0, u.show ? Ce() : de(); }), we(() => { n.value = !1, V && (V.getSubMenuInstance = () => { }); }), o(K), (t, c) => { const p = et("ContextSubMenu", !0); return n.value ? (b(), T(tt, { key: 0, to: `#${l(O)}` }, [ re(ft, ke({ appear: "" }, l(g).menuTransitionProps || { duration: 10 }, { onAfterLeave: c[0] || (c[0] = (a) => v("closeAnimFinished")) }), { default: pe(() => [ !e.destroyOnClose || e.show ? vt((b(), P("div", ke({ key: 0, ref_key: "submenuRoot", ref: f }, t.$attrs, { class: [ "mx-context-menu", l(g).customClass ? l(g).customClass : "", l(g).theme ?? "" ], style: { maxWidth: e.maxWidth ? l(Ve)(e.maxWidth) : `${l(ee).defaultMaxWidth}px`, minWidth: e.minWidth ? l(Ve)(e.minWidth) : `${l(ee).defaultMinWidth}px`, zIndex: l(H), left: `${I.value.x}px`, top: `${I.value.y}px` }, "data-type": "ContextSubMenu", onClick: U }), [ re(l(Ht), { ref_key: "scrollRectRef", ref: B, scroll: "vertical", maxHeight: J.value, containerClass: "mx-context-menu-scroll" }, { default: pe(() => [ D("div", { class: oe(["mx-context-menu-items"]), ref_key: "menu", ref: i }, [ j(t.$slots, "default", {}, () => [ (b(!0), P(Pe, null, Ae(e.items, (a, ae) => (b(), P(Pe, { key: ae }, [ a.hidden !== !0 && a.divided === "up" ? (b(), T(ge, { key: 0 })) : N("", !0), a.hidden !== !0 && a.divided === "self" ? (b(), T(ge, { key: 1 })) : (b(), T(Fe, { key: 2, clickHandler: a.onClick ? (Y) => a.onClick(Y) : void 0, disabled: typeof a.disabled == "object" ? a.disabled.value : a.disabled, hidden: typeof a.hidden == "object" ? a.hidden.value : a.hidden, icon: a.icon, iconFontClass: a.iconFontClass, svgIcon: a.svgIcon, svgProps: a.svgProps, label: a.label, customRender: a.customRender, customClass: a.customClass, checked: typeof a.checked == "object" ? a.checked.value : a.checked, shortcut: a.shortcut, clickClose: a.clickClose, clickableWhenHasChildren: a.clickableWhenHasChildren, preserveIconWidth: a.preserveIconWidth !== void 0 ? a.preserveIconWidth : l(g).preserveIconWidth, showRightArrow: a.children && a.children.length > 0, hasChildren: a.children && a.children.length > 0, rawMenuItem: a, onSubMenuOpen: (Y) => { var Q; return (Q = a.onSubMenuOpen) == null ? void 0 : Q.call(a, Y); }, onSubMenuClose: (Y) => { var Q; return (Q = a.onSubMenuClose) == null ? void 0 : Q.call(a, Y); } }, nt({ _: 2 }, [ a.children && a.children.length > 0 ? { name: "submenu", fn: pe(({ context: Y, show: Q }) => [ re(p, { show: Q, destroyOnClose: e.destroyOnClose, parentMenuItemContext: Y, items: a.children, maxWidth: a.maxWidth, minWidth: a.minWidth, maxHeight: a.maxHeight, adjustPosition: a.adjustSubMenuPosition !== void 0 ? a.adjustSubMenuPosition : l(g).adjustPosition, direction: a.direction !== void 0 ? a.direction : l(g).direction }, null, 8, ["show", "destroyOnClose", "parentMenuItemContext", "items", "maxWidth", "minWidth", "maxHeight", "adjustPosition", "direction"]) ]), key: "0" } : void 0 ]), 1032, ["clickHandler", "disabled", "hidden", "icon", "iconFontClass", "svgIcon", "svgProps", "label", "customRender", "customClass", "checked", "shortcut", "clickClose", "clickableWhenHasChildren", "preserveIconWidth", "showRightArrow", "hasChildren", "rawMenuItem", "onSubMenuOpen", "onSubMenuClose"])), a.hidden !== !0 && (a.divided === "down" || a.divided === !0) ? (b(), T(ge, { key: 3 })) : N("", !0) ], 64))), 128)) ]) ], 512) ]), _: 3 }, 8, ["maxHeight"]) ], 16)), [ [ht, e.show] ]) : N("", !0) ]), _: 3 }, 16) ], 8, ["to"])) : N("", !0); }; } }); const ut = /* @__PURE__ */ te({ __name: "ContextSubMenuWrapper", props: { /** * Menu options */ options: { type: Object, default: null }, /** * Show menu? */ show: { type: null, default: null }, /** * Should the menu be destroyed when it is closed? */ destroyOnClose: { type: Boolean, default: !0 }, /** * Current container, For calculation only */ container: { type: Object, default: null }, /** * Make sure is user set the custom container. */ isFullScreenContainer: { type: Boolean, default: !0 } }, emits: ["close", "closeAnimFinished"], setup(e, { expose: o, emit: s }) { const u = e, v = s, n = ot(), O = W(), { options: d, show: g, destroyOnClose: m, container: x } = ce(u); be(() => { g.value && _(); }), we(() => { f(); }), $e(g, (r) => { r ? _() : (Ye(H), f()); }); const H = { closeMenu: h, isClosed: M, getMenuRef: () => O.value, getMenuDimensions: () => { var r; return ((r = O.value) == null ? void 0 : r.getMenuDimensions()) ?? { width: 0, height: 0 }; } }; let E = !1; function _() { B(), bt(H); } function h(r) { E = !0, v("close", r), d.value.menuTransitionProps || v("closeAnimFinished"), Ye(H); } function M() { return E; } function B() { setTimeout(() => { document.addEventListener("click", k, !0), document.addEventListener("contextmenu", k, !0), document.addEventListener("scroll", y, !0), !u.isFullScreenContainer && x.value && x.value.addEventListener("scroll", y, !0), d.value.keyboardControl !== !1 && document.addEventListener("keydown", C, !0); }, 50); } function f() { document.removeEventListener("contextmenu", k, !0), document.removeEventListener("click", k, !0), document.removeEventListener("scroll", y, !0), !u.isFullScreenContainer && x.value && x.value.removeEventListener("scroll", y, !0), d.value.keyboardControl !== !1 && document.removeEventListener("keydown", C, !0); } const i = W(); G("globalSetCurrentSubMenu", (r) => i.value = r), G("globalGetMenuHostId", x.value.id); function C(r) { var R, F, U, X, L, w, $, K, V, Z, J, ne, I; let A = !0; switch (r.key) { case "Escape": { ((R = i.value) == null ? void 0 : R.isTopLevel()) === !1 ? (F = i.value) == null || F.closeCurrentSubMenu() : h(); break; } case "ArrowDown": (U = i.value) == null || U.moveCurrentItemDown(); break; case "ArrowUp": (X = i.value) == null || X.moveCurrentItemUp(); break; case "Home": (L = i.value) == null || L.moveCurrentItemFirst(); break; case "End": (w = i.value) == null || w.moveCurrentItemLast(); break; case "ArrowLeft": { ($ = i.value) != null && $.closeSelfAndActiveParent() || (V = (K = d.value).onKeyFocusMoveLeft) == null || V.call(K); break; } case "ArrowRight": (Z = i.value) != null && Z.openCurrentItemSubMenu() || (ne = (J = d.value).onKeyFocusMoveRight) == null || ne.call(J); break; case "Enter": (I = i.value) == null || I.triggerCurrentItemClick(r); break; default: A = !1; break; } A && i.value && (r.stopPropagation(), r.preventDefault()); } function y(r) { d.value.closeWhenScroll !== !1 && S(r.target, null); } function k(r) { S(r.target, r); } function S(r, A) { var R, F; for (; r; ) { if (r.classList && r.classList.contains("mx-context-menu")) return; r = r.parentNode; } A ? d.value.clickCloseOnOutside !== !1 ? (f(), h()) : (F = (R = d.value).onClickOnOutside) == null || F.call(R, A) : (f(), h()); } return G("globalOptions", d), G("globalCloseMenu", h), G("globalIsFullScreenContainer", u.isFullScreenContainer), G("globalHasSlot", (r) => n[r] !== void 0), G("globalRenderSlot", (r, A) => j(n, r, { ...A }, () => [Se("span", "Render slot failed")], !1)), G("menuContext", { zIndex: d.value.zIndex || ee.defaultZindex, container: x.value, adjustPadding: { x: 0, y: 0 }, getZoom: () => d.value.zoom || ee.defaultZoom, getParentWidth: () => 0, getParentHeight: () => 0, getPositon: () => [d.value.x, d.value.y], closeOtherSubMenuWithTimeOut: () => { }, checkCloseOtherSubMenuTimeOut: () => !1, addOpenedSubMenu: () => { }, closeOtherSubMenu: () => { }, getParentContext: () => null, getSubMenuInstanceContext: () => null, getElement: () => null, addChildMenuItem: () => { }, removeChildMenuItem: () => { }, markActiveMenuItem: () => { }, markThisOpenedByKeyBoard: () => { }, isOpenedByKeyBoardFlag: () => !1, isMenuItemDataCollectedFlag: () => !1 }), o(H), (r, A) => (b(), T(Le, { ref_key: "submenuInstance", ref: O, show: l(g), destroyOnClose: l(m), items: l(d).items, adjustPosition: l(d).adjustPosition, maxWidth: l(d).maxWidth || l(ee).defaultMaxWidth, minWidth: l(d).minWidth || l(ee).defaultMinWidth, maxHeight: l(d).maxHeight, direction: l(d).direction || l(ee).defaultDirection, onCloseAnimFinished: A[0] || (A[0] = (R) => v("closeAnimFinished")) }, { default: pe(() => [ j(r.$slots, "default") ]), _: 3 }, 8, ["show", "destroyOnClose", "items", "adjustPosition", "maxWidth", "minWidth", "maxHeight", "direction"])); } }); const Gt = /* @__PURE__ */ te({ __name: "ContextMenu", props: { /** * Menu options */ options: { type: Object, default: null }, /** * Show menu? */ show: { type: Boolean, default: !1 }, /** * Should the menu be destroyed when it is closed? */ destroyOnClose: { type: Boolean, default: !0 } }, emits: ["update:show", "close"], setup(e, { expose: o, emit: s }) { const u = s, v = e, { options: n, show: O, destroyOnClose: d } = ce(v), { isNew: g, container: m, eleId: x } = st(n.value), H = W(null), E = ot(); function _(h) { var M, B; u("update:show", !1), u("close"), (B = (M = n.value).onClose) == null || B.call(M, h); } return o({ closeMenu: () => u("update:show", !1), isClosed: () => !O.value, getMenuRef: () => { var h; return (h = H.value) == null ? void 0 : h.getMenuRef(); }, getMenuDimensions: () => { var h; return ((h = H.value) == null ? void 0 : h.getMenuDimensions()) ?? { width: 0, height: 0 }; } }), (h, M) => (b(), T(tt, { to: `#${l(x)}` }, [ re(ut, { ref_key: "menuRef", ref: H, options: l(n), show: l(O), destroyOnClose: l(d), container: l(m), isFullScreenContainer: !l(g), onClose: _ }, nt({ _: 2 }, [ Ae(l(E), (B, f) => ({ name: f, fn: pe((i) => [ j(h.$slots, f, mt(pt(i))) ]) })) ]), 1032, ["options", "show", "destroyOnClose", "container", "isFullScreenContainer"]) ], 8, ["to"])); } }), Jt = te({ name: "ContextMenuGroup", props: { /** * Is this menu disabled? */ disabled: { type: Boolean, default: !1 }, /** * Is this menu hidden? */ hidden: { type: Boolean, default: !1 }, /** * Is this menu disabled? */ clickHandler: { type: Function, default: null }, /** * Menu label */ label: { type: String, default: "" }, /** * Menu icon (for icon class) */ icon: { type: String, default: "" }, /** * Custom icon library font class name. * * Only for css font icon, If you use the svg icon, you do not need to use this. */ iconFontClass: { type: String, default: "iconfont" }, /** * Is this menu item checked? * * The check mark are displayed on the left side of the icon, so it is not recommended to display the icon at the same time. */ checked: { type: Boolean, default: !1 }, /** * Shortcut key text display on the right. * * The shortcut keys here are only for display. You need to handle the key events by yourself. */ shortcut: { type: String, default: "" }, /** * Display icons use svg symbol (`<use xlink:href="#icon-symbol-name">`) , only valid when icon attribute is empty. */ svgIcon: { type: String, default: "" }, /** * The user-defined attribute of the svg tag, which is valid when using `svgIcon`. */ svgProps: { type: Object, default: null }, /** * Should a fixed-width icon area be reserved for menu items without icon. (this item) * * Default is true . * * The width of icon area can be override with css var `--mx-menu-placeholder-width`. */ preserveIconWidth: { type: Boolean, default: !0 }, /** * Show right arrow on this menu? */ showRightArrow: { type: Boolean, default: !1 }, /** * Should close menu when Click this menu item ? */ clickClose: { type: Boolean, default: !0 }, /** * By default, the submenu will automatically adjust its position to prevent it overflow the container. * * If you allow menu overflow containers, you can set this to false. * * Default is inherit from `MenuOptions.adjustPosition` . */ adjustSubMenuPosition: { type: Boolean, default: void 0 }, /** * Max height of submenu */ maxHeight: { type: [String, Number], default: 0 }, /** * Max width of submenu */ maxWidth: { type: [String, Number], default: 0 }, /** * Min width of submenu */ minWidth: { type: [String, Number], default: 0 } }, setup(e, o) { const s = z("globalOptions"), { adjustSubMenuPosition: u, maxWidth: v, minWidth: n, maxHeight: O } = ce(e), d = typeof u.value < "u" ? u.value : s.value.adjustPosition, g = W(), m = W(); return o.expose({ getSubMenuRef: () => g.value, getMenuItemRef: () => m.value }), () => Se(Fe, { ...e, ref: m, showRightArrow: !0, maxWidth: void 0, minWidth: void 0, maxHeight: void 0, adjustSubMenuPosition: void 0, hasChildren: typeof o.slots.default !== void 0 }, o.slots.default ? { //Create SubMenu submenu: (x) => Se(Le, { ref: g, show: x.show, maxWidth: v.value, minWidth: n.value, maxHeight: O.value, adjustPosition: d, parentMenuItemCo