@asup/context-menu 1.3.3 → 1.3.5

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 CHANGED
@@ -1,12 +1,18 @@
1
1
  import "./main.css";
2
- import {jsxs as $duWW8$jsxs, Fragment as $duWW8$Fragment, jsx as $duWW8$jsx} from "react/jsx-runtime";
3
- import $duWW8$react, {useRef as $duWW8$useRef, useState as $duWW8$useState, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect, useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, createContext as $duWW8$createContext} from "react";
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
4
  import {createPortal as $duWW8$createPortal} from "react-dom";
5
5
 
6
6
 
7
7
  function $parcel$export(e, n, v, s) {
8
8
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
9
  }
10
+
11
+ function $parcel$interopDefault(a) {
12
+ return a && a.__esModule ? a.default : a;
13
+ }
14
+
15
+
10
16
  var $b65191f6d0a0a991$exports = {};
11
17
 
12
18
  $parcel$export($b65191f6d0a0a991$exports, "ContextMenuHandler", function () { return $1e1c1e9e0b943830$export$ed4f9641643dc7e4; });
@@ -17,13 +23,48 @@ $parcel$export($b65191f6d0a0a991$exports, "ContextWindowStack", function () { re
17
23
 
18
24
 
19
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-WinFxq-anchor`;
49
+ $47067f35ca62d4a5$export$6ed5f4fbab298e07 = `aiw-WinFxq-caretHolder`;
50
+ $47067f35ca62d4a5$export$218b899e1d476006 = `aiw-WinFxq-contextMenu`;
51
+ $47067f35ca62d4a5$export$ed8ffb5bb55a3bc8 = `aiw-WinFxq-contextMenuHandler`;
52
+ $47067f35ca62d4a5$export$e5ea51c279904378 = `aiw-WinFxq-contextMenuItem`;
53
+ $47067f35ca62d4a5$export$6ada86c5b962aa22 = `aiw-WinFxq-contextMenuItemLabel`;
54
+ $47067f35ca62d4a5$export$683472f6198a076e = `aiw-WinFxq-disabled`;
55
+ $47067f35ca62d4a5$export$73920f18ca706874 = `aiw-WinFxq-hidden`;
56
+ $47067f35ca62d4a5$export$6e0e6ce39e5a0361 = `aiw-WinFxq-subMenu`;
57
+ $47067f35ca62d4a5$export$664c6d24e3175067 = `aiw-WinFxq-visible`;
58
+
59
+
20
60
 
21
61
 
22
62
 
23
- const $6ca59110355c8bf1$export$7e4e6110f96afd7e = ({ entries: entries, target: target, toClose: toClose })=>{
63
+
64
+ const $6ca59110355c8bf1$export$7e4e6110f96afd7e = ({ entries: entries, toClose: toClose })=>{
24
65
  const [visible, setVisible] = (0, $duWW8$useState)(false);
25
66
  return /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
26
- className: "caret-holder",
67
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).caretHolder,
27
68
  onMouseEnter: ()=>{
28
69
  setVisible(true);
29
70
  },
@@ -42,11 +83,10 @@ const $6ca59110355c8bf1$export$7e4e6110f96afd7e = ({ entries: entries, target: t
42
83
  })
43
84
  }),
44
85
  /*#__PURE__*/ (0, $duWW8$jsx)("div", {
45
- className: "sub-menu",
86
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).subMenu,
46
87
  children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
47
88
  visible: visible,
48
89
  entries: entries,
49
- target: target,
50
90
  xPos: 14,
51
91
  yPos: -21,
52
92
  toClose: toClose
@@ -58,11 +98,14 @@ const $6ca59110355c8bf1$export$7e4e6110f96afd7e = ({ entries: entries, target: t
58
98
  $6ca59110355c8bf1$export$7e4e6110f96afd7e.displayName = "ContextSubMenu";
59
99
 
60
100
 
61
- const $567ed433af94513f$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $duWW8$react).forwardRef(({ visible: visible, entries: entries, target: target, xPos: xPos, yPos: yPos, toClose: toClose }, ref)=>{
62
- $567ed433af94513f$export$8dc6765e8be191c7.displayName = "ContextMenu";
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);
63
103
  return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
64
104
  ref: ref,
65
- className: `context-menu${visible ? " visible" : ""}`,
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(" "),
66
109
  style: {
67
110
  top: `${yPos}px`,
68
111
  left: `${xPos}px`
@@ -72,24 +115,34 @@ const $567ed433af94513f$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $duWW8$react
72
115
  e.stopPropagation();
73
116
  },
74
117
  children: entries.map((entry, i)=>/*#__PURE__*/ (0, $duWW8$jsxs)("div", {
75
- className: `context-menu-item${entry.disabled ? " disabled" : ""}`,
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(" "),
76
122
  children: [
77
- /*#__PURE__*/ (0, $duWW8$jsx)("span", {
123
+ typeof entry.label === "string" ? /*#__PURE__*/ (0, $duWW8$jsx)("span", {
78
124
  "aria-label": typeof entry.label === "string" ? entry.label : undefined,
79
125
  "aria-disabled": entry.disabled,
80
- className: "context-menu-item-label",
81
- onMouseDownCapture: (ev)=>{
82
- ev.preventDefault();
83
- ev.stopPropagation();
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();
84
138
  entry.action && !entry.disabled && entry.action(target);
85
139
  !entry.disabled && toClose();
86
140
  },
87
141
  children: entry.label
88
- }),
142
+ }) : entry.label,
89
143
  entry.group && /*#__PURE__*/ (0, $duWW8$jsx)((0, $6ca59110355c8bf1$export$7e4e6110f96afd7e), {
90
144
  toClose: toClose,
91
- entries: entry.group,
92
- target: target
145
+ entries: entry.group
93
146
  })
94
147
  ]
95
148
  }, i))
@@ -100,17 +153,49 @@ $567ed433af94513f$export$8dc6765e8be191c7.displayName = "ContextMenu";
100
153
 
101
154
 
102
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-JfzGeq-caretHolder`;
177
+ $c7a6ae87165004e6$export$683472f6198a076e = `aiw-JfzGeq-disabled`;
178
+ $c7a6ae87165004e6$export$73920f18ca706874 = `aiw-JfzGeq-hidden`;
179
+ $c7a6ae87165004e6$export$59e4b099a896b33 = `aiw-JfzGeq-lowMenu`;
180
+ $c7a6ae87165004e6$export$19fbf76b734bf310 = `aiw-JfzGeq-lowMenu-item`;
181
+ $c7a6ae87165004e6$export$22ec12d194e0789c = `aiw-JfzGeq-lowMenuButtonHolder`;
182
+ $c7a6ae87165004e6$export$2ad34a478577e75d = `aiw-JfzGeq-lowMenuItem`;
183
+ $c7a6ae87165004e6$export$6e0e6ce39e5a0361 = `aiw-JfzGeq-subMenu`;
184
+ $c7a6ae87165004e6$export$664c6d24e3175067 = `aiw-JfzGeq-visible`;
185
+
103
186
 
104
187
 
105
188
 
106
189
 
107
190
 
108
- const $61945e5157f5e5bf$export$251b9f54013cdfac = ({ entry: entry, target: target })=>{
191
+
192
+
193
+ const $61945e5157f5e5bf$export$251b9f54013cdfac = ({ entry: entry })=>{
109
194
  const [visible, setVisible] = (0, $duWW8$useState)(false);
110
195
  if (!entry.group || entry.group.length === 0) return /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Fragment), {});
111
196
  return /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
112
197
  "aria-label": `Sub menu for ${entry.label}`,
113
- className: "caret-holder",
198
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).caretHolder,
114
199
  onMouseEnter: ()=>{
115
200
  setVisible(true);
116
201
  },
@@ -129,11 +214,10 @@ const $61945e5157f5e5bf$export$251b9f54013cdfac = ({ entry: entry, target: targe
129
214
  })
130
215
  }),
131
216
  /*#__PURE__*/ (0, $duWW8$jsx)("div", {
132
- className: "sub-menu",
133
- children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
217
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($c7a6ae87165004e6$exports))).subMenu,
218
+ children: visible && /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
134
219
  visible: visible,
135
220
  entries: entry.group,
136
- target: target,
137
221
  xPos: 14,
138
222
  yPos: entry.group.length * -21 - 8,
139
223
  toClose: ()=>setVisible(false)
@@ -145,24 +229,35 @@ const $61945e5157f5e5bf$export$251b9f54013cdfac = ({ entry: entry, target: targe
145
229
  $61945e5157f5e5bf$export$251b9f54013cdfac.displayName = "LowSubMenu";
146
230
 
147
231
 
148
- const $556d6f9158abfc99$export$aafc28aea571c4bc = ({ entry: entry, target: target })=>{
232
+
233
+ const $556d6f9158abfc99$export$aafc28aea571c4bc = ({ entry: entry })=>{
234
+ const [target, setTarget] = (0, $duWW8$useState)(null);
149
235
  return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
150
- className: `low-menu-item${entry.disabled ? " disabled" : ""}`,
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(" "),
151
240
  "aria-label": typeof entry.label === "string" ? entry.label : undefined,
152
241
  "aria-disabled": entry.disabled,
153
- onClick: (event)=>{
154
- event.preventDefault();
155
- event.stopPropagation();
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();
156
253
  entry.action && !entry.disabled && entry.action(target);
157
254
  },
158
255
  children: [
159
256
  /*#__PURE__*/ (0, $duWW8$jsx)("span", {
160
- className: "low-menu-item-label",
161
257
  children: entry.label
162
258
  }),
163
259
  entry.group && /*#__PURE__*/ (0, $duWW8$jsx)((0, $61945e5157f5e5bf$export$251b9f54013cdfac), {
164
- entry: entry,
165
- target: target
260
+ entry: entry
166
261
  })
167
262
  ]
168
263
  });
@@ -170,42 +265,65 @@ const $556d6f9158abfc99$export$aafc28aea571c4bc = ({ entry: entry, target: targe
170
265
  $556d6f9158abfc99$export$aafc28aea571c4bc.displayName = "LowMenuButton";
171
266
 
172
267
 
173
- const $914758b0c9d59759$export$49e8edc8ebca5f25 = ({ entries: entries, target: target, visible: visible })=>{
268
+ const $914758b0c9d59759$export$49e8edc8ebca5f25 = ({ entries: entries, visible: visible, xPos: xPos, yPos: yPos, maxWidth: maxWidth })=>{
174
269
  return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
175
- className: `low-menu ${visible ? "visible" : "hidden"}`,
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(" "),
176
274
  "aria-label": "Low context menu",
177
- children: entries.map((e, i)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $556d6f9158abfc99$export$aafc28aea571c4bc), {
178
- entry: e,
179
- target: target
180
- }, i))
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
+ })
181
287
  });
182
288
  };
183
289
  $914758b0c9d59759$export$49e8edc8ebca5f25.displayName = "LowMenu";
184
290
 
185
291
 
186
- const $1e1c1e9e0b943830$export$ed4f9641643dc7e4 = ({ children: children, menuItems: menuItems, showLowMenu: showLowMenu = false, style: style = {
187
- height: "fit-content",
188
- width: "fit-content"
189
- } })=>{
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
+ ]);
190
316
  // Menu resources
191
- const divRef = (0, $duWW8$useRef)(null);
317
+ const divHandlderRef = (0, $duWW8$useRef)(null);
192
318
  const menuRef = (0, $duWW8$useRef)(null);
193
319
  const [menuXPos, setMenuXPos] = (0, $duWW8$useState)(0);
194
320
  const [menuYPos, setMenuYPos] = (0, $duWW8$useState)(0);
195
321
  const [menuVisible, setMenuVisible] = (0, $duWW8$useState)(false);
196
- const [target, setTarget] = (0, $duWW8$useState)(null);
197
- const [lowTarget, setLowTarget] = (0, $duWW8$useState)(null);
198
- const [lowMenuVisible, setLowMenuVisible] = (0, $duWW8$useState)(false);
199
- // Show menu when context is requested
200
- const showMenu = (e)=>{
201
- const sel = window.getSelection();
202
- setTarget(sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null);
203
- e.preventDefault();
204
- e.stopPropagation();
205
- setMenuVisible(true);
206
- setMenuXPos(e.pageX);
207
- setMenuYPos(e.pageY);
208
- };
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;
209
327
  // Handle click off the menu
210
328
  const handleClick = (0, $duWW8$useCallback)((e)=>{
211
329
  var _menuRef_current;
@@ -222,55 +340,96 @@ const $1e1c1e9e0b943830$export$ed4f9641643dc7e4 = ({ children: children, menuIte
222
340
  handleClick,
223
341
  menuVisible
224
342
  ]);
225
- return /*#__PURE__*/ (0, $duWW8$jsxs)((0, $duWW8$Fragment), {
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
+ },
226
361
  children: [
227
362
  /*#__PURE__*/ (0, $duWW8$jsx)("div", {
228
- onContextMenu: showLowMenu ? undefined : showMenu,
229
- className: "context-menu-handler",
230
- style: style,
363
+ ref: divHandlderRef,
364
+ ...rest,
365
+ className: [
366
+ (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).contextMenuHandler,
367
+ rest.className
368
+ ].join(" "),
369
+ style: {
370
+ ...rest.style
371
+ },
372
+ onContextMenu: (e)=>{
373
+ if (!showLowMenu) {
374
+ setMenuInDom(true);
375
+ e.preventDefault();
376
+ e.stopPropagation();
377
+ setTimeout(()=>{
378
+ removeController.current.abort();
379
+ setMenuVisible(true);
380
+ setMenuXPos(e.pageX);
381
+ setMenuYPos(e.pageY);
382
+ }, 1);
383
+ }
384
+ },
231
385
  onMouseEnter: ()=>{
232
- showLowMenu && setLowMenuVisible(true);
386
+ if (showLowMenu) {
387
+ setMenuInDom(true);
388
+ setMouseOverHandlerDiv(false);
389
+ setTimeout(()=>{
390
+ removeController.current.abort();
391
+ setMouseOverHandlerDiv(true);
392
+ }, 1);
393
+ }
233
394
  },
234
395
  onMouseLeave: ()=>{
235
- showLowMenu && setLowMenuVisible(false);
396
+ if (showLowMenu) {
397
+ removeController.current.abort();
398
+ removeController.current = new AbortController();
399
+ setMouseOverHandlerDiv(false);
400
+ }
236
401
  },
237
402
  children: children
238
403
  }),
239
- menuVisible && !showLowMenu && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsx)("div", {
240
- style: {
241
- position: "absolute",
242
- top: 0,
243
- left: 0
244
- },
245
- ref: divRef,
246
- children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
247
- visible: true,
248
- ref: menuRef,
249
- entries: menuItems,
250
- xPos: menuXPos,
251
- yPos: menuYPos,
252
- target: target,
253
- toClose: ()=>setMenuVisible(false)
254
- })
255
- }), document.body),
256
- showLowMenu && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
257
- style: {
258
- position: "relative"
259
- },
404
+ menuInDom && divHandlerPos && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsx)("div", {
405
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).anchor,
260
406
  onMouseEnter: ()=>{
261
- const sel = window.getSelection();
262
- const lowSel = sel && sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
263
- setLowTarget(lowSel);
407
+ removeController.current.abort();
408
+ setMouseOverMenu(true);
264
409
  },
265
410
  onMouseLeave: ()=>{
266
- setLowTarget(null);
411
+ removeController.current.abort();
412
+ removeController.current = new AbortController();
413
+ setMouseOverMenu(false);
267
414
  },
268
- children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $914758b0c9d59759$export$49e8edc8ebca5f25), {
269
- visible: lowMenuVisible,
415
+ children: showLowMenu ? /*#__PURE__*/ (0, $duWW8$jsx)((0, $914758b0c9d59759$export$49e8edc8ebca5f25), {
416
+ visible: mouseOverHandlerDiv,
270
417
  entries: menuItems,
271
- target: lowTarget
418
+ xPos: divHandlerPos.left,
419
+ yPos: divHandlerPos.bottom,
420
+ maxWidth: divHandlerPos.width
421
+ }) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
422
+ visible: menuVisible,
423
+ ref: menuRef,
424
+ entries: thisMenuItems,
425
+ xPos: menuXPos,
426
+ yPos: menuYPos,
427
+ toClose: ()=>{
428
+ setMenuVisible(false);
429
+ setMouseOverMenu(false);
430
+ }
272
431
  })
273
- })
432
+ }), document.body)
274
433
  ]
275
434
  });
276
435
  };
@@ -280,6 +439,27 @@ $1e1c1e9e0b943830$export$ed4f9641643dc7e4.displayName = "ContextMenuHandler";
280
439
 
281
440
 
282
441
 
442
+ const $ab4d5d6bf03370d0$export$d81cfea7c54be196 = (divRef)=>{
443
+ if (!divRef.current) return {
444
+ translateX: 0,
445
+ translateY: 0
446
+ };
447
+ else {
448
+ const innerBounce = 16;
449
+ const posn = divRef.current.getBoundingClientRect();
450
+ let translateX = 0;
451
+ if (posn.left < innerBounce) translateX = -posn.left + innerBounce;
452
+ else if (posn.right > window.innerWidth) translateX = Math.max(-posn.left + innerBounce, window.innerWidth - posn.right - innerBounce);
453
+ let translateY = 0;
454
+ if (posn.top < innerBounce) translateY = -posn.top + innerBounce;
455
+ else if (posn.bottom > window.innerHeight) translateY = Math.max(-posn.top + innerBounce, window.innerHeight - posn.bottom - innerBounce);
456
+ return {
457
+ translateX: translateX,
458
+ translateY: translateY
459
+ };
460
+ }
461
+ };
462
+
283
463
 
284
464
 
285
465
 
@@ -313,33 +493,38 @@ const $17c46b9e6a2eb66e$export$9f37482ccd50dad2 = ({ minZIndex: minZIndex = 1000
313
493
  $17c46b9e6a2eb66e$export$9f37482ccd50dad2.displayName = "ContextWindowStack";
314
494
 
315
495
 
316
- const $ab4d5d6bf03370d0$export$d81cfea7c54be196 = (divRef)=>{
317
- if (!divRef.current) return {
318
- translateX: 0,
319
- translateY: 0
320
- };
321
- else {
322
- const innerBounce = 16;
323
- const posn = divRef.current.getBoundingClientRect();
324
- let translateX = 0;
325
- if (posn.left < innerBounce) translateX = -posn.left + innerBounce;
326
- else if (posn.right > window.innerWidth) translateX = Math.max(-posn.left + innerBounce, window.innerWidth - posn.right - innerBounce);
327
- let translateY = 0;
328
- if (posn.top < innerBounce) translateY = -posn.top + innerBounce;
329
- else if (posn.bottom > window.innerHeight) translateY = Math.max(-posn.top + innerBounce, window.innerHeight - posn.bottom - innerBounce);
330
- return {
331
- translateX: translateX,
332
- translateY: translateY
333
- };
334
- }
335
- };
336
-
337
-
338
- const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, title: title, style: style, children: children, onOpen: onOpen, onClose: onClose })=>{
496
+ var $ddf7153c7c69b209$exports = {};
497
+
498
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindow", function () { return $ddf7153c7c69b209$export$72cad2e5ad4d2674; }, function (v) { return $ddf7153c7c69b209$export$72cad2e5ad4d2674 = v; });
499
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowAnchor", function () { return $ddf7153c7c69b209$export$9f3a8a17ac700f7d; }, function (v) { return $ddf7153c7c69b209$export$9f3a8a17ac700f7d = v; });
500
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowBody", function () { return $ddf7153c7c69b209$export$dfb2c4d2d1c0156f; }, function (v) { return $ddf7153c7c69b209$export$dfb2c4d2d1c0156f = v; });
501
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowTitle", function () { return $ddf7153c7c69b209$export$1b02f2cd2f7db0f4; }, function (v) { return $ddf7153c7c69b209$export$1b02f2cd2f7db0f4 = v; });
502
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowTitleClose", function () { return $ddf7153c7c69b209$export$7ba38d4cc2870e66; }, function (v) { return $ddf7153c7c69b209$export$7ba38d4cc2870e66 = v; });
503
+ $parcel$export($ddf7153c7c69b209$exports, "contextWindowTitleText", function () { return $ddf7153c7c69b209$export$cebbac70b4d99c48; }, function (v) { return $ddf7153c7c69b209$export$cebbac70b4d99c48 = v; });
504
+ $parcel$export($ddf7153c7c69b209$exports, "moving", function () { return $ddf7153c7c69b209$export$d03a2f3acc60252b; }, function (v) { return $ddf7153c7c69b209$export$d03a2f3acc60252b = v; });
505
+ var $ddf7153c7c69b209$export$72cad2e5ad4d2674;
506
+ var $ddf7153c7c69b209$export$9f3a8a17ac700f7d;
507
+ var $ddf7153c7c69b209$export$dfb2c4d2d1c0156f;
508
+ var $ddf7153c7c69b209$export$1b02f2cd2f7db0f4;
509
+ var $ddf7153c7c69b209$export$7ba38d4cc2870e66;
510
+ var $ddf7153c7c69b209$export$cebbac70b4d99c48;
511
+ var $ddf7153c7c69b209$export$d03a2f3acc60252b;
512
+ $ddf7153c7c69b209$export$72cad2e5ad4d2674 = `aiw-RIIF9a-contextWindow`;
513
+ $ddf7153c7c69b209$export$9f3a8a17ac700f7d = `aiw-RIIF9a-contextWindowAnchor`;
514
+ $ddf7153c7c69b209$export$dfb2c4d2d1c0156f = `aiw-RIIF9a-contextWindowBody`;
515
+ $ddf7153c7c69b209$export$1b02f2cd2f7db0f4 = `aiw-RIIF9a-contextWindowTitle`;
516
+ $ddf7153c7c69b209$export$7ba38d4cc2870e66 = `aiw-RIIF9a-contextWindowTitleClose`;
517
+ $ddf7153c7c69b209$export$cebbac70b4d99c48 = `aiw-RIIF9a-contextWindowTitleText`;
518
+ $ddf7153c7c69b209$export$d03a2f3acc60252b = `aiw-RIIF9a-moving`;
519
+
520
+
521
+ const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, title: title, children: children, onOpen: onOpen, onClose: onClose, ...rest })=>{
522
+ var _rest_style, _rest_style1, _rest_style2, _rest_style3;
339
523
  const windowStack = (0, $duWW8$useContext)((0, $17c46b9e6a2eb66e$export$aff5d0593e3727b0));
340
524
  const windowId = (0, $duWW8$useRef)(null);
341
525
  const divRef = (0, $duWW8$useRef)(null);
342
526
  const windowRef = (0, $duWW8$useRef)(null);
527
+ const [windowInDOM, setWindowInDOM] = (0, $duWW8$useState)(false);
343
528
  const [windowVisible, setWindowVisible] = (0, $duWW8$useState)(false);
344
529
  const zIndex = (0, $duWW8$useMemo)(()=>{
345
530
  var _windowStack_currentWindows_find;
@@ -392,7 +577,9 @@ const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, t
392
577
  // Update visibility
393
578
  (0, $duWW8$useEffect)(()=>{
394
579
  if (windowStack) {
395
- if (visible && !windowVisible) {
580
+ // Visible set, but not in DOM
581
+ if (visible && !windowInDOM) setWindowInDOM(true);
582
+ else if (visible && windowInDOM && !windowVisible) {
396
583
  if (!windowId.current) {
397
584
  const maxWindowId = Math.max(0, ...windowStack.currentWindows.map((w)=>w.windowId));
398
585
  windowId.current = maxWindowId + 1;
@@ -415,30 +602,33 @@ const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, t
415
602
  }
416
603
  checkPosition();
417
604
  } else if (windowId.current && !visible && windowVisible) setWindowVisible(false);
605
+ else if (windowId.current && !visible && windowInDOM) setWindowInDOM(false);
418
606
  }
419
607
  }, [
420
608
  checkPosition,
421
609
  onOpen,
422
610
  visible,
611
+ windowInDOM,
423
612
  windowStack,
424
613
  windowVisible
425
614
  ]);
426
- var _style_minHeight, _style_minWidth, _style_maxHeight, _style_maxWidth;
615
+ var _rest_style_minHeight, _rest_style_minWidth, _rest_style_maxHeight, _rest_style_maxWidth;
427
616
  return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
428
- className: "contextwindow-anchor",
617
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowAnchor,
429
618
  ref: divRef,
430
- children: windowStack && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsxs)("div", {
619
+ children: windowStack && windowInDOM && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsxs)("div", {
620
+ ...rest,
431
621
  id: id,
432
- className: "contextwindow",
622
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindow,
433
623
  style: {
434
- ...style,
624
+ ...rest.style,
435
625
  opacity: moving ? 0.8 : windowVisible ? 1 : 0,
436
626
  visibility: windowVisible ? "visible" : "hidden",
437
627
  zIndex: zIndex !== null && zIndex !== void 0 ? zIndex : 1,
438
- minHeight: (_style_minHeight = style === null || style === void 0 ? void 0 : style.minHeight) !== null && _style_minHeight !== void 0 ? _style_minHeight : "150px",
439
- minWidth: (_style_minWidth = style === null || style === void 0 ? void 0 : style.minWidth) !== null && _style_minWidth !== void 0 ? _style_minWidth : "200px",
440
- maxHeight: (_style_maxHeight = style === null || style === void 0 ? void 0 : style.maxHeight) !== null && _style_maxHeight !== void 0 ? _style_maxHeight : "1000px",
441
- maxWidth: (_style_maxWidth = style === null || style === void 0 ? void 0 : style.maxWidth) !== null && _style_maxWidth !== void 0 ? _style_maxWidth : "1000px"
628
+ 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",
629
+ 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",
630
+ 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",
631
+ 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"
442
632
  },
443
633
  onClickCapture: ()=>{
444
634
  windowId && windowId.current && windowStack.pushToTop(windowId.current);
@@ -446,7 +636,10 @@ const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, t
446
636
  ref: windowRef,
447
637
  children: [
448
638
  /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
449
- className: `contextwindow-title ${moving ? "moving" : ""}`,
639
+ className: [
640
+ (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitle,
641
+ moving ? (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).moving : ""
642
+ ].filter((c)=>c !== "").join(" "),
450
643
  onMouseDown: (e)=>{
451
644
  if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "none";
452
645
  setMoving(true);
@@ -457,11 +650,11 @@ const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, t
457
650
  },
458
651
  children: [
459
652
  /*#__PURE__*/ (0, $duWW8$jsx)("div", {
460
- className: "contextwindow-title-text",
653
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitleText,
461
654
  children: title
462
655
  }),
463
656
  /*#__PURE__*/ (0, $duWW8$jsx)("div", {
464
- className: "contextwindow-title-close",
657
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitleClose,
465
658
  children: /*#__PURE__*/ (0, $duWW8$jsx)("svg", {
466
659
  xmlns: "http://www.w3.org/2000/svg",
467
660
  width: "16",
@@ -478,7 +671,7 @@ const $b5e8657823def5be$export$1af8984c69ba1b24 = ({ id: id, visible: visible, t
478
671
  ]
479
672
  }),
480
673
  /*#__PURE__*/ (0, $duWW8$jsx)("div", {
481
- className: "contextwindow-body",
674
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowBody,
482
675
  children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
483
676
  children: children
484
677
  })