@asup/context-menu 1.3.8 → 1.3.10

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