@vuu-ui/vuu-popups 0.8.22-debug → 0.8.23-debug
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/cjs/index.js +81 -33
- package/cjs/index.js.map +4 -4
- package/esm/index.js +81 -33
- package/esm/index.js.map +4 -4
- package/index.css +6 -6
- package/index.css.map +2 -2
- package/package.json +5 -5
- package/types/menu/MenuList.d.ts +2 -1
- package/types/menu/use-keyboard-navigation.d.ts +3 -1
- package/types/popup/Popup.d.ts +1 -1
- package/types/popup/getPositionRelativeToAnchor.d.ts +19 -0
- package/types/popup/popup-service.d.ts +11 -3
- package/types/popup/useAnchoredPosition.d.ts +1 -8
- package/types/popup-menu/PopupMenu.d.ts +9 -3
package/esm/index.js
CHANGED
|
@@ -210,7 +210,13 @@ var PopupService = class _PopupService {
|
|
|
210
210
|
_PopupService.escapeKeyListener,
|
|
211
211
|
true
|
|
212
212
|
);
|
|
213
|
-
(_a = _PopupService == null ? void 0 : _PopupService.onClose) == null ? void 0 : _a.call(
|
|
213
|
+
(_a = _PopupService == null ? void 0 : _PopupService.onClose) == null ? void 0 : _a.call(
|
|
214
|
+
_PopupService,
|
|
215
|
+
reason ? {
|
|
216
|
+
...reason,
|
|
217
|
+
closedBy: "popup-service"
|
|
218
|
+
} : void 0
|
|
219
|
+
);
|
|
214
220
|
}
|
|
215
221
|
static keepWithinThePage(el, right = "auto") {
|
|
216
222
|
const target = el.querySelector(".vuuPopupContainer > *");
|
|
@@ -271,8 +277,11 @@ import cx4 from "clsx";
|
|
|
271
277
|
|
|
272
278
|
// src/popup/useAnchoredPosition.ts
|
|
273
279
|
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
280
|
+
|
|
281
|
+
// src/popup/getPositionRelativeToAnchor.ts
|
|
274
282
|
var getPositionRelativeToAnchor = (anchorElement, placement, offsetLeft, offsetTop, minWidth, dimensions) => {
|
|
275
283
|
const { bottom, height, left, right, top, width } = anchorElement.getBoundingClientRect();
|
|
284
|
+
console.log({ top });
|
|
276
285
|
switch (placement) {
|
|
277
286
|
case "below":
|
|
278
287
|
return { left: left + offsetLeft, top: bottom + offsetTop };
|
|
@@ -305,10 +314,12 @@ var getPositionRelativeToAnchor = (anchorElement, placement, offsetLeft, offsetT
|
|
|
305
314
|
}
|
|
306
315
|
default:
|
|
307
316
|
throw Error(
|
|
308
|
-
|
|
317
|
+
`Popup getPositionRelativeToAnchor non-supported placement value ${placement}`
|
|
309
318
|
);
|
|
310
319
|
}
|
|
311
320
|
};
|
|
321
|
+
|
|
322
|
+
// src/popup/useAnchoredPosition.ts
|
|
312
323
|
var useAnchoredPosition = ({
|
|
313
324
|
anchorElement,
|
|
314
325
|
minWidth,
|
|
@@ -403,7 +414,7 @@ var Dialog = ({
|
|
|
403
414
|
} = PopupProps;
|
|
404
415
|
const rootRef = useRef2(null);
|
|
405
416
|
const portalRef = useRef2(null);
|
|
406
|
-
const [themeClass,
|
|
417
|
+
const [themeClass, _, dataMode] = useThemeAttributes();
|
|
407
418
|
const { position } = useAnchoredPosition({
|
|
408
419
|
anchorElement,
|
|
409
420
|
offsetLeft,
|
|
@@ -756,13 +767,13 @@ var useKeyboardNavigation = ({
|
|
|
756
767
|
onOpenMenu == null ? void 0 : onOpenMenu(menuItemEl, true);
|
|
757
768
|
}
|
|
758
769
|
} else if (e.key === "ArrowLeft" && !isRoot(e.target)) {
|
|
759
|
-
onCloseMenu(
|
|
770
|
+
onCloseMenu(e, "close-child-menu");
|
|
760
771
|
} else if (e.key === "Enter") {
|
|
761
772
|
e.preventDefault();
|
|
762
773
|
e.stopPropagation();
|
|
763
774
|
onActivate && onActivate(highlightedIndex);
|
|
764
775
|
} else if (e.key === "Tab") {
|
|
765
|
-
onCloseMenu(-
|
|
776
|
+
onCloseMenu(e, "tab-away");
|
|
766
777
|
}
|
|
767
778
|
},
|
|
768
779
|
[
|
|
@@ -1274,8 +1285,6 @@ var ContextMenu = ({
|
|
|
1274
1285
|
style,
|
|
1275
1286
|
...menuListProps
|
|
1276
1287
|
}) => {
|
|
1277
|
-
const closeHandlerRef = useRef7(onClose);
|
|
1278
|
-
closeHandlerRef.current = onClose;
|
|
1279
1288
|
const id = useId2(idProp);
|
|
1280
1289
|
const closeMenuRef = useRef7(noop);
|
|
1281
1290
|
const [menus, actions] = useItemsWithIdsNext(childrenProp, id);
|
|
@@ -1310,10 +1319,19 @@ var ContextMenu = ({
|
|
|
1310
1319
|
position
|
|
1311
1320
|
});
|
|
1312
1321
|
closeMenuRef.current = closeMenu;
|
|
1313
|
-
const handleCloseMenu = (
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1322
|
+
const handleCloseMenu = useCallback7(
|
|
1323
|
+
(evt, reason) => {
|
|
1324
|
+
navigatingWithKeyboard.current = true;
|
|
1325
|
+
closeMenu();
|
|
1326
|
+
if (reason === "tab-away") {
|
|
1327
|
+
onClose({
|
|
1328
|
+
event: evt,
|
|
1329
|
+
type: "tab-away"
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
},
|
|
1333
|
+
[closeMenu, onClose]
|
|
1334
|
+
);
|
|
1317
1335
|
const handleHighlightMenuItem = () => {
|
|
1318
1336
|
};
|
|
1319
1337
|
const lastMenu = openMenus.length - 1;
|
|
@@ -1534,8 +1552,11 @@ var showContextMenu = (e, menuDescriptors, handleContextMenuAction, {
|
|
|
1534
1552
|
const handleClose = (reason) => {
|
|
1535
1553
|
var _a;
|
|
1536
1554
|
if (reasonIsMenuAction(reason)) {
|
|
1555
|
+
if ((reason == null ? void 0 : reason.closedBy) === "popup-service") {
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1537
1558
|
handleContextMenuAction(reason);
|
|
1538
|
-
PopupService.hidePopup();
|
|
1559
|
+
PopupService.hidePopup(reason);
|
|
1539
1560
|
}
|
|
1540
1561
|
(_a = contextMenuProps == null ? void 0 : contextMenuProps.onClose) == null ? void 0 : _a.call(contextMenuProps, reason);
|
|
1541
1562
|
};
|
|
@@ -1566,30 +1587,37 @@ import {
|
|
|
1566
1587
|
} from "react";
|
|
1567
1588
|
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1568
1589
|
var classBase4 = "vuuPopupMenu";
|
|
1569
|
-
var getPosition2 = (element) => {
|
|
1570
|
-
if (element) {
|
|
1571
|
-
const { bottom, left } = element.getBoundingClientRect();
|
|
1572
|
-
return { x: left, y: bottom + 6 };
|
|
1573
|
-
}
|
|
1574
|
-
};
|
|
1575
1590
|
var PopupMenu = ({
|
|
1591
|
+
anchorElement,
|
|
1576
1592
|
className,
|
|
1577
1593
|
label,
|
|
1578
1594
|
icon = label ? "chevron-down" : "more-vert",
|
|
1579
1595
|
id: idProp,
|
|
1580
1596
|
menuActionHandler,
|
|
1581
1597
|
menuBuilder,
|
|
1598
|
+
menuClassName,
|
|
1582
1599
|
menuLocation = "header",
|
|
1583
1600
|
menuOptions,
|
|
1584
1601
|
onMenuClose,
|
|
1602
|
+
onMenuOpen,
|
|
1603
|
+
popupPlacement = "below-right",
|
|
1585
1604
|
tabIndex = 0,
|
|
1586
1605
|
...htmlAttributes
|
|
1587
1606
|
}) => {
|
|
1588
1607
|
const rootRef = useRef8(null);
|
|
1589
1608
|
const suppressShowMenuRef = useRef8(false);
|
|
1590
|
-
const [menuOpen,
|
|
1609
|
+
const [menuOpen, _setMenuOpen] = useState6(false);
|
|
1591
1610
|
const id = useId3(idProp);
|
|
1592
1611
|
const [showContextMenu2] = useContextMenu(menuBuilder, menuActionHandler);
|
|
1612
|
+
const setMenuOpen = useCallback10(
|
|
1613
|
+
(isOpen) => {
|
|
1614
|
+
_setMenuOpen(isOpen);
|
|
1615
|
+
if (isOpen) {
|
|
1616
|
+
onMenuOpen == null ? void 0 : onMenuOpen();
|
|
1617
|
+
}
|
|
1618
|
+
},
|
|
1619
|
+
[onMenuOpen]
|
|
1620
|
+
);
|
|
1593
1621
|
const handleOpenMenu = useCallback10((el) => {
|
|
1594
1622
|
console.log(`menu Open `, {
|
|
1595
1623
|
el
|
|
@@ -1597,47 +1625,67 @@ var PopupMenu = ({
|
|
|
1597
1625
|
}, []);
|
|
1598
1626
|
const handleMenuClose = useCallback10(
|
|
1599
1627
|
(reason) => {
|
|
1628
|
+
console.log("onClose");
|
|
1600
1629
|
setMenuOpen(false);
|
|
1601
1630
|
if (reasonIsClickAway(reason)) {
|
|
1602
1631
|
const target = reason.mouseEvt.target;
|
|
1603
1632
|
if (target === rootRef.current) {
|
|
1604
1633
|
suppressShowMenuRef.current = true;
|
|
1605
1634
|
}
|
|
1635
|
+
onMenuClose == null ? void 0 : onMenuClose(reason);
|
|
1606
1636
|
} else {
|
|
1607
1637
|
requestAnimationFrame(() => {
|
|
1608
1638
|
var _a;
|
|
1609
1639
|
onMenuClose == null ? void 0 : onMenuClose(reason);
|
|
1610
|
-
if (tabIndex !== -1) {
|
|
1640
|
+
if (tabIndex !== -1 && (reason == null ? void 0 : reason.type) !== "tab-away") {
|
|
1611
1641
|
(_a = rootRef.current) == null ? void 0 : _a.focus();
|
|
1612
1642
|
}
|
|
1613
1643
|
});
|
|
1614
1644
|
}
|
|
1615
1645
|
},
|
|
1616
|
-
[onMenuClose, tabIndex]
|
|
1646
|
+
[onMenuClose, setMenuOpen, tabIndex]
|
|
1617
1647
|
);
|
|
1618
1648
|
const showMenu = useCallback10(
|
|
1619
1649
|
(e) => {
|
|
1650
|
+
var _a;
|
|
1620
1651
|
if (suppressShowMenuRef.current) {
|
|
1621
1652
|
suppressShowMenuRef.current = false;
|
|
1622
1653
|
} else {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1654
|
+
const anchorEl = (_a = anchorElement == null ? void 0 : anchorElement.current) != null ? _a : rootRef.current;
|
|
1655
|
+
if (anchorEl) {
|
|
1656
|
+
const {
|
|
1657
|
+
left: x,
|
|
1658
|
+
top: y,
|
|
1659
|
+
width
|
|
1660
|
+
} = getPositionRelativeToAnchor(anchorEl, popupPlacement, 0, 0);
|
|
1661
|
+
setMenuOpen(true);
|
|
1662
|
+
showContextMenu2(e, menuLocation, {
|
|
1663
|
+
ContextMenuProps: {
|
|
1664
|
+
className: menuClassName,
|
|
1665
|
+
id: `${id}-menu`,
|
|
1666
|
+
onClose: handleMenuClose,
|
|
1667
|
+
openMenu: handleOpenMenu,
|
|
1668
|
+
position: {
|
|
1669
|
+
x,
|
|
1670
|
+
y
|
|
1671
|
+
},
|
|
1672
|
+
style: { width: width ? width - 2 : void 0 }
|
|
1673
|
+
},
|
|
1674
|
+
...menuOptions
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1633
1677
|
}
|
|
1634
1678
|
},
|
|
1635
1679
|
[
|
|
1680
|
+
anchorElement,
|
|
1636
1681
|
handleMenuClose,
|
|
1637
1682
|
handleOpenMenu,
|
|
1638
1683
|
id,
|
|
1684
|
+
menuClassName,
|
|
1639
1685
|
menuLocation,
|
|
1640
1686
|
menuOptions,
|
|
1687
|
+
popupPlacement,
|
|
1688
|
+
setMenuOpen,
|
|
1641
1689
|
showContextMenu2
|
|
1642
1690
|
]
|
|
1643
1691
|
);
|
|
@@ -1645,7 +1693,7 @@ var PopupMenu = ({
|
|
|
1645
1693
|
Button2,
|
|
1646
1694
|
{
|
|
1647
1695
|
...htmlAttributes,
|
|
1648
|
-
"aria-controls": `${id}-menu
|
|
1696
|
+
"aria-controls": menuOpen ? `${id}-menu` : void 0,
|
|
1649
1697
|
"aria-expanded": menuOpen,
|
|
1650
1698
|
"aria-haspopup": "menu",
|
|
1651
1699
|
className: cx7(classBase4, className, {
|
|
@@ -1691,7 +1739,7 @@ var Prompt = ({
|
|
|
1691
1739
|
offsetTop = 0,
|
|
1692
1740
|
placement = "below"
|
|
1693
1741
|
} = PopupProps;
|
|
1694
|
-
const [themeClass,
|
|
1742
|
+
const [themeClass, _, dataMode] = useThemeAttributes4();
|
|
1695
1743
|
const { position } = useAnchoredPosition({
|
|
1696
1744
|
anchorElement,
|
|
1697
1745
|
offsetLeft,
|