@asup/context-menu 1.5.1 → 2.0.0
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/README.md +114 -65
- package/dist/cjs/main.js +260 -200
- package/dist/cjs/main.js.map +1 -1
- package/dist/context-menu.d.ts +14 -22
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/main.js +262 -202
- package/dist/main.js.map +1 -1
- package/package.json +34 -22
package/dist/main.js
CHANGED
|
@@ -3,7 +3,7 @@ import {_ as $duWW8$_} from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import {_ as $duWW8$_1} from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import {_ as $duWW8$_2} from "@swc/helpers/_/_object_without_properties";
|
|
5
5
|
import {jsx as $duWW8$jsx, jsxs as $duWW8$jsxs, Fragment as $duWW8$Fragment} from "react/jsx-runtime";
|
|
6
|
-
import {useRef as $duWW8$useRef, useState as $duWW8$useState, useMemo as $duWW8$useMemo, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect,
|
|
6
|
+
import {useRef as $duWW8$useRef, useState as $duWW8$useState, useMemo as $duWW8$useMemo, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect, useTransition as $duWW8$useTransition, forwardRef as $duWW8$forwardRef, useLayoutEffect as $duWW8$useLayoutEffect, createContext as $duWW8$createContext, useContext as $duWW8$useContext} from "react";
|
|
7
7
|
import {createPortal as $duWW8$createPortal} from "react-dom";
|
|
8
8
|
|
|
9
9
|
|
|
@@ -23,7 +23,6 @@ $parcel$export($b65191f6d0a0a991$exports, "ClickForMenu", function () { return $
|
|
|
23
23
|
$parcel$export($b65191f6d0a0a991$exports, "ContextMenu", function () { return $567ed433af94513f$export$8dc6765e8be191c7; });
|
|
24
24
|
$parcel$export($b65191f6d0a0a991$exports, "ContextMenuHandler", function () { return $1e1c1e9e0b943830$export$ed4f9641643dc7e4; });
|
|
25
25
|
$parcel$export($b65191f6d0a0a991$exports, "ContextWindow", function () { return $b5e8657823def5be$export$1af8984c69ba1b24; });
|
|
26
|
-
$parcel$export($b65191f6d0a0a991$exports, "ContextWindowStack", function () { return $17c46b9e6a2eb66e$export$9f37482ccd50dad2; });
|
|
27
26
|
|
|
28
27
|
|
|
29
28
|
|
|
@@ -81,11 +80,16 @@ function $62873e7e5aeec7f1$export$77bf000da9303d1(_param) {
|
|
|
81
80
|
setTargetHeight
|
|
82
81
|
]);
|
|
83
82
|
// Trigger height change on children update
|
|
84
|
-
(0, $duWW8$
|
|
85
|
-
|
|
83
|
+
const [, startTransition] = (0, $duWW8$useTransition)();
|
|
84
|
+
(0, $duWW8$useEffect)(()=>{
|
|
85
|
+
// Mark this update as non-urgent to avoid cascading render warnings
|
|
86
|
+
startTransition(()=>{
|
|
87
|
+
setTargetHeight();
|
|
88
|
+
});
|
|
86
89
|
}, [
|
|
87
90
|
setTargetHeight,
|
|
88
|
-
children
|
|
91
|
+
children,
|
|
92
|
+
startTransition
|
|
89
93
|
]);
|
|
90
94
|
return /*#__PURE__*/ (0, $duWW8$jsx)("div", (0, $duWW8$_1)((0, $duWW8$_)({}, rest), {
|
|
91
95
|
className: (0, (/*@__PURE__*/$parcel$interopDefault($181673e3e0e596f3$exports))).autoHeightWrapper,
|
|
@@ -152,9 +156,13 @@ $47067f35ca62d4a5$export$664c6d24e3175067 = `aiw-ContextMenu-module-WinFxq-visib
|
|
|
152
156
|
|
|
153
157
|
|
|
154
158
|
|
|
155
|
-
|
|
159
|
+
|
|
160
|
+
const $6ca59110355c8bf1$export$7e4e6110f96afd7e = ({ entries: entries, toClose: toClose })=>{
|
|
161
|
+
const [visible, setVisible] = (0, $duWW8$useState)(false);
|
|
156
162
|
return /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
|
|
157
163
|
className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).caretHolder,
|
|
164
|
+
onMouseEnter: ()=>setVisible(true),
|
|
165
|
+
onMouseLeave: ()=>setVisible(false),
|
|
158
166
|
children: [
|
|
159
167
|
/*#__PURE__*/ (0, $duWW8$jsx)("svg", {
|
|
160
168
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -166,10 +174,10 @@ const $6ca59110355c8bf1$export$7e4e6110f96afd7e = ({ entries: entries, toClose:
|
|
|
166
174
|
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"
|
|
167
175
|
})
|
|
168
176
|
}),
|
|
169
|
-
/*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
177
|
+
visible && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
170
178
|
className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).subMenu,
|
|
171
179
|
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
|
|
172
|
-
visible:
|
|
180
|
+
visible: true,
|
|
173
181
|
entries: entries,
|
|
174
182
|
xPos: 14,
|
|
175
183
|
yPos: -21,
|
|
@@ -184,21 +192,14 @@ $6ca59110355c8bf1$export$7e4e6110f96afd7e.displayName = "ContextSubMenu";
|
|
|
184
192
|
|
|
185
193
|
const $813754bb7a4251f1$export$c868ef28d2ba36f1 = ({ entry: entry, toClose: toClose })=>{
|
|
186
194
|
const [target, setTarget] = (0, $duWW8$useState)(null);
|
|
187
|
-
const [subMenuVisible, setSubMenuVisible] = (0, $duWW8$useState)(false);
|
|
188
195
|
return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
189
196
|
className: [
|
|
190
197
|
(0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).contextMenuItem,
|
|
191
198
|
entry.disabled ? (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).disabled : ""
|
|
192
199
|
].filter((c)=>c !== "").join(" "),
|
|
193
|
-
onMouseEnter: ()=>{
|
|
194
|
-
setSubMenuVisible(true);
|
|
195
|
-
},
|
|
196
|
-
onMouseLeave: ()=>{
|
|
197
|
-
setSubMenuVisible(false);
|
|
198
|
-
},
|
|
199
200
|
children: [
|
|
200
201
|
typeof entry.label === "string" ? /*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
201
|
-
"aria-label":
|
|
202
|
+
"aria-label": entry.label,
|
|
202
203
|
"aria-disabled": entry.disabled,
|
|
203
204
|
className: (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).contextMenuItemLabel,
|
|
204
205
|
onMouseEnter: ()=>{
|
|
@@ -221,24 +222,39 @@ const $813754bb7a4251f1$export$c868ef28d2ba36f1 = ({ entry: entry, toClose: toCl
|
|
|
221
222
|
}) : entry.label,
|
|
222
223
|
entry.group && /*#__PURE__*/ (0, $duWW8$jsx)((0, $6ca59110355c8bf1$export$7e4e6110f96afd7e), {
|
|
223
224
|
toClose: toClose,
|
|
224
|
-
entries: entry.group
|
|
225
|
-
visible: subMenuVisible
|
|
225
|
+
entries: entry.group
|
|
226
226
|
})
|
|
227
227
|
]
|
|
228
228
|
});
|
|
229
229
|
};
|
|
230
230
|
|
|
231
231
|
|
|
232
|
+
// Constants for menu size estimation when ref is not yet available
|
|
233
|
+
const $567ed433af94513f$var$ESTIMATED_MENU_ITEM_HEIGHT = 34;
|
|
234
|
+
const $567ed433af94513f$var$ESTIMATED_MENU_PADDING = 4;
|
|
235
|
+
const $567ed433af94513f$var$ESTIMATED_MENU_WIDTH = 200;
|
|
232
236
|
const $567ed433af94513f$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $duWW8$forwardRef)(({ visible: visible, entries: entries, xPos: xPos, yPos: yPos, toClose: toClose }, ref)=>{
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
237
|
+
// Measure menu size after mount/render to avoid accessing refs during render
|
|
238
|
+
const [menuHeight, setMenuHeight] = (0, $duWW8$useState)(entries.length * $567ed433af94513f$var$ESTIMATED_MENU_ITEM_HEIGHT + $567ed433af94513f$var$ESTIMATED_MENU_PADDING);
|
|
239
|
+
const [menuWidth, setMenuWidth] = (0, $duWW8$useState)($567ed433af94513f$var$ESTIMATED_MENU_WIDTH);
|
|
240
|
+
(0, $duWW8$useLayoutEffect)(()=>{
|
|
241
|
+
// Only measure when visible; ref access inside effect is allowed
|
|
242
|
+
if (visible && ref && typeof ref !== "function" && ref.current instanceof HTMLDivElement) {
|
|
243
|
+
setMenuHeight(ref.current.offsetHeight);
|
|
244
|
+
setMenuWidth(ref.current.offsetWidth);
|
|
245
|
+
}
|
|
246
|
+
// When not visible, fall back to estimates
|
|
247
|
+
if (!visible) {
|
|
248
|
+
setMenuHeight(entries.length * $567ed433af94513f$var$ESTIMATED_MENU_ITEM_HEIGHT + $567ed433af94513f$var$ESTIMATED_MENU_PADDING);
|
|
249
|
+
setMenuWidth($567ed433af94513f$var$ESTIMATED_MENU_WIDTH);
|
|
250
|
+
}
|
|
251
|
+
}, [
|
|
252
|
+
visible,
|
|
253
|
+
entries,
|
|
254
|
+
ref
|
|
255
|
+
]);
|
|
256
|
+
const adjustedYPos = yPos + menuHeight > window.innerHeight ? Math.max(window.innerHeight - menuHeight - $567ed433af94513f$var$ESTIMATED_MENU_PADDING, 0) : yPos;
|
|
257
|
+
const adjustedXPos = xPos + menuWidth > window.innerWidth ? Math.max(window.innerWidth - menuWidth - $567ed433af94513f$var$ESTIMATED_MENU_PADDING, 0) : xPos;
|
|
242
258
|
return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
243
259
|
ref: ref,
|
|
244
260
|
className: [
|
|
@@ -246,8 +262,8 @@ const $567ed433af94513f$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $duWW8$forwa
|
|
|
246
262
|
visible ? (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).visible : (0, (/*@__PURE__*/$parcel$interopDefault($47067f35ca62d4a5$exports))).hidden
|
|
247
263
|
].filter((c)=>c !== "").join(" "),
|
|
248
264
|
style: {
|
|
249
|
-
top: `${
|
|
250
|
-
left: `${
|
|
265
|
+
top: `${adjustedYPos}px`,
|
|
266
|
+
left: `${adjustedXPos}px`
|
|
251
267
|
},
|
|
252
268
|
onContextMenu: (e)=>{
|
|
253
269
|
e.preventDefault();
|
|
@@ -278,18 +294,29 @@ const $c3e82278b501f10c$export$d4ebdd58e04c6ace = (_param)=>{
|
|
|
278
294
|
const menuRef = (0, $duWW8$useRef)(null);
|
|
279
295
|
// Handle click off the menu
|
|
280
296
|
const handleClick = (0, $duWW8$useCallback)((e)=>{
|
|
281
|
-
|
|
282
|
-
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))) setMenuInDom(false);
|
|
297
|
+
if (menuRef.current && (e.target instanceof Element && !menuRef.current.contains(e.target) || !(e.target instanceof Element))) setMenuInDom(false);
|
|
283
298
|
}, []);
|
|
284
|
-
const removeController = (0, $duWW8$useRef)(
|
|
299
|
+
const removeController = (0, $duWW8$useRef)(null);
|
|
300
|
+
const removeTimeoutRef = (0, $duWW8$useRef)(null);
|
|
285
301
|
(0, $duWW8$useEffect)(()=>{
|
|
286
|
-
if (!menuVisible) {
|
|
287
|
-
|
|
302
|
+
if (!menuVisible && removeTimeoutRef.current === null) {
|
|
303
|
+
// Only create a new controller when scheduling a new timeout
|
|
304
|
+
if (removeController.current) removeController.current.abort();
|
|
288
305
|
removeController.current = new AbortController();
|
|
289
|
-
|
|
290
|
-
|
|
306
|
+
const controller = removeController.current;
|
|
307
|
+
// Set up the timeout with a reference to the current controller
|
|
308
|
+
removeTimeoutRef.current = setTimeout(()=>{
|
|
309
|
+
if (!controller.signal.aborted) setMenuInDom(false);
|
|
310
|
+
removeTimeoutRef.current = null;
|
|
291
311
|
}, 300);
|
|
292
312
|
}
|
|
313
|
+
return ()=>{
|
|
314
|
+
// Clean up on unmount or when menuVisible changes
|
|
315
|
+
if (removeTimeoutRef.current) {
|
|
316
|
+
clearTimeout(removeTimeoutRef.current);
|
|
317
|
+
removeTimeoutRef.current = null;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
293
320
|
}, [
|
|
294
321
|
menuVisible
|
|
295
322
|
]);
|
|
@@ -298,7 +325,7 @@ const $c3e82278b501f10c$export$d4ebdd58e04c6ace = (_param)=>{
|
|
|
298
325
|
if (menuInDom) document.addEventListener("mousedown", handleClick);
|
|
299
326
|
return ()=>{
|
|
300
327
|
document.removeEventListener("mousedown", handleClick);
|
|
301
|
-
removeController.current.abort();
|
|
328
|
+
if (removeController.current) removeController.current.abort();
|
|
302
329
|
};
|
|
303
330
|
}, [
|
|
304
331
|
handleClick,
|
|
@@ -315,7 +342,7 @@ const $c3e82278b501f10c$export$d4ebdd58e04c6ace = (_param)=>{
|
|
|
315
342
|
e.preventDefault();
|
|
316
343
|
e.stopPropagation();
|
|
317
344
|
setTimeout(()=>{
|
|
318
|
-
removeController.current.abort();
|
|
345
|
+
if (removeController.current) removeController.current.abort();
|
|
319
346
|
setMenuVisible(true);
|
|
320
347
|
setMenuXPos(e.pageX);
|
|
321
348
|
setMenuYPos(e.pageY);
|
|
@@ -468,7 +495,7 @@ $556d6f9158abfc99$export$aafc28aea571c4bc.displayName = "LowMenuButton";
|
|
|
468
495
|
|
|
469
496
|
const $914758b0c9d59759$export$49e8edc8ebca5f25 = ({ entries: entries, visible: visible, xPos: xPos, yPos: yPos, maxWidth: maxWidth })=>{
|
|
470
497
|
// Only show the low menu if it is on the screen
|
|
471
|
-
if (xPos
|
|
498
|
+
if (xPos >= window.innerWidth || yPos >= window.innerHeight) return /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Fragment), {});
|
|
472
499
|
// Show the menu
|
|
473
500
|
return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
474
501
|
className: [
|
|
@@ -503,7 +530,6 @@ const $1e1c1e9e0b943830$export$ed4f9641643dc7e4 = (_param)=>{
|
|
|
503
530
|
"menuItems",
|
|
504
531
|
"showLowMenu"
|
|
505
532
|
]);
|
|
506
|
-
var _divHandlderRef_current;
|
|
507
533
|
// Check for higher content menu
|
|
508
534
|
const higherContext = (0, $duWW8$useContext)($1e1c1e9e0b943830$export$fc58dc71afe92de2);
|
|
509
535
|
const thisMenuItems = (0, $duWW8$useMemo)(()=>[
|
|
@@ -536,8 +562,34 @@ const $1e1c1e9e0b943830$export$ed4f9641643dc7e4 = (_param)=>{
|
|
|
536
562
|
const [menuInDom, setMenuInDom] = (0, $duWW8$useState)(false);
|
|
537
563
|
const [mouseOverHandlerDiv, setMouseOverHandlerDiv] = (0, $duWW8$useState)(false);
|
|
538
564
|
const [mouseOverMenu, setMouseOverMenu] = (0, $duWW8$useState)(false);
|
|
539
|
-
//
|
|
540
|
-
const divHandlerPos =
|
|
565
|
+
// Holder position - measured in an effect to avoid reading refs during render
|
|
566
|
+
const [divHandlerPos, setDivHandlerPos] = (0, $duWW8$useState)(null);
|
|
567
|
+
(0, $duWW8$useLayoutEffect)(()=>{
|
|
568
|
+
function updatePos() {
|
|
569
|
+
if (divHandlderRef.current) setDivHandlerPos(divHandlderRef.current.getBoundingClientRect());
|
|
570
|
+
}
|
|
571
|
+
// When the handler is hovered or the menu is mounted, ensure we have a fresh position
|
|
572
|
+
if (mouseOverHandlerDiv || menuInDom) updatePos();
|
|
573
|
+
// Attach listeners while the menu/low-menu may be visible so the position stays correct
|
|
574
|
+
if (mouseOverHandlerDiv || menuInDom) {
|
|
575
|
+
window.addEventListener("resize", updatePos);
|
|
576
|
+
// listen on capture to catch scrolls from ancestor elements as well
|
|
577
|
+
window.addEventListener("scroll", updatePos, true);
|
|
578
|
+
let ro = null;
|
|
579
|
+
if (typeof ResizeObserver !== "undefined" && divHandlderRef.current) {
|
|
580
|
+
ro = new ResizeObserver(()=>updatePos());
|
|
581
|
+
ro.observe(divHandlderRef.current);
|
|
582
|
+
}
|
|
583
|
+
return ()=>{
|
|
584
|
+
window.removeEventListener("resize", updatePos);
|
|
585
|
+
window.removeEventListener("scroll", updatePos, true);
|
|
586
|
+
if (ro) ro.disconnect();
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
}, [
|
|
590
|
+
mouseOverHandlerDiv,
|
|
591
|
+
menuInDom
|
|
592
|
+
]);
|
|
541
593
|
// Handle click off the menu
|
|
542
594
|
const handleClick = (0, $duWW8$useCallback)((e)=>{
|
|
543
595
|
var _menuRef_current;
|
|
@@ -703,62 +755,41 @@ $ddf7153c7c69b209$export$cebbac70b4d99c48 = `aiw-ContextWindow-module-RIIF9a-con
|
|
|
703
755
|
$ddf7153c7c69b209$export$d03a2f3acc60252b = `aiw-ContextWindow-module-RIIF9a-moving`;
|
|
704
756
|
|
|
705
757
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const $
|
|
710
|
-
const
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
windowId: windowId,
|
|
718
|
-
zIndex: minZIndex + otherWindows.length
|
|
758
|
+
const $b5e8657823def5be$export$4f9fb66ac71c7da5 = 3000;
|
|
759
|
+
const $b5e8657823def5be$var$CONTEXT_WINDOW_DATA_ATTR = "data-context-window";
|
|
760
|
+
// Helper function to get the highest zIndex from all context windows in the DOM
|
|
761
|
+
const $b5e8657823def5be$var$getMaxZIndex = (componentMinZIndex)=>{
|
|
762
|
+
const windows = document.body.querySelectorAll(`[${$b5e8657823def5be$var$CONTEXT_WINDOW_DATA_ATTR}]`);
|
|
763
|
+
let maxZIndex = componentMinZIndex - 1;
|
|
764
|
+
windows.forEach((win)=>{
|
|
765
|
+
const zIndexStr = win.style.zIndex;
|
|
766
|
+
if (zIndexStr) {
|
|
767
|
+
const zIndex = parseInt(zIndexStr, 10);
|
|
768
|
+
if (!isNaN(zIndex) && zIndex > maxZIndex) maxZIndex = zIndex;
|
|
719
769
|
}
|
|
720
|
-
]);
|
|
721
|
-
};
|
|
722
|
-
const $17c46b9e6a2eb66e$export$9f37482ccd50dad2 = ({ minZIndex: minZIndex = 1000, children: children })=>{
|
|
723
|
-
const [currentWindows, setCurrentWindows] = (0, $duWW8$useState)([]);
|
|
724
|
-
return /*#__PURE__*/ (0, $duWW8$jsx)($17c46b9e6a2eb66e$export$aff5d0593e3727b0.Provider, {
|
|
725
|
-
value: {
|
|
726
|
-
currentWindows: currentWindows.map((w)=>({
|
|
727
|
-
windowId: w.windowId,
|
|
728
|
-
zIndex: minZIndex + w.zIndex
|
|
729
|
-
})),
|
|
730
|
-
pushToTop: (ret)=>$17c46b9e6a2eb66e$var$pushToTop(ret, minZIndex, currentWindows, setCurrentWindows)
|
|
731
|
-
},
|
|
732
|
-
children: children
|
|
733
770
|
});
|
|
771
|
+
return maxZIndex;
|
|
734
772
|
};
|
|
735
|
-
$17c46b9e6a2eb66e$export$9f37482ccd50dad2.displayName = "ContextWindowStack";
|
|
736
|
-
|
|
737
|
-
|
|
738
773
|
const $b5e8657823def5be$export$1af8984c69ba1b24 = (_param)=>{
|
|
739
|
-
var { id: id, visible: visible, title: title, titleElement: titleElement, children: children, onOpen: onOpen, onClose: onClose } = _param, rest = (0, $duWW8$_2)(_param, [
|
|
774
|
+
var { id: id, visible: visible, title: title, titleElement: titleElement, children: children, onOpen: onOpen, onClose: onClose, minZIndex: minZIndex = $b5e8657823def5be$export$4f9fb66ac71c7da5 } = _param, rest = (0, $duWW8$_2)(_param, [
|
|
740
775
|
"id",
|
|
741
776
|
"visible",
|
|
742
777
|
"title",
|
|
743
778
|
"titleElement",
|
|
744
779
|
"children",
|
|
745
780
|
"onOpen",
|
|
746
|
-
"onClose"
|
|
781
|
+
"onClose",
|
|
782
|
+
"minZIndex"
|
|
747
783
|
]);
|
|
748
784
|
var _rest_style, _rest_style1, _rest_style2, _rest_style3;
|
|
749
|
-
const windowStack = (0, $duWW8$useContext)((0, $17c46b9e6a2eb66e$export$aff5d0593e3727b0));
|
|
750
|
-
const windowId = (0, $duWW8$useRef)(null);
|
|
751
785
|
const divRef = (0, $duWW8$useRef)(null);
|
|
752
786
|
const windowRef = (0, $duWW8$useRef)(null);
|
|
787
|
+
const [zIndex, setZIndex] = (0, $duWW8$useState)(minZIndex);
|
|
788
|
+
const resizeListenerRef = (0, $duWW8$useRef)(null);
|
|
789
|
+
// Track internal state: whether window is in DOM and whether it's been positioned
|
|
753
790
|
const [windowInDOM, setWindowInDOM] = (0, $duWW8$useState)(false);
|
|
754
791
|
const [windowVisible, setWindowVisible] = (0, $duWW8$useState)(false);
|
|
755
|
-
const
|
|
756
|
-
var _windowStack_currentWindows_find;
|
|
757
|
-
var _windowStack_currentWindows_find_zIndex;
|
|
758
|
-
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;
|
|
759
|
-
}, [
|
|
760
|
-
windowStack === null || windowStack === void 0 ? void 0 : windowStack.currentWindows
|
|
761
|
-
]);
|
|
792
|
+
const [, startTransition] = (0, $duWW8$useTransition)();
|
|
762
793
|
// Position
|
|
763
794
|
const windowPos = (0, $duWW8$useRef)({
|
|
764
795
|
x: 0,
|
|
@@ -787,145 +818,175 @@ const $b5e8657823def5be$export$1af8984c69ba1b24 = (_param)=>{
|
|
|
787
818
|
}, [
|
|
788
819
|
move
|
|
789
820
|
]);
|
|
821
|
+
// Store stable references to mouseMove and mouseUp for cleanup
|
|
822
|
+
const mouseMoveRef = (0, $duWW8$useRef)(mouseMove);
|
|
823
|
+
const mouseUpRef = (0, $duWW8$useRef)(()=>{});
|
|
790
824
|
const mouseUp = (0, $duWW8$useCallback)((e)=>{
|
|
791
825
|
e.preventDefault();
|
|
792
826
|
e.stopPropagation();
|
|
793
827
|
setMoving(false);
|
|
794
828
|
checkPosition();
|
|
795
|
-
document.removeEventListener("mousemove",
|
|
796
|
-
document.removeEventListener("mouseup",
|
|
797
|
-
|
|
829
|
+
document.removeEventListener("mousemove", mouseMoveRef.current);
|
|
830
|
+
document.removeEventListener("mouseup", mouseUpRef.current);
|
|
831
|
+
if (resizeListenerRef.current) {
|
|
832
|
+
window.removeEventListener("resize", resizeListenerRef.current);
|
|
833
|
+
resizeListenerRef.current = null;
|
|
834
|
+
}
|
|
798
835
|
if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "auto";
|
|
799
836
|
}, [
|
|
800
|
-
checkPosition
|
|
801
|
-
|
|
837
|
+
checkPosition
|
|
838
|
+
]);
|
|
839
|
+
// Update refs when callbacks change
|
|
840
|
+
(0, $duWW8$useEffect)(()=>{
|
|
841
|
+
mouseMoveRef.current = mouseMove;
|
|
842
|
+
mouseUpRef.current = mouseUp;
|
|
843
|
+
}, [
|
|
844
|
+
mouseMove,
|
|
845
|
+
mouseUp
|
|
802
846
|
]);
|
|
803
|
-
//
|
|
847
|
+
// Helper function to push this window to the top
|
|
848
|
+
const pushToTop = (0, $duWW8$useCallback)(()=>{
|
|
849
|
+
const maxZIndex = $b5e8657823def5be$var$getMaxZIndex(minZIndex);
|
|
850
|
+
setZIndex(maxZIndex + 1);
|
|
851
|
+
}, [
|
|
852
|
+
minZIndex
|
|
853
|
+
]);
|
|
854
|
+
// Sync windowInDOM with visible prop using a layout effect to avoid ESLint warnings
|
|
855
|
+
// This effect derives state from props, which is acceptable when there's no synchronous setState
|
|
804
856
|
(0, $duWW8$useEffect)(()=>{
|
|
805
|
-
if (
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
857
|
+
if (visible && !windowInDOM) // Window should be in DOM when visible becomes true
|
|
858
|
+
startTransition(()=>{
|
|
859
|
+
setWindowInDOM(true);
|
|
860
|
+
});
|
|
861
|
+
else if (!visible && windowInDOM) // Window should leave DOM when visible becomes false
|
|
862
|
+
startTransition(()=>{
|
|
863
|
+
setWindowInDOM(false);
|
|
864
|
+
setWindowVisible(false);
|
|
865
|
+
});
|
|
866
|
+
}, [
|
|
867
|
+
visible,
|
|
868
|
+
windowInDOM,
|
|
869
|
+
startTransition
|
|
870
|
+
]);
|
|
871
|
+
// Position and show window after it's added to DOM
|
|
872
|
+
(0, $duWW8$useEffect)(()=>{
|
|
873
|
+
if (windowInDOM && !windowVisible && visible && divRef.current && windowRef.current) {
|
|
874
|
+
// Position the window
|
|
875
|
+
const parentPos = divRef.current.getBoundingClientRect();
|
|
876
|
+
const pos = windowRef.current.getBoundingClientRect();
|
|
877
|
+
const windowHeight = pos.bottom - pos.top;
|
|
878
|
+
windowRef.current.style.left = `${parentPos.left}px`;
|
|
879
|
+
windowRef.current.style.top = `${parentPos.bottom + windowHeight < window.innerHeight ? parentPos.bottom : Math.max(0, parentPos.top - windowHeight)}px`;
|
|
880
|
+
windowRef.current.style.transform = "";
|
|
881
|
+
windowPos.current = {
|
|
882
|
+
x: 0,
|
|
883
|
+
y: 0
|
|
884
|
+
};
|
|
885
|
+
checkPosition();
|
|
886
|
+
// Update z-index and make visible - use startTransition
|
|
887
|
+
const maxZ = $b5e8657823def5be$var$getMaxZIndex(minZIndex);
|
|
888
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
889
|
+
startTransition(()=>{
|
|
890
|
+
setZIndex(maxZ + 1);
|
|
891
|
+
setWindowVisible(true);
|
|
892
|
+
});
|
|
832
893
|
}
|
|
833
894
|
}, [
|
|
895
|
+
windowInDOM,
|
|
896
|
+
windowVisible,
|
|
897
|
+
visible,
|
|
834
898
|
checkPosition,
|
|
899
|
+
minZIndex,
|
|
835
900
|
onOpen,
|
|
836
|
-
|
|
837
|
-
windowInDOM,
|
|
838
|
-
windowStack,
|
|
839
|
-
windowVisible
|
|
901
|
+
startTransition
|
|
840
902
|
]);
|
|
903
|
+
// Cleanup effect to remove event listeners on unmount
|
|
904
|
+
(0, $duWW8$useEffect)(()=>{
|
|
905
|
+
return ()=>{
|
|
906
|
+
// Clean up event listeners if component unmounts while dragging
|
|
907
|
+
document.removeEventListener("mousemove", mouseMoveRef.current);
|
|
908
|
+
document.removeEventListener("mouseup", mouseUpRef.current);
|
|
909
|
+
if (resizeListenerRef.current) {
|
|
910
|
+
window.removeEventListener("resize", resizeListenerRef.current);
|
|
911
|
+
resizeListenerRef.current = null;
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
}, []);
|
|
841
915
|
var _rest_style_minHeight, _rest_style_minWidth, _rest_style_maxHeight, _rest_style_maxWidth;
|
|
842
|
-
return /*#__PURE__*/ (0, $duWW8$
|
|
916
|
+
return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
843
917
|
className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowAnchor,
|
|
844
918
|
ref: divRef,
|
|
845
|
-
children:
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
role: "button",
|
|
904
|
-
"aria-label": "Close",
|
|
905
|
-
onClick: onClose,
|
|
906
|
-
title: `Close ${title && title.trim() !== "" ? title : "window"}`,
|
|
907
|
-
children: /*#__PURE__*/ (0, $duWW8$jsx)("svg", {
|
|
908
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
909
|
-
width: "16",
|
|
910
|
-
height: "16",
|
|
911
|
-
fill: "currentColor",
|
|
912
|
-
viewBox: "0 0 16 16",
|
|
913
|
-
children: /*#__PURE__*/ (0, $duWW8$jsx)("path", {
|
|
914
|
-
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"
|
|
915
|
-
})
|
|
919
|
+
children: windowInDOM && /*#__PURE__*/ (0, $duWW8$createPortal)(/*#__PURE__*/ (0, $duWW8$jsxs)("div", (0, $duWW8$_1)((0, $duWW8$_)({}, rest), {
|
|
920
|
+
ref: windowRef,
|
|
921
|
+
id: id,
|
|
922
|
+
[$b5e8657823def5be$var$CONTEXT_WINDOW_DATA_ATTR]: "true",
|
|
923
|
+
className: [
|
|
924
|
+
(0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindow,
|
|
925
|
+
rest.className
|
|
926
|
+
].filter((c)=>c).join(" "),
|
|
927
|
+
style: (0, $duWW8$_1)((0, $duWW8$_)({}, rest.style), {
|
|
928
|
+
opacity: moving ? 0.8 : windowVisible ? 1 : 0,
|
|
929
|
+
visibility: windowVisible ? "visible" : "hidden",
|
|
930
|
+
zIndex: zIndex,
|
|
931
|
+
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",
|
|
932
|
+
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",
|
|
933
|
+
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",
|
|
934
|
+
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"
|
|
935
|
+
}),
|
|
936
|
+
onClickCapture: (e)=>{
|
|
937
|
+
var _rest_onClickCapture;
|
|
938
|
+
pushToTop();
|
|
939
|
+
(_rest_onClickCapture = rest.onClickCapture) === null || _rest_onClickCapture === void 0 ? void 0 : _rest_onClickCapture.call(rest, e);
|
|
940
|
+
},
|
|
941
|
+
children: [
|
|
942
|
+
/*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
943
|
+
className: [
|
|
944
|
+
(0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitle,
|
|
945
|
+
moving ? (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).moving : ""
|
|
946
|
+
].filter((c)=>c !== "").join(" "),
|
|
947
|
+
onMouseDown: (e)=>{
|
|
948
|
+
if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "none";
|
|
949
|
+
setMoving(true);
|
|
950
|
+
pushToTop();
|
|
951
|
+
document.addEventListener("mouseup", mouseUpRef.current);
|
|
952
|
+
document.addEventListener("mousemove", mouseMoveRef.current);
|
|
953
|
+
const resizeListener = ()=>checkPosition();
|
|
954
|
+
resizeListenerRef.current = resizeListener;
|
|
955
|
+
window.addEventListener("resize", resizeListener);
|
|
956
|
+
},
|
|
957
|
+
children: [
|
|
958
|
+
/*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
959
|
+
className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitleText,
|
|
960
|
+
title: title,
|
|
961
|
+
children: titleElement ? titleElement : title
|
|
962
|
+
}),
|
|
963
|
+
/*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
964
|
+
className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowTitleClose,
|
|
965
|
+
role: "button",
|
|
966
|
+
"aria-label": "Close",
|
|
967
|
+
onClick: onClose,
|
|
968
|
+
title: `Close ${title && title.trim() !== "" ? title : "window"}`,
|
|
969
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("svg", {
|
|
970
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
971
|
+
width: "16",
|
|
972
|
+
height: "16",
|
|
973
|
+
fill: "currentColor",
|
|
974
|
+
viewBox: "0 0 16 16",
|
|
975
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("path", {
|
|
976
|
+
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"
|
|
916
977
|
})
|
|
917
978
|
})
|
|
918
|
-
]
|
|
919
|
-
}),
|
|
920
|
-
/*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
921
|
-
className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowBody,
|
|
922
|
-
children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
923
|
-
children: children
|
|
924
979
|
})
|
|
980
|
+
]
|
|
981
|
+
}),
|
|
982
|
+
/*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
983
|
+
className: (0, (/*@__PURE__*/$parcel$interopDefault($ddf7153c7c69b209$exports))).contextWindowBody,
|
|
984
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
985
|
+
children: children
|
|
925
986
|
})
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
987
|
+
})
|
|
988
|
+
]
|
|
989
|
+
})), document.body)
|
|
929
990
|
});
|
|
930
991
|
};
|
|
931
992
|
$b5e8657823def5be$export$1af8984c69ba1b24.displayName = "ContextWindow";
|
|
@@ -935,6 +996,5 @@ $b5e8657823def5be$export$1af8984c69ba1b24.displayName = "ContextWindow";
|
|
|
935
996
|
|
|
936
997
|
|
|
937
998
|
|
|
938
|
-
|
|
939
|
-
export {$62873e7e5aeec7f1$export$77bf000da9303d1 as AutoHeight, $c3e82278b501f10c$export$d4ebdd58e04c6ace as ClickForMenu, $567ed433af94513f$export$8dc6765e8be191c7 as ContextMenu, $1e1c1e9e0b943830$export$ed4f9641643dc7e4 as ContextMenuHandler, $b5e8657823def5be$export$1af8984c69ba1b24 as ContextWindow, $17c46b9e6a2eb66e$export$9f37482ccd50dad2 as ContextWindowStack};
|
|
999
|
+
export {$62873e7e5aeec7f1$export$77bf000da9303d1 as AutoHeight, $c3e82278b501f10c$export$d4ebdd58e04c6ace as ClickForMenu, $567ed433af94513f$export$8dc6765e8be191c7 as ContextMenu, $1e1c1e9e0b943830$export$ed4f9641643dc7e4 as ContextMenuHandler, $b5e8657823def5be$export$1af8984c69ba1b24 as ContextWindow};
|
|
940
1000
|
//# sourceMappingURL=main.js.map
|