@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/cjs/index.js
CHANGED
|
@@ -273,7 +273,13 @@ var PopupService = class _PopupService {
|
|
|
273
273
|
_PopupService.escapeKeyListener,
|
|
274
274
|
true
|
|
275
275
|
);
|
|
276
|
-
(_a = _PopupService == null ? void 0 : _PopupService.onClose) == null ? void 0 : _a.call(
|
|
276
|
+
(_a = _PopupService == null ? void 0 : _PopupService.onClose) == null ? void 0 : _a.call(
|
|
277
|
+
_PopupService,
|
|
278
|
+
reason ? {
|
|
279
|
+
...reason,
|
|
280
|
+
closedBy: "popup-service"
|
|
281
|
+
} : void 0
|
|
282
|
+
);
|
|
277
283
|
}
|
|
278
284
|
static keepWithinThePage(el, right = "auto") {
|
|
279
285
|
const target = el.querySelector(".vuuPopupContainer > *");
|
|
@@ -334,8 +340,11 @@ var import_clsx4 = __toESM(require("clsx"));
|
|
|
334
340
|
|
|
335
341
|
// src/popup/useAnchoredPosition.ts
|
|
336
342
|
var import_react2 = require("react");
|
|
343
|
+
|
|
344
|
+
// src/popup/getPositionRelativeToAnchor.ts
|
|
337
345
|
var getPositionRelativeToAnchor = (anchorElement, placement, offsetLeft, offsetTop, minWidth, dimensions) => {
|
|
338
346
|
const { bottom, height, left, right, top, width } = anchorElement.getBoundingClientRect();
|
|
347
|
+
console.log({ top });
|
|
339
348
|
switch (placement) {
|
|
340
349
|
case "below":
|
|
341
350
|
return { left: left + offsetLeft, top: bottom + offsetTop };
|
|
@@ -368,10 +377,12 @@ var getPositionRelativeToAnchor = (anchorElement, placement, offsetLeft, offsetT
|
|
|
368
377
|
}
|
|
369
378
|
default:
|
|
370
379
|
throw Error(
|
|
371
|
-
|
|
380
|
+
`Popup getPositionRelativeToAnchor non-supported placement value ${placement}`
|
|
372
381
|
);
|
|
373
382
|
}
|
|
374
383
|
};
|
|
384
|
+
|
|
385
|
+
// src/popup/useAnchoredPosition.ts
|
|
375
386
|
var useAnchoredPosition = ({
|
|
376
387
|
anchorElement,
|
|
377
388
|
minWidth,
|
|
@@ -466,7 +477,7 @@ var Dialog = ({
|
|
|
466
477
|
} = PopupProps;
|
|
467
478
|
const rootRef = (0, import_react3.useRef)(null);
|
|
468
479
|
const portalRef = (0, import_react3.useRef)(null);
|
|
469
|
-
const [themeClass,
|
|
480
|
+
const [themeClass, _, dataMode] = (0, import_vuu_utils.useThemeAttributes)();
|
|
470
481
|
const { position } = useAnchoredPosition({
|
|
471
482
|
anchorElement,
|
|
472
483
|
offsetLeft,
|
|
@@ -810,13 +821,13 @@ var useKeyboardNavigation = ({
|
|
|
810
821
|
onOpenMenu == null ? void 0 : onOpenMenu(menuItemEl, true);
|
|
811
822
|
}
|
|
812
823
|
} else if (e.key === "ArrowLeft" && !isRoot(e.target)) {
|
|
813
|
-
onCloseMenu(
|
|
824
|
+
onCloseMenu(e, "close-child-menu");
|
|
814
825
|
} else if (e.key === "Enter") {
|
|
815
826
|
e.preventDefault();
|
|
816
827
|
e.stopPropagation();
|
|
817
828
|
onActivate && onActivate(highlightedIndex);
|
|
818
829
|
} else if (e.key === "Tab") {
|
|
819
|
-
onCloseMenu(-
|
|
830
|
+
onCloseMenu(e, "tab-away");
|
|
820
831
|
}
|
|
821
832
|
},
|
|
822
833
|
[
|
|
@@ -1323,8 +1334,6 @@ var ContextMenu = ({
|
|
|
1323
1334
|
style,
|
|
1324
1335
|
...menuListProps
|
|
1325
1336
|
}) => {
|
|
1326
|
-
const closeHandlerRef = (0, import_react10.useRef)(onClose);
|
|
1327
|
-
closeHandlerRef.current = onClose;
|
|
1328
1337
|
const id = (0, import_vuu_utils5.useId)(idProp);
|
|
1329
1338
|
const closeMenuRef = (0, import_react10.useRef)(noop);
|
|
1330
1339
|
const [menus, actions] = useItemsWithIdsNext(childrenProp, id);
|
|
@@ -1359,10 +1368,19 @@ var ContextMenu = ({
|
|
|
1359
1368
|
position
|
|
1360
1369
|
});
|
|
1361
1370
|
closeMenuRef.current = closeMenu;
|
|
1362
|
-
const handleCloseMenu = ()
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1371
|
+
const handleCloseMenu = (0, import_react10.useCallback)(
|
|
1372
|
+
(evt, reason) => {
|
|
1373
|
+
navigatingWithKeyboard.current = true;
|
|
1374
|
+
closeMenu();
|
|
1375
|
+
if (reason === "tab-away") {
|
|
1376
|
+
onClose({
|
|
1377
|
+
event: evt,
|
|
1378
|
+
type: "tab-away"
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
},
|
|
1382
|
+
[closeMenu, onClose]
|
|
1383
|
+
);
|
|
1366
1384
|
const handleHighlightMenuItem = () => {
|
|
1367
1385
|
};
|
|
1368
1386
|
const lastMenu = openMenus.length - 1;
|
|
@@ -1580,8 +1598,11 @@ var showContextMenu = (e, menuDescriptors, handleContextMenuAction, {
|
|
|
1580
1598
|
const handleClose = (reason) => {
|
|
1581
1599
|
var _a;
|
|
1582
1600
|
if (reasonIsMenuAction(reason)) {
|
|
1601
|
+
if ((reason == null ? void 0 : reason.closedBy) === "popup-service") {
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1583
1604
|
handleContextMenuAction(reason);
|
|
1584
|
-
PopupService.hidePopup();
|
|
1605
|
+
PopupService.hidePopup(reason);
|
|
1585
1606
|
}
|
|
1586
1607
|
(_a = contextMenuProps == null ? void 0 : contextMenuProps.onClose) == null ? void 0 : _a.call(contextMenuProps, reason);
|
|
1587
1608
|
};
|
|
@@ -1608,30 +1629,37 @@ var import_clsx7 = __toESM(require("clsx"));
|
|
|
1608
1629
|
var import_react14 = require("react");
|
|
1609
1630
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1610
1631
|
var classBase4 = "vuuPopupMenu";
|
|
1611
|
-
var getPosition2 = (element) => {
|
|
1612
|
-
if (element) {
|
|
1613
|
-
const { bottom, left } = element.getBoundingClientRect();
|
|
1614
|
-
return { x: left, y: bottom + 6 };
|
|
1615
|
-
}
|
|
1616
|
-
};
|
|
1617
1632
|
var PopupMenu = ({
|
|
1633
|
+
anchorElement,
|
|
1618
1634
|
className,
|
|
1619
1635
|
label,
|
|
1620
1636
|
icon = label ? "chevron-down" : "more-vert",
|
|
1621
1637
|
id: idProp,
|
|
1622
1638
|
menuActionHandler,
|
|
1623
1639
|
menuBuilder,
|
|
1640
|
+
menuClassName,
|
|
1624
1641
|
menuLocation = "header",
|
|
1625
1642
|
menuOptions,
|
|
1626
1643
|
onMenuClose,
|
|
1644
|
+
onMenuOpen,
|
|
1645
|
+
popupPlacement = "below-right",
|
|
1627
1646
|
tabIndex = 0,
|
|
1628
1647
|
...htmlAttributes
|
|
1629
1648
|
}) => {
|
|
1630
1649
|
const rootRef = (0, import_react14.useRef)(null);
|
|
1631
1650
|
const suppressShowMenuRef = (0, import_react14.useRef)(false);
|
|
1632
|
-
const [menuOpen,
|
|
1651
|
+
const [menuOpen, _setMenuOpen] = (0, import_react14.useState)(false);
|
|
1633
1652
|
const id = (0, import_vuu_utils7.useId)(idProp);
|
|
1634
1653
|
const [showContextMenu2] = useContextMenu(menuBuilder, menuActionHandler);
|
|
1654
|
+
const setMenuOpen = (0, import_react14.useCallback)(
|
|
1655
|
+
(isOpen) => {
|
|
1656
|
+
_setMenuOpen(isOpen);
|
|
1657
|
+
if (isOpen) {
|
|
1658
|
+
onMenuOpen == null ? void 0 : onMenuOpen();
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
[onMenuOpen]
|
|
1662
|
+
);
|
|
1635
1663
|
const handleOpenMenu = (0, import_react14.useCallback)((el) => {
|
|
1636
1664
|
console.log(`menu Open `, {
|
|
1637
1665
|
el
|
|
@@ -1639,47 +1667,67 @@ var PopupMenu = ({
|
|
|
1639
1667
|
}, []);
|
|
1640
1668
|
const handleMenuClose = (0, import_react14.useCallback)(
|
|
1641
1669
|
(reason) => {
|
|
1670
|
+
console.log("onClose");
|
|
1642
1671
|
setMenuOpen(false);
|
|
1643
1672
|
if (reasonIsClickAway(reason)) {
|
|
1644
1673
|
const target = reason.mouseEvt.target;
|
|
1645
1674
|
if (target === rootRef.current) {
|
|
1646
1675
|
suppressShowMenuRef.current = true;
|
|
1647
1676
|
}
|
|
1677
|
+
onMenuClose == null ? void 0 : onMenuClose(reason);
|
|
1648
1678
|
} else {
|
|
1649
1679
|
requestAnimationFrame(() => {
|
|
1650
1680
|
var _a;
|
|
1651
1681
|
onMenuClose == null ? void 0 : onMenuClose(reason);
|
|
1652
|
-
if (tabIndex !== -1) {
|
|
1682
|
+
if (tabIndex !== -1 && (reason == null ? void 0 : reason.type) !== "tab-away") {
|
|
1653
1683
|
(_a = rootRef.current) == null ? void 0 : _a.focus();
|
|
1654
1684
|
}
|
|
1655
1685
|
});
|
|
1656
1686
|
}
|
|
1657
1687
|
},
|
|
1658
|
-
[onMenuClose, tabIndex]
|
|
1688
|
+
[onMenuClose, setMenuOpen, tabIndex]
|
|
1659
1689
|
);
|
|
1660
1690
|
const showMenu = (0, import_react14.useCallback)(
|
|
1661
1691
|
(e) => {
|
|
1692
|
+
var _a;
|
|
1662
1693
|
if (suppressShowMenuRef.current) {
|
|
1663
1694
|
suppressShowMenuRef.current = false;
|
|
1664
1695
|
} else {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1696
|
+
const anchorEl = (_a = anchorElement == null ? void 0 : anchorElement.current) != null ? _a : rootRef.current;
|
|
1697
|
+
if (anchorEl) {
|
|
1698
|
+
const {
|
|
1699
|
+
left: x,
|
|
1700
|
+
top: y,
|
|
1701
|
+
width
|
|
1702
|
+
} = getPositionRelativeToAnchor(anchorEl, popupPlacement, 0, 0);
|
|
1703
|
+
setMenuOpen(true);
|
|
1704
|
+
showContextMenu2(e, menuLocation, {
|
|
1705
|
+
ContextMenuProps: {
|
|
1706
|
+
className: menuClassName,
|
|
1707
|
+
id: `${id}-menu`,
|
|
1708
|
+
onClose: handleMenuClose,
|
|
1709
|
+
openMenu: handleOpenMenu,
|
|
1710
|
+
position: {
|
|
1711
|
+
x,
|
|
1712
|
+
y
|
|
1713
|
+
},
|
|
1714
|
+
style: { width: width ? width - 2 : void 0 }
|
|
1715
|
+
},
|
|
1716
|
+
...menuOptions
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1675
1719
|
}
|
|
1676
1720
|
},
|
|
1677
1721
|
[
|
|
1722
|
+
anchorElement,
|
|
1678
1723
|
handleMenuClose,
|
|
1679
1724
|
handleOpenMenu,
|
|
1680
1725
|
id,
|
|
1726
|
+
menuClassName,
|
|
1681
1727
|
menuLocation,
|
|
1682
1728
|
menuOptions,
|
|
1729
|
+
popupPlacement,
|
|
1730
|
+
setMenuOpen,
|
|
1683
1731
|
showContextMenu2
|
|
1684
1732
|
]
|
|
1685
1733
|
);
|
|
@@ -1687,7 +1735,7 @@ var PopupMenu = ({
|
|
|
1687
1735
|
import_core2.Button,
|
|
1688
1736
|
{
|
|
1689
1737
|
...htmlAttributes,
|
|
1690
|
-
"aria-controls": `${id}-menu
|
|
1738
|
+
"aria-controls": menuOpen ? `${id}-menu` : void 0,
|
|
1691
1739
|
"aria-expanded": menuOpen,
|
|
1692
1740
|
"aria-haspopup": "menu",
|
|
1693
1741
|
className: (0, import_clsx7.default)(classBase4, className, {
|
|
@@ -1733,7 +1781,7 @@ var Prompt = ({
|
|
|
1733
1781
|
offsetTop = 0,
|
|
1734
1782
|
placement = "below"
|
|
1735
1783
|
} = PopupProps;
|
|
1736
|
-
const [themeClass,
|
|
1784
|
+
const [themeClass, _, dataMode] = (0, import_vuu_utils8.useThemeAttributes)();
|
|
1737
1785
|
const { position } = useAnchoredPosition({
|
|
1738
1786
|
anchorElement,
|
|
1739
1787
|
offsetLeft,
|