@x-tech-laboratories/x-libs 0.14.0 → 0.14.2

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.
@@ -2,8 +2,8 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  // Menus and popovers on the native popover: closed by Escape or a click elsewhere, and here also by scrolling or leaving the window.
3
3
  import { Fragment, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
4
4
  import { item_after_key, item_starting_with, on_screen_position } from "../menus.js";
5
- // Shows the element as a popover while it is rendered, calling the latest on_close once it closes for any reason.
6
- function use_popover(on_close, opener) {
5
+ // Shows the element as a popover while it is rendered, calling the latest on_close once it closes for any reason; a manual one closes itself on a press outside it.
6
+ function use_popover(on_close, opener, manual = false) {
7
7
  const element = useRef(null);
8
8
  const close = useRef(on_close);
9
9
  close.current = on_close;
@@ -14,15 +14,18 @@ function use_popover(on_close, opener) {
14
14
  popover.hidePopover(); };
15
15
  const toggled = (event) => { if (event.newState === "closed")
16
16
  close.current(); };
17
- const outside_scroll = (event) => { if (!popover.contains(event.target))
17
+ const outside = (event) => { if (!popover.contains(event.target))
18
18
  hide(); };
19
19
  popover.addEventListener("toggle", toggled);
20
20
  window.addEventListener("blur", hide);
21
- window.addEventListener("scroll", outside_scroll, true);
21
+ window.addEventListener("scroll", outside, true);
22
+ if (manual)
23
+ window.addEventListener("pointerdown", outside, true);
22
24
  return () => {
23
25
  popover.removeEventListener("toggle", toggled);
24
26
  window.removeEventListener("blur", hide);
25
- window.removeEventListener("scroll", outside_scroll, true);
27
+ window.removeEventListener("scroll", outside, true);
28
+ window.removeEventListener("pointerdown", outside, true);
26
29
  };
27
30
  }, []);
28
31
  const return_focus = () => {
@@ -126,14 +129,15 @@ export function MenuList({ items, on_close }) {
126
129
  item.run();
127
130
  }, children: [_jsx("span", { className: "menu-label", children: item.label }), item.hint && _jsx("span", { className: "menu-hint", children: item.hint })] })] }, item.label))) }));
128
131
  }
132
+ // Manual, since on Linux the menu opens on the button's press and an auto popover would close on its release.
129
133
  export function ContextMenu({ x, y, items, on_close, label }) {
130
- const { element: menu, dismiss, return_focus } = use_popover(on_close);
134
+ const { element: menu, dismiss, return_focus } = use_popover(on_close, undefined, true);
131
135
  const keys = use_menu_keys(menu, dismiss, true);
132
136
  useLayoutEffect(() => {
133
137
  show_at(menu.current, x, y);
134
138
  menu.current.querySelector(item_selector)?.focus();
135
139
  }, [x, y]);
136
- return (_jsx("div", { ref: menu, popover: "auto", className: "menu", role: "menu", "aria-label": label, tabIndex: -1, onKeyDown: keys, children: _jsx(MenuList, { items: items, on_close: () => { return_focus(); on_close(); } }) }));
140
+ return (_jsx("div", { ref: menu, popover: "manual", className: "menu", role: "menu", "aria-label": label, tabIndex: -1, onKeyDown: keys, children: _jsx(MenuList, { items: items, on_close: () => { return_focus(); on_close(); } }) }));
137
141
  }
138
142
  let open_menu = null;
139
143
  let next_menu_id = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-tech-laboratories/x-libs",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {