@asup/context-menu 1.3.10 → 1.3.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/main.js ADDED
@@ -0,0 +1,713 @@
1
+ import "./main.css";
2
+ import {jsx as $duWW8$jsx, jsxs as $duWW8$jsxs, Fragment as $duWW8$Fragment} from "react/jsx-runtime";
3
+ import {createContext as $duWW8$createContext, useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, useRef as $duWW8$useRef, useState as $duWW8$useState, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect, forwardRef as $duWW8$forwardRef} from "react";
4
+ import {createPortal as $duWW8$createPortal} from "react-dom";
5
+
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
+ }
10
+
11
+ function $parcel$interopDefault(a) {
12
+ return a && a.__esModule ? a.default : a;
13
+ }
14
+
15
+
16
+ var $b65191f6d0a0a991$exports = {};
17
+
18
+ $parcel$export($b65191f6d0a0a991$exports, "ContextMenuHandler", function () { return $1e1c1e9e0b943830$export$ed4f9641643dc7e4; });
19
+ $parcel$export($b65191f6d0a0a991$exports, "ContextWindow", function () { return $b5e8657823def5be$export$1af8984c69ba1b24; });
20
+ $parcel$export($b65191f6d0a0a991$exports, "ContextWindowStack", function () { return $17c46b9e6a2eb66e$export$9f37482ccd50dad2; });
21
+
22
+
23
+
24
+
25
+
26
+ var $47067f35ca62d4a5$exports = {};
27
+
28
+ $parcel$export($47067f35ca62d4a5$exports, "anchor", function () { return $47067f35ca62d4a5$export$2e2992790a6f69a8; }, function (v) { return $47067f35ca62d4a5$export$2e2992790a6f69a8 = v; });
29
+ $parcel$export($47067f35ca62d4a5$exports, "caretHolder", function () { return $47067f35ca62d4a5$export$6ed5f4fbab298e07; }, function (v) { return $47067f35ca62d4a5$export$6ed5f4fbab298e07 = v; });
30
+ $parcel$export($47067f35ca62d4a5$exports, "contextMenu", function () { return $47067f35ca62d4a5$export$218b899e1d476006; }, function (v) { return $47067f35ca62d4a5$export$218b899e1d476006 = v; });
31
+ $parcel$export($47067f35ca62d4a5$exports, "contextMenuHandler", function () { return $47067f35ca62d4a5$export$ed8ffb5bb55a3bc8; }, function (v) { return $47067f35ca62d4a5$export$ed8ffb5bb55a3bc8 = v; });
32
+ $parcel$export($47067f35ca62d4a5$exports, "contextMenuItem", function () { return $47067f35ca62d4a5$export$e5ea51c279904378; }, function (v) { return $47067f35ca62d4a5$export$e5ea51c279904378 = v; });
33
+ $parcel$export($47067f35ca62d4a5$exports, "contextMenuItemLabel", function () { return $47067f35ca62d4a5$export$6ada86c5b962aa22; }, function (v) { return $47067f35ca62d4a5$export$6ada86c5b962aa22 = v; });
34
+ $parcel$export($47067f35ca62d4a5$exports, "disabled", function () { return $47067f35ca62d4a5$export$683472f6198a076e; }, function (v) { return $47067f35ca62d4a5$export$683472f6198a076e = v; });
35
+ $parcel$export($47067f35ca62d4a5$exports, "hidden", function () { return $47067f35ca62d4a5$export$73920f18ca706874; }, function (v) { return $47067f35ca62d4a5$export$73920f18ca706874 = v; });
36
+ $parcel$export($47067f35ca62d4a5$exports, "subMenu", function () { return $47067f35ca62d4a5$export$6e0e6ce39e5a0361; }, function (v) { return $47067f35ca62d4a5$export$6e0e6ce39e5a0361 = v; });
37
+ $parcel$export($47067f35ca62d4a5$exports, "visible", function () { return $47067f35ca62d4a5$export$664c6d24e3175067; }, function (v) { return $47067f35ca62d4a5$export$664c6d24e3175067 = v; });
38
+ var $47067f35ca62d4a5$export$2e2992790a6f69a8;
39
+ var $47067f35ca62d4a5$export$6ed5f4fbab298e07;
40
+ var $47067f35ca62d4a5$export$218b899e1d476006;
41
+ var $47067f35ca62d4a5$export$ed8ffb5bb55a3bc8;
42
+ var $47067f35ca62d4a5$export$e5ea51c279904378;
43
+ var $47067f35ca62d4a5$export$6ada86c5b962aa22;
44
+ var $47067f35ca62d4a5$export$683472f6198a076e;
45
+ var $47067f35ca62d4a5$export$73920f18ca706874;
46
+ var $47067f35ca62d4a5$export$6e0e6ce39e5a0361;
47
+ var $47067f35ca62d4a5$export$664c6d24e3175067;
48
+ $47067f35ca62d4a5$export$2e2992790a6f69a8 = `aiw-ContextMenu-module-WinFxq-anchor`;
49
+ $47067f35ca62d4a5$export$6ed5f4fbab298e07 = `aiw-ContextMenu-module-WinFxq-caretHolder`;
50
+ $47067f35ca62d4a5$export$218b899e1d476006 = `aiw-ContextMenu-module-WinFxq-contextMenu`;
51
+ $47067f35ca62d4a5$export$ed8ffb5bb55a3bc8 = `aiw-ContextMenu-module-WinFxq-contextMenuHandler`;
52
+ $47067f35ca62d4a5$export$e5ea51c279904378 = `aiw-ContextMenu-module-WinFxq-contextMenuItem`;
53
+ $47067f35ca62d4a5$export$6ada86c5b962aa22 = `aiw-ContextMenu-module-WinFxq-contextMenuItemLabel`;
54
+ $47067f35ca62d4a5$export$683472f6198a076e = `aiw-ContextMenu-module-WinFxq-disabled`;
55
+ $47067f35ca62d4a5$export$73920f18ca706874 = `aiw-ContextMenu-module-WinFxq-hidden`;
56
+ $47067f35ca62d4a5$export$6e0e6ce39e5a0361 = `aiw-ContextMenu-module-WinFxq-subMenu`;
57
+ $47067f35ca62d4a5$export$664c6d24e3175067 = `aiw-ContextMenu-module-WinFxq-visible`;
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+ const $6ca59110355c8bf1$export$7e4e6110f96afd7e = ({ entries: entries, toClose: toClose, visible: visible })=>{
67
+ return /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
68
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).caretHolder,
69
+ children: [
70
+ /*#__PURE__*/ (0, $duWW8$jsx)("svg", {
71
+ xmlns: "http://www.w3.org/2000/svg",
72
+ width: "16",
73
+ height: "16",
74
+ fill: "currentColor",
75
+ viewBox: "0 0 16 16",
76
+ children: /*#__PURE__*/ (0, $duWW8$jsx)("path", {
77
+ d: "m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"
78
+ })
79
+ }),
80
+ /*#__PURE__*/ (0, $duWW8$jsx)("div", {
81
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).subMenu,
82
+ children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
83
+ visible: visible,
84
+ entries: entries,
85
+ xPos: 14,
86
+ yPos: -21,
87
+ toClose: toClose
88
+ })
89
+ })
90
+ ]
91
+ });
92
+ };
93
+ $6ca59110355c8bf1$export$7e4e6110f96afd7e.displayName = "ContextSubMenu";
94
+
95
+
96
+ const $813754bb7a4251f1$export$c868ef28d2ba36f1 = ({ entry: entry, toClose: toClose })=>{
97
+ const [target, setTarget] = (0, $duWW8$useState)(null);
98
+ const [subMenuVisible, setSubMenuVisible] = (0, $duWW8$useState)(false);
99
+ return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
100
+ className: [
101
+ (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).contextMenuItem,
102
+ entry.disabled ? (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).disabled : ""
103
+ ].filter((c)=>c !== "").join(" "),
104
+ onMouseEnter: ()=>{
105
+ setSubMenuVisible(true);
106
+ },
107
+ onMouseLeave: ()=>{
108
+ setSubMenuVisible(false);
109
+ },
110
+ children: [
111
+ typeof entry.label === "string" ? /*#__PURE__*/ (0, $duWW8$jsx)("span", {
112
+ "aria-label": typeof entry.label === "string" ? entry.label : undefined,
113
+ "aria-disabled": entry.disabled,
114
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).contextMenuItemLabel,
115
+ onMouseEnter: ()=>{
116
+ const sel = window.getSelection();
117
+ const target = sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
118
+ setTarget(target);
119
+ },
120
+ onMouseLeave: ()=>{
121
+ setTarget(null);
122
+ },
123
+ onMouseDownCapture: (e)=>{
124
+ e.preventDefault();
125
+ e.stopPropagation();
126
+ entry.action && !entry.disabled && entry.action(target);
127
+ !entry.disabled && toClose();
128
+ },
129
+ children: entry.label
130
+ }) : entry.label,
131
+ entry.group && /*#__PURE__*/ (0, $duWW8$jsx)((0, $6ca59110355c8bf1$export$7e4e6110f96afd7e), {
132
+ toClose: toClose,
133
+ entries: entry.group,
134
+ visible: subMenuVisible
135
+ })
136
+ ]
137
+ });
138
+ };
139
+
140
+
141
+ const $567ed433af94513f$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $duWW8$forwardRef)(({ visible: visible, entries: entries, xPos: xPos, yPos: yPos, toClose: toClose }, ref)=>{
142
+ return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
143
+ ref: ref,
144
+ className: [
145
+ (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).contextMenu,
146
+ visible ? (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).visible : (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).hidden
147
+ ].filter((c)=>c !== "").join(" "),
148
+ style: {
149
+ top: `${yPos}px`,
150
+ left: `${xPos}px`
151
+ },
152
+ onContextMenuCapture: (e)=>{
153
+ e.preventDefault();
154
+ e.stopPropagation();
155
+ },
156
+ children: entries.map((entry, i)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $813754bb7a4251f1$export$c868ef28d2ba36f1), {
157
+ entry: entry,
158
+ toClose: toClose
159
+ }, i))
160
+ });
161
+ });
162
+ $567ed433af94513f$export$8dc6765e8be191c7.displayName = "ContextMenu";
163
+
164
+
165
+
166
+
167
+ var $c7a6ae87165004e6$exports = {};
168
+
169
+ $parcel$export($c7a6ae87165004e6$exports, "caretHolder", function () { return $c7a6ae87165004e6$export$6ed5f4fbab298e07; }, function (v) { return $c7a6ae87165004e6$export$6ed5f4fbab298e07 = v; });
170
+ $parcel$export($c7a6ae87165004e6$exports, "disabled", function () { return $c7a6ae87165004e6$export$683472f6198a076e; }, function (v) { return $c7a6ae87165004e6$export$683472f6198a076e = v; });
171
+ $parcel$export($c7a6ae87165004e6$exports, "hidden", function () { return $c7a6ae87165004e6$export$73920f18ca706874; }, function (v) { return $c7a6ae87165004e6$export$73920f18ca706874 = v; });
172
+ $parcel$export($c7a6ae87165004e6$exports, "lowMenu", function () { return $c7a6ae87165004e6$export$59e4b099a896b33; }, function (v) { return $c7a6ae87165004e6$export$59e4b099a896b33 = v; });
173
+ $parcel$export($c7a6ae87165004e6$exports, "lowMenu-item", function () { return $c7a6ae87165004e6$export$19fbf76b734bf310; }, function (v) { return $c7a6ae87165004e6$export$19fbf76b734bf310 = v; });
174
+ $parcel$export($c7a6ae87165004e6$exports, "lowMenuButtonHolder", function () { return $c7a6ae87165004e6$export$22ec12d194e0789c; }, function (v) { return $c7a6ae87165004e6$export$22ec12d194e0789c = v; });
175
+ $parcel$export($c7a6ae87165004e6$exports, "lowMenuItem", function () { return $c7a6ae87165004e6$export$2ad34a478577e75d; }, function (v) { return $c7a6ae87165004e6$export$2ad34a478577e75d = v; });
176
+ $parcel$export($c7a6ae87165004e6$exports, "subMenu", function () { return $c7a6ae87165004e6$export$6e0e6ce39e5a0361; }, function (v) { return $c7a6ae87165004e6$export$6e0e6ce39e5a0361 = v; });
177
+ $parcel$export($c7a6ae87165004e6$exports, "visible", function () { return $c7a6ae87165004e6$export$664c6d24e3175067; }, function (v) { return $c7a6ae87165004e6$export$664c6d24e3175067 = v; });
178
+ var $c7a6ae87165004e6$export$6ed5f4fbab298e07;
179
+ var $c7a6ae87165004e6$export$683472f6198a076e;
180
+ var $c7a6ae87165004e6$export$73920f18ca706874;
181
+ var $c7a6ae87165004e6$export$59e4b099a896b33;
182
+ var $c7a6ae87165004e6$export$19fbf76b734bf310;
183
+ var $c7a6ae87165004e6$export$22ec12d194e0789c;
184
+ var $c7a6ae87165004e6$export$2ad34a478577e75d;
185
+ var $c7a6ae87165004e6$export$6e0e6ce39e5a0361;
186
+ var $c7a6ae87165004e6$export$664c6d24e3175067;
187
+ $c7a6ae87165004e6$export$6ed5f4fbab298e07 = `aiw-LowMenu-module-JfzGeq-caretHolder`;
188
+ $c7a6ae87165004e6$export$683472f6198a076e = `aiw-LowMenu-module-JfzGeq-disabled`;
189
+ $c7a6ae87165004e6$export$73920f18ca706874 = `aiw-LowMenu-module-JfzGeq-hidden`;
190
+ $c7a6ae87165004e6$export$59e4b099a896b33 = `aiw-LowMenu-module-JfzGeq-lowMenu`;
191
+ $c7a6ae87165004e6$export$19fbf76b734bf310 = `aiw-LowMenu-module-JfzGeq-lowMenu-item`;
192
+ $c7a6ae87165004e6$export$22ec12d194e0789c = `aiw-LowMenu-module-JfzGeq-lowMenuButtonHolder`;
193
+ $c7a6ae87165004e6$export$2ad34a478577e75d = `aiw-LowMenu-module-JfzGeq-lowMenuItem`;
194
+ $c7a6ae87165004e6$export$6e0e6ce39e5a0361 = `aiw-LowMenu-module-JfzGeq-subMenu`;
195
+ $c7a6ae87165004e6$export$664c6d24e3175067 = `aiw-LowMenu-module-JfzGeq-visible`;
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+ const $61945e5157f5e5bf$export$251b9f54013cdfac = ({ entry: entry })=>{
205
+ const [visible, setVisible] = (0, $duWW8$useState)(false);
206
+ if (!entry.group || entry.group.length === 0) return /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Fragment), {});
207
+ return /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
208
+ "aria-label": `Sub menu for ${entry.label}`,
209
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).caretHolder,
210
+ onMouseEnter: ()=>{
211
+ setVisible(true);
212
+ },
213
+ onMouseLeave: ()=>{
214
+ setVisible(false);
215
+ },
216
+ children: [
217
+ /*#__PURE__*/ (0, $duWW8$jsx)("svg", {
218
+ xmlns: "http://www.w3.org/2000/svg",
219
+ width: "16",
220
+ height: "16",
221
+ fill: "currentColor",
222
+ viewBox: "0 0 16 16",
223
+ children: /*#__PURE__*/ (0, $duWW8$jsx)("path", {
224
+ d: "m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"
225
+ })
226
+ }),
227
+ /*#__PURE__*/ (0, $duWW8$jsx)("div", {
228
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).subMenu,
229
+ children: visible && /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
230
+ visible: visible,
231
+ entries: entry.group,
232
+ xPos: 14,
233
+ yPos: entry.group.length * -21 - 8,
234
+ toClose: ()=>setVisible(false)
235
+ })
236
+ })
237
+ ]
238
+ });
239
+ };
240
+ $61945e5157f5e5bf$export$251b9f54013cdfac.displayName = "LowSubMenu";
241
+
242
+
243
+
244
+ const $556d6f9158abfc99$export$aafc28aea571c4bc = ({ entry: entry })=>{
245
+ const [target, setTarget] = (0, $duWW8$useState)(null);
246
+ return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
247
+ className: [
248
+ (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).lowMenuItem,
249
+ entry.disabled ? (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).disabled : ""
250
+ ].filter((c)=>c !== "").join(" "),
251
+ "aria-label": typeof entry.label === "string" ? entry.label : undefined,
252
+ "aria-disabled": entry.disabled,
253
+ onMouseEnter: ()=>{
254
+ const sel = window.getSelection();
255
+ const target = sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
256
+ setTarget(target);
257
+ },
258
+ onMouseLeave: ()=>{
259
+ setTarget(null);
260
+ },
261
+ onClick: (e)=>{
262
+ e.preventDefault();
263
+ e.stopPropagation();
264
+ entry.action && !entry.disabled && entry.action(target);
265
+ },
266
+ children: [
267
+ /*#__PURE__*/ (0, $duWW8$jsx)("span", {
268
+ children: entry.label
269
+ }),
270
+ entry.group && /*#__PURE__*/ (0, $duWW8$jsx)((0, $61945e5157f5e5bf$export$251b9f54013cdfac), {
271
+ entry: entry
272
+ })
273
+ ]
274
+ });
275
+ };
276
+ $556d6f9158abfc99$export$aafc28aea571c4bc.displayName = "LowMenuButton";
277
+
278
+
279
+ const $914758b0c9d59759$export$49e8edc8ebca5f25 = ({ entries: entries, visible: visible, xPos: xPos, yPos: yPos, maxWidth: maxWidth })=>{
280
+ return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
281
+ className: [
282
+ (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).lowMenu,
283
+ visible ? (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).visible : (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).hidden
284
+ ].join(" "),
285
+ "aria-label": "Low context menu",
286
+ style: {
287
+ left: `${xPos}px`,
288
+ top: `${yPos}px`,
289
+ maxWidth: `calc(${maxWidth}px)`,
290
+ width: `calc(${maxWidth}px - 4px)`
291
+ },
292
+ children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
293
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).lowMenuButtonHolder,
294
+ children: entries.map((e, i)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $556d6f9158abfc99$export$aafc28aea571c4bc), {
295
+ entry: e
296
+ }, i))
297
+ })
298
+ });
299
+ };
300
+ $914758b0c9d59759$export$49e8edc8ebca5f25.displayName = "LowMenu";
301
+
302
+
303
+ const $1e1c1e9e0b943830$export$fc58dc71afe92de2 = /*#__PURE__*/ (0, $duWW8$createContext)(null);
304
+ const $1e1c1e9e0b943830$export$ed4f9641643dc7e4 = ({ children: children, menuItems: menuItems, showLowMenu: showLowMenu = false, ...rest })=>{
305
+ // Check for higher content menu
306
+ const higherContext = (0, $duWW8$useContext)($1e1c1e9e0b943830$export$fc58dc71afe92de2);
307
+ const thisMenuItems = (0, $duWW8$useMemo)(()=>[
308
+ ...higherContext !== null ? [
309
+ ...higherContext.menuItems,
310
+ {
311
+ label: /*#__PURE__*/ (0, $duWW8$jsx)("hr", {
312
+ style: {
313
+ flexGrow: 1,
314
+ cursor: "none",
315
+ margin: "0",
316
+ padding: "0"
317
+ }
318
+ })
319
+ }
320
+ ] : [],
321
+ ...menuItems
322
+ ], [
323
+ higherContext,
324
+ menuItems
325
+ ]);
326
+ // Menu resources
327
+ const divHandlderRef = (0, $duWW8$useRef)(null);
328
+ const menuRef = (0, $duWW8$useRef)(null);
329
+ const [menuXPos, setMenuXPos] = (0, $duWW8$useState)(0);
330
+ const [menuYPos, setMenuYPos] = (0, $duWW8$useState)(0);
331
+ const [menuVisible, setMenuVisible] = (0, $duWW8$useState)(false);
332
+ const [menuInDom, setMenuInDom] = (0, $duWW8$useState)(false);
333
+ const [mouseOverHandlerDiv, setMouseOverHandlerDiv] = (0, $duWW8$useState)(false);
334
+ const [mouseOverMenu, setMouseOverMenu] = (0, $duWW8$useState)(false);
335
+ // Get holder position
336
+ const divHandlerPos = divHandlderRef ? divHandlderRef.current?.getBoundingClientRect() : null;
337
+ // Handle click off the menu
338
+ const handleClick = (0, $duWW8$useCallback)((e)=>{
339
+ if (menuRef.current && (e.target instanceof Element && !menuRef.current?.contains(e.target) || !(e.target instanceof Element))) setMenuVisible(false);
340
+ }, []);
341
+ // Update the document click handler
342
+ (0, $duWW8$useEffect)(()=>{
343
+ if (menuVisible) document.addEventListener("mousedown", handleClick);
344
+ else document.removeEventListener("mousedown", handleClick);
345
+ return ()=>{
346
+ document.removeEventListener("mousedown", handleClick);
347
+ };
348
+ }, [
349
+ handleClick,
350
+ menuVisible
351
+ ]);
352
+ const removeController = (0, $duWW8$useRef)(new AbortController());
353
+ (0, $duWW8$useEffect)(()=>{
354
+ if (!mouseOverMenu && !menuVisible && !mouseOverHandlerDiv) {
355
+ removeController.current.abort();
356
+ removeController.current = new AbortController();
357
+ setTimeout(()=>{
358
+ if (!removeController.current.signal.aborted) setMenuInDom(false);
359
+ }, 300);
360
+ }
361
+ }, [
362
+ mouseOverHandlerDiv,
363
+ menuVisible,
364
+ mouseOverMenu
365
+ ]);
366
+ return /*#__PURE__*/ (0, $duWW8$jsxs)($1e1c1e9e0b943830$export$fc58dc71afe92de2.Provider, {
367
+ value: {
368
+ menuItems: thisMenuItems
369
+ },
370
+ children: [
371
+ /*#__PURE__*/ (0, $duWW8$jsx)("div", {
372
+ ref: divHandlderRef,
373
+ ...rest,
374
+ className: [
375
+ (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).contextMenuHandler,
376
+ rest.className
377
+ ].join(" "),
378
+ onContextMenu: (e)=>{
379
+ if (!showLowMenu) {
380
+ setMenuInDom(true);
381
+ e.preventDefault();
382
+ e.stopPropagation();
383
+ setTimeout(()=>{
384
+ removeController.current.abort();
385
+ setMenuVisible(true);
386
+ setMenuXPos(e.pageX);
387
+ setMenuYPos(e.pageY);
388
+ }, 1);
389
+ }
390
+ },
391
+ onMouseEnter: (e)=>{
392
+ if (showLowMenu) {
393
+ setMenuInDom(true);
394
+ setMouseOverHandlerDiv(false);
395
+ setTimeout(()=>{
396
+ removeController.current.abort();
397
+ setMouseOverHandlerDiv(true);
398
+ }, 1);
399
+ }
400
+ rest.onMouseEnter && rest.onMouseEnter(e);
401
+ },
402
+ onMouseLeave: (e)=>{
403
+ if (showLowMenu) {
404
+ removeController.current.abort();
405
+ removeController.current = new AbortController();
406
+ setMouseOverHandlerDiv(false);
407
+ }
408
+ rest.onMouseLeave && rest.onMouseLeave(e);
409
+ },
410
+ children: children
411
+ }),
412
+ menuInDom && divHandlerPos && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsx)("div", {
413
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).anchor,
414
+ onMouseEnter: ()=>{
415
+ removeController.current.abort();
416
+ setMouseOverMenu(true);
417
+ },
418
+ onMouseLeave: ()=>{
419
+ removeController.current.abort();
420
+ removeController.current = new AbortController();
421
+ setMouseOverMenu(false);
422
+ },
423
+ children: showLowMenu ? /*#__PURE__*/ (0, $duWW8$jsx)((0, $914758b0c9d59759$export$49e8edc8ebca5f25), {
424
+ visible: mouseOverHandlerDiv,
425
+ entries: menuItems,
426
+ xPos: divHandlerPos.left,
427
+ yPos: divHandlerPos.bottom,
428
+ maxWidth: divHandlerPos.width
429
+ }) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
430
+ visible: menuVisible,
431
+ ref: menuRef,
432
+ entries: thisMenuItems,
433
+ xPos: menuXPos,
434
+ yPos: menuYPos,
435
+ toClose: ()=>{
436
+ setMenuVisible(false);
437
+ setMouseOverMenu(false);
438
+ }
439
+ })
440
+ }), document.body)
441
+ ]
442
+ });
443
+ };
444
+ $1e1c1e9e0b943830$export$ed4f9641643dc7e4.displayName = "ContextMenuHandler";
445
+
446
+
447
+
448
+
449
+
450
+ const $ab4d5d6bf03370d0$export$d81cfea7c54be196 = (divRef)=>{
451
+ if (!divRef.current) return {
452
+ translateX: 0,
453
+ translateY: 0
454
+ };
455
+ else {
456
+ const innerBounce = 16;
457
+ const posn = divRef.current.getBoundingClientRect();
458
+ let translateX = 0;
459
+ if (posn.left < innerBounce) translateX = -posn.left + innerBounce;
460
+ else if (posn.right > window.innerWidth) translateX = Math.max(-posn.left + innerBounce, window.innerWidth - posn.right - innerBounce);
461
+ let translateY = 0;
462
+ if (posn.top < innerBounce) translateY = -posn.top + innerBounce;
463
+ else if (posn.bottom > window.innerHeight) translateY = Math.max(-posn.top + innerBounce, window.innerHeight - posn.bottom - innerBounce);
464
+ return {
465
+ translateX: translateX,
466
+ translateY: translateY
467
+ };
468
+ }
469
+ };
470
+
471
+
472
+ var $ddf7153c7c69b209$exports = {};
473
+
474
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindow", function () { return $ddf7153c7c69b209$export$72cad2e5ad4d2674; }, function (v) { return $ddf7153c7c69b209$export$72cad2e5ad4d2674 = v; });
475
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowAnchor", function () { return $ddf7153c7c69b209$export$9f3a8a17ac700f7d; }, function (v) { return $ddf7153c7c69b209$export$9f3a8a17ac700f7d = v; });
476
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowBody", function () { return $ddf7153c7c69b209$export$dfb2c4d2d1c0156f; }, function (v) { return $ddf7153c7c69b209$export$dfb2c4d2d1c0156f = v; });
477
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowTitle", function () { return $ddf7153c7c69b209$export$1b02f2cd2f7db0f4; }, function (v) { return $ddf7153c7c69b209$export$1b02f2cd2f7db0f4 = v; });
478
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowTitleClose", function () { return $ddf7153c7c69b209$export$7ba38d4cc2870e66; }, function (v) { return $ddf7153c7c69b209$export$7ba38d4cc2870e66 = v; });
479
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowTitleText", function () { return $ddf7153c7c69b209$export$cebbac70b4d99c48; }, function (v) { return $ddf7153c7c69b209$export$cebbac70b4d99c48 = v; });
480
+ $parcel$export($ddf7153c7c69b209$exports, "moving", function () { return $ddf7153c7c69b209$export$d03a2f3acc60252b; }, function (v) { return $ddf7153c7c69b209$export$d03a2f3acc60252b = v; });
481
+ var $ddf7153c7c69b209$export$72cad2e5ad4d2674;
482
+ var $ddf7153c7c69b209$export$9f3a8a17ac700f7d;
483
+ var $ddf7153c7c69b209$export$dfb2c4d2d1c0156f;
484
+ var $ddf7153c7c69b209$export$1b02f2cd2f7db0f4;
485
+ var $ddf7153c7c69b209$export$7ba38d4cc2870e66;
486
+ var $ddf7153c7c69b209$export$cebbac70b4d99c48;
487
+ var $ddf7153c7c69b209$export$d03a2f3acc60252b;
488
+ $ddf7153c7c69b209$export$72cad2e5ad4d2674 = `aiw-ContextWindow-module-RIIF9a-contextWindow`;
489
+ $ddf7153c7c69b209$export$9f3a8a17ac700f7d = `aiw-ContextWindow-module-RIIF9a-contextWindowAnchor`;
490
+ $ddf7153c7c69b209$export$dfb2c4d2d1c0156f = `aiw-ContextWindow-module-RIIF9a-contextWindowBody`;
491
+ $ddf7153c7c69b209$export$1b02f2cd2f7db0f4 = `aiw-ContextWindow-module-RIIF9a-contextWindowTitle`;
492
+ $ddf7153c7c69b209$export$7ba38d4cc2870e66 = `aiw-ContextWindow-module-RIIF9a-contextWindowTitleClose`;
493
+ $ddf7153c7c69b209$export$cebbac70b4d99c48 = `aiw-ContextWindow-module-RIIF9a-contextWindowTitleText`;
494
+ $ddf7153c7c69b209$export$d03a2f3acc60252b = `aiw-ContextWindow-module-RIIF9a-moving`;
495
+
496
+
497
+
498
+
499
+ const $17c46b9e6a2eb66e$export$aff5d0593e3727b0 = /*#__PURE__*/ (0, $duWW8$createContext)(null);
500
+ const $17c46b9e6a2eb66e$var$pushToTop = (windowId, minZIndex, windowList, setWindowList)=>{
501
+ const otherWindows = windowList.filter((w)=>w.windowId !== windowId).map((w, i)=>({
502
+ windowId: w.windowId,
503
+ zIndex: minZIndex + i
504
+ }));
505
+ setWindowList([
506
+ ...otherWindows,
507
+ {
508
+ windowId: windowId,
509
+ zIndex: minZIndex + otherWindows.length
510
+ }
511
+ ]);
512
+ };
513
+ const $17c46b9e6a2eb66e$export$9f37482ccd50dad2 = ({ minZIndex: minZIndex = 1000, children: children })=>{
514
+ const [currentWindows, setCurrentWindows] = (0, $duWW8$useState)([]);
515
+ return /*#__PURE__*/ (0, $duWW8$jsx)($17c46b9e6a2eb66e$export$aff5d0593e3727b0.Provider, {
516
+ value: {
517
+ currentWindows: currentWindows.map((w)=>({
518
+ windowId: w.windowId,
519
+ zIndex: minZIndex + w.zIndex
520
+ })),
521
+ pushToTop: (ret)=>$17c46b9e6a2eb66e$var$pushToTop(ret, minZIndex, currentWindows, setCurrentWindows)
522
+ },
523
+ children: children
524
+ });
525
+ };
526
+ $17c46b9e6a2eb66e$export$9f37482ccd50dad2.displayName = "ContextWindowStack";
527
+
528
+
529
+ const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, title: title, titleElement: titleElement, children: children, onOpen: onOpen, onClose: onClose, ...rest })=>{
530
+ const windowStack = (0, $duWW8$useContext)((0, $17c46b9e6a2eb66e$export$aff5d0593e3727b0));
531
+ const windowId = (0, $duWW8$useRef)(null);
532
+ const divRef = (0, $duWW8$useRef)(null);
533
+ const windowRef = (0, $duWW8$useRef)(null);
534
+ const [windowInDOM, setWindowInDOM] = (0, $duWW8$useState)(false);
535
+ const [windowVisible, setWindowVisible] = (0, $duWW8$useState)(false);
536
+ const zIndex = (0, $duWW8$useMemo)(()=>{
537
+ return windowStack?.currentWindows.find((w)=>w.windowId === windowId.current)?.zIndex ?? 1;
538
+ }, [
539
+ windowStack?.currentWindows
540
+ ]);
541
+ // Position
542
+ const windowPos = (0, $duWW8$useRef)({
543
+ x: 0,
544
+ y: 0
545
+ });
546
+ const [moving, setMoving] = (0, $duWW8$useState)(false);
547
+ const move = (0, $duWW8$useCallback)((x, y)=>{
548
+ if (windowRef.current && windowPos.current) {
549
+ const window1 = windowRef.current;
550
+ const pos = windowPos.current;
551
+ pos.x += x;
552
+ pos.y += y;
553
+ window1.style.transform = `translate(${pos.x}px, ${pos.y}px)`;
554
+ }
555
+ }, []);
556
+ const checkPosition = (0, $duWW8$useCallback)(()=>{
557
+ const chkPos = (0, $ab4d5d6bf03370d0$export$d81cfea7c54be196)(windowRef);
558
+ move(chkPos.translateX, chkPos.translateY);
559
+ }, [
560
+ move
561
+ ]);
562
+ const mouseMove = (0, $duWW8$useCallback)((e)=>{
563
+ e.preventDefault();
564
+ e.stopPropagation();
565
+ move(e.movementX, e.movementY);
566
+ }, [
567
+ move
568
+ ]);
569
+ const mouseUp = (0, $duWW8$useCallback)((e)=>{
570
+ e.preventDefault();
571
+ e.stopPropagation();
572
+ setMoving(false);
573
+ checkPosition();
574
+ document.removeEventListener("mousemove", mouseMove);
575
+ document.removeEventListener("mouseup", mouseUp);
576
+ window.removeEventListener("resize", checkPosition);
577
+ if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "auto";
578
+ }, [
579
+ checkPosition,
580
+ mouseMove
581
+ ]);
582
+ // Update visibility
583
+ (0, $duWW8$useEffect)(()=>{
584
+ if (windowStack) {
585
+ // Visible set, but not in DOM
586
+ if (visible && !windowInDOM) setWindowInDOM(true);
587
+ else if (visible && windowInDOM && !windowVisible) {
588
+ if (!windowId.current) {
589
+ const maxWindowId = Math.max(0, ...windowStack.currentWindows.map((w)=>w.windowId));
590
+ windowId.current = maxWindowId + 1;
591
+ }
592
+ windowStack.pushToTop(windowId.current);
593
+ setWindowVisible(visible);
594
+ onOpen && onOpen();
595
+ // Get starting position
596
+ if (divRef.current && windowRef.current) {
597
+ const parentPos = divRef.current.getBoundingClientRect();
598
+ const pos = windowRef.current.getBoundingClientRect();
599
+ const windowHeight = pos.bottom - pos.top;
600
+ windowRef.current.style.left = `${parentPos.left}px`;
601
+ windowRef.current.style.top = `${parentPos.bottom + windowHeight < window.innerHeight ? parentPos.bottom : Math.max(0, parentPos.top - windowHeight)}px`;
602
+ windowRef.current.style.transform = "";
603
+ windowPos.current = {
604
+ x: 0,
605
+ y: 0
606
+ };
607
+ }
608
+ checkPosition();
609
+ } else if (windowId.current && !visible && windowVisible) setWindowVisible(false);
610
+ else if (windowId.current && !visible && windowInDOM) setWindowInDOM(false);
611
+ }
612
+ }, [
613
+ checkPosition,
614
+ onOpen,
615
+ visible,
616
+ windowInDOM,
617
+ windowStack,
618
+ windowVisible
619
+ ]);
620
+ return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
621
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowAnchor,
622
+ ref: divRef,
623
+ children: [
624
+ !windowStack && /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
625
+ ...rest,
626
+ children: [
627
+ false,
628
+ children
629
+ ]
630
+ }),
631
+ windowStack && windowInDOM && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsxs)("div", {
632
+ ...rest,
633
+ ref: windowRef,
634
+ id: id,
635
+ className: [
636
+ (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindow,
637
+ rest.className
638
+ ].join(" "),
639
+ style: {
640
+ ...rest.style,
641
+ opacity: moving ? 0.8 : windowVisible ? 1 : 0,
642
+ visibility: windowVisible ? "visible" : "hidden",
643
+ zIndex: zIndex ?? 1,
644
+ minHeight: rest.style?.minHeight ?? "150px",
645
+ minWidth: rest.style?.minWidth ?? "200px",
646
+ maxHeight: rest.style?.maxHeight ?? "1000px",
647
+ maxWidth: rest.style?.maxWidth ?? "1000px"
648
+ },
649
+ onClickCapture: (e)=>{
650
+ windowId && windowId.current && windowStack.pushToTop(windowId.current);
651
+ rest.onClickCapture && rest.onClickCapture(e);
652
+ },
653
+ children: [
654
+ /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
655
+ className: [
656
+ (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitle,
657
+ moving ? (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).moving : ""
658
+ ].filter((c)=>c !== "").join(" "),
659
+ onMouseDown: (e)=>{
660
+ if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "none";
661
+ setMoving(true);
662
+ windowId && windowId.current && windowStack.pushToTop(windowId.current);
663
+ document.addEventListener("mouseup", mouseUp);
664
+ document.addEventListener("mousemove", mouseMove);
665
+ window.addEventListener("resize", ()=>checkPosition());
666
+ },
667
+ children: [
668
+ /*#__PURE__*/ (0, $duWW8$jsx)("div", {
669
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitleText,
670
+ title: title,
671
+ children: titleElement ? titleElement : title
672
+ }),
673
+ /*#__PURE__*/ (0, $duWW8$jsx)("div", {
674
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitleClose,
675
+ role: "button",
676
+ "aria-label": "Close",
677
+ onClick: onClose,
678
+ title: `Close ${title && title.trim() !== "" ? title : "window"}`,
679
+ children: /*#__PURE__*/ (0, $duWW8$jsx)("svg", {
680
+ xmlns: "http://www.w3.org/2000/svg",
681
+ width: "16",
682
+ height: "16",
683
+ fill: "currentColor",
684
+ viewBox: "0 0 16 16",
685
+ "aria-label": "Close window",
686
+ children: /*#__PURE__*/ (0, $duWW8$jsx)("path", {
687
+ d: "M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"
688
+ })
689
+ })
690
+ })
691
+ ]
692
+ }),
693
+ /*#__PURE__*/ (0, $duWW8$jsx)("div", {
694
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowBody,
695
+ children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
696
+ children: children
697
+ })
698
+ })
699
+ ]
700
+ }), document.body)
701
+ ]
702
+ });
703
+ };
704
+ $b5e8657823def5be$export$1af8984c69ba1b24.displayName = "ContextWindow";
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+ export {$1e1c1e9e0b943830$export$ed4f9641643dc7e4 as ContextMenuHandler, $b5e8657823def5be$export$1af8984c69ba1b24 as ContextWindow, $17c46b9e6a2eb66e$export$9f37482ccd50dad2 as ContextWindowStack};
713
+ //# sourceMappingURL=main.js.map