@floegence/floe-webapp-core 0.39.4 → 0.39.5

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.
@@ -4,7 +4,7 @@ export { Input, Textarea, NumberInput, AffixInput, type InputProps, type InputSi
4
4
  export { Dialog, ConfirmDialog, type DialogProps, type ConfirmDialogProps } from './Dialog';
5
5
  export { FloatingWindow, type FloatingWindowProps } from './FloatingWindow';
6
6
  export { createFloatingPresence, type FloatingPresence, type FloatingPresenceOptions, type FloatingPresenceState, } from './floatingPresence';
7
- export { MENU_ITEM_SELECTOR, focusMenuItem, getMenuItems, handleMenuKeyboardNavigation, moveMenuFocus, type MenuDismissReason, type MenuFocusMode, type MenuKeyboardNavigationOptions, } from './menuUtils';
7
+ export { MENU_ITEM_SELECTOR, focusMenuItem, getMenuItems, handleMenuKeyboardNavigation, moveMenuFocus, type MenuDismissReason, type MenuFocusMode, type MenuItemNavigationOptions, type MenuKeyboardNavigationOptions, } from './menuUtils';
8
8
  export { resolveFloatingWindowViewport, type FloatingWindowRect, type FloatingWindowViewport, type FloatingWindowViewportInsets, } from './floatingWindowGeometry';
9
9
  export { Dropdown, Select, type DropdownProps, type DropdownItem, type SelectProps, } from './Dropdown';
10
10
  export { SurfaceFloatingLayer, type SurfaceFloatingLayerPosition, type SurfaceFloatingLayerProps, type SurfaceFloatingLayerSize, } from './SurfaceFloatingLayer';
@@ -10,8 +10,13 @@ export type MenuBoundaryRect = Readonly<{
10
10
  }>;
11
11
  export type MenuFocusMode = 'first' | 'last' | 'selected';
12
12
  export type MenuDismissReason = 'escape' | 'tab' | 'shift-tab';
13
- export type MenuKeyboardNavigationOptions = Readonly<{
13
+ export type MenuItemNavigationOptions = Readonly<{
14
+ includeAriaDisabledItems?: boolean;
15
+ }>;
16
+ export type MenuKeyboardNavigationOptions = MenuItemNavigationOptions & Readonly<{
14
17
  onDismiss: (reason: MenuDismissReason) => void;
18
+ onActivate?: (item: HTMLElement) => void;
19
+ preventDefaultOnTab?: boolean;
15
20
  }>;
16
21
  export declare function resolveViewportMenuBoundaryRect(): MenuBoundaryRect;
17
22
  export declare function clampMenuPosition(anchor: Readonly<{
@@ -33,7 +38,7 @@ export declare function calculateSubmenuPosition(parentRect: DOMRect, submenuRec
33
38
  y: number;
34
39
  };
35
40
  export declare function getWrappedMenuItemIndex(length: number, currentIndex: number, delta: 1 | -1): number | null;
36
- export declare function getMenuItems(root: ParentNode | null | undefined): HTMLElement[];
37
- export declare function focusMenuItem(root: ParentNode | null | undefined, mode?: MenuFocusMode): boolean;
38
- export declare function moveMenuFocus(root: ParentNode | null | undefined, current: HTMLElement | null, delta: 1 | -1): boolean;
41
+ export declare function getMenuItems(root: ParentNode | null | undefined, options?: MenuItemNavigationOptions): HTMLElement[];
42
+ export declare function focusMenuItem(root: ParentNode | null | undefined, mode?: MenuFocusMode, options?: MenuItemNavigationOptions): boolean;
43
+ export declare function moveMenuFocus(root: ParentNode | null | undefined, current: HTMLElement | null, delta: 1 | -1, options?: MenuItemNavigationOptions): boolean;
39
44
  export declare function handleMenuKeyboardNavigation(event: KeyboardEvent, options: MenuKeyboardNavigationOptions): boolean;
@@ -1,5 +1,5 @@
1
- const E = 8, h = '[role="menuitem"]:not([disabled]):not([aria-disabled="true"])';
2
- function M() {
1
+ const E = 8, I = '[role="menuitem"]:not([disabled]):not([aria-disabled="true"])';
2
+ function c() {
3
3
  return typeof window > "u" ? {
4
4
  left: 0,
5
5
  top: 0,
@@ -16,97 +16,102 @@ function M() {
16
16
  height: window.innerHeight
17
17
  };
18
18
  }
19
- function f(t) {
20
- return t ?? M();
19
+ function l(t) {
20
+ return t ?? c();
21
21
  }
22
- function w(t, e, r) {
23
- const n = f(r);
24
- let o = t.x, i = t.y;
25
- return o + e.width > n.right - 8 && (o = n.right - e.width - 8), i + e.height > n.bottom - 8 && (i = n.bottom - e.height - 8), {
26
- x: Math.max(n.left + 8, o),
27
- y: Math.max(n.top + 8, i)
22
+ function A(t, e, a) {
23
+ const n = l(a);
24
+ let i = t.x, r = t.y;
25
+ return i + e.width > n.right - 8 && (i = n.right - e.width - 8), r + e.height > n.bottom - 8 && (r = n.bottom - e.height - 8), {
26
+ x: Math.max(n.left + 8, i),
27
+ y: Math.max(n.top + 8, r)
28
28
  };
29
29
  }
30
- function T(t, e, r, n) {
31
- const o = f(n);
32
- let i;
33
- switch (r) {
30
+ function T(t, e, a, n) {
31
+ const i = l(n);
32
+ let r;
33
+ switch (a) {
34
34
  case "center":
35
- i = t.left + t.width / 2 - e.width / 2;
35
+ r = t.left + t.width / 2 - e.width / 2;
36
36
  break;
37
37
  case "end":
38
- i = t.right - e.width;
38
+ r = t.right - e.width;
39
39
  break;
40
40
  default:
41
- i = t.left;
41
+ r = t.left;
42
42
  }
43
- let a = t.bottom + 4;
44
- if (i + e.width > o.right - 8 && (i = o.right - e.width - 8), i = Math.max(o.left + 8, i), a + e.height > o.bottom - 8) {
45
- const s = t.top - o.top - 8, d = o.bottom - t.bottom - 8;
46
- s > d && s >= e.height ? a = t.top - e.height - 4 : a = o.bottom - e.height - 8;
43
+ let o = t.bottom + 4;
44
+ if (r + e.width > i.right - 8 && (r = i.right - e.width - 8), r = Math.max(i.left + 8, r), o + e.height > i.bottom - 8) {
45
+ const f = t.top - i.top - 8, d = i.bottom - t.bottom - 8;
46
+ f > d && f >= e.height ? o = t.top - e.height - 4 : o = i.bottom - e.height - 8;
47
47
  }
48
- return a = Math.max(o.top + 8, a), { x: i, y: a };
48
+ return o = Math.max(i.top + 8, o), { x: r, y: o };
49
49
  }
50
- function A(t, e, r) {
51
- const n = f(r);
52
- let o = t.right, i = t.top;
53
- if (o + e.width > n.right - 8) {
54
- const a = t.left - e.width;
55
- a >= n.left + 8 ? o = a : o = n.right - e.width - 8;
50
+ function m(t, e, a) {
51
+ const n = l(a);
52
+ let i = t.right, r = t.top;
53
+ if (i + e.width > n.right - 8) {
54
+ const o = t.left - e.width;
55
+ o >= n.left + 8 ? i = o : i = n.right - e.width - 8;
56
56
  }
57
- return i + e.height > n.bottom - 8 && (i = n.bottom - e.height - 8), o = Math.max(n.left + 8, o), i = Math.max(n.top + 8, i), { x: o, y: i };
57
+ return r + e.height > n.bottom - 8 && (r = n.bottom - e.height - 8), i = Math.max(n.left + 8, i), r = Math.max(n.top + 8, r), { x: i, y: r };
58
58
  }
59
- function c(t, e, r) {
60
- return t <= 0 ? null : e < 0 ? r > 0 ? 0 : t - 1 : (e + r + t) % t;
59
+ function M(t, e, a) {
60
+ return t <= 0 ? null : e < 0 ? a > 0 ? 0 : t - 1 : (e + a + t) % t;
61
61
  }
62
- function I(t) {
63
- return !t || typeof HTMLElement > "u" ? [] : Array.from(t.querySelectorAll(h)).filter(
64
- (e) => e instanceof HTMLElement
62
+ function u(t, e = {}) {
63
+ if (!t || typeof HTMLElement > "u") return [];
64
+ const a = e.includeAriaDisabledItems ? '[role="menuitem"]:not([disabled])' : I;
65
+ return Array.from(t.querySelectorAll(a)).filter(
66
+ (n) => n instanceof HTMLElement
65
67
  );
66
68
  }
67
- function l(t, e = "first") {
68
- const r = I(t);
69
- if (!r.length) return !1;
70
- let n = r[0];
71
- return e === "last" ? n = r[r.length - 1] : e === "selected" && (n = r.find((o) => o.getAttribute("data-floe-selected") === "true") ?? r[0]), n.focus(), !0;
72
- }
73
- function u(t, e, r) {
74
- const n = I(t);
69
+ function s(t, e = "first", a = {}) {
70
+ const n = u(t, a);
75
71
  if (!n.length) return !1;
76
- const o = e ? n.indexOf(e) : -1, i = c(n.length, o, r);
77
- return i === null ? !1 : (n[i]?.focus(), !0);
72
+ let i = n[0];
73
+ return e === "last" ? i = n[n.length - 1] : e === "selected" && (i = n.find((r) => r.getAttribute("data-floe-selected") === "true") ?? n[0]), i.focus(), !0;
74
+ }
75
+ function h(t, e, a, n = {}) {
76
+ const i = u(t, n);
77
+ if (!i.length) return !1;
78
+ const r = e ? i.indexOf(e) : -1, o = M(i.length, r, a);
79
+ return o === null ? !1 : (i[o]?.focus(), !0);
78
80
  }
79
- function P(t, e) {
80
- const r = typeof HTMLElement < "u" && t.target instanceof HTMLElement ? t.target : null, n = r?.closest('[role="menu"]');
81
+ function w(t, e) {
82
+ const a = typeof HTMLElement < "u" && t.target instanceof HTMLElement ? t.target : null, n = a?.closest('[role="menu"]');
81
83
  if (!n) return !1;
82
- const o = r?.closest(h);
84
+ const i = u(n, e), r = a?.closest('[role="menuitem"]'), o = r && i.includes(r) ? r : null;
83
85
  switch (t.key) {
84
86
  case "ArrowDown":
85
- return t.preventDefault(), u(n, o, 1), !0;
87
+ return t.preventDefault(), h(n, o, 1, e), !0;
86
88
  case "ArrowUp":
87
- return t.preventDefault(), u(n, o, -1), !0;
89
+ return t.preventDefault(), h(n, o, -1, e), !0;
88
90
  case "Home":
89
- return t.preventDefault(), l(n, "first"), !0;
91
+ return t.preventDefault(), s(n, "first", e), !0;
90
92
  case "End":
91
- return t.preventDefault(), l(n, "last"), !0;
93
+ return t.preventDefault(), s(n, "last", e), !0;
94
+ case "Enter":
95
+ case " ":
96
+ return o ? o.getAttribute("aria-disabled") === "true" ? (t.preventDefault(), !0) : e.onActivate ? (t.preventDefault(), e.onActivate(o), !0) : !1 : !1;
92
97
  case "Escape":
93
98
  return t.preventDefault(), t.stopPropagation(), e.onDismiss("escape"), !0;
94
99
  case "Tab":
95
- return e.onDismiss(t.shiftKey ? "shift-tab" : "tab"), !0;
100
+ return e.preventDefaultOnTab && t.preventDefault(), e.onDismiss(t.shiftKey ? "shift-tab" : "tab"), !0;
96
101
  default:
97
102
  return !1;
98
103
  }
99
104
  }
100
105
  export {
101
- h as MENU_ITEM_SELECTOR,
106
+ I as MENU_ITEM_SELECTOR,
102
107
  E as VIEWPORT_MARGIN,
103
108
  T as calculateMenuPosition,
104
- A as calculateSubmenuPosition,
105
- w as clampMenuPosition,
106
- l as focusMenuItem,
107
- I as getMenuItems,
108
- c as getWrappedMenuItemIndex,
109
- P as handleMenuKeyboardNavigation,
110
- u as moveMenuFocus,
111
- M as resolveViewportMenuBoundaryRect
109
+ m as calculateSubmenuPosition,
110
+ A as clampMenuPosition,
111
+ s as focusMenuItem,
112
+ u as getMenuItems,
113
+ M as getWrappedMenuItemIndex,
114
+ w as handleMenuKeyboardNavigation,
115
+ h as moveMenuFocus,
116
+ c as resolveViewportMenuBoundaryRect
112
117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.39.4",
3
+ "version": "0.39.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",