@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/dist/cjs/main.js CHANGED
@@ -40,7 +40,6 @@ $parcel$export($a68bd8a6c0fd98c2$exports, "ClickForMenu", function () { return $
40
40
  $parcel$export($a68bd8a6c0fd98c2$exports, "ContextMenu", function () { return $5150b66b01c99189$export$8dc6765e8be191c7; });
41
41
  $parcel$export($a68bd8a6c0fd98c2$exports, "ContextMenuHandler", function () { return $3c568ee547c732c3$export$ed4f9641643dc7e4; });
42
42
  $parcel$export($a68bd8a6c0fd98c2$exports, "ContextWindow", function () { return $46fb0088a1bbb6d8$export$1af8984c69ba1b24; });
43
- $parcel$export($a68bd8a6c0fd98c2$exports, "ContextWindowStack", function () { return $16208d559c772441$export$9f37482ccd50dad2; });
44
43
 
45
44
 
46
45
 
@@ -98,11 +97,16 @@ function $95149596d5a7ed2b$export$77bf000da9303d1(_param) {
98
97
  setTargetHeight
99
98
  ]);
100
99
  // Trigger height change on children update
101
- (0, $gTuX4$react.useLayoutEffect)(()=>{
102
- setTargetHeight();
100
+ const [, startTransition] = (0, $gTuX4$react.useTransition)();
101
+ (0, $gTuX4$react.useEffect)(()=>{
102
+ // Mark this update as non-urgent to avoid cascading render warnings
103
+ startTransition(()=>{
104
+ setTargetHeight();
105
+ });
103
106
  }, [
104
107
  setTargetHeight,
105
- children
108
+ children,
109
+ startTransition
106
110
  ]);
107
111
  return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", (0, $gTuX4$swchelperscjs_object_spread_propscjs._)((0, $gTuX4$swchelperscjs_object_spreadcjs._)({}, rest), {
108
112
  className: (0, (/*@__PURE__*/$parcel$interopDefault($796f463330153c24$exports))).autoHeightWrapper,
@@ -169,9 +173,13 @@ $da5a7b95ca760552$export$664c6d24e3175067 = `aiw-ContextMenu-module-WinFxq-visib
169
173
 
170
174
 
171
175
 
172
- const $d35a356381c44181$export$7e4e6110f96afd7e = ({ entries: entries, toClose: toClose, visible: visible })=>{
176
+
177
+ const $d35a356381c44181$export$7e4e6110f96afd7e = ({ entries: entries, toClose: toClose })=>{
178
+ const [visible, setVisible] = (0, $gTuX4$react.useState)(false);
173
179
  return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("span", {
174
180
  className: (0, (/*@__PURE__*/$parcel$interopDefault($da5a7b95ca760552$exports))).caretHolder,
181
+ onMouseEnter: ()=>setVisible(true),
182
+ onMouseLeave: ()=>setVisible(false),
175
183
  children: [
176
184
  /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("svg", {
177
185
  xmlns: "http://www.w3.org/2000/svg",
@@ -183,10 +191,10 @@ const $d35a356381c44181$export$7e4e6110f96afd7e = ({ entries: entries, toClose:
183
191
  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"
184
192
  })
185
193
  }),
186
- /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
194
+ visible && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
187
195
  className: (0, (/*@__PURE__*/$parcel$interopDefault($da5a7b95ca760552$exports))).subMenu,
188
196
  children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $5150b66b01c99189$export$8dc6765e8be191c7), {
189
- visible: visible,
197
+ visible: true,
190
198
  entries: entries,
191
199
  xPos: 14,
192
200
  yPos: -21,
@@ -201,21 +209,14 @@ $d35a356381c44181$export$7e4e6110f96afd7e.displayName = "ContextSubMenu";
201
209
 
202
210
  const $1e1f300656d89038$export$c868ef28d2ba36f1 = ({ entry: entry, toClose: toClose })=>{
203
211
  const [target, setTarget] = (0, $gTuX4$react.useState)(null);
204
- const [subMenuVisible, setSubMenuVisible] = (0, $gTuX4$react.useState)(false);
205
212
  return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
206
213
  className: [
207
214
  (0, (/*@__PURE__*/$parcel$interopDefault($da5a7b95ca760552$exports))).contextMenuItem,
208
215
  entry.disabled ? (0, (/*@__PURE__*/$parcel$interopDefault($da5a7b95ca760552$exports))).disabled : ""
209
216
  ].filter((c)=>c !== "").join(" "),
210
- onMouseEnter: ()=>{
211
- setSubMenuVisible(true);
212
- },
213
- onMouseLeave: ()=>{
214
- setSubMenuVisible(false);
215
- },
216
217
  children: [
217
218
  typeof entry.label === "string" ? /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("span", {
218
- "aria-label": typeof entry.label === "string" ? entry.label : undefined,
219
+ "aria-label": entry.label,
219
220
  "aria-disabled": entry.disabled,
220
221
  className: (0, (/*@__PURE__*/$parcel$interopDefault($da5a7b95ca760552$exports))).contextMenuItemLabel,
221
222
  onMouseEnter: ()=>{
@@ -238,24 +239,39 @@ const $1e1f300656d89038$export$c868ef28d2ba36f1 = ({ entry: entry, toClose: toCl
238
239
  }) : entry.label,
239
240
  entry.group && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $d35a356381c44181$export$7e4e6110f96afd7e), {
240
241
  toClose: toClose,
241
- entries: entry.group,
242
- visible: subMenuVisible
242
+ entries: entry.group
243
243
  })
244
244
  ]
245
245
  });
246
246
  };
247
247
 
248
248
 
249
+ // Constants for menu size estimation when ref is not yet available
250
+ const $5150b66b01c99189$var$ESTIMATED_MENU_ITEM_HEIGHT = 34;
251
+ const $5150b66b01c99189$var$ESTIMATED_MENU_PADDING = 4;
252
+ const $5150b66b01c99189$var$ESTIMATED_MENU_WIDTH = 200;
249
253
  const $5150b66b01c99189$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $gTuX4$react.forwardRef)(({ visible: visible, entries: entries, xPos: xPos, yPos: yPos, toClose: toClose }, ref)=>{
250
- // Check that menu can fit inside the window
251
- let menuHeight = entries.length * 34 + 4;
252
- let menuWidth = 200;
253
- if (ref && typeof ref !== "function" && ref.current instanceof HTMLDivElement) {
254
- menuHeight = ref.current.offsetHeight;
255
- menuWidth = ref.current.offsetWidth;
256
- }
257
- if (yPos + menuHeight > window.innerHeight) yPos = Math.max(window.innerHeight - menuHeight - 4, 0);
258
- if (xPos + menuWidth > window.innerWidth) xPos = Math.max(window.innerWidth - menuWidth - 4, 0);
254
+ // Measure menu size after mount/render to avoid accessing refs during render
255
+ const [menuHeight, setMenuHeight] = (0, $gTuX4$react.useState)(entries.length * $5150b66b01c99189$var$ESTIMATED_MENU_ITEM_HEIGHT + $5150b66b01c99189$var$ESTIMATED_MENU_PADDING);
256
+ const [menuWidth, setMenuWidth] = (0, $gTuX4$react.useState)($5150b66b01c99189$var$ESTIMATED_MENU_WIDTH);
257
+ (0, $gTuX4$react.useLayoutEffect)(()=>{
258
+ // Only measure when visible; ref access inside effect is allowed
259
+ if (visible && ref && typeof ref !== "function" && ref.current instanceof HTMLDivElement) {
260
+ setMenuHeight(ref.current.offsetHeight);
261
+ setMenuWidth(ref.current.offsetWidth);
262
+ }
263
+ // When not visible, fall back to estimates
264
+ if (!visible) {
265
+ setMenuHeight(entries.length * $5150b66b01c99189$var$ESTIMATED_MENU_ITEM_HEIGHT + $5150b66b01c99189$var$ESTIMATED_MENU_PADDING);
266
+ setMenuWidth($5150b66b01c99189$var$ESTIMATED_MENU_WIDTH);
267
+ }
268
+ }, [
269
+ visible,
270
+ entries,
271
+ ref
272
+ ]);
273
+ const adjustedYPos = yPos + menuHeight > window.innerHeight ? Math.max(window.innerHeight - menuHeight - $5150b66b01c99189$var$ESTIMATED_MENU_PADDING, 0) : yPos;
274
+ const adjustedXPos = xPos + menuWidth > window.innerWidth ? Math.max(window.innerWidth - menuWidth - $5150b66b01c99189$var$ESTIMATED_MENU_PADDING, 0) : xPos;
259
275
  return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
260
276
  ref: ref,
261
277
  className: [
@@ -263,8 +279,8 @@ const $5150b66b01c99189$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $gTuX4$react
263
279
  visible ? (0, (/*@__PURE__*/$parcel$interopDefault($da5a7b95ca760552$exports))).visible : (0, (/*@__PURE__*/$parcel$interopDefault($da5a7b95ca760552$exports))).hidden
264
280
  ].filter((c)=>c !== "").join(" "),
265
281
  style: {
266
- top: `${yPos}px`,
267
- left: `${xPos}px`
282
+ top: `${adjustedYPos}px`,
283
+ left: `${adjustedXPos}px`
268
284
  },
269
285
  onContextMenu: (e)=>{
270
286
  e.preventDefault();
@@ -295,18 +311,29 @@ const $a79b75d040e03c92$export$d4ebdd58e04c6ace = (_param)=>{
295
311
  const menuRef = (0, $gTuX4$react.useRef)(null);
296
312
  // Handle click off the menu
297
313
  const handleClick = (0, $gTuX4$react.useCallback)((e)=>{
298
- var _menuRef_current;
299
- 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);
314
+ if (menuRef.current && (e.target instanceof Element && !menuRef.current.contains(e.target) || !(e.target instanceof Element))) setMenuInDom(false);
300
315
  }, []);
301
- const removeController = (0, $gTuX4$react.useRef)(new AbortController());
316
+ const removeController = (0, $gTuX4$react.useRef)(null);
317
+ const removeTimeoutRef = (0, $gTuX4$react.useRef)(null);
302
318
  (0, $gTuX4$react.useEffect)(()=>{
303
- if (!menuVisible) {
304
- removeController.current.abort();
319
+ if (!menuVisible && removeTimeoutRef.current === null) {
320
+ // Only create a new controller when scheduling a new timeout
321
+ if (removeController.current) removeController.current.abort();
305
322
  removeController.current = new AbortController();
306
- setTimeout(()=>{
307
- if (!removeController.current.signal.aborted) setMenuInDom(false);
323
+ const controller = removeController.current;
324
+ // Set up the timeout with a reference to the current controller
325
+ removeTimeoutRef.current = setTimeout(()=>{
326
+ if (!controller.signal.aborted) setMenuInDom(false);
327
+ removeTimeoutRef.current = null;
308
328
  }, 300);
309
329
  }
330
+ return ()=>{
331
+ // Clean up on unmount or when menuVisible changes
332
+ if (removeTimeoutRef.current) {
333
+ clearTimeout(removeTimeoutRef.current);
334
+ removeTimeoutRef.current = null;
335
+ }
336
+ };
310
337
  }, [
311
338
  menuVisible
312
339
  ]);
@@ -315,7 +342,7 @@ const $a79b75d040e03c92$export$d4ebdd58e04c6ace = (_param)=>{
315
342
  if (menuInDom) document.addEventListener("mousedown", handleClick);
316
343
  return ()=>{
317
344
  document.removeEventListener("mousedown", handleClick);
318
- removeController.current.abort();
345
+ if (removeController.current) removeController.current.abort();
319
346
  };
320
347
  }, [
321
348
  handleClick,
@@ -332,7 +359,7 @@ const $a79b75d040e03c92$export$d4ebdd58e04c6ace = (_param)=>{
332
359
  e.preventDefault();
333
360
  e.stopPropagation();
334
361
  setTimeout(()=>{
335
- removeController.current.abort();
362
+ if (removeController.current) removeController.current.abort();
336
363
  setMenuVisible(true);
337
364
  setMenuXPos(e.pageX);
338
365
  setMenuYPos(e.pageY);
@@ -485,7 +512,7 @@ $b34598671fff4a77$export$aafc28aea571c4bc.displayName = "LowMenuButton";
485
512
 
486
513
  const $10d1ee4e7fc9bbbd$export$49e8edc8ebca5f25 = ({ entries: entries, visible: visible, xPos: xPos, yPos: yPos, maxWidth: maxWidth })=>{
487
514
  // Only show the low menu if it is on the screen
488
- if (xPos > window.innerWidth || yPos > window.innerHeight) return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $gTuX4$reactjsxruntime.Fragment), {});
515
+ if (xPos >= window.innerWidth || yPos >= window.innerHeight) return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $gTuX4$reactjsxruntime.Fragment), {});
489
516
  // Show the menu
490
517
  return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
491
518
  className: [
@@ -520,7 +547,6 @@ const $3c568ee547c732c3$export$ed4f9641643dc7e4 = (_param)=>{
520
547
  "menuItems",
521
548
  "showLowMenu"
522
549
  ]);
523
- var _divHandlderRef_current;
524
550
  // Check for higher content menu
525
551
  const higherContext = (0, $gTuX4$react.useContext)($3c568ee547c732c3$export$fc58dc71afe92de2);
526
552
  const thisMenuItems = (0, $gTuX4$react.useMemo)(()=>[
@@ -553,8 +579,34 @@ const $3c568ee547c732c3$export$ed4f9641643dc7e4 = (_param)=>{
553
579
  const [menuInDom, setMenuInDom] = (0, $gTuX4$react.useState)(false);
554
580
  const [mouseOverHandlerDiv, setMouseOverHandlerDiv] = (0, $gTuX4$react.useState)(false);
555
581
  const [mouseOverMenu, setMouseOverMenu] = (0, $gTuX4$react.useState)(false);
556
- // Get holder position
557
- const divHandlerPos = divHandlderRef ? (_divHandlderRef_current = divHandlderRef.current) === null || _divHandlderRef_current === void 0 ? void 0 : _divHandlderRef_current.getBoundingClientRect() : null;
582
+ // Holder position - measured in an effect to avoid reading refs during render
583
+ const [divHandlerPos, setDivHandlerPos] = (0, $gTuX4$react.useState)(null);
584
+ (0, $gTuX4$react.useLayoutEffect)(()=>{
585
+ function updatePos() {
586
+ if (divHandlderRef.current) setDivHandlerPos(divHandlderRef.current.getBoundingClientRect());
587
+ }
588
+ // When the handler is hovered or the menu is mounted, ensure we have a fresh position
589
+ if (mouseOverHandlerDiv || menuInDom) updatePos();
590
+ // Attach listeners while the menu/low-menu may be visible so the position stays correct
591
+ if (mouseOverHandlerDiv || menuInDom) {
592
+ window.addEventListener("resize", updatePos);
593
+ // listen on capture to catch scrolls from ancestor elements as well
594
+ window.addEventListener("scroll", updatePos, true);
595
+ let ro = null;
596
+ if (typeof ResizeObserver !== "undefined" && divHandlderRef.current) {
597
+ ro = new ResizeObserver(()=>updatePos());
598
+ ro.observe(divHandlderRef.current);
599
+ }
600
+ return ()=>{
601
+ window.removeEventListener("resize", updatePos);
602
+ window.removeEventListener("scroll", updatePos, true);
603
+ if (ro) ro.disconnect();
604
+ };
605
+ }
606
+ }, [
607
+ mouseOverHandlerDiv,
608
+ menuInDom
609
+ ]);
558
610
  // Handle click off the menu
559
611
  const handleClick = (0, $gTuX4$react.useCallback)((e)=>{
560
612
  var _menuRef_current;
@@ -720,62 +772,41 @@ $7c5fb3f6c1601913$export$cebbac70b4d99c48 = `aiw-ContextWindow-module-RIIF9a-con
720
772
  $7c5fb3f6c1601913$export$d03a2f3acc60252b = `aiw-ContextWindow-module-RIIF9a-moving`;
721
773
 
722
774
 
723
-
724
-
725
- const $16208d559c772441$export$aff5d0593e3727b0 = /*#__PURE__*/ (0, $gTuX4$react.createContext)(null);
726
- const $16208d559c772441$var$pushToTop = (windowId, minZIndex, windowList, setWindowList)=>{
727
- const otherWindows = windowList.filter((w)=>w.windowId !== windowId).map((w, i)=>({
728
- windowId: w.windowId,
729
- zIndex: minZIndex + i
730
- }));
731
- setWindowList([
732
- ...otherWindows,
733
- {
734
- windowId: windowId,
735
- zIndex: minZIndex + otherWindows.length
775
+ const $46fb0088a1bbb6d8$export$4f9fb66ac71c7da5 = 3000;
776
+ const $46fb0088a1bbb6d8$var$CONTEXT_WINDOW_DATA_ATTR = "data-context-window";
777
+ // Helper function to get the highest zIndex from all context windows in the DOM
778
+ const $46fb0088a1bbb6d8$var$getMaxZIndex = (componentMinZIndex)=>{
779
+ const windows = document.body.querySelectorAll(`[${$46fb0088a1bbb6d8$var$CONTEXT_WINDOW_DATA_ATTR}]`);
780
+ let maxZIndex = componentMinZIndex - 1;
781
+ windows.forEach((win)=>{
782
+ const zIndexStr = win.style.zIndex;
783
+ if (zIndexStr) {
784
+ const zIndex = parseInt(zIndexStr, 10);
785
+ if (!isNaN(zIndex) && zIndex > maxZIndex) maxZIndex = zIndex;
736
786
  }
737
- ]);
738
- };
739
- const $16208d559c772441$export$9f37482ccd50dad2 = ({ minZIndex: minZIndex = 1000, children: children })=>{
740
- const [currentWindows, setCurrentWindows] = (0, $gTuX4$react.useState)([]);
741
- return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)($16208d559c772441$export$aff5d0593e3727b0.Provider, {
742
- value: {
743
- currentWindows: currentWindows.map((w)=>({
744
- windowId: w.windowId,
745
- zIndex: minZIndex + w.zIndex
746
- })),
747
- pushToTop: (ret)=>$16208d559c772441$var$pushToTop(ret, minZIndex, currentWindows, setCurrentWindows)
748
- },
749
- children: children
750
787
  });
788
+ return maxZIndex;
751
789
  };
752
- $16208d559c772441$export$9f37482ccd50dad2.displayName = "ContextWindowStack";
753
-
754
-
755
790
  const $46fb0088a1bbb6d8$export$1af8984c69ba1b24 = (_param)=>{
756
- var { id: id, visible: visible, title: title, titleElement: titleElement, children: children, onOpen: onOpen, onClose: onClose } = _param, rest = (0, $gTuX4$swchelperscjs_object_without_propertiescjs._)(_param, [
791
+ var { id: id, visible: visible, title: title, titleElement: titleElement, children: children, onOpen: onOpen, onClose: onClose, minZIndex: minZIndex = $46fb0088a1bbb6d8$export$4f9fb66ac71c7da5 } = _param, rest = (0, $gTuX4$swchelperscjs_object_without_propertiescjs._)(_param, [
757
792
  "id",
758
793
  "visible",
759
794
  "title",
760
795
  "titleElement",
761
796
  "children",
762
797
  "onOpen",
763
- "onClose"
798
+ "onClose",
799
+ "minZIndex"
764
800
  ]);
765
801
  var _rest_style, _rest_style1, _rest_style2, _rest_style3;
766
- const windowStack = (0, $gTuX4$react.useContext)((0, $16208d559c772441$export$aff5d0593e3727b0));
767
- const windowId = (0, $gTuX4$react.useRef)(null);
768
802
  const divRef = (0, $gTuX4$react.useRef)(null);
769
803
  const windowRef = (0, $gTuX4$react.useRef)(null);
804
+ const [zIndex, setZIndex] = (0, $gTuX4$react.useState)(minZIndex);
805
+ const resizeListenerRef = (0, $gTuX4$react.useRef)(null);
806
+ // Track internal state: whether window is in DOM and whether it's been positioned
770
807
  const [windowInDOM, setWindowInDOM] = (0, $gTuX4$react.useState)(false);
771
808
  const [windowVisible, setWindowVisible] = (0, $gTuX4$react.useState)(false);
772
- const zIndex = (0, $gTuX4$react.useMemo)(()=>{
773
- var _windowStack_currentWindows_find;
774
- var _windowStack_currentWindows_find_zIndex;
775
- 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;
776
- }, [
777
- windowStack === null || windowStack === void 0 ? void 0 : windowStack.currentWindows
778
- ]);
809
+ const [, startTransition] = (0, $gTuX4$react.useTransition)();
779
810
  // Position
780
811
  const windowPos = (0, $gTuX4$react.useRef)({
781
812
  x: 0,
@@ -804,145 +835,175 @@ const $46fb0088a1bbb6d8$export$1af8984c69ba1b24 = (_param)=>{
804
835
  }, [
805
836
  move
806
837
  ]);
838
+ // Store stable references to mouseMove and mouseUp for cleanup
839
+ const mouseMoveRef = (0, $gTuX4$react.useRef)(mouseMove);
840
+ const mouseUpRef = (0, $gTuX4$react.useRef)(()=>{});
807
841
  const mouseUp = (0, $gTuX4$react.useCallback)((e)=>{
808
842
  e.preventDefault();
809
843
  e.stopPropagation();
810
844
  setMoving(false);
811
845
  checkPosition();
812
- document.removeEventListener("mousemove", mouseMove);
813
- document.removeEventListener("mouseup", mouseUp);
814
- window.removeEventListener("resize", checkPosition);
846
+ document.removeEventListener("mousemove", mouseMoveRef.current);
847
+ document.removeEventListener("mouseup", mouseUpRef.current);
848
+ if (resizeListenerRef.current) {
849
+ window.removeEventListener("resize", resizeListenerRef.current);
850
+ resizeListenerRef.current = null;
851
+ }
815
852
  if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "auto";
816
853
  }, [
817
- checkPosition,
818
- mouseMove
854
+ checkPosition
855
+ ]);
856
+ // Update refs when callbacks change
857
+ (0, $gTuX4$react.useEffect)(()=>{
858
+ mouseMoveRef.current = mouseMove;
859
+ mouseUpRef.current = mouseUp;
860
+ }, [
861
+ mouseMove,
862
+ mouseUp
819
863
  ]);
820
- // Update visibility
864
+ // Helper function to push this window to the top
865
+ const pushToTop = (0, $gTuX4$react.useCallback)(()=>{
866
+ const maxZIndex = $46fb0088a1bbb6d8$var$getMaxZIndex(minZIndex);
867
+ setZIndex(maxZIndex + 1);
868
+ }, [
869
+ minZIndex
870
+ ]);
871
+ // Sync windowInDOM with visible prop using a layout effect to avoid ESLint warnings
872
+ // This effect derives state from props, which is acceptable when there's no synchronous setState
821
873
  (0, $gTuX4$react.useEffect)(()=>{
822
- if (windowStack) {
823
- // Visible set, but not in DOM
824
- if (visible && !windowInDOM) setWindowInDOM(true);
825
- else if (visible && windowInDOM && !windowVisible) {
826
- if (!windowId.current) {
827
- const maxWindowId = Math.max(0, ...windowStack.currentWindows.map((w)=>w.windowId));
828
- windowId.current = maxWindowId + 1;
829
- }
830
- windowStack.pushToTop(windowId.current);
831
- setWindowVisible(visible);
832
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
833
- // Get starting position
834
- if (divRef.current && windowRef.current) {
835
- const parentPos = divRef.current.getBoundingClientRect();
836
- const pos = windowRef.current.getBoundingClientRect();
837
- const windowHeight = pos.bottom - pos.top;
838
- windowRef.current.style.left = `${parentPos.left}px`;
839
- windowRef.current.style.top = `${parentPos.bottom + windowHeight < window.innerHeight ? parentPos.bottom : Math.max(0, parentPos.top - windowHeight)}px`;
840
- windowRef.current.style.transform = "";
841
- windowPos.current = {
842
- x: 0,
843
- y: 0
844
- };
845
- }
846
- checkPosition();
847
- } else if (windowId.current && !visible && windowVisible) setWindowVisible(false);
848
- else if (windowId.current && !visible && windowInDOM) setWindowInDOM(false);
874
+ if (visible && !windowInDOM) // Window should be in DOM when visible becomes true
875
+ startTransition(()=>{
876
+ setWindowInDOM(true);
877
+ });
878
+ else if (!visible && windowInDOM) // Window should leave DOM when visible becomes false
879
+ startTransition(()=>{
880
+ setWindowInDOM(false);
881
+ setWindowVisible(false);
882
+ });
883
+ }, [
884
+ visible,
885
+ windowInDOM,
886
+ startTransition
887
+ ]);
888
+ // Position and show window after it's added to DOM
889
+ (0, $gTuX4$react.useEffect)(()=>{
890
+ if (windowInDOM && !windowVisible && visible && divRef.current && windowRef.current) {
891
+ // Position the window
892
+ const parentPos = divRef.current.getBoundingClientRect();
893
+ const pos = windowRef.current.getBoundingClientRect();
894
+ const windowHeight = pos.bottom - pos.top;
895
+ windowRef.current.style.left = `${parentPos.left}px`;
896
+ windowRef.current.style.top = `${parentPos.bottom + windowHeight < window.innerHeight ? parentPos.bottom : Math.max(0, parentPos.top - windowHeight)}px`;
897
+ windowRef.current.style.transform = "";
898
+ windowPos.current = {
899
+ x: 0,
900
+ y: 0
901
+ };
902
+ checkPosition();
903
+ // Update z-index and make visible - use startTransition
904
+ const maxZ = $46fb0088a1bbb6d8$var$getMaxZIndex(minZIndex);
905
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen();
906
+ startTransition(()=>{
907
+ setZIndex(maxZ + 1);
908
+ setWindowVisible(true);
909
+ });
849
910
  }
850
911
  }, [
912
+ windowInDOM,
913
+ windowVisible,
914
+ visible,
851
915
  checkPosition,
916
+ minZIndex,
852
917
  onOpen,
853
- visible,
854
- windowInDOM,
855
- windowStack,
856
- windowVisible
918
+ startTransition
857
919
  ]);
920
+ // Cleanup effect to remove event listeners on unmount
921
+ (0, $gTuX4$react.useEffect)(()=>{
922
+ return ()=>{
923
+ // Clean up event listeners if component unmounts while dragging
924
+ document.removeEventListener("mousemove", mouseMoveRef.current);
925
+ document.removeEventListener("mouseup", mouseUpRef.current);
926
+ if (resizeListenerRef.current) {
927
+ window.removeEventListener("resize", resizeListenerRef.current);
928
+ resizeListenerRef.current = null;
929
+ }
930
+ };
931
+ }, []);
858
932
  var _rest_style_minHeight, _rest_style_minWidth, _rest_style_maxHeight, _rest_style_maxWidth;
859
- return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
933
+ return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
860
934
  className: (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowAnchor,
861
935
  ref: divRef,
862
- children: [
863
- !windowStack && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", (0, $gTuX4$swchelperscjs_object_spread_propscjs._)((0, $gTuX4$swchelperscjs_object_spreadcjs._)({}, rest), {
864
- children: [
865
- process.env.NODE_ENV !== "production" && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
866
- style: {
867
- backgroundColor: "red",
868
- color: "white",
869
- padding: "8px",
870
- fontSize: "48px"
871
- },
872
- children: "WARNING: No ContextWindowStack found"
873
- }),
874
- children
875
- ]
876
- })),
877
- windowStack && windowInDOM && /*#__PURE__*/ (0, $gTuX4$reactdom.createPortal)(/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", (0, $gTuX4$swchelperscjs_object_spread_propscjs._)((0, $gTuX4$swchelperscjs_object_spreadcjs._)({}, rest), {
878
- ref: windowRef,
879
- id: id,
880
- className: [
881
- (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindow,
882
- rest.className
883
- ].filter((c)=>c).join(" "),
884
- style: (0, $gTuX4$swchelperscjs_object_spread_propscjs._)((0, $gTuX4$swchelperscjs_object_spreadcjs._)({}, rest.style), {
885
- opacity: moving ? 0.8 : windowVisible ? 1 : 0,
886
- visibility: windowVisible ? "visible" : "hidden",
887
- zIndex: zIndex !== null && zIndex !== void 0 ? zIndex : 1,
888
- 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",
889
- 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",
890
- 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",
891
- 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"
892
- }),
893
- onClickCapture: (e)=>{
894
- var _rest_onClickCapture;
895
- if (windowId.current) windowStack.pushToTop(windowId.current);
896
- (_rest_onClickCapture = rest.onClickCapture) === null || _rest_onClickCapture === void 0 ? void 0 : _rest_onClickCapture.call(rest, e);
897
- },
898
- children: [
899
- /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
900
- className: [
901
- (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowTitle,
902
- moving ? (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).moving : ""
903
- ].filter((c)=>c !== "").join(" "),
904
- onMouseDown: (e)=>{
905
- if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "none";
906
- setMoving(true);
907
- if (windowId.current) windowStack.pushToTop(windowId.current);
908
- document.addEventListener("mouseup", mouseUp);
909
- document.addEventListener("mousemove", mouseMove);
910
- window.addEventListener("resize", ()=>checkPosition());
911
- },
912
- children: [
913
- /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
914
- className: (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowTitleText,
915
- title: title,
916
- children: titleElement ? titleElement : title
917
- }),
918
- /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
919
- className: (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowTitleClose,
920
- role: "button",
921
- "aria-label": "Close",
922
- onClick: onClose,
923
- title: `Close ${title && title.trim() !== "" ? title : "window"}`,
924
- children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("svg", {
925
- xmlns: "http://www.w3.org/2000/svg",
926
- width: "16",
927
- height: "16",
928
- fill: "currentColor",
929
- viewBox: "0 0 16 16",
930
- children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("path", {
931
- 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"
932
- })
936
+ children: windowInDOM && /*#__PURE__*/ (0, $gTuX4$reactdom.createPortal)(/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", (0, $gTuX4$swchelperscjs_object_spread_propscjs._)((0, $gTuX4$swchelperscjs_object_spreadcjs._)({}, rest), {
937
+ ref: windowRef,
938
+ id: id,
939
+ [$46fb0088a1bbb6d8$var$CONTEXT_WINDOW_DATA_ATTR]: "true",
940
+ className: [
941
+ (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindow,
942
+ rest.className
943
+ ].filter((c)=>c).join(" "),
944
+ style: (0, $gTuX4$swchelperscjs_object_spread_propscjs._)((0, $gTuX4$swchelperscjs_object_spreadcjs._)({}, rest.style), {
945
+ opacity: moving ? 0.8 : windowVisible ? 1 : 0,
946
+ visibility: windowVisible ? "visible" : "hidden",
947
+ zIndex: zIndex,
948
+ 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",
949
+ 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",
950
+ 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",
951
+ 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"
952
+ }),
953
+ onClickCapture: (e)=>{
954
+ var _rest_onClickCapture;
955
+ pushToTop();
956
+ (_rest_onClickCapture = rest.onClickCapture) === null || _rest_onClickCapture === void 0 ? void 0 : _rest_onClickCapture.call(rest, e);
957
+ },
958
+ children: [
959
+ /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
960
+ className: [
961
+ (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowTitle,
962
+ moving ? (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).moving : ""
963
+ ].filter((c)=>c !== "").join(" "),
964
+ onMouseDown: (e)=>{
965
+ if (e.target && (e.target instanceof HTMLElement || e.target instanceof SVGElement)) e.target.style.userSelect = "none";
966
+ setMoving(true);
967
+ pushToTop();
968
+ document.addEventListener("mouseup", mouseUpRef.current);
969
+ document.addEventListener("mousemove", mouseMoveRef.current);
970
+ const resizeListener = ()=>checkPosition();
971
+ resizeListenerRef.current = resizeListener;
972
+ window.addEventListener("resize", resizeListener);
973
+ },
974
+ children: [
975
+ /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
976
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowTitleText,
977
+ title: title,
978
+ children: titleElement ? titleElement : title
979
+ }),
980
+ /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
981
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowTitleClose,
982
+ role: "button",
983
+ "aria-label": "Close",
984
+ onClick: onClose,
985
+ title: `Close ${title && title.trim() !== "" ? title : "window"}`,
986
+ children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("svg", {
987
+ xmlns: "http://www.w3.org/2000/svg",
988
+ width: "16",
989
+ height: "16",
990
+ fill: "currentColor",
991
+ viewBox: "0 0 16 16",
992
+ children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("path", {
993
+ 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"
933
994
  })
934
995
  })
935
- ]
936
- }),
937
- /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
938
- className: (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowBody,
939
- children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
940
- children: children
941
996
  })
997
+ ]
998
+ }),
999
+ /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
1000
+ className: (0, (/*@__PURE__*/$parcel$interopDefault($7c5fb3f6c1601913$exports))).contextWindowBody,
1001
+ children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
1002
+ children: children
942
1003
  })
943
- ]
944
- })), document.body)
945
- ]
1004
+ })
1005
+ ]
1006
+ })), document.body)
946
1007
  });
947
1008
  };
948
1009
  $46fb0088a1bbb6d8$export$1af8984c69ba1b24.displayName = "ContextWindow";
@@ -950,7 +1011,6 @@ $46fb0088a1bbb6d8$export$1af8984c69ba1b24.displayName = "ContextWindow";
950
1011
 
951
1012
 
952
1013
 
953
-
954
1014
  $parcel$exportWildcard(module.exports, $a68bd8a6c0fd98c2$exports);
955
1015
 
956
1016