st-comp 0.0.163 → 0.0.164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";const t=require("vue"),g=require("./_plugin-vue_export-helper-f246444f.cjs");const y={__name:"index",emits:["close","open"],setup(d,{emit:f}){const m=f,s=t.ref(),c=t.ref(),i=t.ref({x:0,y:0}),u=t.ref(!1),p=t.computed(()=>({display:u.value?"block":"none",top:`${i.value.y}px`,left:`${i.value.x}px`})),r=()=>{u.value=!1,m("close"),document.removeEventListener("click",r)},v=e=>{var n;(n=c.value)!=null&&n.contains(e.relatedTarget)||r()},x=async e=>{if(e.preventDefault(),u.value&&c.value){const a=c.value.getBoundingClientRect();if(e.clientX>=a.left&&e.clientX<=a.right&&e.clientY>=a.top&&e.clientY<=a.bottom)return}const n=s.value.getBoundingClientRect();let o=e.clientX-n.left,l=e.clientY-n.top;i.value={x:o,y:l},u.value=!0,m("open"),await t.nextTick(),_(),document.addEventListener("click",r)},_=()=>{if(!c.value||!s.value)return;const e=s.value.getBoundingClientRect(),n=c.value.getBoundingClientRect();let{x:o,y:l}=i.value;o+n.width>e.width&&(o=Math.max(0,o-n.width)),l+n.height>e.height&&(l=Math.max(0,l-n.height)),o<0&&(o=0),l<0&&(l=0),i.value={x:o,y:l}};return(e,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"contextmenuRef",ref:s,class:"contextmenu",onMouseleave:v,onContextmenu:x},[t.renderSlot(e.$slots,"default",{},void 0,!0),u.value?(t.openBlock(),t.createElementBlock("div",{key:0,ref_key:"contextmenuContentRef",ref:c,class:"contextmenu-popover",style:t.normalizeStyle(p.value),onContextmenu:n[0]||(n[0]=t.withModifiers(()=>{},["stop"]))},[t.renderSlot(e.$slots,"popover",{},void 0,!0)],36)):t.createCommentVNode("",!0)],544))}},C=g._export_sfc(y,[["__scopeId","data-v-34926651"]]),h={install(d){d.component("st-contextmenu",C)}};module.exports=h;
@@ -0,0 +1,60 @@
1
+ import { ref as a, computed as h, openBlock as f, createElementBlock as p, renderSlot as v, normalizeStyle as R, withModifiers as k, createCommentVNode as M, nextTick as B } from "vue";
2
+ import { _ as w } from "./_plugin-vue_export-helper-dad06003.js";
3
+ const S = {
4
+ __name: "index",
5
+ emits: ["close", "open"],
6
+ setup(m, { emit: x }) {
7
+ const d = x, u = a(), l = a(), i = a({ x: 0, y: 0 }), c = a(!1), _ = h(() => ({
8
+ display: c.value ? "block" : "none",
9
+ top: `${i.value.y}px`,
10
+ left: `${i.value.x}px`
11
+ })), r = () => {
12
+ c.value = !1, d("close"), document.removeEventListener("click", r);
13
+ }, g = (e) => {
14
+ var t;
15
+ (t = l.value) != null && t.contains(e.relatedTarget) || r();
16
+ }, y = async (e) => {
17
+ if (e.preventDefault(), c.value && l.value) {
18
+ const s = l.value.getBoundingClientRect();
19
+ if (e.clientX >= s.left && e.clientX <= s.right && e.clientY >= s.top && e.clientY <= s.bottom)
20
+ return;
21
+ }
22
+ const t = u.value.getBoundingClientRect();
23
+ let n = e.clientX - t.left, o = e.clientY - t.top;
24
+ i.value = { x: n, y: o }, c.value = !0, d("open"), await B(), C(), document.addEventListener("click", r);
25
+ }, C = () => {
26
+ if (!l.value || !u.value)
27
+ return;
28
+ const e = u.value.getBoundingClientRect(), t = l.value.getBoundingClientRect();
29
+ let { x: n, y: o } = i.value;
30
+ n + t.width > e.width && (n = Math.max(0, n - t.width)), o + t.height > e.height && (o = Math.max(0, o - t.height)), n < 0 && (n = 0), o < 0 && (o = 0), i.value = { x: n, y: o };
31
+ };
32
+ return (e, t) => (f(), p("div", {
33
+ ref_key: "contextmenuRef",
34
+ ref: u,
35
+ class: "contextmenu",
36
+ onMouseleave: g,
37
+ onContextmenu: y
38
+ }, [
39
+ v(e.$slots, "default", {}, void 0, !0),
40
+ c.value ? (f(), p("div", {
41
+ key: 0,
42
+ ref_key: "contextmenuContentRef",
43
+ ref: l,
44
+ class: "contextmenu-popover",
45
+ style: R(_.value),
46
+ onContextmenu: t[0] || (t[0] = k(() => {
47
+ }, ["stop"]))
48
+ }, [
49
+ v(e.$slots, "popover", {}, void 0, !0)
50
+ ], 36)) : M("", !0)
51
+ ], 544));
52
+ }
53
+ }, $ = /* @__PURE__ */ w(S, [["__scopeId", "data-v-34926651"]]), X = {
54
+ install(m) {
55
+ m.component("st-contextmenu", $);
56
+ }
57
+ };
58
+ export {
59
+ X as default
60
+ };