vexip-ui
Version:
A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good
81 lines (80 loc) • 2.86 kB
JavaScript
import { defineComponent as k, ref as s, reactive as w, createBlock as x, openBlock as c, unref as e, withModifiers as S, normalizeStyle as $, normalizeClass as b, withCtx as C, createVNode as B, createElementBlock as R, Fragment as z, renderList as F } from "vue";
import "../dropdown/index.mjs";
import "../dropdown-list/index.mjs";
import "../renderer/index.mjs";
import { useNameHelper as N } from "@vexip-ui/config";
import { useRtl as E } from "@vexip-ui/hooks";
import { isFunction as _ } from "@vexip-ui/utils";
import { renderItem as H } from "./render.mjs";
import I from "../dropdown/dropdown.vue2.mjs";
import L from "../dropdown/dropdown-list.vue2.mjs";
import M from "../renderer/renderer.mjs";
const K = /* @__PURE__ */ k({
name: "Contextmenu",
__name: "contextmenu",
setup(O, { expose: g }) {
const n = N("contextmenu"), { isRtl: y } = E(), o = s(!1), i = s([]), f = s(!1), a = w({
x: 0,
y: 0
}), u = s(null), m = s(null);
function h(l) {
return a.x = l.clientX || 0, a.y = l.clientY || 0, i.value = l.configs, f.value = l.appear ?? !1, o.value = !0, new Promise((r) => {
u.value = (t) => {
r(t);
}, m.value = () => {
r(null);
};
});
}
function p() {
u.value = null, m.value = null;
}
function v(l) {
o.value = !1, _(u.value) && (u.value(l), p());
}
function d() {
o.value = !1, _(m.value) && (m.value(), p());
}
return g({ visible: o, position: a, openContextmenu: h, handleSelect: v, handleCancel: d }), (l, r) => (c(), x(e(I), {
visible: o.value,
"onUpdate:visible": r[0] || (r[0] = (t) => o.value = t),
class: b([e(n).b(), e(n).bs("vars")]),
trigger: "click",
placement: e(y) ? "left-start" : "right-start",
appear: f.value,
transfer: !1,
style: $({
top: `${a.y}px`,
left: `${a.x}px`
}),
onContextmenu: r[1] || (r[1] = S(() => {
}, ["prevent", "stop"])),
onSelect: v,
onOutsideClose: d
}, {
drop: C(() => [
B(e(L), {
class: b([
e(n).be("list"),
i.value.some((t) => t.icon) ? e(n).bem("list", "icons") : e(n).bem("list", "no-icon"),
i.value.some((t) => t.children && t.children.length) ? e(n).bem("list", "arrows") : e(n).bem("list", "no-arrow")
])
}, {
default: C(() => [
(c(!0), R(z, null, F(i.value, (t) => (c(), x(e(M), {
key: t.key,
data: { config: t, nh: e(n) },
renderer: e(H)
}, null, 8, ["data", "renderer"]))), 128))
]),
_: 1
}, 8, ["class"])
]),
_: 1
}, 8, ["visible", "class", "placement", "appear", "style"]));
}
});
export {
K as default
};
//# sourceMappingURL=contextmenu.vue2.mjs.map