asterui 0.12.10 → 0.12.12
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.
- package/dist/components/Anchor.d.ts +10 -0
- package/dist/components/Breadcrumb.d.ts +20 -3
- package/dist/components/ContextMenu.d.ts +39 -3
- package/dist/components/Menu.d.ts +29 -4
- package/dist/components/Space.d.ts +1 -0
- package/dist/components/Splitter.d.ts +2 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +63 -65
- package/dist/index.js.map +1 -1
- package/dist/index100.js +11 -44
- package/dist/index100.js.map +1 -1
- package/dist/index101.js +12 -10
- package/dist/index101.js.map +1 -1
- package/dist/index102.js +7 -14
- package/dist/index102.js.map +1 -1
- package/dist/index103.js +12 -7
- package/dist/index103.js.map +1 -1
- package/dist/index104.js +29 -11
- package/dist/index104.js.map +1 -1
- package/dist/index105.js +16 -29
- package/dist/index105.js.map +1 -1
- package/dist/index19.js +161 -63
- package/dist/index19.js.map +1 -1
- package/dist/index3.js +81 -65
- package/dist/index3.js.map +1 -1
- package/dist/index51.js +110 -104
- package/dist/index51.js.map +1 -1
- package/dist/index74.js +37 -25
- package/dist/index74.js.map +1 -1
- package/dist/index75.js +223 -103
- package/dist/index75.js.map +1 -1
- package/dist/index76.js +21 -51
- package/dist/index76.js.map +1 -1
- package/dist/index77.js +31 -22
- package/dist/index77.js.map +1 -1
- package/dist/index78.js +22 -31
- package/dist/index78.js.map +1 -1
- package/dist/index79.js +327 -20
- package/dist/index79.js.map +1 -1
- package/dist/index8.js +32 -8
- package/dist/index8.js.map +1 -1
- package/dist/index80.js +50 -323
- package/dist/index80.js.map +1 -1
- package/dist/index81.js +40 -56
- package/dist/index81.js.map +1 -1
- package/dist/index82.js +23 -40
- package/dist/index82.js.map +1 -1
- package/dist/index83.js +93 -21
- package/dist/index83.js.map +1 -1
- package/dist/index84.js +148 -87
- package/dist/index84.js.map +1 -1
- package/dist/index85.js +152 -147
- package/dist/index85.js.map +1 -1
- package/dist/index86.js +63 -159
- package/dist/index86.js.map +1 -1
- package/dist/index87.js +35 -65
- package/dist/index87.js.map +1 -1
- package/dist/index88.js +234 -35
- package/dist/index88.js.map +1 -1
- package/dist/index89.js +31 -231
- package/dist/index89.js.map +1 -1
- package/dist/index90.js +210 -34
- package/dist/index90.js.map +1 -1
- package/dist/index91.js +198 -195
- package/dist/index91.js.map +1 -1
- package/dist/index92.js +241 -159
- package/dist/index92.js.map +1 -1
- package/dist/index93.js +166 -283
- package/dist/index93.js.map +1 -1
- package/dist/index94.js +253 -173
- package/dist/index94.js.map +1 -1
- package/dist/index95.js +14 -258
- package/dist/index95.js.map +1 -1
- package/dist/index96.js +31 -12
- package/dist/index96.js.map +1 -1
- package/dist/index97.js +5 -32
- package/dist/index97.js.map +1 -1
- package/dist/index98.js +13 -5
- package/dist/index98.js.map +1 -1
- package/dist/index99.js +43 -11
- package/dist/index99.js.map +1 -1
- package/package.json +1 -1
- package/dist/components/Stack.d.ts +0 -10
- package/dist/index106.js +0 -21
- package/dist/index106.js.map +0 -1
package/dist/index104.js
CHANGED
|
@@ -1,16 +1,34 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
function f
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { useState as v, useCallback as i, useEffect as l } from "react";
|
|
2
|
+
function c(n, f = {}) {
|
|
3
|
+
const { target: u, event: o = "keydown", preventDefault: r = !1 } = f, [a, d] = v(!1), t = i(
|
|
4
|
+
(e) => {
|
|
5
|
+
e.key === n && (r && e.preventDefault(), d(!0));
|
|
6
|
+
},
|
|
7
|
+
[n, r]
|
|
8
|
+
), s = i(
|
|
9
|
+
(e) => {
|
|
10
|
+
e.key === n && d(!1);
|
|
11
|
+
},
|
|
12
|
+
[n]
|
|
13
|
+
);
|
|
14
|
+
return l(() => {
|
|
15
|
+
const e = u ?? window;
|
|
16
|
+
return o === "keydown" ? (e.addEventListener("keydown", t), e.addEventListener("keyup", s)) : e.addEventListener("keyup", t), () => {
|
|
17
|
+
e.removeEventListener("keydown", t), e.removeEventListener("keyup", s);
|
|
10
18
|
};
|
|
11
|
-
}, [
|
|
19
|
+
}, [u, o, t, s]), a;
|
|
20
|
+
}
|
|
21
|
+
function y(n, f, u = {}) {
|
|
22
|
+
const { target: o, event: r = "keydown", preventDefault: a = !1 } = u;
|
|
23
|
+
l(() => {
|
|
24
|
+
const d = o ?? window, t = (s) => {
|
|
25
|
+
s.key === n && (a && s.preventDefault(), f(s));
|
|
26
|
+
};
|
|
27
|
+
return d.addEventListener(r, t), () => d.removeEventListener(r, t);
|
|
28
|
+
}, [o, n, f, r, a]);
|
|
12
29
|
}
|
|
13
30
|
export {
|
|
14
|
-
|
|
31
|
+
c as useKeyPress,
|
|
32
|
+
y as useKeyPressCallback
|
|
15
33
|
};
|
|
16
34
|
//# sourceMappingURL=index104.js.map
|
package/dist/index104.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index104.js","sources":["../src/hooks/
|
|
1
|
+
{"version":3,"file":"index104.js","sources":["../src/hooks/useKeyPress.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react'\n\nexport interface UseKeyPressOptions {\n /** Target element (default: window) */\n target?: HTMLElement | Window | null\n /** Event type: 'keydown' | 'keyup' (default: 'keydown') */\n event?: 'keydown' | 'keyup'\n /** Prevent default browser behavior */\n preventDefault?: boolean\n}\n\n/**\n * Hook that detects when a specific key is pressed.\n *\n * @param targetKey - Key to detect (e.g., 'Enter', 'Escape', 'a')\n * @param options - Configuration options\n * @returns Whether the key is currently pressed\n *\n * @example\n * const enterPressed = useKeyPress('Enter')\n * const escapePressed = useKeyPress('Escape')\n *\n * useEffect(() => {\n * if (escapePressed) closeModal()\n * }, [escapePressed])\n *\n * @example\n * // With callback for immediate action\n * useKeyPress('Escape', { preventDefault: true })\n */\nexport function useKeyPress(\n targetKey: string,\n options: UseKeyPressOptions = {}\n): boolean {\n const { target, event = 'keydown', preventDefault = false } = options\n const [keyPressed, setKeyPressed] = useState(false)\n\n const downHandler = useCallback(\n (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n if (preventDefault) e.preventDefault()\n setKeyPressed(true)\n }\n },\n [targetKey, preventDefault]\n )\n\n const upHandler = useCallback(\n (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n setKeyPressed(false)\n }\n },\n [targetKey]\n )\n\n useEffect(() => {\n const targetElement = target ?? window\n\n if (event === 'keydown') {\n targetElement.addEventListener('keydown', downHandler as EventListener)\n targetElement.addEventListener('keyup', upHandler as EventListener)\n } else {\n targetElement.addEventListener('keyup', downHandler as EventListener)\n }\n\n return () => {\n targetElement.removeEventListener('keydown', downHandler as EventListener)\n targetElement.removeEventListener('keyup', upHandler as EventListener)\n }\n }, [target, event, downHandler, upHandler])\n\n return keyPressed\n}\n\n/**\n * Hook that calls a callback when a specific key is pressed.\n *\n * @param targetKey - Key to detect\n * @param callback - Function to call when key is pressed\n * @param options - Configuration options\n *\n * @example\n * useKeyPressCallback('Escape', () => closeModal())\n * useKeyPressCallback('Enter', () => submitForm(), { preventDefault: true })\n */\nexport function useKeyPressCallback(\n targetKey: string,\n callback: (event: KeyboardEvent) => void,\n options: UseKeyPressOptions = {}\n): void {\n const { target, event = 'keydown', preventDefault = false } = options\n\n useEffect(() => {\n const targetElement = target ?? window\n\n const handler = (e: KeyboardEvent) => {\n if (e.key === targetKey) {\n if (preventDefault) e.preventDefault()\n callback(e)\n }\n }\n\n targetElement.addEventListener(event, handler as EventListener)\n return () => targetElement.removeEventListener(event, handler as EventListener)\n }, [target, targetKey, callback, event, preventDefault])\n}\n"],"names":["useKeyPress","targetKey","options","target","event","preventDefault","keyPressed","setKeyPressed","useState","downHandler","useCallback","upHandler","useEffect","targetElement","useKeyPressCallback","callback","handler","e"],"mappings":";AA8BO,SAASA,EACdC,GACAC,IAA8B,IACrB;AACT,QAAM,EAAE,QAAAC,GAAQ,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
|
-
import { useState as
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return l(() => {
|
|
15
|
-
const e = u ?? window;
|
|
16
|
-
return o === "keydown" ? (e.addEventListener("keydown", t), e.addEventListener("keyup", s)) : e.addEventListener("keyup", t), () => {
|
|
17
|
-
e.removeEventListener("keydown", t), e.removeEventListener("keyup", s);
|
|
1
|
+
import { useState as t, useEffect as d } from "react";
|
|
2
|
+
function r() {
|
|
3
|
+
const [i, n] = t(() => typeof window > "u" ? { width: 0, height: 0 } : {
|
|
4
|
+
width: window.innerWidth,
|
|
5
|
+
height: window.innerHeight
|
|
6
|
+
});
|
|
7
|
+
return d(() => {
|
|
8
|
+
if (typeof window > "u") return;
|
|
9
|
+
const e = () => {
|
|
10
|
+
n({
|
|
11
|
+
width: window.innerWidth,
|
|
12
|
+
height: window.innerHeight
|
|
13
|
+
});
|
|
18
14
|
};
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
function y(n, f, u = {}) {
|
|
22
|
-
const { target: o, event: r = "keydown", preventDefault: a = !1 } = u;
|
|
23
|
-
l(() => {
|
|
24
|
-
const d = o ?? window, t = (s) => {
|
|
25
|
-
s.key === n && (a && s.preventDefault(), f(s));
|
|
26
|
-
};
|
|
27
|
-
return d.addEventListener(r, t), () => d.removeEventListener(r, t);
|
|
28
|
-
}, [o, n, f, r, a]);
|
|
15
|
+
return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
16
|
+
}, []), i;
|
|
29
17
|
}
|
|
30
18
|
export {
|
|
31
|
-
|
|
32
|
-
y as useKeyPressCallback
|
|
19
|
+
r as useWindowSize
|
|
33
20
|
};
|
|
34
21
|
//# sourceMappingURL=index105.js.map
|
package/dist/index105.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index105.js","sources":["../src/hooks/
|
|
1
|
+
{"version":3,"file":"index105.js","sources":["../src/hooks/useWindowSize.ts"],"sourcesContent":["import { useState, useEffect } from 'react'\n\nexport interface WindowSize {\n width: number\n height: number\n}\n\n/**\n * Hook that tracks window dimensions.\n * Updates on window resize.\n *\n * @returns Object with current width and height\n *\n * @example\n * const { width, height } = useWindowSize()\n *\n * return (\n * <div>\n * Window: {width} x {height}\n * {width < 768 && <MobileNav />}\n * </div>\n * )\n */\nexport function useWindowSize(): WindowSize {\n const [windowSize, setWindowSize] = useState<WindowSize>(() => {\n if (typeof window === 'undefined') {\n return { width: 0, height: 0 }\n }\n return {\n width: window.innerWidth,\n height: window.innerHeight,\n }\n })\n\n useEffect(() => {\n if (typeof window === 'undefined') return\n\n const handleResize = () => {\n setWindowSize({\n width: window.innerWidth,\n height: window.innerHeight,\n })\n }\n\n window.addEventListener('resize', handleResize)\n return () => window.removeEventListener('resize', handleResize)\n }, [])\n\n return windowSize\n}\n"],"names":["useWindowSize","windowSize","setWindowSize","useState","useEffect","handleResize"],"mappings":";AAuBO,SAASA,IAA4B;AAC1C,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAqB,MACnD,OAAO,SAAW,MACb,EAAE,OAAO,GAAG,QAAQ,EAAA,IAEtB;AAAA,IACL,OAAO,OAAO;AAAA,IACd,QAAQ,OAAO;AAAA,EAAA,CAElB;AAED,SAAAC,EAAU,MAAM;AACd,QAAI,OAAO,SAAW,IAAa;AAEnC,UAAMC,IAAe,MAAM;AACzB,MAAAH,EAAc;AAAA,QACZ,OAAO,OAAO;AAAA,QACd,QAAQ,OAAO;AAAA,MAAA,CAChB;AAAA,IACH;AAEA,kBAAO,iBAAiB,UAAUG,CAAY,GACvC,MAAM,OAAO,oBAAoB,UAAUA,CAAY;AAAA,EAChE,GAAG,CAAA,CAAE,GAEEJ;AACT;"}
|
package/dist/index19.js
CHANGED
|
@@ -1,25 +1,107 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
const
|
|
5
|
-
const
|
|
1
|
+
import { jsxs as b, Fragment as P, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import T, { useState as g, useRef as C, useCallback as M, useEffect as N, createContext as W, useContext as z } from "react";
|
|
3
|
+
import { createPortal as B } from "react-dom";
|
|
4
|
+
const E = W(null), I = () => {
|
|
5
|
+
const e = z(E);
|
|
6
|
+
if (!e)
|
|
7
|
+
throw new Error("ContextMenu compound components must be used within a ContextMenu");
|
|
8
|
+
return e;
|
|
9
|
+
}, A = ({
|
|
10
|
+
itemKey: e,
|
|
11
|
+
children: u,
|
|
12
|
+
icon: l,
|
|
13
|
+
disabled: s = !1,
|
|
14
|
+
danger: d = !1,
|
|
15
|
+
className: o = ""
|
|
16
|
+
}) => {
|
|
17
|
+
const { onSelect: h, onClose: t } = I();
|
|
18
|
+
return /* @__PURE__ */ n("li", { className: o, children: /* @__PURE__ */ b(
|
|
19
|
+
"button",
|
|
20
|
+
{
|
|
21
|
+
onClick: () => {
|
|
22
|
+
s || (h(e), t());
|
|
23
|
+
},
|
|
24
|
+
disabled: s,
|
|
25
|
+
className: `
|
|
26
|
+
flex items-center gap-2 w-full px-4 py-2 text-left text-sm
|
|
27
|
+
${s ? "opacity-50 cursor-not-allowed" : "hover:bg-base-200"}
|
|
28
|
+
${d ? "text-error hover:bg-error/10" : ""}
|
|
29
|
+
`,
|
|
30
|
+
children: [
|
|
31
|
+
l && /* @__PURE__ */ n("span", { className: "w-4 h-4", children: l }),
|
|
32
|
+
/* @__PURE__ */ n("span", { className: "flex-1", children: u })
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
) });
|
|
36
|
+
}, H = ({ className: e = "" }) => /* @__PURE__ */ n("li", { className: `divider my-1 ${e}` }), K = ({
|
|
37
|
+
itemKey: e,
|
|
38
|
+
label: u,
|
|
39
|
+
icon: l,
|
|
40
|
+
disabled: s = !1,
|
|
41
|
+
children: d,
|
|
42
|
+
className: o = ""
|
|
43
|
+
}) => {
|
|
44
|
+
const [h, t] = g(!1), a = C(null), c = () => {
|
|
45
|
+
s || (a.current && clearTimeout(a.current), t(!0));
|
|
46
|
+
}, m = () => {
|
|
47
|
+
a.current = setTimeout(() => t(!1), 100);
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ b(
|
|
50
|
+
"li",
|
|
51
|
+
{
|
|
52
|
+
onMouseEnter: c,
|
|
53
|
+
onMouseLeave: m,
|
|
54
|
+
className: `relative ${o}`,
|
|
55
|
+
children: [
|
|
56
|
+
/* @__PURE__ */ b(
|
|
57
|
+
"button",
|
|
58
|
+
{
|
|
59
|
+
disabled: s,
|
|
60
|
+
className: `
|
|
61
|
+
flex items-center gap-2 w-full px-4 py-2 text-left text-sm
|
|
62
|
+
${s ? "opacity-50 cursor-not-allowed" : "hover:bg-base-200"}
|
|
63
|
+
`,
|
|
64
|
+
children: [
|
|
65
|
+
l && /* @__PURE__ */ n("span", { className: "w-4 h-4", children: l }),
|
|
66
|
+
/* @__PURE__ */ n("span", { className: "flex-1", children: u }),
|
|
67
|
+
/* @__PURE__ */ n("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ n("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5l7 7-7 7" }) })
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
),
|
|
71
|
+
h && /* @__PURE__ */ n(
|
|
72
|
+
"ul",
|
|
73
|
+
{
|
|
74
|
+
className: "menu bg-base-100 rounded-box shadow-lg border border-base-300 absolute left-full top-0 min-w-[160px] z-50 p-1",
|
|
75
|
+
onMouseEnter: c,
|
|
76
|
+
onMouseLeave: m,
|
|
77
|
+
children: d
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
}, L = ({ item: e, onSelect: u, onClose: l }) => {
|
|
84
|
+
const [s, d] = g(!1), o = C(null);
|
|
6
85
|
if (e.divider)
|
|
7
|
-
return /* @__PURE__ */
|
|
8
|
-
const
|
|
9
|
-
e.disabled || e.children && e.children.length > 0 || (
|
|
10
|
-
}, t = e.children && e.children.length > 0
|
|
11
|
-
|
|
86
|
+
return /* @__PURE__ */ n("li", { className: "divider my-1" });
|
|
87
|
+
const h = () => {
|
|
88
|
+
e.disabled || e.children && e.children.length > 0 || (u(e.key), l());
|
|
89
|
+
}, t = e.children && e.children.length > 0, a = () => {
|
|
90
|
+
t && (o.current && clearTimeout(o.current), d(!0));
|
|
91
|
+
}, c = () => {
|
|
92
|
+
t && (o.current = setTimeout(() => d(!1), 100));
|
|
93
|
+
};
|
|
94
|
+
return /* @__PURE__ */ b(
|
|
12
95
|
"li",
|
|
13
96
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
onMouseLeave: () => t && m(!1),
|
|
97
|
+
onMouseEnter: a,
|
|
98
|
+
onMouseLeave: c,
|
|
17
99
|
className: "relative",
|
|
18
100
|
children: [
|
|
19
|
-
/* @__PURE__ */
|
|
101
|
+
/* @__PURE__ */ b(
|
|
20
102
|
"button",
|
|
21
103
|
{
|
|
22
|
-
onClick:
|
|
104
|
+
onClick: h,
|
|
23
105
|
disabled: e.disabled,
|
|
24
106
|
className: `
|
|
25
107
|
flex items-center gap-2 w-full px-4 py-2 text-left text-sm
|
|
@@ -27,75 +109,91 @@ const C = ({ item: e, onSelect: h, onClose: c }) => {
|
|
|
27
109
|
${e.danger ? "text-error hover:bg-error/10" : ""}
|
|
28
110
|
`,
|
|
29
111
|
children: [
|
|
30
|
-
e.icon && /* @__PURE__ */
|
|
31
|
-
/* @__PURE__ */
|
|
32
|
-
t && /* @__PURE__ */
|
|
112
|
+
e.icon && /* @__PURE__ */ n("span", { className: "w-4 h-4", children: e.icon }),
|
|
113
|
+
/* @__PURE__ */ n("span", { className: "flex-1", children: e.label }),
|
|
114
|
+
t && /* @__PURE__ */ n("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ n("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5l7 7-7 7" }) })
|
|
33
115
|
]
|
|
34
116
|
}
|
|
35
117
|
),
|
|
36
|
-
t &&
|
|
118
|
+
t && s && /* @__PURE__ */ n(
|
|
119
|
+
"ul",
|
|
120
|
+
{
|
|
121
|
+
className: "menu bg-base-100 rounded-box shadow-lg border border-base-300 absolute left-full top-0 min-w-[160px] z-50 p-1",
|
|
122
|
+
onMouseEnter: a,
|
|
123
|
+
onMouseLeave: c,
|
|
124
|
+
children: e.children.map((m) => /* @__PURE__ */ n(L, { item: m, onSelect: u, onClose: l }, m.key))
|
|
125
|
+
}
|
|
126
|
+
)
|
|
37
127
|
]
|
|
38
128
|
}
|
|
39
129
|
);
|
|
40
|
-
},
|
|
130
|
+
}, O = ({
|
|
41
131
|
children: e,
|
|
42
|
-
items:
|
|
43
|
-
onSelect:
|
|
44
|
-
disabled:
|
|
45
|
-
className:
|
|
132
|
+
items: u,
|
|
133
|
+
onSelect: l,
|
|
134
|
+
disabled: s = !1,
|
|
135
|
+
className: d = ""
|
|
46
136
|
}) => {
|
|
47
|
-
const [
|
|
48
|
-
(
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
let
|
|
52
|
-
|
|
137
|
+
const [o, h] = g(!1), [t, a] = g({ x: 0, y: 0 }), c = C(null), m = C(null), S = M(
|
|
138
|
+
(r) => {
|
|
139
|
+
if (s) return;
|
|
140
|
+
r.preventDefault(), r.stopPropagation();
|
|
141
|
+
let i = r.clientX, f = r.clientY;
|
|
142
|
+
a({ x: i, y: f }), h(!0);
|
|
53
143
|
},
|
|
54
|
-
[
|
|
55
|
-
),
|
|
56
|
-
|
|
57
|
-
}, []),
|
|
58
|
-
(
|
|
59
|
-
|
|
144
|
+
[s]
|
|
145
|
+
), x = M(() => {
|
|
146
|
+
h(!1);
|
|
147
|
+
}, []), y = M(
|
|
148
|
+
(r) => {
|
|
149
|
+
l?.(r);
|
|
60
150
|
},
|
|
61
|
-
[
|
|
151
|
+
[l]
|
|
62
152
|
);
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
66
|
-
let { x:
|
|
67
|
-
|
|
153
|
+
N(() => {
|
|
154
|
+
if (o && c.current) {
|
|
155
|
+
const i = c.current.getBoundingClientRect(), f = window.innerWidth, p = window.innerHeight;
|
|
156
|
+
let { x: v, y: w } = t;
|
|
157
|
+
v + i.width > f && (v = f - i.width - 8), w + i.height > p && (w = p - i.height - 8), (v !== t.x || w !== t.y) && a({ x: v, y: w });
|
|
68
158
|
}
|
|
69
|
-
}, [
|
|
70
|
-
if (!
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
|
|
159
|
+
}, [o, t]), N(() => {
|
|
160
|
+
if (!o) return;
|
|
161
|
+
const r = (p) => {
|
|
162
|
+
c.current && !c.current.contains(p.target) && x();
|
|
163
|
+
}, i = (p) => {
|
|
164
|
+
p.key === "Escape" && x();
|
|
165
|
+
}, f = () => {
|
|
166
|
+
x();
|
|
77
167
|
};
|
|
78
|
-
return document.addEventListener("mousedown",
|
|
79
|
-
document.removeEventListener("mousedown",
|
|
168
|
+
return document.addEventListener("mousedown", r), document.addEventListener("keydown", i), document.addEventListener("scroll", f, !0), () => {
|
|
169
|
+
document.removeEventListener("mousedown", r), document.removeEventListener("keydown", i), document.removeEventListener("scroll", f, !0);
|
|
80
170
|
};
|
|
81
|
-
}, [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
171
|
+
}, [o, x]);
|
|
172
|
+
const k = T.Children.toArray(e), R = k[0], $ = k.slice(1), j = u && u.length > 0, D = {
|
|
173
|
+
onSelect: y,
|
|
174
|
+
onClose: x
|
|
175
|
+
};
|
|
176
|
+
return /* @__PURE__ */ b(P, { children: [
|
|
177
|
+
/* @__PURE__ */ n("div", { ref: m, onContextMenu: S, className: "inline-block", children: R }),
|
|
178
|
+
o && B(
|
|
179
|
+
/* @__PURE__ */ n(E.Provider, { value: D, children: /* @__PURE__ */ n(
|
|
85
180
|
"ul",
|
|
86
181
|
{
|
|
87
|
-
ref:
|
|
88
|
-
className: `menu bg-base-100 rounded-box shadow-lg border border-base-300 min-w-[160px] p-1 fixed z-[9999] ${
|
|
182
|
+
ref: c,
|
|
183
|
+
className: `menu bg-base-100 rounded-box shadow-lg border border-base-300 min-w-[160px] p-1 fixed z-[9999] ${d}`,
|
|
89
184
|
style: { left: t.x, top: t.y },
|
|
90
|
-
children:
|
|
185
|
+
children: j ? u.map((r) => /* @__PURE__ */ n(L, { item: r, onSelect: y, onClose: x }, r.key)) : $
|
|
91
186
|
}
|
|
92
|
-
),
|
|
187
|
+
) }),
|
|
93
188
|
document.body
|
|
94
189
|
)
|
|
95
190
|
] });
|
|
96
|
-
}
|
|
97
|
-
|
|
191
|
+
}, Y = Object.assign(O, {
|
|
192
|
+
Item: A,
|
|
193
|
+
Divider: H,
|
|
194
|
+
SubMenu: K
|
|
195
|
+
});
|
|
98
196
|
export {
|
|
99
|
-
|
|
197
|
+
Y as ContextMenu
|
|
100
198
|
};
|
|
101
199
|
//# sourceMappingURL=index19.js.map
|
package/dist/index19.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index19.js","sources":["../src/components/ContextMenu.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useCallback } from 'react'\nimport { createPortal } from 'react-dom'\n\nexport interface ContextMenuItem {\n key: string\n label: React.ReactNode\n icon?: React.ReactNode\n disabled?: boolean\n danger?: boolean\n divider?: boolean\n children?: ContextMenuItem[]\n}\n\nexport interface ContextMenuProps {\n /** Element that triggers the context menu on right-click */\n children: React.ReactNode\n /** Menu items */\n items: ContextMenuItem[]\n /** Callback when an item is selected */\n onSelect?: (key: string) => void\n /** Whether the context menu is disabled */\n disabled?: boolean\n /** Additional CSS classes for the menu */\n className?: string\n}\n\ninterface MenuPosition {\n x: number\n y: number\n}\n\nconst MenuItem: React.FC<{\n item: ContextMenuItem\n onSelect: (key: string) => void\n onClose: () => void\n}> = ({ item, onSelect, onClose }) => {\n const [showSubmenu, setShowSubmenu] = useState(false)\n const itemRef = useRef<HTMLLIElement>(null)\n\n if (item.divider) {\n return <li className=\"divider my-1\"></li>\n }\n\n const handleClick = () => {\n if (item.disabled) return\n if (item.children && item.children.length > 0) return\n onSelect(item.key)\n onClose()\n }\n\n const hasSubmenu = item.children && item.children.length > 0\n\n return (\n <li\n ref={itemRef}\n onMouseEnter={() => hasSubmenu && setShowSubmenu(true)}\n onMouseLeave={() => hasSubmenu && setShowSubmenu(false)}\n className=\"relative\"\n >\n <button\n onClick={handleClick}\n disabled={item.disabled}\n className={`\n flex items-center gap-2 w-full px-4 py-2 text-left text-sm\n ${item.disabled ? 'opacity-50 cursor-not-allowed' : 'hover:bg-base-200'}\n ${item.danger ? 'text-error hover:bg-error/10' : ''}\n `}\n >\n {item.icon && <span className=\"w-4 h-4\">{item.icon}</span>}\n <span className=\"flex-1\">{item.label}</span>\n {hasSubmenu && (\n <svg className=\"w-4 h-4\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth={2} d=\"M9 5l7 7-7 7\" />\n </svg>\n )}\n </button>\n {hasSubmenu && showSubmenu && (\n <ul className=\"menu bg-base-100 rounded-box shadow-lg border border-base-300 absolute left-full top-0 min-w-[160px] z-50\">\n {item.children!.map((child) => (\n <MenuItem key={child.key} item={child} onSelect={onSelect} onClose={onClose} />\n ))}\n </ul>\n )}\n </li>\n )\n}\n\nexport const ContextMenu: React.FC<ContextMenuProps> = ({\n children,\n items,\n onSelect,\n disabled = false,\n className = '',\n}) => {\n const [visible, setVisible] = useState(false)\n const [position, setPosition] = useState<MenuPosition>({ x: 0, y: 0 })\n const menuRef = useRef<HTMLUListElement>(null)\n const triggerRef = useRef<HTMLDivElement>(null)\n\n const handleContextMenu = useCallback(\n (e: React.MouseEvent) => {\n if (disabled) return\n e.preventDefault()\n e.stopPropagation()\n\n // Calculate position, ensuring menu stays within viewport\n let x = e.clientX\n let y = e.clientY\n\n // We'll adjust after render when we know menu dimensions\n setPosition({ x, y })\n setVisible(true)\n },\n [disabled]\n )\n\n const handleClose = useCallback(() => {\n setVisible(false)\n }, [])\n\n const handleSelect = useCallback(\n (key: string) => {\n onSelect?.(key)\n },\n [onSelect]\n )\n\n // Adjust position after menu renders to keep it in viewport\n useEffect(() => {\n if (visible && menuRef.current) {\n const menu = menuRef.current\n const rect = menu.getBoundingClientRect()\n const viewportWidth = window.innerWidth\n const viewportHeight = window.innerHeight\n\n let { x, y } = position\n\n if (x + rect.width > viewportWidth) {\n x = viewportWidth - rect.width - 8\n }\n if (y + rect.height > viewportHeight) {\n y = viewportHeight - rect.height - 8\n }\n\n if (x !== position.x || y !== position.y) {\n setPosition({ x, y })\n }\n }\n }, [visible, position])\n\n // Close on click outside or escape\n useEffect(() => {\n if (!visible) return\n\n const handleClickOutside = (e: MouseEvent) => {\n if (menuRef.current && !menuRef.current.contains(e.target as Node)) {\n handleClose()\n }\n }\n\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n handleClose()\n }\n }\n\n const handleScroll = () => {\n handleClose()\n }\n\n document.addEventListener('mousedown', handleClickOutside)\n document.addEventListener('keydown', handleEscape)\n document.addEventListener('scroll', handleScroll, true)\n\n return () => {\n document.removeEventListener('mousedown', handleClickOutside)\n document.removeEventListener('keydown', handleEscape)\n document.removeEventListener('scroll', handleScroll, true)\n }\n }, [visible, handleClose])\n\n return (\n <>\n <div ref={triggerRef} onContextMenu={handleContextMenu} className=\"inline-block\">\n {children}\n </div>\n {visible &&\n createPortal(\n <ul\n ref={menuRef}\n className={`menu bg-base-100 rounded-box shadow-lg border border-base-300 min-w-[160px] p-1 fixed z-[9999] ${className}`}\n style={{ left: position.x, top: position.y }}\n >\n {items.map((item) => (\n <MenuItem key={item.key} item={item} onSelect={handleSelect} onClose={handleClose} />\n ))}\n </ul>,\n document.body\n )}\n </>\n )\n}\n\nContextMenu.displayName = 'ContextMenu'\n"],"names":["MenuItem","item","onSelect","onClose","showSubmenu","setShowSubmenu","useState","itemRef","useRef","jsx","handleClick","hasSubmenu","jsxs","child","ContextMenu","children","items","disabled","className","visible","setVisible","position","setPosition","menuRef","triggerRef","handleContextMenu","useCallback","e","x","y","handleClose","handleSelect","key","useEffect","rect","viewportWidth","viewportHeight","handleClickOutside","handleEscape","handleScroll","Fragment","createPortal"],"mappings":";;;AA+BA,MAAMA,IAID,CAAC,EAAE,MAAAC,GAAM,UAAAC,GAAU,SAAAC,QAAc;AACpC,QAAM,CAACC,GAAaC,CAAc,IAAIC,EAAS,EAAK,GAC9CC,IAAUC,EAAsB,IAAI;AAE1C,MAAIP,EAAK;AACP,WAAO,gBAAAQ,EAAC,MAAA,EAAG,WAAU,eAAA,CAAe;AAGtC,QAAMC,IAAc,MAAM;AACxB,IAAIT,EAAK,YACLA,EAAK,YAAYA,EAAK,SAAS,SAAS,MAC5CC,EAASD,EAAK,GAAG,GACjBE,EAAA;AAAA,EACF,GAEMQ,IAAaV,EAAK,YAAYA,EAAK,SAAS,SAAS;AAE3D,SACE,gBAAAW;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAKL;AAAA,MACL,cAAc,MAAMI,KAAcN,EAAe,EAAI;AAAA,MACrD,cAAc,MAAMM,KAAcN,EAAe,EAAK;AAAA,MACtD,WAAU;AAAA,MAEV,UAAA;AAAA,QAAA,gBAAAO;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,SAASF;AAAA,YACT,UAAUT,EAAK;AAAA,YACf,WAAW;AAAA;AAAA,YAEPA,EAAK,WAAW,kCAAkC,mBAAmB;AAAA,YACrEA,EAAK,SAAS,iCAAiC,EAAE;AAAA;AAAA,YAGpD,UAAA;AAAA,cAAAA,EAAK,QAAQ,gBAAAQ,EAAC,QAA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AC,SAAI,KAAKe,GAAY,eAAeC,GAAmB,WAAU,gBAC/D,UAAAV,GACH;AAAA,IACCI,KACCsB;AAAA,MACE,gBAAAhC;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,KAAKc;AAAA,UACL,WAAW,kGAAkGL,CAAS;AAAA,UACtH,OAAO,EAAE,MAAMG,EAAS,GAAG,KAAKA,EAAS,EAAA;AAAA,UAExC,UAAAL,EAAM,IAAI,CAACf,MACV,gBAAAQ,EAACT,GAAA,EAAwB,MAAAC,GAAY,UAAU8B,GAAc,SAASD,EAAA,GAAvD7B,EAAK,GAA+D,CACpF;AAAA,QAAA;AAAA,MAAA;AAAA,MAEH,SAAS;AAAA,IAAA;AAAA,EACX,GACJ;AAEJ;AAEAa,EAAY,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index19.js","sources":["../src/components/ContextMenu.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useCallback, createContext, useContext } from 'react'\nimport { createPortal } from 'react-dom'\n\nexport interface ContextMenuItem {\n key: string\n label: React.ReactNode\n icon?: React.ReactNode\n disabled?: boolean\n danger?: boolean\n divider?: boolean\n children?: ContextMenuItem[]\n}\n\nexport interface ContextMenuProps {\n /** Element that triggers the context menu on right-click */\n children: React.ReactNode\n /** Menu items (data-driven pattern) */\n items?: ContextMenuItem[]\n /** Callback when an item is selected */\n onSelect?: (key: string) => void\n /** Whether the context menu is disabled */\n disabled?: boolean\n /** Additional CSS classes for the menu */\n className?: string\n}\n\nexport interface ContextMenuItemProps {\n /** Unique key for the item */\n itemKey: string\n /** Item content */\n children: React.ReactNode\n /** Icon to display before label */\n icon?: React.ReactNode\n /** Whether the item is disabled */\n disabled?: boolean\n /** Show as danger/destructive action */\n danger?: boolean\n /** Additional CSS classes */\n className?: string\n}\n\nexport interface ContextMenuDividerProps {\n /** Additional CSS classes */\n className?: string\n}\n\nexport interface ContextMenuSubMenuProps {\n /** Unique key for the submenu */\n itemKey: string\n /** Submenu label */\n label: React.ReactNode\n /** Icon to display before label */\n icon?: React.ReactNode\n /** Whether the submenu is disabled */\n disabled?: boolean\n /** Submenu items */\n children: React.ReactNode\n /** Additional CSS classes */\n className?: string\n}\n\ninterface ContextMenuContextValue {\n onSelect: (key: string) => void\n onClose: () => void\n}\n\ninterface MenuPosition {\n x: number\n y: number\n}\n\nconst ContextMenuContext = createContext<ContextMenuContextValue | null>(null)\n\nconst useContextMenuContext = () => {\n const context = useContext(ContextMenuContext)\n if (!context) {\n throw new Error('ContextMenu compound components must be used within a ContextMenu')\n }\n return context\n}\n\n// Compound pattern components\nconst ContextMenuItemComponent: React.FC<ContextMenuItemProps> = ({\n itemKey,\n children,\n icon,\n disabled = false,\n danger = false,\n className = '',\n}) => {\n const { onSelect, onClose } = useContextMenuContext()\n\n const handleClick = () => {\n if (disabled) return\n onSelect(itemKey)\n onClose()\n }\n\n return (\n <li className={className}>\n <button\n onClick={handleClick}\n disabled={disabled}\n className={`\n flex items-center gap-2 w-full px-4 py-2 text-left text-sm\n ${disabled ? 'opacity-50 cursor-not-allowed' : 'hover:bg-base-200'}\n ${danger ? 'text-error hover:bg-error/10' : ''}\n `}\n >\n {icon && <span className=\"w-4 h-4\">{icon}</span>}\n <span className=\"flex-1\">{children}</span>\n </button>\n </li>\n )\n}\n\nconst ContextMenuDividerComponent: React.FC<ContextMenuDividerProps> = ({ className = '' }) => {\n return <li className={`divider my-1 ${className}`}></li>\n}\n\nconst ContextMenuSubMenuComponent: React.FC<ContextMenuSubMenuProps> = ({\n itemKey: _itemKey,\n label,\n icon,\n disabled = false,\n children,\n className = '',\n}) => {\n const [showSubmenu, setShowSubmenu] = useState(false)\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n const handleMouseEnter = () => {\n if (disabled) return\n if (timeoutRef.current) clearTimeout(timeoutRef.current)\n setShowSubmenu(true)\n }\n\n const handleMouseLeave = () => {\n timeoutRef.current = setTimeout(() => setShowSubmenu(false), 100)\n }\n\n return (\n <li\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n className={`relative ${className}`}\n >\n <button\n disabled={disabled}\n className={`\n flex items-center gap-2 w-full px-4 py-2 text-left text-sm\n ${disabled ? 'opacity-50 cursor-not-allowed' : 'hover:bg-base-200'}\n `}\n >\n {icon && <span className=\"w-4 h-4\">{icon}</span>}\n <span className=\"flex-1\">{label}</span>\n <svg className=\"w-4 h-4\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth={2} d=\"M9 5l7 7-7 7\" />\n </svg>\n </button>\n {showSubmenu && (\n <ul\n className=\"menu bg-base-100 rounded-box shadow-lg border border-base-300 absolute left-full top-0 min-w-[160px] z-50 p-1\"\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n {children}\n </ul>\n )}\n </li>\n )\n}\n\n// Data-driven pattern internal component\nconst MenuItem: React.FC<{\n item: ContextMenuItem\n onSelect: (key: string) => void\n onClose: () => void\n}> = ({ item, onSelect, onClose }) => {\n const [showSubmenu, setShowSubmenu] = useState(false)\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n if (item.divider) {\n return <li className=\"divider my-1\"></li>\n }\n\n const handleClick = () => {\n if (item.disabled) return\n if (item.children && item.children.length > 0) return\n onSelect(item.key)\n onClose()\n }\n\n const hasSubmenu = item.children && item.children.length > 0\n\n const handleMouseEnter = () => {\n if (!hasSubmenu) return\n if (timeoutRef.current) clearTimeout(timeoutRef.current)\n setShowSubmenu(true)\n }\n\n const handleMouseLeave = () => {\n if (!hasSubmenu) return\n timeoutRef.current = setTimeout(() => setShowSubmenu(false), 100)\n }\n\n return (\n <li\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n className=\"relative\"\n >\n <button\n onClick={handleClick}\n disabled={item.disabled}\n className={`\n flex items-center gap-2 w-full px-4 py-2 text-left text-sm\n ${item.disabled ? 'opacity-50 cursor-not-allowed' : 'hover:bg-base-200'}\n ${item.danger ? 'text-error hover:bg-error/10' : ''}\n `}\n >\n {item.icon && <span className=\"w-4 h-4\">{item.icon}</span>}\n <span className=\"flex-1\">{item.label}</span>\n {hasSubmenu && (\n <svg className=\"w-4 h-4\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth={2} d=\"M9 5l7 7-7 7\" />\n </svg>\n )}\n </button>\n {hasSubmenu && showSubmenu && (\n <ul\n className=\"menu bg-base-100 rounded-box shadow-lg border border-base-300 absolute left-full top-0 min-w-[160px] z-50 p-1\"\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n {item.children!.map((child) => (\n <MenuItem key={child.key} item={child} onSelect={onSelect} onClose={onClose} />\n ))}\n </ul>\n )}\n </li>\n )\n}\n\nconst ContextMenuRoot: React.FC<ContextMenuProps> = ({\n children,\n items,\n onSelect,\n disabled = false,\n className = '',\n}) => {\n const [visible, setVisible] = useState(false)\n const [position, setPosition] = useState<MenuPosition>({ x: 0, y: 0 })\n const menuRef = useRef<HTMLUListElement>(null)\n const triggerRef = useRef<HTMLDivElement>(null)\n\n const handleContextMenu = useCallback(\n (e: React.MouseEvent) => {\n if (disabled) return\n e.preventDefault()\n e.stopPropagation()\n\n // Calculate position, ensuring menu stays within viewport\n let x = e.clientX\n let y = e.clientY\n\n // We'll adjust after render when we know menu dimensions\n setPosition({ x, y })\n setVisible(true)\n },\n [disabled]\n )\n\n const handleClose = useCallback(() => {\n setVisible(false)\n }, [])\n\n const handleSelect = useCallback(\n (key: string) => {\n onSelect?.(key)\n },\n [onSelect]\n )\n\n // Adjust position after menu renders to keep it in viewport\n useEffect(() => {\n if (visible && menuRef.current) {\n const menu = menuRef.current\n const rect = menu.getBoundingClientRect()\n const viewportWidth = window.innerWidth\n const viewportHeight = window.innerHeight\n\n let { x, y } = position\n\n if (x + rect.width > viewportWidth) {\n x = viewportWidth - rect.width - 8\n }\n if (y + rect.height > viewportHeight) {\n y = viewportHeight - rect.height - 8\n }\n\n if (x !== position.x || y !== position.y) {\n setPosition({ x, y })\n }\n }\n }, [visible, position])\n\n // Close on click outside or escape\n useEffect(() => {\n if (!visible) return\n\n const handleClickOutside = (e: MouseEvent) => {\n if (menuRef.current && !menuRef.current.contains(e.target as Node)) {\n handleClose()\n }\n }\n\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n handleClose()\n }\n }\n\n const handleScroll = () => {\n handleClose()\n }\n\n document.addEventListener('mousedown', handleClickOutside)\n document.addEventListener('keydown', handleEscape)\n document.addEventListener('scroll', handleScroll, true)\n\n return () => {\n document.removeEventListener('mousedown', handleClickOutside)\n document.removeEventListener('keydown', handleEscape)\n document.removeEventListener('scroll', handleScroll, true)\n }\n }, [visible, handleClose])\n\n // Determine if using data-driven or compound pattern\n // Find menu content children (not the trigger element)\n const childArray = React.Children.toArray(children)\n const triggerChild = childArray[0]\n const menuChildren = childArray.slice(1)\n const useDataDriven = items && items.length > 0\n\n const contextValue: ContextMenuContextValue = {\n onSelect: handleSelect,\n onClose: handleClose,\n }\n\n return (\n <>\n <div ref={triggerRef} onContextMenu={handleContextMenu} className=\"inline-block\">\n {triggerChild}\n </div>\n {visible &&\n createPortal(\n <ContextMenuContext.Provider value={contextValue}>\n <ul\n ref={menuRef}\n className={`menu bg-base-100 rounded-box shadow-lg border border-base-300 min-w-[160px] p-1 fixed z-[9999] ${className}`}\n style={{ left: position.x, top: position.y }}\n >\n {useDataDriven\n ? items!.map((item) => (\n <MenuItem key={item.key} item={item} onSelect={handleSelect} onClose={handleClose} />\n ))\n : menuChildren}\n </ul>\n </ContextMenuContext.Provider>,\n document.body\n )}\n </>\n )\n}\n\n// Assign compound components\nexport const ContextMenu = Object.assign(ContextMenuRoot, {\n Item: ContextMenuItemComponent,\n Divider: ContextMenuDividerComponent,\n SubMenu: ContextMenuSubMenuComponent,\n})\n"],"names":["ContextMenuContext","createContext","useContextMenuContext","context","useContext","ContextMenuItemComponent","itemKey","children","icon","disabled","danger","className","onSelect","onClose","jsx","jsxs","ContextMenuDividerComponent","ContextMenuSubMenuComponent","_itemKey","label","showSubmenu","setShowSubmenu","useState","timeoutRef","useRef","handleMouseEnter","handleMouseLeave","MenuItem","item","handleClick","hasSubmenu","child","ContextMenuRoot","items","visible","setVisible","position","setPosition","menuRef","triggerRef","handleContextMenu","useCallback","e","x","y","handleClose","handleSelect","key","useEffect","rect","viewportWidth","viewportHeight","handleClickOutside","handleEscape","handleScroll","childArray","React","triggerChild","menuChildren","useDataDriven","contextValue","Fragment","createPortal","ContextMenu"],"mappings":";;;AAuEA,MAAMA,IAAqBC,EAA8C,IAAI,GAEvEC,IAAwB,MAAM;AAClC,QAAMC,IAAUC,EAAWJ,CAAkB;AAC7C,MAAI,CAACG;AACH,UAAM,IAAI,MAAM,mEAAmE;AAErF,SAAOA;AACT,GAGME,IAA2D,CAAC;AAAA,EAChE,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,QAAAC,IAAS;AAAA,EACT,WAAAC,IAAY;AACd,MAAM;AACJ,QAAM,EAAE,UAAAC,GAAU,SAAAC,EAAA,IAAYX,EAAA;AAQ9B,SACE,gBAAAY,EAAC,QAAG,WAAAH,GACF,UAAA,gBAAAI;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,SATc,MAAM;AACxB,QAAIN,MACJG,EAASN,CAAO,GAChBO,EAAA;AAAA,MACF;AAAA,MAMM,UAAAJ;AAAA,MACA,WAAW;AAAA;AAAA,YAEPA,IAAW,kCAAkC,mBAAmB;AAAA,YAChEC,IAAS,iCAAiC,EAAE;AAAA;AAAA,MAG/C,UAAA;AAAA,QAAAF,KAAQ,gBAAAM,EAAC,QAAA,EAAK,WAAU,WAAW,UAAAN,GAAK;AAAA,QACzC,gBAAAM,EAAC,QAAA,EAAK,WAAU,UAAU,UAAAP,EAAA,CAAS;AAAA,MAAA;AAA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