@funstack/ui 0.1.0-alpha.7 → 0.1.0-alpha.9

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.
Files changed (76) hide show
  1. package/dist/combobox/combobox-popup.mjs +1 -1
  2. package/dist/combobox/combobox-popup.mjs.map +1 -1
  3. package/dist/csp/csp-provider.d.mts +25 -0
  4. package/dist/csp/csp-provider.d.mts.map +1 -0
  5. package/dist/csp/csp-provider.mjs +24 -0
  6. package/dist/csp/csp-provider.mjs.map +1 -0
  7. package/dist/csp/index.d.mts +3 -0
  8. package/dist/csp/index.mjs +3 -0
  9. package/dist/csp/style-hashes.d.mts +19 -0
  10. package/dist/csp/style-hashes.d.mts.map +1 -0
  11. package/dist/csp/style-hashes.mjs +21 -0
  12. package/dist/csp/style-hashes.mjs.map +1 -0
  13. package/dist/index.d.mts +7 -3
  14. package/dist/index.mjs +3 -1
  15. package/dist/internal/anchor-position.d.mts +11 -3
  16. package/dist/internal/anchor-position.d.mts.map +1 -1
  17. package/dist/internal/anchor-position.mjs +180 -6
  18. package/dist/internal/anchor-position.mjs.map +1 -1
  19. package/dist/internal/csp-context.mjs +8 -0
  20. package/dist/internal/csp-context.mjs.map +1 -0
  21. package/dist/internal/tooltip-warm.mjs +29 -0
  22. package/dist/internal/tooltip-warm.mjs.map +1 -0
  23. package/dist/internal/use-popover-popup.mjs +22 -4
  24. package/dist/internal/use-popover-popup.mjs.map +1 -1
  25. package/dist/internal/use-resolved-placement.mjs +146 -0
  26. package/dist/internal/use-resolved-placement.mjs.map +1 -0
  27. package/dist/menu/index.d.mts +5 -1
  28. package/dist/menu/index.d.mts.map +1 -1
  29. package/dist/menu/index.mjs +5 -1
  30. package/dist/menu/index.mjs.map +1 -1
  31. package/dist/menu/menu-context-trigger.d.mts +46 -0
  32. package/dist/menu/menu-context-trigger.d.mts.map +1 -0
  33. package/dist/menu/menu-context-trigger.mjs +405 -0
  34. package/dist/menu/menu-context-trigger.mjs.map +1 -0
  35. package/dist/menu/menu-context.mjs +44 -1
  36. package/dist/menu/menu-context.mjs.map +1 -1
  37. package/dist/menu/menu-dom.mjs +42 -2
  38. package/dist/menu/menu-dom.mjs.map +1 -1
  39. package/dist/menu/menu-popup.d.mts +36 -8
  40. package/dist/menu/menu-popup.d.mts.map +1 -1
  41. package/dist/menu/menu-popup.mjs +214 -22
  42. package/dist/menu/menu-popup.mjs.map +1 -1
  43. package/dist/menu/menu-root.d.mts +5 -0
  44. package/dist/menu/menu-root.d.mts.map +1 -1
  45. package/dist/menu/menu-root.mjs +56 -6
  46. package/dist/menu/menu-root.mjs.map +1 -1
  47. package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
  48. package/dist/menu/menu-submenu-trigger.mjs +27 -11
  49. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  50. package/dist/popover/popover-popup.d.mts +21 -7
  51. package/dist/popover/popover-popup.d.mts.map +1 -1
  52. package/dist/popover/popover-popup.mjs +16 -6
  53. package/dist/popover/popover-popup.mjs.map +1 -1
  54. package/dist/tooltip/index.d.mts +8 -5
  55. package/dist/tooltip/index.d.mts.map +1 -1
  56. package/dist/tooltip/index.mjs +6 -3
  57. package/dist/tooltip/index.mjs.map +1 -1
  58. package/dist/tooltip/tooltip-arrow.d.mts +30 -0
  59. package/dist/tooltip/tooltip-arrow.d.mts.map +1 -0
  60. package/dist/tooltip/tooltip-arrow.mjs +45 -0
  61. package/dist/tooltip/tooltip-arrow.mjs.map +1 -0
  62. package/dist/tooltip/tooltip-context.d.mts +7 -0
  63. package/dist/tooltip/tooltip-context.d.mts.map +1 -1
  64. package/dist/tooltip/tooltip-context.mjs +2 -1
  65. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  66. package/dist/tooltip/tooltip-popup.d.mts +21 -6
  67. package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
  68. package/dist/tooltip/tooltip-popup.mjs +28 -6
  69. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  70. package/dist/tooltip/tooltip-trigger.d.mts +9 -2
  71. package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
  72. package/dist/tooltip/tooltip-trigger.mjs +21 -5
  73. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  74. package/dist/tooltip/use-tooltip-interaction.mjs +26 -2
  75. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  76. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"menu-dom.mjs","names":[],"sources":["../../src/menu/menu-dom.ts"],"sourcesContent":["\"use client\";\n// DOM helpers shared by the Menu parts. Items are read from the DOM when they are needed (a key\n// press, an open), never registered (design/components/menu.md 13 and 14).\n\nconst ITEM_SELECTOR = '[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]';\n\n/** The items of `popup` in DOM order, without the items of its submenus. Disabled included. */\nexport function menuItems(popup: Element): HTMLElement[] {\n return Array.from(popup.querySelectorAll<HTMLElement>(ITEM_SELECTOR)).filter(\n (item) => item.closest('[role=\"menu\"]') === popup,\n );\n}\n\nexport function isMenuItem(element: Element, popup: Element): boolean {\n return element.matches(ITEM_SELECTOR) && element.closest('[role=\"menu\"]') === popup;\n}\n\n/**\n * Disabled by its `disabled` prop. Keys on `data-disabled`, not `aria-disabled`: an item is also\n * `aria-disabled` while its own action is pending (#81). A pending item is an ordinary item for\n * navigation; only the open focus (`edgeItem`) skips items with the `disabled` prop. Arrow keys,\n * Home / End and typeahead skip nothing.\n */\nexport function isDisabledItem(item: Element): boolean {\n return item.hasAttribute(\"data-disabled\");\n}\n\n/** The first (or last) enabled item; the first (or last) item if all are disabled. */\nexport function edgeItem(popup: Element, which: \"first\" | \"last\"): HTMLElement | null {\n const items = menuItems(popup);\n const ordered = which === \"first\" ? items : [...items].reverse();\n return ordered.find((item) => !isDisabledItem(item)) ?? ordered[0] ?? null;\n}\n\n/** Keyboard focus: the ring shows even where the engine's heuristic would not (as Tabs). */\nexport function focusItem(item: HTMLElement): void {\n item.focus({ focusVisible: true } as FocusOptions);\n}\n\n/** The text typeahead matches: the item's `label` prop, else its text content. */\nexport function typeaheadText(item: Element): string {\n return (item.getAttribute(\"data-typeahead\") ?? item.textContent ?? \"\").trim().toLowerCase();\n}\n\nexport function isRtl(element: Element): boolean {\n return getComputedStyle(element).direction === \"rtl\";\n}\n\nexport function hasModifier(event: { altKey: boolean; ctrlKey: boolean; metaKey: boolean }) {\n return event.altKey || event.ctrlKey || event.metaKey;\n}\n"],"mappings":";;AAIA,MAAM,gBAAgB;;AAGtB,SAAgB,UAAU,OAA+B;CACvD,OAAO,MAAM,KAAK,MAAM,iBAA8B,aAAa,CAAC,CAAC,CAAC,QACnE,SAAS,KAAK,QAAQ,iBAAe,MAAM,KAC9C;AACF;AAEA,SAAgB,WAAW,SAAkB,OAAyB;CACpE,OAAO,QAAQ,QAAQ,aAAa,KAAK,QAAQ,QAAQ,iBAAe,MAAM;AAChF;;;;;;;AAQA,SAAgB,eAAe,MAAwB;CACrD,OAAO,KAAK,aAAa,eAAe;AAC1C;;AAGA,SAAgB,SAAS,OAAgB,OAA6C;CACpF,MAAM,QAAQ,UAAU,KAAK;CAC7B,MAAM,UAAU,UAAU,UAAU,QAAQ,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ;CAC/D,OAAO,QAAQ,MAAM,SAAS,CAAC,eAAe,IAAI,CAAC,KAAK,QAAQ,MAAM;AACxE;;AAGA,SAAgB,UAAU,MAAyB;CACjD,KAAK,MAAM,EAAE,cAAc,KAAK,CAAiB;AACnD;;AAGA,SAAgB,cAAc,MAAuB;CACnD,QAAQ,KAAK,aAAa,gBAAgB,KAAK,KAAK,eAAe,GAAA,CAAI,KAAK,CAAC,CAAC,YAAY;AAC5F;AAEA,SAAgB,MAAM,SAA2B;CAC/C,OAAO,iBAAiB,OAAO,CAAC,CAAC,cAAc;AACjD;AAEA,SAAgB,YAAY,OAAgE;CAC1F,OAAO,MAAM,UAAU,MAAM,WAAW,MAAM;AAChD"}
1
+ {"version":3,"file":"menu-dom.mjs","names":[],"sources":["../../src/menu/menu-dom.ts"],"sourcesContent":["\"use client\";\n// DOM helpers shared by the Menu parts. Items are read from the DOM when they are needed (a key\n// press, an open), never registered (design/components/menu.md 13 and 14).\n\nexport const ITEM_SELECTOR = '[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]';\n\n/** The items of `popup` in DOM order, without the items of its submenus. Disabled included. */\nexport function menuItems(popup: Element): HTMLElement[] {\n return Array.from(popup.querySelectorAll<HTMLElement>(ITEM_SELECTOR)).filter(\n (item) => item.closest('[role=\"menu\"]') === popup,\n );\n}\n\nexport function isMenuItem(element: Element, popup: Element): boolean {\n return element.matches(ITEM_SELECTOR) && element.closest('[role=\"menu\"]') === popup;\n}\n\n/**\n * Disabled by its `disabled` prop. Keys on `data-disabled`, not `aria-disabled`: an item is also\n * `aria-disabled` while its own action is pending (#81). A pending item is an ordinary item for\n * navigation; only the open focus (`edgeItem`) skips items with the `disabled` prop. Arrow keys,\n * Home / End and typeahead skip nothing.\n */\nexport function isDisabledItem(item: Element): boolean {\n return item.hasAttribute(\"data-disabled\");\n}\n\n/** The first (or last) enabled item; the first (or last) item if all are disabled. */\nexport function edgeItem(popup: Element, which: \"first\" | \"last\"): HTMLElement | null {\n const items = menuItems(popup);\n const ordered = which === \"first\" ? items : [...items].reverse();\n return ordered.find((item) => !isDisabledItem(item)) ?? ordered[0] ?? null;\n}\n\n/** Keyboard focus: the ring shows even where the engine's heuristic would not (as Tabs). */\nexport function focusItem(item: HTMLElement): void {\n item.focus({ focusVisible: true } as FocusOptions);\n}\n\n/** The text typeahead matches: the item's `label` prop, else its text content. */\nexport function typeaheadText(item: Element): string {\n return (item.getAttribute(\"data-typeahead\") ?? item.textContent ?? \"\").trim().toLowerCase();\n}\n\nexport function isRtl(element: Element): boolean {\n return getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * `setPointerCapture`, which throws `NotFoundError` for a pointer the engine no longer tracks\n * (context-menu.md 2.1). A silent no-op when no button is down. `true` when the capture was\n * taken (the press-drag-release gesture runs only then, 2.6).\n */\nexport function capturePointer(element: Element | null, pointerId: number | undefined): boolean {\n if (element === null || pointerId === undefined) return false;\n try {\n element.setPointerCapture(pointerId);\n return true;\n } catch {\n // Not an active pointer (a synthetic event, a released button): nothing to capture.\n return false;\n }\n}\n\n/** `<input>` types that take no text: their `contextmenu` is not an editing one. */\nconst NON_TEXT_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"hidden\",\n]);\n\n/**\n * An editable target keeps the browser's own context menu by default (context-menu.md 2.3): a\n * text-taking `<input>`, a `<textarea>`, or editable content.\n */\nexport function isEditableTarget(target: EventTarget | null): boolean {\n if (target === null || (target as Node).nodeType !== 1) return false;\n const element = target as HTMLElement;\n if (element.closest(\"textarea\") !== null) return true;\n const input = element.closest(\"input\");\n if (input !== null && !NON_TEXT_INPUTS.has(input.type)) return true;\n // `isContentEditable` where implemented (every engine; not jsdom).\n if (typeof element.isContentEditable === \"boolean\") return element.isContentEditable;\n return element.closest('[contenteditable]:not([contenteditable=\"false\"])') !== null;\n}\n\nexport function hasModifier(event: { altKey: boolean; ctrlKey: boolean; metaKey: boolean }) {\n return event.altKey || event.ctrlKey || event.metaKey;\n}\n"],"mappings":";;AAIA,MAAa,gBAAgB;;AAG7B,SAAgB,UAAU,OAA+B;CACvD,OAAO,MAAM,KAAK,MAAM,iBAA8B,aAAa,CAAC,CAAC,CAAC,QACnE,SAAS,KAAK,QAAQ,iBAAe,MAAM,KAC9C;AACF;AAEA,SAAgB,WAAW,SAAkB,OAAyB;CACpE,OAAO,QAAQ,QAAA,4EAAqB,KAAK,QAAQ,QAAQ,iBAAe,MAAM;AAChF;;;;;;;AAQA,SAAgB,eAAe,MAAwB;CACrD,OAAO,KAAK,aAAa,eAAe;AAC1C;;AAGA,SAAgB,SAAS,OAAgB,OAA6C;CACpF,MAAM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lign, AnchorSide } from "../internal/anchor-position.mjs";
3
3
  import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
4
4
  //#region src/menu/menu-popup.d.ts
5
+ /** `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). */
5
6
  export type MenuSide = AnchorSide;
6
7
  export type MenuAlign = AnchorAlign;
7
8
  export interface MenuPopupState {
8
9
  /** Committed open state. Read `:popover-open` for the DOM truth. */
9
10
  readonly open: boolean;
11
+ /**
12
+ * While shown: the physical side the browser placed the popup on (after any fallback flip;
13
+ * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu
14
+ * is placed at a point (`context`).
15
+ */
10
16
  readonly side: MenuSide | null;
17
+ /** While shown: the resolved alignment; otherwise the `align` prop. */
11
18
  readonly align: MenuAlign;
12
19
  /** This popup belongs to a submenu. */
13
20
  readonly submenu: boolean;
21
+ /**
22
+ * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with
23
+ * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).
24
+ */
25
+ readonly context: boolean;
14
26
  }
15
- export interface MenuPopupProps extends Omit<ComponentPropsWithRef<"div">, "id" | "popover" | "role" | "aria-labelledby" | "onKeyDown" | "onFocus" | "onBlur" | "onMouseDown" | "onPointerEnter" | "onPointerLeave" | "onToggle" | "onBeforeToggle" | "className" | "style" | "children"> {
27
+ export interface MenuPopupProps extends Omit<ComponentPropsWithRef<"div">, "id" | "popover" | "role" | "aria-labelledby" | "onKeyDown" | "onFocus" | "onBlur" | "onMouseDown" | "onContextMenu" | "onPointerEnter" | "onPointerLeave" | "onToggle" | "onBeforeToggle" | "className" | "style" | "children"> {
16
28
  /**
17
29
  * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`
18
- * flipping it when it does not fit. Default `"bottom"` for a top-level menu, `"right"` for a
19
- * submenu (whose fallback is `flip-inline` only). `null` emits no inline positioning (and no
20
- * `data-side` / `data-align`): the stylesheet owns placement.
30
+ * flipping it when it does not fit. Default `"bottom"` for a top-level menu, `"inline-end"` for
31
+ * a submenu (the right of the item in LTR, its left in RTL; its fallback is `flip-inline`
32
+ * only). `"left"` / `"right"` stay physical. `null` emits no inline positioning (and no
33
+ * `data-side` / `data-align`): the stylesheet owns placement. Ignored for an open from a
34
+ * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the
35
+ * inline point placement and the library's `@position-try` rules, leaving only
36
+ * `--menu-point-x` / `--menu-point-y`.
21
37
  */
22
38
  side?: MenuSide | null;
23
- /** Alignment along the side. Default `"start"`. Ignored when `side` is `null`. */
39
+ /**
40
+ * Alignment along the side. Default `"start"` (both levels): inline-relative on a top / bottom
41
+ * side (mirrored under `direction: rtl`), the top edges on the others. Ignored when `side` is
42
+ * `null`.
43
+ */
24
44
  align?: MenuAlign;
25
45
  /**
26
46
  * `false` (default): the items are not rendered while the menu is closed; mounting them is part
@@ -54,12 +74,20 @@ export interface MenuPopupProps extends Omit<ComponentPropsWithRef<"div">, "id"
54
74
  * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with
55
75
  * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft
56
76
  * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).
57
- * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
77
+ * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While
78
+ * shown, those are where the browser placed it (conventions 13.2), otherwise the requested
79
+ * values.
58
80
  *
59
81
  * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),
60
82
  * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on
61
- * non-item space keeps focus on the current item), `onPointerEnter` / `onPointerLeave`, and
62
- * `data-side` / `data-align` unless `side` is `null`.
83
+ * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this
84
+ * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`
85
+ * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`
86
+ * (placed at the pointer: `--menu-point-x` / `--menu-point-y` inline, and unless `side` is
87
+ * `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's
88
+ * `@position-try` fallbacks, whose rules
89
+ * it renders as a hoisted `<style>`). A top-level menu closes at once on a right- or
90
+ * middle-click outside it.
63
91
  */
64
92
  export declare function MenuPopup({ side: sideProp, align, keepMounted, experimental_focusgroup, transition, className, style, children, render, ...rest }: MenuPopupProps): ReactNode;
65
93
  export declare namespace MenuPopup {
@@ -1 +1 @@
1
- {"version":3,"file":"menu-popup.d.mts","names":[],"sources":["../../src/menu/menu-popup.tsx"],"mappings":";;;;YAkCY,WAAW;YACX,YAAY;iBAEP;;WAEN;WACA,MAAM;WACN,OAAO;;WAEP;;iBAGM,uBAAuB,KACtC;;;;;;;EAuBA,OAAO;;EAEP,QAAQ;;;;;;EAMR;;;;;;;EAOA;;;;;;;EAOA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;wBA4BpC,YACd,MAAM,UACN,OACA,aACA,yBACA,YACA,WACA,OACA,UACA,WACG,QACF,iBAAc;yBAXD"}
1
+ {"version":3,"file":"menu-popup.d.mts","names":[],"sources":["../../src/menu/menu-popup.tsx"],"mappings":";;;;;YA2DY,WAAW;YACX,YAAY;iBAEP;;WAEN;;;;;;WAMA,MAAM;;WAEN,OAAO;;WAEP;;;;;WAKA;;iBAGM,uBAAuB,KACtC;;;;;;;;;;;EA4BA,OAAO;;;;;;EAMP,QAAQ;;;;;;EAMR;;;;;;;EAOA;;;;;;;EAOA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;wBAkLpC,YACd,MAAM,UACN,OACA,aACA,yBACA,YACA,WACA,OACA,UACA,WACG,QACF,iBAAc;yBAXD"}
@@ -4,13 +4,16 @@ import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
4
4
  import { mergeRefs } from "../internal/merge-props.mjs";
5
5
  import { resolveStateValue } from "../internal/render-element.mjs";
6
6
  import { useRender } from "../internal/use-render.mjs";
7
- import { POSITION_TRY_FALLBACKS, positionArea } from "../internal/anchor-position.mjs";
7
+ import { useLatest } from "../internal/use-latest.mjs";
8
+ import { FSUI_PRECEDENCE, MENU_POINT_FALLBACKS, MENU_POINT_GAP, MENU_POINT_HREF, MENU_POINT_RULES, MENU_POINT_TOUCH_GAP, MENU_POINT_X, MENU_POINT_Y, POSITION_TRY_FALLBACKS, positionArea } from "../internal/anchor-position.mjs";
9
+ import { useResolvedPlacement } from "../internal/use-resolved-placement.mjs";
10
+ import { CSPContext } from "../internal/csp-context.mjs";
8
11
  import { usePopoverPopup } from "../internal/use-popover-popup.mjs";
9
- import { MenuListContext, useMenuContext } from "./menu-context.mjs";
10
- import { edgeItem, focusItem, hasModifier, isMenuItem, isRtl, menuItems, typeaheadText } from "./menu-dom.mjs";
12
+ import { MenuListContext, claimPress, isHandledBy, useMenuContext } from "./menu-context.mjs";
13
+ import { capturePointer, edgeItem, focusItem, hasModifier, isMenuItem, isRtl, menuItems, typeaheadText } from "./menu-dom.mjs";
11
14
  import { scheduleHoverClose } from "./menu-hover.mjs";
12
- import { Activity, useCallback, useMemo, useRef, useSyncExternalStore } from "react";
13
- import { jsx } from "react/jsx-runtime";
15
+ import { Activity, use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useSyncExternalStore } from "react";
16
+ import { jsx, jsxs } from "react/jsx-runtime";
14
17
  //#region src/menu/menu-popup.tsx
15
18
  /** Engine capabilities never change while the page lives. */
16
19
  const subscribeNever = () => () => {};
@@ -20,22 +23,164 @@ const isDev = process.env.NODE_ENV !== "production";
20
23
  /** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */
21
24
  const FOCUSABLE_SELECTOR = "a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])";
22
25
  /**
26
+ * The inline placement of a point open (context-menu.md 3.3): the point and the gap as custom
27
+ * properties (`--menu-point-gap`: `0px`, `16px` for a touch or pen open, 4.7), and unless the
28
+ * stylesheet owns placement, the menu below the point (`top`) or, for a touch or pen open, above
29
+ * it (`bottom`), and by the popup's direction read at the open (4.6, #88), `left` (LTR) or
30
+ * `right` (RTL: the menu's right edge at the point), with the other two insets `auto`
31
+ * (longhands, so React never sees a shorthand next to its longhands), `position-area: none` (a
32
+ * consumer's anchored `position-area` would otherwise place the popup inside a grid area) and
33
+ * the library's fallbacks for that direction and pointer kind, spelled by generation parity
34
+ * (4.3).
35
+ */
36
+ function pointStyle(point, stylesheetOwned) {
37
+ const vars = {
38
+ [MENU_POINT_X]: `${point.x}px`,
39
+ [MENU_POINT_Y]: `${point.y}px`,
40
+ [MENU_POINT_GAP]: point.offset ? MENU_POINT_TOUCH_GAP : "0px"
41
+ };
42
+ if (stylesheetOwned) return vars;
43
+ const rtl = point.direction === "rtl";
44
+ const kind = point.offset ? "touch" : "mouse";
45
+ return {
46
+ ...vars,
47
+ top: point.offset ? "auto" : `calc(var(${MENU_POINT_Y}) + var(${MENU_POINT_GAP}))`,
48
+ right: rtl ? `calc(100% - var(${MENU_POINT_X}))` : "auto",
49
+ bottom: point.offset ? `calc(100% - var(${MENU_POINT_Y}) + var(${MENU_POINT_GAP}))` : "auto",
50
+ left: rtl ? "auto" : `var(${MENU_POINT_X})`,
51
+ positionArea: "none",
52
+ positionTryFallbacks: MENU_POINT_FALLBACKS[point.direction][kind][point.generation % 2]
53
+ };
54
+ }
55
+ /**
56
+ * The element under a wheel event that can scroll the way the wheel turns, up to `popup`: then
57
+ * the wheel is the menu's own and the page under it is not involved.
58
+ */
59
+ function scrollsWithin(popup, target, event) {
60
+ const vertical = Math.abs(event.deltaY) >= Math.abs(event.deltaX);
61
+ const delta = vertical ? event.deltaY : event.deltaX;
62
+ if (delta === 0) return true;
63
+ let element = target instanceof Element ? target : null;
64
+ while (element !== null && popup.contains(element)) {
65
+ const computed = element.ownerDocument.defaultView?.getComputedStyle(element);
66
+ const overflow = computed?.[vertical ? "overflowY" : "overflowX"] ?? "";
67
+ if (overflow === "auto" || overflow === "scroll" || overflow === "overlay") {
68
+ const room = vertical ? element.scrollHeight - element.clientHeight : element.scrollWidth - element.clientWidth;
69
+ const offset = vertical ? element.scrollTop : element.scrollLeft;
70
+ const min = !vertical && computed?.direction === "rtl" ? -room : 0;
71
+ if (room > 0 && (delta > 0 ? offset < min + room - .5 : offset > min + .5)) return true;
72
+ }
73
+ element = element.parentElement;
74
+ }
75
+ return false;
76
+ }
77
+ /**
78
+ * The outside right- and middle-click close of a top-level menu (context-menu.md 5): a
79
+ * `contextmenu` outside the menu tree that this menu's ContextTrigger did not handle, or a
80
+ * middle-button `pointerdown` outside it, hides the root popup at once (`"dismiss"` through the
81
+ * `toggle` notification). Chromium's click-based light dismiss ignores those buttons.
82
+ *
83
+ * Wave 11 (#88, 4.8): while the menu is placed at a point (read at each event: a right-click may
84
+ * re-place a Trigger-opened menu), a `scroll` of the document or of an element that contains the
85
+ * region closes it the same way; scrolls elsewhere and inside the menu are ignored. Scrolling
86
+ * already in flight at the open (a smooth scroll, trackpad momentum) does not count: scroll
87
+ * events are ignored until the first animation frame without one (review L6). And a `wheel`
88
+ * over any menu never scrolls the page: it is prevented unless something in the menu under the
89
+ * pointer can scroll that way, or it is a zoom (`ctrlKey`: Ctrl+wheel, trackpad pinch). Returns
90
+ * the cleanup.
91
+ */
92
+ function listenOutside(popup, menu, placement) {
93
+ const doc = popup.ownerDocument;
94
+ const inside = (target) => target instanceof Node && popup.contains(target);
95
+ const close = () => {
96
+ if (popup.matches(":popover-open")) popup.hidePopover();
97
+ };
98
+ const onContextMenu = (event) => {
99
+ if (inside(event.target) || isHandledBy(event, menu)) return;
100
+ close();
101
+ };
102
+ const onPointerDown = (event) => {
103
+ if (event.button !== 1 || inside(event.target)) return;
104
+ close();
105
+ };
106
+ const view = doc.defaultView;
107
+ let settling = typeof view?.requestAnimationFrame === "function";
108
+ let scrolledThisFrame = false;
109
+ let frame = 0;
110
+ const tick = () => {
111
+ if (scrolledThisFrame) {
112
+ scrolledThisFrame = false;
113
+ frame = view.requestAnimationFrame(tick);
114
+ } else settling = false;
115
+ };
116
+ if (settling) frame = view.requestAnimationFrame(tick);
117
+ const onScroll = (event) => {
118
+ if (settling) {
119
+ scrolledThisFrame = true;
120
+ return;
121
+ }
122
+ const current = placement();
123
+ if (current.kind !== "point") return;
124
+ const target = event.target;
125
+ if (target instanceof Node && target.nodeType !== Node.DOCUMENT_NODE) {
126
+ if (inside(target) || !target.contains(current.source)) return;
127
+ }
128
+ close();
129
+ };
130
+ const onWheel = (event) => {
131
+ if (event.ctrlKey) return;
132
+ if (!scrollsWithin(popup, event.target, event)) event.preventDefault();
133
+ };
134
+ doc.addEventListener("contextmenu", onContextMenu);
135
+ doc.addEventListener("pointerdown", onPointerDown, true);
136
+ doc.addEventListener("scroll", onScroll, {
137
+ capture: true,
138
+ passive: true
139
+ });
140
+ popup.addEventListener("wheel", onWheel, { passive: false });
141
+ return () => {
142
+ if (settling) view.cancelAnimationFrame(frame);
143
+ doc.removeEventListener("contextmenu", onContextMenu);
144
+ doc.removeEventListener("pointerdown", onPointerDown, true);
145
+ doc.removeEventListener("scroll", onScroll, { capture: true });
146
+ popup.removeEventListener("wheel", onWheel);
147
+ };
148
+ }
149
+ /**
23
150
  * The menu itself: `<div popover="auto" role="menu" aria-labelledby={trigger} tabindex="-1">`,
24
151
  * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):
25
152
  * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with
26
153
  * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft
27
154
  * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).
28
- * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
155
+ * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While
156
+ * shown, those are where the browser placed it (conventions 13.2), otherwise the requested
157
+ * values.
29
158
  *
30
159
  * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),
31
160
  * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on
32
- * non-item space keeps focus on the current item), `onPointerEnter` / `onPointerLeave`, and
33
- * `data-side` / `data-align` unless `side` is `null`.
161
+ * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this
162
+ * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`
163
+ * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`
164
+ * (placed at the pointer: `--menu-point-x` / `--menu-point-y` inline, and unless `side` is
165
+ * `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's
166
+ * `@position-try` fallbacks, whose rules
167
+ * it renders as a hoisted `<style>`). A top-level menu closes at once on a right- or
168
+ * middle-click outside it.
34
169
  */
35
170
  function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_focusgroup = false, transition, className, style, children, render, ...rest }) {
36
171
  const menu = useMenuContext("Menu.Popup");
37
172
  const { popover, submenu, loop } = menu;
38
- const side = sideProp === void 0 ? submenu ? "right" : "bottom" : sideProp;
173
+ const csp = use(CSPContext);
174
+ const latestPlacement = useLatest(menu.placement);
175
+ const sideOption = sideProp === void 0 ? submenu ? "inline-end" : "bottom" : sideProp;
176
+ const point = menu.placement.kind === "point" ? menu.placement : null;
177
+ const requestedSide = point !== null ? null : sideOption;
178
+ const placement = useResolvedPlacement({
179
+ side: requestedSide,
180
+ align
181
+ });
182
+ const { side } = placement;
183
+ const resolvedAlign = placement.align;
39
184
  const nativeFocusgroup = useSyncExternalStore(subscribeNever, () => experimental_focusgroup && "focusGroup" in HTMLElement.prototype, () => false);
40
185
  const typeahead = useRef({
41
186
  text: "",
@@ -45,7 +190,13 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
45
190
  const { text, at } = typeahead.current;
46
191
  return text !== "" && Date.now() - at <= TYPEAHEAD_RESET_MS;
47
192
  }, []);
48
- const { setElement, visible, wrapContent } = usePopoverPopup(popover, {
193
+ const outside = useRef(null);
194
+ const stopOutside = useCallback(() => {
195
+ outside.current?.();
196
+ outside.current = null;
197
+ }, []);
198
+ useEffect(() => stopOutside, [stopOutside]);
199
+ const { setElement, visible, wrapContent, reshow } = usePopoverPopup(popover, {
49
200
  part: "Menu.Popup",
50
201
  initialFocus: void 0,
51
202
  resolveInitialFocus: (popup) => {
@@ -58,13 +209,40 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
58
209
  } : element;
59
210
  },
60
211
  keepMounted,
61
- transition
212
+ transition,
213
+ source: () => point !== null ? point.source : popover.triggerRef.current,
214
+ onToggle: (event) => {
215
+ if (submenu) return;
216
+ const element = popover.popupRef.current;
217
+ if (event.newState === "open" && element !== null && element.matches(":popover-open")) outside.current ??= listenOutside(element, menu, () => latestPlacement.current);
218
+ else if (event.newState === "closed") stopOutside();
219
+ }
220
+ });
221
+ const shownKey = useRef(null);
222
+ useLayoutEffect(() => {
223
+ const element = popover.popupRef.current;
224
+ if (element === null) return;
225
+ const key = point !== null ? point.generation : "anchor";
226
+ if (element.matches(":popover-open")) {
227
+ if (shownKey.current !== null && shownKey.current !== key && reshow()) capturePointer(element, point?.pointerId);
228
+ shownKey.current = key;
229
+ } else {
230
+ shownKey.current = null;
231
+ if (!visible && point !== null && !popover.pending && !popover.intended()) menu.resetPlacement(point.generation);
232
+ }
62
233
  });
63
234
  const devRef = useCallback((element) => {
64
235
  if (isDev && element.tagName === "DIALOG") console.error("Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog focusing steps, which fight the menu's item focus.");
65
- return () => {};
236
+ const onPointerDown = (event) => claimPress(event);
237
+ element.addEventListener("pointerdown", onPointerDown);
238
+ return () => element.removeEventListener("pointerdown", onPointerDown);
66
239
  }, []);
67
- const ref = useMemo(() => mergeRefs(setElement, devRef), [setElement, devRef]);
240
+ const placementRef = placement.ref;
241
+ const ref = useMemo(() => mergeRefs(setElement, devRef, placementRef), [
242
+ setElement,
243
+ devRef,
244
+ placementRef
245
+ ]);
68
246
  const listContext = useMemo(() => ({
69
247
  menu,
70
248
  nativeFocusgroup,
@@ -77,8 +255,9 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
77
255
  const state = {
78
256
  open: popover.committed,
79
257
  side,
80
- align,
81
- submenu
258
+ align: resolvedAlign,
259
+ submenu,
260
+ context: point !== null
82
261
  };
83
262
  const runTypeahead = (popup, current, key) => {
84
263
  const now = Date.now();
@@ -160,6 +339,9 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
160
339
  onKeyDown,
161
340
  onBlur,
162
341
  onMouseDown,
342
+ onContextMenu: (event) => {
343
+ event.preventDefault();
344
+ },
163
345
  ...submenu && {
164
346
  onPointerEnter: (event) => {
165
347
  if (event.pointerType !== "touch") menu.timers.cancelClose();
@@ -170,9 +352,16 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
170
352
  },
171
353
  ...side !== null && {
172
354
  "data-side": side,
173
- "data-align": align
174
- }
355
+ "data-align": resolvedAlign
356
+ },
357
+ "data-context": point !== null ? "" : void 0
175
358
  };
359
+ const pointRules = point !== null && sideOption !== null ? /* @__PURE__ */ jsx("style", {
360
+ href: MENU_POINT_HREF,
361
+ precedence: FSUI_PRECEDENCE,
362
+ nonce: csp?.nonce,
363
+ children: MENU_POINT_RULES
364
+ }) : null;
176
365
  const content = (s) => {
177
366
  let node;
178
367
  if (keepMounted === true) node = /* @__PURE__ */ jsx(Activity, {
@@ -180,12 +369,12 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
180
369
  children: wrapContent(resolveStateValue(children, s))
181
370
  });
182
371
  else node = visible ? wrapContent(resolveStateValue(children, s)) : null;
183
- return /* @__PURE__ */ jsx(MenuListContext, {
372
+ return /* @__PURE__ */ jsxs(MenuListContext, {
184
373
  value: listContext,
185
- children: /* @__PURE__ */ jsx(ToolbarContext, {
374
+ children: [pointRules, /* @__PURE__ */ jsx(ToolbarContext, {
186
375
  value: null,
187
376
  children: node
188
- })
377
+ })]
189
378
  });
190
379
  };
191
380
  const element = useRender({
@@ -193,8 +382,11 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
193
382
  render,
194
383
  state,
195
384
  className,
196
- style: side === null ? style : (s) => ({
197
- positionArea: positionArea(side, align),
385
+ style: point !== null ? (s) => ({
386
+ ...pointStyle(point, sideOption === null),
387
+ ...resolveStateValue(style, s)
388
+ }) : requestedSide === null ? style : (s) => ({
389
+ positionArea: positionArea(requestedSide, align),
198
390
  positionTryFallbacks: submenu ? "flip-inline" : POSITION_TRY_FALLBACKS,
199
391
  ...resolveStateValue(style, s)
200
392
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { Activity, useCallback, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { POSITION_TRY_FALLBACKS, positionArea } from \"../internal/anchor-position.js\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { mergeRefs } from \"../internal/merge-props.js\";\nimport { ToolbarContext } from \"../internal/toolbar-context.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport {\n edgeItem,\n focusItem,\n hasModifier,\n isMenuItem,\n isRtl,\n menuItems,\n typeaheadText,\n} from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\n\nexport type MenuSide = AnchorSide;\nexport type MenuAlign = AnchorAlign;\n\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n readonly side: MenuSide | null;\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n}\n\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. Default `\"bottom\"` for a top-level menu, `\"right\"` for a\n * submenu (whose fallback is `flip-inline` only). `null` emits no inline positioning (and no\n * `data-side` / `data-align`): the stylesheet owns placement.\n */\n side?: MenuSide | null;\n /** Alignment along the side. Default `\"start\"`. Ignored when `side` is `null`. */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines. Default `false`.\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, MenuPopupState>;\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** Engine capabilities never change while the page lives. */\nconst subscribeNever = () => () => {};\n\n/** Typeahead buffer lifetime after the last keystroke (design 5.1). */\nconst TYPEAHEAD_RESET_MS = 500;\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onPointerEnter` / `onPointerLeave`, and\n * `data-side` / `data-align` unless `side` is `null`.\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const side = sideProp === undefined ? (submenu ? \"right\" : \"bottom\") : sideProp;\n\n // As Tabs.List (#43): detected only with the flag, never during SSR or hydration.\n const nativeFocusgroup = useSyncExternalStore(\n subscribeNever,\n () => experimental_focusgroup && \"focusGroup\" in HTMLElement.prototype,\n () => false,\n );\n\n const typeahead = useRef({ text: \"\", at: 0 });\n const typingAhead = useCallback(() => {\n const { text, at } = typeahead.current;\n return text !== \"\" && Date.now() - at <= TYPEAHEAD_RESET_MS;\n }, []);\n\n const { setElement, visible, wrapContent } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n initialFocus: undefined,\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so (H1).\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n });\n\n const devRef = useCallback((element: HTMLElement) => {\n if (isDev && element.tagName === \"DIALOG\") {\n console.error(\n \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\",\n );\n }\n return () => {};\n }, []);\n const ref = useMemo(() => mergeRefs(setElement, devRef), [setElement, devRef]);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = { open: popover.committed, side, align, submenu };\n\n const runTypeahead = (popup: HTMLElement, current: HTMLElement | null, key: string): boolean => {\n const now = Date.now();\n const buffer = typeahead.current;\n if (buffer.text === \"\" || now - buffer.at > TYPEAHEAD_RESET_MS) buffer.text = \"\";\n if (key === \" \" && buffer.text === \"\") return false;\n buffer.text += key.toLowerCase();\n buffer.at = now;\n const items = menuItems(popup);\n if (items.length === 0) return true;\n // A repeated single character cycles through the items starting with it; a longer buffer\n // keeps the current item while it still matches (design 5.1).\n const repeated = [...buffer.text].every((c) => c === buffer.text[0]);\n const search = repeated ? buffer.text[0]! : buffer.text;\n const index = current === null ? -1 : items.indexOf(current);\n const start = repeated || index < 0 ? index + 1 : index;\n for (let i = 0; i < items.length; i++) {\n const item = items[(start + i) % items.length]!;\n if (typeaheadText(item).startsWith(search)) {\n if (item !== current) focusItem(item);\n break;\n }\n }\n return true;\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || hasModifier(event)) return;\n const popup = event.currentTarget;\n const target = event.target as HTMLElement;\n const onItem = isMenuItem(target, popup);\n if (!onItem && target !== popup) return;\n const key = event.key;\n\n // ArrowLeft (ArrowRight in RTL) closes a submenu; focus returns to its SubmenuTrigger\n // through the popover hook's nested focus rule (design 6.3).\n if (submenu && key === (isRtl(popup) ? \"ArrowRight\" : \"ArrowLeft\")) {\n event.preventDefault();\n popover.requestClose(event.nativeEvent, \"activate\");\n return;\n }\n\n if (key === \"ArrowDown\" || key === \"ArrowUp\" || key === \"Home\" || key === \"End\") {\n if (!onItem) {\n // The popup itself has focus (no items at open, or focus landed on it some other way):\n // into the list from its edge (review M1).\n event.preventDefault();\n const items = menuItems(popup);\n const item = key === \"ArrowDown\" || key === \"Home\" ? items[0] : items.at(-1);\n if (item !== undefined) focusItem(item);\n return;\n }\n // The browser moves focus itself where `focusgroup` is implemented.\n if (nativeFocusgroup) return;\n event.preventDefault();\n const items = menuItems(popup);\n const index = items.indexOf(target);\n const last = items.length - 1;\n let next: number;\n if (key === \"Home\") next = 0;\n else if (key === \"End\") next = last;\n else if (key === \"ArrowDown\") next = index >= last ? (loop ? 0 : last) : index + 1;\n else next = index <= 0 ? (loop ? last : 0) : index - 1;\n const item = items[next];\n if (item !== undefined && item !== target) focusItem(item);\n return;\n }\n\n if (key.length === 1 && runTypeahead(popup, onItem ? target : null, key)) {\n event.preventDefault();\n }\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (popup.matches(\":popover-open\")) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (review M1, the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n const content = (s: MenuPopupState): ReactNode => {\n let node: ReactNode;\n if (keepMounted === true) {\n node = (\n <Activity mode={visible ? \"visible\" : \"hidden\"}>\n {wrapContent(resolveStateValue(children, s))}\n </Activity>\n );\n } else {\n node = visible ? wrapContent(resolveStateValue(children, s)) : null;\n }\n // Not part of an enclosing Toolbar: a Menu.Trigger or ToggleGroup in here sees no Toolbar.\n return (\n <MenuListContext value={listContext}>\n <ToolbarContext value={null}>{node}</ToolbarContext>\n </MenuListContext>\n );\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n side === null\n ? style\n : (s) => ({\n positionArea: positionArea(side, align),\n positionTryFallbacks: submenu ? \"flip-inline\" : POSITION_TRY_FALLBACKS,\n ...resolveStateValue(style, s),\n }),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;AAqGA,MAAM,6BAA6B,CAAC;;AAGpC,MAAM,qBAAqB;AAE3B,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,qBACJ;;;;;;;;;;;;;;AAeF,SAAgB,UAAU,EACxB,MAAM,UACN,QAAQ,SACR,aACA,0BAA0B,OAC1B,YACA,WACA,OACA,UACA,QACA,GAAG,QACc;CACjB,MAAM,OAAO,eAAe,YAAY;CACxC,MAAM,EAAE,SAAS,SAAS,SAAS;CACnC,MAAM,OAAO,aAAa,KAAA,IAAa,UAAU,UAAU,WAAY;CAGvE,MAAM,mBAAmB,qBACvB,sBACM,2BAA2B,gBAAgB,YAAY,iBACvD,KACR;CAEA,MAAM,YAAY,OAAO;EAAE,MAAM;EAAI,IAAI;CAAE,CAAC;CAC5C,MAAM,cAAc,kBAAkB;EACpC,MAAM,EAAE,MAAM,OAAO,UAAU;EAC/B,OAAO,SAAS,MAAM,KAAK,IAAI,IAAI,MAAM;CAC3C,GAAG,CAAC,CAAC;CAEL,MAAM,EAAE,YAAY,SAAS,gBAAgB,gBAAgB,SAAS;EACpE,MAAM;EACN,cAAc,KAAA;EAId,sBAAsB,UAAU;GAC9B,MAAM,EAAE,OAAO,Y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aAAa,MAAM,KAAK;GACtC,sBAAsB,UAAU,gBAAgB;GAChD,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACN,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
1
+ {"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport {\n Activity,\n use,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport {\n FSUI_PRECEDENCE,\n MENU_POINT_FALLBACKS,\n MENU_POINT_GAP,\n MENU_POINT_HREF,\n MENU_POINT_RULES,\n MENU_POINT_TOUCH_GAP,\n MENU_POINT_X,\n MENU_POINT_Y,\n POSITION_TRY_FALLBACKS,\n positionArea,\n} from \"../internal/anchor-position.js\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { mergeRefs } from \"../internal/merge-props.js\";\nimport { ToolbarContext } from \"../internal/toolbar-context.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { useResolvedPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { claimPress, isHandledBy, MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuContextValue, MenuListContextValue, MenuPlacement } from \"./menu-context.js\";\nimport {\n capturePointer,\n edgeItem,\n focusItem,\n hasModifier,\n isMenuItem,\n isRtl,\n menuItems,\n typeaheadText,\n} from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). */\nexport type MenuSide = AnchorSide;\nexport type MenuAlign = AnchorAlign;\n\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu\n * is placed at a point (`context`).\n */\n readonly side: MenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n /**\n * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with\n * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).\n */\n readonly context: boolean;\n}\n\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onContextMenu\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. Default `\"bottom\"` for a top-level menu, `\"inline-end\"` for\n * a submenu (the right of the item in LTR, its left in RTL; its fallback is `flip-inline`\n * only). `\"left\"` / `\"right\"` stay physical. `null` emits no inline positioning (and no\n * `data-side` / `data-align`): the stylesheet owns placement. Ignored for an open from a\n * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the\n * inline point placement and the library's `@position-try` rules, leaving only\n * `--menu-point-x` / `--menu-point-y`.\n */\n side?: MenuSide | null;\n /**\n * Alignment along the side. Default `\"start\"` (both levels): inline-relative on a top / bottom\n * side (mirrored under `direction: rtl`), the top edges on the others. Ignored when `side` is\n * `null`.\n */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines. Default `false`.\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, MenuPopupState>;\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** Engine capabilities never change while the page lives. */\nconst subscribeNever = () => () => {};\n\n/** Typeahead buffer lifetime after the last keystroke (design 5.1). */\nconst TYPEAHEAD_RESET_MS = 500;\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\ntype PointPlacement = Extract<MenuPlacement, { kind: \"point\" }>;\n\n/**\n * The inline placement of a point open (context-menu.md 3.3): the point and the gap as custom\n * properties (`--menu-point-gap`: `0px`, `16px` for a touch or pen open, 4.7), and unless the\n * stylesheet owns placement, the menu below the point (`top`) or, for a touch or pen open, above\n * it (`bottom`), and by the popup's direction read at the open (4.6, #88), `left` (LTR) or\n * `right` (RTL: the menu's right edge at the point), with the other two insets `auto`\n * (longhands, so React never sees a shorthand next to its longhands), `position-area: none` (a\n * consumer's anchored `position-area` would otherwise place the popup inside a grid area) and\n * the library's fallbacks for that direction and pointer kind, spelled by generation parity\n * (4.3).\n */\nfunction pointStyle(point: PointPlacement, stylesheetOwned: boolean): CSSProperties {\n const vars = {\n [MENU_POINT_X]: `${point.x}px`,\n [MENU_POINT_Y]: `${point.y}px`,\n [MENU_POINT_GAP]: point.offset ? MENU_POINT_TOUCH_GAP : \"0px\",\n };\n if (stylesheetOwned) return vars as CSSProperties;\n const rtl = point.direction === \"rtl\";\n const kind = point.offset ? \"touch\" : \"mouse\";\n return {\n ...vars,\n top: point.offset ? \"auto\" : `calc(var(${MENU_POINT_Y}) + var(${MENU_POINT_GAP}))`,\n right: rtl ? `calc(100% - var(${MENU_POINT_X}))` : \"auto\",\n bottom: point.offset ? `calc(100% - var(${MENU_POINT_Y}) + var(${MENU_POINT_GAP}))` : \"auto\",\n left: rtl ? \"auto\" : `var(${MENU_POINT_X})`,\n positionArea: \"none\",\n positionTryFallbacks: MENU_POINT_FALLBACKS[point.direction][kind][point.generation % 2],\n } as CSSProperties;\n}\n\n/**\n * The element under a wheel event that can scroll the way the wheel turns, up to `popup`: then\n * the wheel is the menu's own and the page under it is not involved.\n */\nfunction scrollsWithin(popup: HTMLElement, target: EventTarget | null, event: WheelEvent) {\n const vertical = Math.abs(event.deltaY) >= Math.abs(event.deltaX);\n const delta = vertical ? event.deltaY : event.deltaX;\n if (delta === 0) return true;\n let element = target instanceof Element ? target : null;\n while (element !== null && popup.contains(element)) {\n const computed = element.ownerDocument.defaultView?.getComputedStyle(element);\n const overflow = computed?.[vertical ? \"overflowY\" : \"overflowX\"] ?? \"\";\n if (overflow === \"auto\" || overflow === \"scroll\" || overflow === \"overlay\") {\n // Scroll offsets run 0..room (down, or right in LTR) or -room..0 (right to left).\n const room = vertical\n ? element.scrollHeight - element.clientHeight\n : element.scrollWidth - element.clientWidth;\n const offset = vertical ? element.scrollTop : element.scrollLeft;\n const min = !vertical && computed?.direction === \"rtl\" ? -room : 0;\n if (room > 0 && (delta > 0 ? offset < min + room - 0.5 : offset > min + 0.5)) return true;\n }\n element = element.parentElement;\n }\n return false;\n}\n\n/**\n * The outside right- and middle-click close of a top-level menu (context-menu.md 5): a\n * `contextmenu` outside the menu tree that this menu's ContextTrigger did not handle, or a\n * middle-button `pointerdown` outside it, hides the root popup at once (`\"dismiss\"` through the\n * `toggle` notification). Chromium's click-based light dismiss ignores those buttons.\n *\n * Wave 11 (#88, 4.8): while the menu is placed at a point (read at each event: a right-click may\n * re-place a Trigger-opened menu), a `scroll` of the document or of an element that contains the\n * region closes it the same way; scrolls elsewhere and inside the menu are ignored. Scrolling\n * already in flight at the open (a smooth scroll, trackpad momentum) does not count: scroll\n * events are ignored until the first animation frame without one (review L6). And a `wheel`\n * over any menu never scrolls the page: it is prevented unless something in the menu under the\n * pointer can scroll that way, or it is a zoom (`ctrlKey`: Ctrl+wheel, trackpad pinch). Returns\n * the cleanup.\n */\nfunction listenOutside(\n popup: HTMLElement,\n menu: MenuContextValue,\n placement: () => MenuPlacement,\n): () => void {\n const doc = popup.ownerDocument;\n const inside = (target: EventTarget | null) => target instanceof Node && popup.contains(target);\n const close = () => {\n if (popup.matches(\":popover-open\")) popup.hidePopover();\n };\n // Bubble phase: the region's handler ran first and marked a move.\n const onContextMenu = (event: Event) => {\n if (inside(event.target) || isHandledBy(event, menu)) return;\n close();\n };\n const onPointerDown = (event: Event) => {\n if ((event as globalThis.PointerEvent).button !== 1 || inside(event.target)) return;\n close();\n };\n // Scroll events run in a frame's rendering steps, before its animation frame callbacks: the\n // first callback that saw none since the last one ends the in-flight scroll window.\n const view = doc.defaultView;\n let settling = typeof view?.requestAnimationFrame === \"function\";\n let scrolledThisFrame = false;\n let frame = 0;\n const tick = () => {\n if (scrolledThisFrame) {\n scrolledThisFrame = false;\n frame = view!.requestAnimationFrame(tick);\n } else settling = false;\n };\n if (settling) frame = view!.requestAnimationFrame(tick);\n const onScroll = (event: Event) => {\n if (settling) {\n scrolledThisFrame = true;\n return;\n }\n const current = placement();\n if (current.kind !== \"point\") return;\n const target = event.target;\n // The point is meaningless once the content under it moved: the document, or a scroller\n // around the region (React Aria's rule). A scroller elsewhere or inside the menu is not.\n if (target instanceof Node && target.nodeType !== Node.DOCUMENT_NODE) {\n if (inside(target) || !target.contains(current.source)) return;\n }\n close();\n };\n // Native menus never scroll the page from inside the menu; a non-overflowing popup would chain\n // the wheel to the page (Firefox ignores `overscroll-behavior` there).\n const onWheel = (event: WheelEvent) => {\n // A zoom, not a scroll: Ctrl+wheel and a trackpad pinch (`wheel` with `ctrlKey`) stay the\n // user's (review L3).\n if (event.ctrlKey) return;\n if (!scrollsWithin(popup, event.target, event)) event.preventDefault();\n };\n doc.addEventListener(\"contextmenu\", onContextMenu);\n doc.addEventListener(\"pointerdown\", onPointerDown, true);\n doc.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n popup.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => {\n if (settling) view!.cancelAnimationFrame(frame);\n doc.removeEventListener(\"contextmenu\", onContextMenu);\n doc.removeEventListener(\"pointerdown\", onPointerDown, true);\n doc.removeEventListener(\"scroll\", onScroll, { capture: true });\n popup.removeEventListener(\"wheel\", onWheel);\n };\n}\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While\n * shown, those are where the browser placed it (conventions 13.2), otherwise the requested\n * values.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this\n * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`\n * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`\n * (placed at the pointer: `--menu-point-x` / `--menu-point-y` inline, and unless `side` is\n * `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's\n * `@position-try` fallbacks, whose rules\n * it renders as a hoisted `<style>`). A top-level menu closes at once on a right- or\n * middle-click outside it.\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const csp = use(CSPContext);\n // The listeners installed at the open read the placement of the latest commit (4.8).\n const latestPlacement = useLatest(menu.placement);\n // A submenu opens on the inline-end side of its item: the side ArrowRight (ArrowLeft in RTL)\n // points to (wave 11, #53).\n const sideOption = sideProp === undefined ? (submenu ? \"inline-end\" : \"bottom\") : sideProp;\n // A ContextTrigger's open is placed at the point; nothing is anchored (context-menu.md 3.3).\n const point = menu.placement.kind === \"point\" ? menu.placement : null;\n const requestedSide = point !== null ? null : sideOption;\n // Resolved while shown (conventions 13.2); idle for a point open, which has no side.\n const placement = useResolvedPlacement({ side: requestedSide, align });\n const { side } = placement;\n const resolvedAlign = placement.align;\n\n // As Tabs.List (#43): detected only with the flag, never during SSR or hydration.\n const nativeFocusgroup = useSyncExternalStore(\n subscribeNever,\n () => experimental_focusgroup && \"focusGroup\" in HTMLElement.prototype,\n () => false,\n );\n\n const typeahead = useRef({ text: \"\", at: 0 });\n const typingAhead = useCallback(() => {\n const { text, at } = typeahead.current;\n return text !== \"\" && Date.now() - at <= TYPEAHEAD_RESET_MS;\n }, []);\n\n // The outside right- / middle-click listeners of a top-level menu, while it is shown.\n const outside = useRef<(() => void) | null>(null);\n const stopOutside = useCallback(() => {\n outside.current?.();\n outside.current = null;\n }, []);\n useEffect(() => stopOutside, [stopOutside]);\n\n const { setElement, visible, wrapContent, reshow } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n initialFocus: undefined,\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so (H1).\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n // A point open nests through the region that opened it (context-menu.md 3.1).\n source: () => (point !== null ? point.source : popover.triggerRef.current),\n onToggle: (event) => {\n if (submenu) return;\n const element = popover.popupRef.current;\n if (event.newState === \"open\" && element !== null && element.matches(\":popover-open\")) {\n outside.current ??= listenOutside(element, menu, () => latestPlacement.current);\n } else if (event.newState === \"closed\") {\n stopOutside();\n }\n },\n });\n\n // A move (context-menu.md 4.3): the popup is shown and the placement changed since it was\n // shown (a new point, or a right-click in the region while a Trigger open is shown). Re-show\n // it so the respelled fallbacks place it afresh, the source is the region and the first item\n // is focused again; then capture the still-pressed pointer again, against the Firefox / WebKit\n // `pointerup` light dismiss. Runs after the hook's apply effect (declared after it).\n // Once the popup is not visible (hidden, exit animation over) and no open is intended or in\n // flight, a point placement goes back to anchored for the next open that is not a\n // ContextTrigger's: after a point open that was shown and closed, and after one that was\n // rejected or refused (review L1).\n const shownKey = useRef<number | \"anchor\" | null>(null);\n useLayoutEffect(() => {\n const element = popover.popupRef.current;\n if (element === null) return;\n const key = point !== null ? point.generation : \"anchor\";\n if (element.matches(\":popover-open\")) {\n if (shownKey.current !== null && shownKey.current !== key && reshow()) {\n capturePointer(element, point?.pointerId);\n }\n shownKey.current = key;\n } else {\n shownKey.current = null;\n if (!visible && point !== null && !popover.pending && !popover.intended()) {\n menu.resetPlacement(point.generation);\n }\n }\n });\n\n const devRef = useCallback((element: HTMLElement) => {\n if (isDev && element.tagName === \"DIALOG\") {\n console.error(\n \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\",\n );\n }\n // A press inside a menu is never a long-press of a Menu.ContextTrigger around it (review M1).\n // Native, so it runs before React's root listener dispatches to the region.\n const onPointerDown = (event: Event) => claimPress(event);\n element.addEventListener(\"pointerdown\", onPointerDown);\n return () => element.removeEventListener(\"pointerdown\", onPointerDown);\n }, []);\n const placementRef = placement.ref;\n const ref = useMemo(\n () => mergeRefs(setElement, devRef, placementRef),\n [setElement, devRef, placementRef],\n );\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = {\n open: popover.committed,\n side,\n align: resolvedAlign,\n submenu,\n context: point !== null,\n };\n\n const runTypeahead = (popup: HTMLElement, current: HTMLElement | null, key: string): boolean => {\n const now = Date.now();\n const buffer = typeahead.current;\n if (buffer.text === \"\" || now - buffer.at > TYPEAHEAD_RESET_MS) buffer.text = \"\";\n if (key === \" \" && buffer.text === \"\") return false;\n buffer.text += key.toLowerCase();\n buffer.at = now;\n const items = menuItems(popup);\n if (items.length === 0) return true;\n // A repeated single character cycles through the items starting with it; a longer buffer\n // keeps the current item while it still matches (design 5.1).\n const repeated = [...buffer.text].every((c) => c === buffer.text[0]);\n const search = repeated ? buffer.text[0]! : buffer.text;\n const index = current === null ? -1 : items.indexOf(current);\n const start = repeated || index < 0 ? index + 1 : index;\n for (let i = 0; i < items.length; i++) {\n const item = items[(start + i) % items.length]!;\n if (typeaheadText(item).startsWith(search)) {\n if (item !== current) focusItem(item);\n break;\n }\n }\n return true;\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || hasModifier(event)) return;\n const popup = event.currentTarget;\n const target = event.target as HTMLElement;\n const onItem = isMenuItem(target, popup);\n if (!onItem && target !== popup) return;\n const key = event.key;\n\n // ArrowLeft (ArrowRight in RTL) closes a submenu; focus returns to its SubmenuTrigger\n // through the popover hook's nested focus rule (design 6.3).\n if (submenu && key === (isRtl(popup) ? \"ArrowRight\" : \"ArrowLeft\")) {\n event.preventDefault();\n popover.requestClose(event.nativeEvent, \"activate\");\n return;\n }\n\n if (key === \"ArrowDown\" || key === \"ArrowUp\" || key === \"Home\" || key === \"End\") {\n if (!onItem) {\n // The popup itself has focus (no items at open, or focus landed on it some other way):\n // into the list from its edge (review M1).\n event.preventDefault();\n const items = menuItems(popup);\n const item = key === \"ArrowDown\" || key === \"Home\" ? items[0] : items.at(-1);\n if (item !== undefined) focusItem(item);\n return;\n }\n // The browser moves focus itself where `focusgroup` is implemented.\n if (nativeFocusgroup) return;\n event.preventDefault();\n const items = menuItems(popup);\n const index = items.indexOf(target);\n const last = items.length - 1;\n let next: number;\n if (key === \"Home\") next = 0;\n else if (key === \"End\") next = last;\n else if (key === \"ArrowDown\") next = index >= last ? (loop ? 0 : last) : index + 1;\n else next = index <= 0 ? (loop ? last : 0) : index - 1;\n const item = items[next];\n if (item !== undefined && item !== target) focusItem(item);\n return;\n }\n\n if (key.length === 1 && runTypeahead(popup, onItem ? target : null, key)) {\n event.preventDefault();\n }\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (popup.matches(\":popover-open\")) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (review M1, the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n // No native menu over the custom one. The popup is a sibling of any ContextTrigger, so this\n // event never reaches a region as a move; an outer region sees it prevented and stays quiet.\n onContextMenu: (event: MouseEvent<HTMLElement>) => {\n event.preventDefault();\n },\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...(side !== null && { \"data-side\": side, \"data-align\": resolvedAlign }),\n \"data-context\": point !== null ? \"\" : undefined,\n };\n\n // The shipped `@position-try` rules (conventions 12): hoisted into <head> and deduplicated by\n // React, rendered only by a point open that does not opt out with `side={null}`, with the\n // `<CSPProvider>` nonce for a nonce-based `style-src`.\n const pointRules =\n point !== null && sideOption !== null ? (\n <style href={MENU_POINT_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {MENU_POINT_RULES}\n </style>\n ) : null;\n\n const content = (s: MenuPopupState): ReactNode => {\n let node: ReactNode;\n if (keepMounted === true) {\n node = (\n <Activity mode={visible ? \"visible\" : \"hidden\"}>\n {wrapContent(resolveStateValue(children, s))}\n </Activity>\n );\n } else {\n node = visible ? wrapContent(resolveStateValue(children, s)) : null;\n }\n // Not part of an enclosing Toolbar: a Menu.Trigger or ToggleGroup in here sees no Toolbar.\n return (\n <MenuListContext value={listContext}>\n {pointRules}\n <ToolbarContext value={null}>{node}</ToolbarContext>\n </MenuListContext>\n );\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement (the requested one: the browser keeps choosing from it) sits under\n // the consumer's style: the consumer wins.\n style:\n point !== null\n ? (s) => ({ ...pointStyle(point, sideOption === null), ...resolveStateValue(style, s) })\n : requestedSide === null\n ? style\n : (s) => ({\n positionArea: positionArea(requestedSide, align),\n positionTryFallbacks: submenu ? \"flip-inline\" : POSITION_TRY_FALLBACKS,\n ...resolveStateValue(style, s),\n }),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkJA,MAAM,6BAA6B,CAAC;;AAGpC,MAAM,qBAAqB;AAE3B,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,qBACJ;;;;;;;;;;;;AAeF,SAAS,WAAW,OAAuB,iBAAyC;CAClF,MAAM,OAAO;GACV,eAAe,GAAG,MAAM,EAAE;GAC1B,eAAe,GAAG,MAAM,EAAE;GAC1B,iBAAiB,MAAM,SAAS,uBAAuB;CAC1D;CACA,IAAI,iBAAiB,OAAO;CAC5B,MAAM,MAAM,MAAM,cAAc;CAChC,MAAM,OAAO,MAAM,SAAS,UAAU;CACtC,OAAO;EACL,GAAG;EACH,KAAK,MAAM,SAAS,SAAS,YAAY,aAAa,UAAU,eAAe;EAC/E,OAAO,MAAM,mBAAmB,aAAa,MAAM;EACnD,QAAQ,MAAM,SAAS,mBAAmB,aAAa,UAAU,eAAe,MAAM;EACt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qC;IACpD,IAAI,MAAM,gBAAgB,SAAS,KAAK,OAAO,YAAY;GAC7D;GACA,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,mBAAmB,MAAM,MAAM,WAAW;GAC/E;EACF;EACA,GAAI,SAAS,QAAQ;GAAE,aAAa;GAAM,cAAc;EAAc;EACtE,gBAAgB,UAAU,OAAO,KAAK,KAAA;CACxC;CAKA,MAAM,aACJ,UAAU,QAAQ,eAAe,OAC/B,oBAAC,SAAD;EAAO,MAAM;EAAiB,YAAY;EAAiB,OAAO,KAAK;EACpE,UAAA;CACI,CAAA,IACL;CAEN,MAAM,WAAW,MAAiC;EAChD,IAAI;EACJ,IAAI,gBAAgB,MAClB,OACE,oBAAC,UAAD;GAAU,MAAM,UAAU,YAAY;GACnC,UAAA,YAAY,kBAAkB,UAAU,CAAC,CAAC;EACnC,CAAA;OAGZ,OAAO,UAAU,YAAY,kBAAkB,UAAU,CAAC,CAAC,IAAI;EAGjE,OACE,qBAAC,iBAAD;GAAiB,OAAO;GAAxB,UAAA,CACG,YACD,oBAAC,gBAAD;IAAgB,OAAO;IAAO,UAAA;GAAqB,CAAA,CACpC;;CAErB;CAEA,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAGA,OACE,UAAU,QACL,OAAO;GAAE,GAAG,WAAW,OAAO,eAAe,IAAI;GAAG,GAAG,kBAAkB,OAAO,CAAC;EAAE,KACpF,kBAAkB,OAChB,SACC,OAAO;GACN,cAAc,aAAa,eAAe,KAAK;GAC/C,sBAAsB,UAAU,gBAAgB;GAChD,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACR,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
@@ -21,6 +21,11 @@ export interface MenuRootState {
21
21
  readonly pending: boolean;
22
22
  /** This Root is a submenu (rendered inside a `Menu.Popup`). */
23
23
  readonly submenu: boolean;
24
+ /**
25
+ * The current open (optimistic) came from a `Menu.ContextTrigger`: the menu is placed at the
26
+ * pointer rather than against the Trigger.
27
+ */
28
+ readonly context: boolean;
24
29
  }
25
30
  export interface MenuRootProps {
26
31
  /** Controlled open state. `undefined` means uncontrolled. */
@@ -1 +1 @@
1
- {"version":3,"file":"menu-root.d.mts","names":[],"sources":["../../src/menu/menu-root.tsx"],"mappings":";;;;iBAYiB,8BAA8B;;;;;;;;;;WAUpC,QAAQ;;iBAGF;;WAEN;;WAEA;;WAEA;;iBAGM;;EAEf;;EAEA;;;;;;;;EAQA,mBAAmB,sBAAsB;;EAEzC;;EAEA;;;;;EAKA;EACA,WAAW,WAAW,WAAW;;wBAenB,WACd,MACA,aACA,kBACA,MACA,OACA,YACA,YACC,gCAAa,IAAA;yBARA"}
1
+ {"version":3,"file":"menu-root.d.mts","names":[],"sources":["../../src/menu/menu-root.tsx"],"mappings":";;;;iBAuBiB,8BAA8B;;;;;;;;;;WAUpC,QAAQ;;iBAGF;;WAEN;;WAEA;;WAEA;;;;;WAKA;;iBAGM;;EAEf;;EAEA;;;;;;;;EAQA,mBAAmB,sBAAsB;;EAEzC;;EAEA;;;;;EAKA;EACA,WAAW,WAAW,WAAW;;wBAenB,WACd,MACA,aACA,kBACA,MACA,OACA,YACA,YACC,gCAAa,IAAA;yBARA"}