@funstack/ui 0.1.0-alpha.8 → 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 (68) 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 +169 -18
  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-resolved-placement.mjs +146 -0
  24. package/dist/internal/use-resolved-placement.mjs.map +1 -0
  25. package/dist/menu/menu-context-trigger.d.mts.map +1 -1
  26. package/dist/menu/menu-context-trigger.mjs +198 -19
  27. package/dist/menu/menu-context-trigger.mjs.map +1 -1
  28. package/dist/menu/menu-context.mjs +11 -1
  29. package/dist/menu/menu-context.mjs.map +1 -1
  30. package/dist/menu/menu-dom.mjs +9 -5
  31. package/dist/menu/menu-dom.mjs.map +1 -1
  32. package/dist/menu/menu-popup.d.mts +20 -6
  33. package/dist/menu/menu-popup.d.mts.map +1 -1
  34. package/dist/menu/menu-popup.mjs +119 -26
  35. package/dist/menu/menu-popup.mjs.map +1 -1
  36. package/dist/menu/menu-root.d.mts.map +1 -1
  37. package/dist/menu/menu-root.mjs +11 -3
  38. package/dist/menu/menu-root.mjs.map +1 -1
  39. package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
  40. package/dist/menu/menu-submenu-trigger.mjs +27 -11
  41. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  42. package/dist/popover/popover-popup.d.mts +21 -7
  43. package/dist/popover/popover-popup.d.mts.map +1 -1
  44. package/dist/popover/popover-popup.mjs +16 -6
  45. package/dist/popover/popover-popup.mjs.map +1 -1
  46. package/dist/tooltip/index.d.mts +8 -5
  47. package/dist/tooltip/index.d.mts.map +1 -1
  48. package/dist/tooltip/index.mjs +6 -3
  49. package/dist/tooltip/index.mjs.map +1 -1
  50. package/dist/tooltip/tooltip-arrow.d.mts +30 -0
  51. package/dist/tooltip/tooltip-arrow.d.mts.map +1 -0
  52. package/dist/tooltip/tooltip-arrow.mjs +45 -0
  53. package/dist/tooltip/tooltip-arrow.mjs.map +1 -0
  54. package/dist/tooltip/tooltip-context.d.mts +7 -0
  55. package/dist/tooltip/tooltip-context.d.mts.map +1 -1
  56. package/dist/tooltip/tooltip-context.mjs +2 -1
  57. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  58. package/dist/tooltip/tooltip-popup.d.mts +21 -6
  59. package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
  60. package/dist/tooltip/tooltip-popup.mjs +28 -6
  61. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  62. package/dist/tooltip/tooltip-trigger.d.mts +9 -2
  63. package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
  64. package/dist/tooltip/tooltip-trigger.mjs +21 -5
  65. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  66. package/dist/tooltip/use-tooltip-interaction.mjs +26 -2
  67. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  68. package/package.json +2 -1
@@ -0,0 +1,146 @@
1
+ "use client";
2
+ import { parsePositionArea } from "./anchor-position.mjs";
3
+ import { useCallback, useLayoutEffect, useRef, useState } from "react";
4
+ import { flushSync } from "react-dom";
5
+ //#region src/internal/use-resolved-placement.ts
6
+ const toDirection = (value) => value === "rtl" ? "rtl" : "ltr";
7
+ /**
8
+ * Where the browser actually placed an anchored popup (design/conventions.md 13.2): the
9
+ * `position-try-fallbacks` option it applied, read from `getComputedStyle(popup).positionArea`
10
+ * while the popup is shown and parsed into a physical side and an alignment. Observation, not
11
+ * positioning: the browser keeps placing the popup; this only reports where.
12
+ *
13
+ * Sources: a `ResizeObserver` on the popup from mount (hidden to shown is a resize, delivered
14
+ * after layout and before paint, so the first painted frame carries the resolved side), `toggle`
15
+ * (and the jsdom shim's), and while shown `scroll` on the document (capture, passive: nested
16
+ * scrollers too) and `resize` on the window, each read at once and again in the next two
17
+ * animation frames (an engine applies the option a scroll calls for only in the layout after the
18
+ * event). The write is urgent (`flushSync`, so the attribute lands before paint; conventions 3.5)
19
+ * and happens only when the rendered pair would change: a popup with a physical `side` that opens
20
+ * where it was asked costs no render (the state holds `null` then). A logical side
21
+ * (`inline-start` / `inline-end`) costs one render on show and one on hide, because `data-side`
22
+ * turns physical while shown. Hidden again resets to the requested values, once the popup no
23
+ * longer renders (an exit animation keeps the resolved side to its end).
24
+ *
25
+ * Idle with `side: null` (a stylesheet's `@position-try` rules may set insets the parser cannot
26
+ * interpret): no reads, the result's `side` is `null`. Runs whatever opened the popup, the
27
+ * native `interestfor` and `commandfor` paths included.
28
+ */
29
+ function useResolvedPlacement(request) {
30
+ const { side, align } = request;
31
+ const [resolved, setResolved] = useState(null);
32
+ const written = useRef(null);
33
+ const requested = useRef(request);
34
+ const sync = useRef(null);
35
+ const ref = useCallback((element) => {
36
+ if (element === null) return;
37
+ const doc = element.ownerDocument;
38
+ const win = doc.defaultView ?? window;
39
+ const write = (value, urgent) => {
40
+ const next = value !== null && value.side === requested.current.side && value.align === requested.current.align ? null : value;
41
+ const previous = written.current;
42
+ if (previous === next || previous !== null && next !== null && previous.side === next.side && previous.align === next.align) return;
43
+ written.current = next;
44
+ if (urgent) flushSync(() => setResolved(next));
45
+ else setResolved(next);
46
+ };
47
+ let listening = false;
48
+ const listen = (on) => {
49
+ if (on === listening) return;
50
+ listening = on;
51
+ if (on) {
52
+ doc.addEventListener("scroll", onMove, {
53
+ capture: true,
54
+ passive: true
55
+ });
56
+ win.addEventListener("resize", onMove);
57
+ } else {
58
+ doc.removeEventListener("scroll", onMove, { capture: true });
59
+ win.removeEventListener("resize", onMove);
60
+ cancelFrames();
61
+ }
62
+ };
63
+ let frame = 0;
64
+ let again = false;
65
+ const cancelFrames = () => {
66
+ if (frame !== 0) win.cancelAnimationFrame(frame);
67
+ frame = 0;
68
+ again = false;
69
+ };
70
+ const readLater = () => {
71
+ if (frame !== 0) {
72
+ again = true;
73
+ return;
74
+ }
75
+ frame = win.requestAnimationFrame(() => {
76
+ read(true);
77
+ if (!listening) return;
78
+ frame = win.requestAnimationFrame(() => {
79
+ frame = 0;
80
+ read(true);
81
+ if (again && listening) {
82
+ again = false;
83
+ readLater();
84
+ }
85
+ });
86
+ });
87
+ };
88
+ const read = (urgent) => {
89
+ if (requested.current.side === null) {
90
+ listen(false);
91
+ write(null, urgent);
92
+ return;
93
+ }
94
+ if (element.isConnected && element.matches(":popover-open")) {
95
+ listen(true);
96
+ const style = getComputedStyle(element);
97
+ const placement = parsePositionArea(style.positionArea, toDirection(style.direction), () => toDirection(getComputedStyle(doc.documentElement).direction), style.writingMode || "horizontal-tb");
98
+ write(placement, urgent);
99
+ return;
100
+ }
101
+ listen(false);
102
+ if (written.current !== null && (!element.isConnected || element.getClientRects().length === 0)) write(null, urgent);
103
+ };
104
+ function onEvent() {
105
+ read(true);
106
+ }
107
+ function onMove() {
108
+ read(true);
109
+ if (listening) readLater();
110
+ }
111
+ sync.current = read;
112
+ const observer = typeof ResizeObserver === "function" ? new ResizeObserver(onEvent) : null;
113
+ observer?.observe(element);
114
+ element.addEventListener("toggle", onEvent);
115
+ return () => {
116
+ observer?.disconnect();
117
+ element.removeEventListener("toggle", onEvent);
118
+ listen(false);
119
+ if (sync.current === read) sync.current = null;
120
+ };
121
+ }, []);
122
+ useLayoutEffect(() => {
123
+ requested.current = {
124
+ side,
125
+ align
126
+ };
127
+ sync.current?.(false);
128
+ }, [side, align]);
129
+ if (side === null) return {
130
+ side: null,
131
+ align,
132
+ ref
133
+ };
134
+ return resolved === null ? {
135
+ side,
136
+ align,
137
+ ref
138
+ } : {
139
+ ...resolved,
140
+ ref
141
+ };
142
+ }
143
+ //#endregion
144
+ export { useResolvedPlacement };
145
+
146
+ //# sourceMappingURL=use-resolved-placement.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resolved-placement.mjs","names":[],"sources":["../../src/internal/use-resolved-placement.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { RefCallback } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { parsePositionArea } from \"./anchor-position.js\";\nimport type {\n AnchorAlign,\n AnchorSide,\n Direction,\n PhysicalSide,\n ResolvedPlacement,\n} from \"./anchor-position.js\";\n\nexport interface PlacementRequest<Side extends AnchorSide> {\n /** The requested side; `null` when the stylesheet owns placement (the hook is idle). */\n readonly side: Side | null;\n readonly align: AnchorAlign;\n}\n\nexport interface PlacementResult<Side extends AnchorSide> {\n /** The resolved physical side while the popup is shown, else the requested side. */\n readonly side: Side | PhysicalSide | null;\n /** The resolved alignment while shown, else the requested one. */\n readonly align: AnchorAlign;\n /** Merge into the popup element's ref. Stable. */\n readonly ref: RefCallback<HTMLElement>;\n}\n\nconst toDirection = (value: string): Direction => (value === \"rtl\" ? \"rtl\" : \"ltr\");\n\n/**\n * Where the browser actually placed an anchored popup (design/conventions.md 13.2): the\n * `position-try-fallbacks` option it applied, read from `getComputedStyle(popup).positionArea`\n * while the popup is shown and parsed into a physical side and an alignment. Observation, not\n * positioning: the browser keeps placing the popup; this only reports where.\n *\n * Sources: a `ResizeObserver` on the popup from mount (hidden to shown is a resize, delivered\n * after layout and before paint, so the first painted frame carries the resolved side), `toggle`\n * (and the jsdom shim's), and while shown `scroll` on the document (capture, passive: nested\n * scrollers too) and `resize` on the window, each read at once and again in the next two\n * animation frames (an engine applies the option a scroll calls for only in the layout after the\n * event). The write is urgent (`flushSync`, so the attribute lands before paint; conventions 3.5)\n * and happens only when the rendered pair would change: a popup with a physical `side` that opens\n * where it was asked costs no render (the state holds `null` then). A logical side\n * (`inline-start` / `inline-end`) costs one render on show and one on hide, because `data-side`\n * turns physical while shown. Hidden again resets to the requested values, once the popup no\n * longer renders (an exit animation keeps the resolved side to its end).\n *\n * Idle with `side: null` (a stylesheet's `@position-try` rules may set insets the parser cannot\n * interpret): no reads, the result's `side` is `null`. Runs whatever opened the popup, the\n * native `interestfor` and `commandfor` paths included.\n */\nexport function useResolvedPlacement<Side extends AnchorSide>(\n request: PlacementRequest<Side>,\n): PlacementResult<Side> {\n const { side, align } = request;\n const [resolved, setResolved] = useState<ResolvedPlacement | null>(null);\n // What the state holds (or is about to hold), so an unchanged read schedules nothing.\n const written = useRef<ResolvedPlacement | null>(null);\n // The request the element is rendered with (kept by the layout effect below).\n const requested = useRef<PlacementRequest<Side>>(request);\n // The mounted element's read, for the layout effect below.\n const sync = useRef<((urgent: boolean) => void) | null>(null);\n\n const ref = useCallback((element: HTMLElement | null) => {\n if (element === null) return;\n const doc = element.ownerDocument;\n const win = doc.defaultView ?? window;\n\n const write = (value: ResolvedPlacement | null, urgent: boolean) => {\n // Where it was asked to be: the requested values say so already, no state needed.\n const next =\n value !== null &&\n value.side === requested.current.side &&\n value.align === requested.current.align\n ? null\n : value;\n const previous = written.current;\n if (\n previous === next ||\n (previous !== null &&\n next !== null &&\n previous.side === next.side &&\n previous.align === next.align)\n ) {\n return;\n }\n written.current = next;\n if (urgent) flushSync(() => setResolved(next));\n else setResolved(next);\n };\n\n let listening = false;\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n if (on) {\n doc.addEventListener(\"scroll\", onMove, { capture: true, passive: true });\n win.addEventListener(\"resize\", onMove);\n } else {\n doc.removeEventListener(\"scroll\", onMove, { capture: true });\n win.removeEventListener(\"resize\", onMove);\n cancelFrames();\n }\n };\n\n // Both engines (Chromium 156, Firefox 157) apply the scroll-dependent anchoring state, the\n // option and the scroll-compensated geometry alike, in the layout of the frame after the\n // `scroll` event: a read in the handler, or in a rAF registered from it (which runs before\n // that layout), sees the old option even after a forced layout. The timing is unspecified\n // (css-anchor-position-1 §3.3 issue), so read again in the next two frames; a scroll that\n // arrives while that is pending restarts it at the end, so the last scroll is always followed.\n // Separately, Chromium 156 keeps an overflowing option for a top-layer popover once the first\n // frames after the show have passed (a bug, §6.5; upstream item #92): then no frame reads a\n // new option, and `data-side` correctly keeps reporting the applied one. Do not drop the\n // frame reads \"because Chromium does not re-choose\": when it does, it lags like Firefox.\n let frame = 0;\n let again = false;\n const cancelFrames = () => {\n if (frame !== 0) win.cancelAnimationFrame(frame);\n frame = 0;\n again = false;\n };\n const readLater = () => {\n if (frame !== 0) {\n again = true;\n return;\n }\n frame = win.requestAnimationFrame(() => {\n read(true);\n // The popup was found hidden (or `side` turned null): `listen(false)` ended the pair.\n if (!listening) return;\n frame = win.requestAnimationFrame(() => {\n frame = 0;\n read(true);\n if (again && listening) {\n again = false;\n readLater();\n }\n });\n });\n };\n\n const read = (urgent: boolean) => {\n if (requested.current.side === null) {\n listen(false);\n write(null, urgent);\n return;\n }\n if (element.isConnected && element.matches(\":popover-open\")) {\n listen(true);\n const style = getComputedStyle(element);\n const placement = parsePositionArea(\n style.positionArea,\n toDirection(style.direction),\n () => toDirection(getComputedStyle(doc.documentElement).direction),\n style.writingMode || \"horizontal-tb\",\n );\n write(placement, urgent);\n return;\n }\n listen(false);\n // Hidden, but still rendered while an exit animation runs: keep the resolved side to the\n // end of it. The ResizeObserver sees the box go and resets then.\n // Nothing written, nothing to reset: skip the forced layout (every mount and request change\n // of a hidden popup comes through here).\n if (\n written.current !== null &&\n (!element.isConnected || element.getClientRects().length === 0)\n ) {\n write(null, urgent);\n }\n };\n\n function onEvent() {\n read(true);\n }\n function onMove() {\n // In every Chromium 156 / Firefox 157 probe this read still saw the old option (see the\n // frame reads above); kept as cover for WebKit, which was not probed, at the cost of one\n // style read per scroll event.\n read(true);\n if (listening) readLater();\n }\n\n sync.current = read;\n const observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(onEvent) : null;\n observer?.observe(element);\n element.addEventListener(\"toggle\", onEvent);\n return () => {\n observer?.disconnect();\n element.removeEventListener(\"toggle\", onEvent);\n listen(false);\n if (sync.current === read) sync.current = null;\n };\n }, []);\n\n // A changed request while shown places the popup differently: read again (a layout effect, so\n // the corrected attribute is in the same frame). Also how `side={null}` turns the hook off.\n useLayoutEffect(() => {\n requested.current = { side, align };\n sync.current?.(false);\n }, [side, align]);\n\n if (side === null) return { side: null, align, ref };\n return resolved === null ? { side, align, ref } : { ...resolved, ref };\n}\n"],"mappings":";;;;;AA4BA,MAAM,eAAe,UAA8B,UAAU,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;AAwB7E,SAAgB,qBACd,SACuB;CACvB,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,CAAC,UAAU,eAAe,SAAmC,IAAI;CAEvE,MAAM,UAAU,OAAiC,IAAI;CAErD,MAAM,YAAY,OAA+B,OAAO;CAExD,MAAM,OAAO,OAA2C,IAAI;CAE5D,MAAM,MAAM,aAAa,YAAgC;EACvD,IAAI,YAAY,MAAM;EACtB,MAAM,MAAM,QAAQ;EACpB,MAAM,MAAM,IAAI,eAAe;EAE/B,MAAM,SAAS,OAAiC,WAAoB;GAElE,MAAM,OACJ,UAAU,QACV,MAAM,SAAS,UAAU,QAAQ,QACjC,MAAM,UAAU,UAAU,QAAQ,QAC9B,OACA;GACN,MAAM,WAAW,QAAQ;GACzB,IACE,aAAa,QACZ,aAAa,QACZ,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AM,WAAW,MAAM;IACvB;GACF;GACA,OAAO,KAAK;GAKZ,IACE,QAAQ,YAAY,SACnB,CAAC,QAAQ,eAAe,QAAQ,eAAe,CAAC,CAAC,WAAW,IAE7D,MAAM,MAAM,MAAM;EAEtB;EAEA,SAAS,UAAU;GACjB,KAAK,IAAI;EACX;EACA,SAAS,SAAS;GAIhB,KAAK,IAAI;GACT,IAAI,WAAW,UAAU;EAC3B;EAEA,KAAK,UAAU;EACf,MAAM,WAAW,OAAO,mBAAmB,aAAa,IAAI,eAAe,OAAO,IAAI;EACtF,UAAU,QAAQ,OAAO;EACzB,QAAQ,iBAAiB,UAAU,OAAO;EAC1C,aAAa;GACX,UAAU,WAAW;GACrB,QAAQ,oBAAoB,UAAU,OAAO;GAC7C,OAAO,KAAK;GACZ,IAAI,KAAK,YAAY,MAAM,KAAK,UAAU;EAC5C;CACF,GAAG,CAAC,CAAC;CAIL,sBAAsB;EACpB,UAAU,UAAU;GAAE;GAAM;EAAM;EAClC,KAAK,UAAU,KAAK;CACtB,GAAG,CAAC,MAAM,KAAK,CAAC;CAEhB,IAAI,SAAS,MAAM,OAAO;EAAE,MAAM;EAAM;EAAO;CAAI;CACnD,OAAO,aAAa,OAAO;EAAE;EAAM;EAAO;CAAI,IAAI;EAAE,GAAG;EAAU;CAAI;AACvE"}
@@ -1 +1 @@
1
- {"version":3,"file":"menu-context-trigger.d.mts","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"mappings":";;;iBAuBiB;;WAEN;;WAEA;WACA;;iBAGM,gCAAgC,KAC/C;;EAWA;;;;;;EAMA;;EAEA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;wBA6BpC,qBACd,UACA,iBACA,gBACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBATV"}
1
+ {"version":3,"file":"menu-context-trigger.d.mts","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"mappings":";;;iBAwBiB;;WAEN;;WAEA;WACA;;iBAGM,gCAAgC,KAC/C;;EAWA;;;;;;EAMA;;EAEA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;wBAiNpC,qBACd,UACA,iBACA,gBACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBATV"}
@@ -3,14 +3,153 @@ import { dataAttr } from "../internal/data-attr.mjs";
3
3
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
4
4
  import { resolveStateValue } from "../internal/render-element.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
- import { MenuRegionContext, claimPress, isPressClaimed, markHandled, useMenuContext } from "./menu-context.mjs";
7
- import { capturePointer, isEditableTarget } from "./menu-dom.mjs";
6
+ import { MenuRegionContext, claimPress, isPressClaimed, markHandled, submenuHover, useMenuContext } from "./menu-context.mjs";
7
+ import { capturePointer, isDisabledItem, isEditableTarget } from "./menu-dom.mjs";
8
8
  import { useCallback, useEffect, useRef } from "react";
9
9
  import { jsx } from "react/jsx-runtime";
10
10
  //#region src/menu/menu-context-trigger.tsx
11
- /** Movement that cancels a long-press (Base UI's slop). */
11
+ /** Movement that cancels a long-press (Base UI's slop); also a touch drag's activation slop. */
12
12
  const LONG_PRESS_SLOP = 10;
13
+ /**
14
+ * Movement a mouse or pen press-drag-release needs before a release activates or dismisses
15
+ * (Chromium's `kMaximumLengthMovedToActivate`, macOS's "moved"; context-menu.md 2.6).
16
+ */
17
+ const DRAG_SLOP = 4;
18
+ /** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */
19
+ const DRAG_DISMISS_DELAY = 500;
13
20
  const isDev = process.env.NODE_ENV !== "production";
21
+ const isTouchLike = (pointerType) => pointerType === "touch" || pointerType === "pen";
22
+ /**
23
+ * Press-drag-release (context-menu.md 2.6): while the popup holds the capture of `pointerId`
24
+ * (taken at the open), every `pointermove` and the `pointerup` target the popup and items never
25
+ * see boundary events, so the gesture hit-tests with `elementFromPoint`. A move focuses the item
26
+ * under the pointer quietly (a SubmenuTrigger also starts its hover intent); a release more than
27
+ * the slop away from the open point activates an enabled, non-submenu item through its
28
+ * `click()` (Menu's one activation path), or dismisses the menu when it lands outside every popup
29
+ * of the tree at least 500 ms after the open; any other release leaves the menu open. Ends at the
30
+ * release, `pointercancel`, `lostpointercapture` and the menu closing. Returns the cleanup.
31
+ *
32
+ * The 500 ms count from when the popup is shown, not from the press: with an async
33
+ * `openChangeAction` or suspending items the menu appears only when they settle (review M2). A
34
+ * gesture that starts on a popup already showing (a move) counts from its start.
35
+ */
36
+ function startDrag(popup, options) {
37
+ const doc = popup.ownerDocument;
38
+ let shownAt = popup.matches(":popover-open") ? performance.now() : null;
39
+ let submenuTrigger = null;
40
+ const ours = (event) => event.pointerId === options.pointerId;
41
+ const hitTest = (event) => typeof doc.elementFromPoint === "function" ? doc.elementFromPoint(event.clientX, event.clientY) : null;
42
+ /** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */
43
+ const itemAt = (target) => {
44
+ const item = target?.closest("[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]") ?? null;
45
+ return item !== null && popup.contains(item) ? item : null;
46
+ };
47
+ /** The pointer is over the submenu `trigger` opens (its popup is the `commandfor` target). */
48
+ const inSubmenuOf = (trigger, target) => {
49
+ const id = trigger.getAttribute("commandfor");
50
+ const submenu = id === null ? null : doc.getElementById(id);
51
+ return submenu !== null && target !== null && submenu.contains(target);
52
+ };
53
+ const hoverSubmenu = (next, event) => {
54
+ if (next === submenuTrigger) return;
55
+ if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);
56
+ submenuTrigger = next;
57
+ if (next !== null) submenuHover(next)?.enter(event);
58
+ };
59
+ const onMove = (event) => {
60
+ if (!ours(event)) return;
61
+ const target = hitTest(event);
62
+ const item = itemAt(target);
63
+ if (item !== null && doc.activeElement !== item) item.focus({ focusVisible: false });
64
+ if (item !== null && submenuHover(item) !== void 0) hoverSubmenu(item, event);
65
+ else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) hoverSubmenu(null, event);
66
+ };
67
+ const onUp = (event) => {
68
+ if (!ours(event)) return;
69
+ end();
70
+ if (!(Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop)) return;
71
+ const target = hitTest(event);
72
+ if (target !== null && popup.contains(target)) {
73
+ const item = itemAt(target);
74
+ if (item === null || isDisabledItem(item) || item.hasAttribute("aria-haspopup")) return;
75
+ options.activate(item);
76
+ return;
77
+ }
78
+ if (shownAt !== null && performance.now() - shownAt >= DRAG_DISMISS_DELAY && popup.matches(":popover-open")) popup.hidePopover();
79
+ };
80
+ const onEnd = (event) => {
81
+ if (ours(event)) end();
82
+ };
83
+ const onToggle = () => {
84
+ if (!popup.matches(":popover-open")) end();
85
+ else shownAt ??= performance.now();
86
+ };
87
+ const end = () => {
88
+ popup.removeEventListener("pointermove", onMove);
89
+ popup.removeEventListener("pointerup", onUp);
90
+ popup.removeEventListener("pointercancel", onEnd);
91
+ popup.removeEventListener("lostpointercapture", onEnd);
92
+ popup.removeEventListener("toggle", onToggle);
93
+ submenuTrigger = null;
94
+ };
95
+ popup.addEventListener("pointermove", onMove);
96
+ popup.addEventListener("pointerup", onUp);
97
+ popup.addEventListener("pointercancel", onEnd);
98
+ popup.addEventListener("lostpointercapture", onEnd);
99
+ popup.addEventListener("toggle", onToggle);
100
+ return end;
101
+ }
102
+ /** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */
103
+ const TOUCH_END_WAIT = 250;
104
+ /**
105
+ * While the finger that opened a touch menu is still down, the browser must not take its drag
106
+ * as a pan (it would end the stream with `pointercancel`): a non-passive document `touchmove`
107
+ * listener prevents it (context-menu.md 2.2). The lift's `touchend`, which follows that
108
+ * pointer's `pointerup`, is prevented as well, so the engine synthesises no click from it: a click
109
+ * where the finger was (beside the offset menu) would light-dismiss the menu in Chromium, and one
110
+ * over an item would activate it a second time. Ends at that `touchend` / `touchcancel`, at the
111
+ * pointer's `pointercancel`, and shortly after its `pointerup` if no touch event follows (a
112
+ * synthetic pointer). Returns the cleanup.
113
+ *
114
+ * Only the gesture finger's lift ends it (review L4): another finger lifting while it is still
115
+ * down must not hand its next slide to panning. Pointer events expose no `Touch.identifier`, so
116
+ * the lift is recognised by order: the engines dispatch a lift's `pointerup` and `touchend` from
117
+ * the same input, the `pointerup` first. A `touchend` before that pointer's `pointerup` is another
118
+ * finger's; it is still prevented (no click may light-dismiss the menu mid-gesture).
119
+ */
120
+ function guardTouch(doc, pointerId) {
121
+ let fallback;
122
+ let lifted = false;
123
+ const onTouchMove = (event) => {
124
+ if (event.cancelable) event.preventDefault();
125
+ };
126
+ const onTouchEnd = (event) => {
127
+ if (event.cancelable) event.preventDefault();
128
+ if (lifted) end();
129
+ };
130
+ const onPointerUp = (event) => {
131
+ if (event.pointerId !== pointerId) return;
132
+ lifted = true;
133
+ fallback ??= setTimeout(end, TOUCH_END_WAIT);
134
+ };
135
+ const onPointerCancel = (event) => {
136
+ if (event.pointerId === pointerId) end();
137
+ };
138
+ const end = () => {
139
+ if (fallback !== void 0) clearTimeout(fallback);
140
+ doc.removeEventListener("touchmove", onTouchMove);
141
+ doc.removeEventListener("touchend", onTouchEnd);
142
+ doc.removeEventListener("touchcancel", end, true);
143
+ doc.removeEventListener("pointerup", onPointerUp, true);
144
+ doc.removeEventListener("pointercancel", onPointerCancel, true);
145
+ };
146
+ doc.addEventListener("touchmove", onTouchMove, { passive: false });
147
+ doc.addEventListener("touchend", onTouchEnd, { passive: false });
148
+ doc.addEventListener("touchcancel", end, true);
149
+ doc.addEventListener("pointerup", onPointerUp, true);
150
+ doc.addEventListener("pointercancel", onPointerCancel, true);
151
+ return end;
152
+ }
14
153
  /**
15
154
  * A region whose `contextmenu` (right-click, Ctrl+click, Shift+F10 / the ContextMenu key at a
16
155
  * focused descendant) or touch / pen long-press opens the Root's `Menu.Popup` at the pointer
@@ -35,22 +174,30 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
35
174
  const lastKeyDown = useRef(-1);
36
175
  const longPress = useRef(null);
37
176
  const disarmSwallow = useRef(null);
177
+ const endDrag = useRef(null);
38
178
  const warnedNoPopup = useRef(false);
39
179
  const cancelLongPress = useCallback(() => {
40
180
  if (longPress.current !== null) clearTimeout(longPress.current.timer);
41
181
  longPress.current = null;
42
182
  }, []);
183
+ const stopDrag = useCallback(() => {
184
+ endDrag.current?.();
185
+ endDrag.current = null;
186
+ }, []);
43
187
  useEffect(() => () => {
44
188
  cancelLongPress();
189
+ stopDrag();
45
190
  disarmSwallow.current?.();
46
- }, [cancelLongPress]);
191
+ }, [cancelLongPress, stopDrag]);
47
192
  useEffect(() => {
48
193
  if (disabled) cancelLongPress();
49
194
  }, [disabled, cancelLongPress]);
50
195
  const open = popover.optimistic;
51
196
  useEffect(() => {
52
- if (!open) disarmSwallow.current?.();
53
- }, [open]);
197
+ if (open) return;
198
+ disarmSwallow.current?.();
199
+ stopDrag();
200
+ }, [open, stopDrag]);
54
201
  const modalityRef = useCallback((element) => {
55
202
  const onKeyDown = () => {
56
203
  lastKeyDown.current = ++sequence.current;
@@ -82,7 +229,7 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
82
229
  * after a long-press; a swallow left armed would eat the next keyboard activation
83
230
  * (`element.click()`).
84
231
  */
85
- const armClickSwallow = (doc, pointerId) => {
232
+ const armClickSwallow = (doc, pointerId, releasing = false) => {
86
233
  disarmSwallow.current?.();
87
234
  let released;
88
235
  const onClick = (event) => {
@@ -109,6 +256,31 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
109
256
  doc.addEventListener("pointerup", onRelease, true);
110
257
  doc.addEventListener("pointercancel", onRelease, true);
111
258
  disarmSwallow.current = disarm;
259
+ if (releasing) released = setTimeout(disarm, 0);
260
+ };
261
+ /**
262
+ * Starts the press-drag-release gesture of 2.6 on the pointer the popup captured at this open
263
+ * or move (a new one replaces the running one), with the touch guard for a finger.
264
+ */
265
+ const beginDrag = (popup, pointerId, point, pointerType, slop) => {
266
+ stopDrag();
267
+ const doc = popup.ownerDocument;
268
+ const end = startDrag(popup, {
269
+ pointerId,
270
+ x: point.x,
271
+ y: point.y,
272
+ slop,
273
+ activate: (item) => {
274
+ disarmSwallow.current?.();
275
+ item.click();
276
+ armClickSwallow(doc, pointerId, true);
277
+ }
278
+ });
279
+ const unguard = pointerType === "touch" ? guardTouch(doc, pointerId) : null;
280
+ endDrag.current = () => {
281
+ end();
282
+ unguard?.();
283
+ };
112
284
  };
113
285
  /**
114
286
  * The event comes from this Root's own popup, rendered inside the region (a table row, where a
@@ -126,19 +298,23 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
126
298
  if (popup === null) return;
127
299
  native.preventDefault();
128
300
  markHandled(native, menu);
301
+ const timed = longPress.current;
129
302
  cancelLongPress();
130
303
  const keyboard = native.button === -1 || lastKeyDown.current > lastPointerDown.current;
131
- const pointerId = native.pointerId;
132
- const id = typeof pointerId === "number" ? pointerId : void 0;
133
- if (native.buttons !== 0) capturePointer(popup, id);
134
- menu.openAt({
304
+ const pointerEvent = native;
305
+ const pointerType = timed?.pointerType ?? (typeof pointerEvent.pointerType === "string" ? pointerEvent.pointerType : "mouse");
306
+ const pointerId = native.buttons !== 0 && typeof pointerEvent.pointerId === "number" ? pointerEvent.pointerId : timed?.pointerId ?? void 0;
307
+ const point = {
135
308
  x: native.clientX,
136
309
  y: native.clientY
137
- }, {
310
+ };
311
+ if (pointerId !== void 0 && capturePointer(popup, pointerId)) beginDrag(popup, pointerId, point, pointerType, timed !== null || pointerType === "touch" ? LONG_PRESS_SLOP : DRAG_SLOP);
312
+ menu.openAt(point, {
138
313
  source: event.currentTarget,
139
314
  event: native,
140
315
  pointer: !keyboard,
141
- pointerId: id
316
+ pointerId,
317
+ offset: !keyboard && isTouchLike(pointerType)
142
318
  });
143
319
  };
144
320
  const onPointerDown = (event) => {
@@ -153,25 +329,28 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
153
329
  if (editableTargets === "native" && isEditableTarget(native.target)) return;
154
330
  claimPress(native);
155
331
  const source = event.currentTarget;
156
- const { pointerId, clientX, clientY } = native;
332
+ const { pointerId, pointerType, clientX, clientY } = native;
157
333
  const timer = setTimeout(() => {
158
334
  longPress.current = null;
159
335
  const popup = popupElement();
160
336
  if (popup === null) return;
161
- capturePointer(popup, pointerId);
162
- armClickSwallow(source.ownerDocument, pointerId);
163
- menu.openAt({
337
+ const point = {
164
338
  x: clientX,
165
339
  y: clientY
166
- }, {
340
+ };
341
+ if (capturePointer(popup, pointerId)) beginDrag(popup, pointerId, point, pointerType, LONG_PRESS_SLOP);
342
+ armClickSwallow(source.ownerDocument, pointerId);
343
+ menu.openAt(point, {
167
344
  source,
168
345
  event: native,
169
346
  pointer: true,
170
- pointerId
347
+ pointerId,
348
+ offset: true
171
349
  });
172
350
  }, Math.max(0, longPressDelay));
173
351
  longPress.current = {
174
352
  pointerId,
353
+ pointerType,
175
354
  x: clientX,
176
355
  y: clientY,
177
356
  timer
@@ -1 +1 @@
1
- {"version":3,"file":"menu-context-trigger.mjs","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport {\n claimPress,\n isPressClaimed,\n markHandled,\n MenuRegionContext,\n useMenuContext,\n} from \"./menu-context.js\";\nimport { capturePointer, isEditableTarget } from \"./menu-dom.js\";\n\nexport interface MenuContextTriggerState {\n /** Optimistic open state (the Root's). */\n readonly open: boolean;\n /** The Root's transition is pending (an open or a close in flight). */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface MenuContextTriggerProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"onContextMenu\"\n | \"onPointerDown\"\n | \"onPointerMove\"\n | \"onPointerUp\"\n | \"onPointerCancel\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The region does nothing; a `contextmenu` bubbles on to an outer region. `data-disabled`. */\n disabled?: boolean;\n /**\n * What a `contextmenu` (or long-press) on an editable target inside the region opens: the\n * browser's own menu (`\"native\"`, default: copy and paste keep working) or this menu.\n * Editable: a text-taking `<input>`, a `<textarea>`, an element with `isContentEditable`.\n */\n editableTargets?: \"native\" | \"menu\";\n /** Milliseconds a touch or pen pointer must stay down (within 10 px) to open. Default 500. */\n longPressDelay?: number;\n className?: StateValue<string | undefined, MenuContextTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuContextTriggerState>;\n children?: StateValue<ReactNode, MenuContextTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>;\n}\n\n/** Movement that cancels a long-press (Base UI's slop). */\nconst LONG_PRESS_SLOP = 10;\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\ninterface LongPress {\n readonly pointerId: number;\n readonly x: number;\n readonly y: number;\n readonly timer: ReturnType<typeof setTimeout>;\n}\n\n/**\n * A region whose `contextmenu` (right-click, Ctrl+click, Shift+F10 / the ContextMenu key at a\n * focused descendant) or touch / pen long-press opens the Root's `Menu.Popup` at the pointer\n * (design/components/context-menu.md). A plain element (default `div`) with no role and no ARIA:\n * the region keeps its own semantics (`render={<tr />}`), and keyboard users reach it through\n * focusable content inside it. A second right-click inside the region while the menu is open moves\n * the menu there. Render the `Menu.Popup` as a sibling of the region where the markup allows; in\n * a table row (`render={<tr />}`), inside one of its cells: events from inside the popup are\n * never the region's.\n *\n * Owned keys (conventions 1.2): `onContextMenu`, `onPointerDown`, `onPointerMove`,\n * `onPointerUp`, `onPointerCancel`, `data-open`, `data-pending`, `data-disabled`, and the style\n * key `WebkitTouchCallout` (`\"none\"`; the consumer's `style` wins).\n */\nexport function MenuContextTrigger({\n disabled = false,\n editableTargets = \"native\",\n longPressDelay = 500,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuContextTriggerProps) {\n const menu = useMenuContext(\"Menu.ContextTrigger\");\n const { popover } = menu;\n useDevWarning(\n menu.submenu,\n \"Menu.ContextTrigger: rendered in a submenu. A Menu.Root inside a Menu.Popup is a submenu; a \" +\n \"context menu region belongs to a top-level Menu.Root.\",\n );\n useDevWarning(\n longPressDelay < 0,\n \"Menu.ContextTrigger: `longPressDelay` is negative; it is a number of milliseconds.\",\n );\n\n // Modality bookkeeping (design 2.1): a sequence number, not a clock, so two events in the same\n // millisecond still order.\n const sequence = useRef(0);\n const lastPointerDown = useRef(-1);\n const lastKeyDown = useRef(-1);\n const longPress = useRef<LongPress | null>(null);\n // Disarms the one-shot click swallow armed by a long-press open.\n const disarmSwallow = useRef<(() => void) | null>(null);\n const warnedNoPopup = useRef(false);\n\n const cancelLongPress = useCallback(() => {\n if (longPress.current !== null) clearTimeout(longPress.current.timer);\n longPress.current = null;\n }, []);\n\n useEffect(\n () => () => {\n cancelLongPress();\n disarmSwallow.current?.();\n },\n [cancelLongPress],\n );\n // A region disabled mid-gesture opens nothing.\n useEffect(() => {\n if (disabled) cancelLongPress();\n }, [disabled, cancelLongPress]);\n\n // A close ends any armed click swallow (review H1).\n const open = popover.optimistic;\n useEffect(() => {\n if (!open) disarmSwallow.current?.();\n }, [open]);\n\n // The modality bookkeeping observes `keydown` and `pointerdown` without owning them (the region\n // is full of the consumer's interactive content), in the capture phase, so a descendant's\n // `stopPropagation()` (a slider, a drag handle) does not hide them (review L2).\n const modalityRef = useCallback((element: HTMLElement) => {\n const onKeyDown = () => {\n lastKeyDown.current = ++sequence.current;\n };\n const onPointerDown = () => {\n lastPointerDown.current = ++sequence.current;\n };\n element.addEventListener(\"keydown\", onKeyDown, true);\n element.addEventListener(\"pointerdown\", onPointerDown, true);\n return () => {\n element.removeEventListener(\"keydown\", onKeyDown, true);\n element.removeEventListener(\"pointerdown\", onPointerDown, true);\n };\n }, []);\n\n /** The popup element to capture on and open, or `null` (no Popup mounted: nothing opens). */\n const popupElement = (): HTMLElement | null => {\n const popup = popover.popupRef.current;\n if (popup === null && isDev && !warnedNoPopup.current) {\n warnedNoPopup.current = true;\n console.error(\n \"Menu.ContextTrigger: a context menu was requested but the Menu.Root has no mounted \" +\n \"Menu.Popup; the browser's own menu shows instead.\",\n );\n }\n return popup;\n };\n\n /**\n * One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),\n * scoped to that release (review H1): the click comes in the same task as the `pointerup` of\n * `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at\n * once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click\n * after a long-press; a swallow left armed would eat the next keyboard activation\n * (`element.click()`).\n */\n const armClickSwallow = (doc: Document, pointerId: number) => {\n disarmSwallow.current?.();\n let released: ReturnType<typeof setTimeout> | undefined;\n const onClick = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n disarm();\n };\n const onRelease = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n if (released === undefined) released = setTimeout(disarm, 0);\n };\n const disarm = () => {\n if (released !== undefined) clearTimeout(released);\n doc.removeEventListener(\"click\", onClick, true);\n doc.removeEventListener(\"pointerdown\", disarm, true);\n doc.removeEventListener(\"keydown\", disarm, true);\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n if (disarmSwallow.current === disarm) disarmSwallow.current = null;\n };\n doc.addEventListener(\"click\", onClick, true);\n doc.addEventListener(\"pointerdown\", disarm, true);\n doc.addEventListener(\"keydown\", disarm, true);\n doc.addEventListener(\"pointerup\", onRelease, true);\n doc.addEventListener(\"pointercancel\", onRelease, true);\n disarmSwallow.current = disarm;\n };\n\n /**\n * The event comes from this Root's own popup, rendered inside the region (a table row, where a\n * `<div>` cannot be a sibling of the `<tr>`): never a move or a long-press of the region.\n */\n const fromOwnPopup = (target: EventTarget | null): boolean => {\n const popup = popover.popupRef.current;\n return popup !== null && target instanceof Node && popup.contains(target);\n };\n\n const onContextMenu = (event: MouseEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n // An inner region or a consumer handler was first (the Popup's own handler prevents a\n // right-click inside the menu); a disabled region lets the event bubble on to an outer\n // region (design 2.4).\n if (native.defaultPrevented || disabled || fromOwnPopup(native.target)) return;\n // Copy and paste keep the browser's menu (2.3).\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n const popup = popupElement();\n if (popup === null) return;\n native.preventDefault();\n markHandled(native, menu);\n // Android and pen: the platform's own `contextmenu` arrived during our timer; it opens.\n cancelLongPress();\n const keyboard = native.button === -1 || lastKeyDown.current > lastPointerDown.current;\n const pointerId = (native as globalThis.PointerEvent).pointerId;\n const id = typeof pointerId === \"number\" ? pointerId : undefined;\n // whatwg/html#10905: in Firefox and WebKit the pending `pointerup` would light-dismiss a\n // menu opened between `pointerdown` and `pointerup`. Capture now, on the still-hidden popup:\n // the open commit lands at an unpredictable time relative to the `pointerup`.\n if (native.buttons !== 0) capturePointer(popup, id);\n menu.openAt(\n { x: native.clientX, y: native.clientY },\n { source: event.currentTarget, event: native, pointer: !keyboard, pointerId: id },\n );\n };\n\n // The long-press only; the modality bookkeeping is `modalityRef`'s.\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n if (longPress.current !== null) {\n // A second finger: not a long-press.\n cancelLongPress();\n return;\n }\n if (disabled || (native.pointerType !== \"touch\" && native.pointerType !== \"pen\")) return;\n // A press inside any Menu.Popup (this Root's, or another menu inside the region) is claimed by\n // that popup; a press an inner region already times is claimed by it.\n if (fromOwnPopup(native.target)) return;\n if (!native.isPrimary || isPressClaimed(native)) return;\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n // The innermost enabled region times the press; outer regions leave it (as `contextmenu`'s\n // `defaultPrevented` rule, design 2.4).\n claimPress(native);\n const source = event.currentTarget;\n const { pointerId, clientX, clientY } = native;\n const timer = setTimeout(\n () => {\n longPress.current = null;\n const popup = popupElement();\n if (popup === null) return;\n // The finger is still down: its `pointerup` would light-dismiss in WebKit.\n capturePointer(popup, pointerId);\n armClickSwallow(source.ownerDocument, pointerId);\n menu.openAt(\n { x: clientX, y: clientY },\n { source, event: native, pointer: true, pointerId },\n );\n },\n Math.max(0, longPressDelay),\n );\n longPress.current = { pointerId, x: clientX, y: clientY, timer };\n };\n\n const onPointerMove = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press === null || event.pointerId !== press.pointerId) return;\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > LONG_PRESS_SLOP) {\n cancelLongPress();\n }\n };\n\n // `pointercancel`: the browser took the gesture for panning (the region stays scrollable).\n const onPointerEnd = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press !== null && event.pointerId === press.pointerId) cancelLongPress();\n };\n\n const state: MenuContextTriggerState = {\n open: popover.optimistic,\n pending: popover.pending,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n onContextMenu,\n onPointerDown,\n onPointerMove,\n onPointerUp: onPointerEnd,\n onPointerCancel: onPointerEnd,\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // iOS link and image previews appear at about the long-press time (2.2).\n style: (s) => ({ WebkitTouchCallout: \"none\", ...resolveStateValue(style, s) }),\n // A Menu.Root inside is a nested region's menu (no \"outside its Popup\" warning).\n children: (s) => (\n <MenuRegionContext value={true}>{resolveStateValue(children, s)}</MenuRegionContext>\n ),\n props: rest,\n libraryProps,\n ref: modalityRef,\n });\n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,GAAG;GAAS,GAAG;GAAS;EAAM;CACjE;CAEA,MAAM,iBAAiB,UAAqC;EAC1D,MAAM,QAAQ,UAAU;EACxB,IAAI,UAAU,QAAQ,MAAM,cAAc,MAAM,WAAW;EAC3D,IAAI,KAAK,MAAM,MAAM,UAAU,MAAM,GAAG,MAAM,UAAU,MAAM,CAAC,IAAI,iBACjE,gBAAgB;CAEpB;CAGA,MAAM,gBAAgB,UAAqC;EACzD,MAAM,QAAQ,UAAU;EACxB,IAAI,UAAU,QAAQ,MAAM,cAAc,MAAM,WAAW,gBAAgB;CAC7E;CAEA,MAAM,QAAiC;EACrC,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;CACF;CAEA,MAAM,eAA8D;EAClE;EACA;EACA;EACA,aAAa;EACb,iBAAiB;EACjB,aAAa,SAAS,MAAM,IAAI;EAChC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAAiE;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,QAAQ,OAAO;GAAE,oBAAoB;GAAQ,GAAG,kBAAkB,OAAO,CAAC;EAAE;EAE5E,WAAW,MACT,oBAAC,mBAAD;GAAmB,OAAO;GAAO,UAAA,kBAAkB,UAAU,CAAC;EAAqB,CAAA;EAErF,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,mBAAmB,cAAc"}
1
+ {"version":3,"file":"menu-context-trigger.mjs","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport {\n claimPress,\n isPressClaimed,\n markHandled,\n MenuRegionContext,\n submenuHover,\n useMenuContext,\n} from \"./menu-context.js\";\nimport { capturePointer, isDisabledItem, isEditableTarget, ITEM_SELECTOR } from \"./menu-dom.js\";\n\nexport interface MenuContextTriggerState {\n /** Optimistic open state (the Root's). */\n readonly open: boolean;\n /** The Root's transition is pending (an open or a close in flight). */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface MenuContextTriggerProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"onContextMenu\"\n | \"onPointerDown\"\n | \"onPointerMove\"\n | \"onPointerUp\"\n | \"onPointerCancel\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The region does nothing; a `contextmenu` bubbles on to an outer region. `data-disabled`. */\n disabled?: boolean;\n /**\n * What a `contextmenu` (or long-press) on an editable target inside the region opens: the\n * browser's own menu (`\"native\"`, default: copy and paste keep working) or this menu.\n * Editable: a text-taking `<input>`, a `<textarea>`, an element with `isContentEditable`.\n */\n editableTargets?: \"native\" | \"menu\";\n /** Milliseconds a touch or pen pointer must stay down (within 10 px) to open. Default 500. */\n longPressDelay?: number;\n className?: StateValue<string | undefined, MenuContextTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuContextTriggerState>;\n children?: StateValue<ReactNode, MenuContextTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>;\n}\n\n/** Movement that cancels a long-press (Base UI's slop); also a touch drag's activation slop. */\nconst LONG_PRESS_SLOP = 10;\n/**\n * Movement a mouse or pen press-drag-release needs before a release activates or dismisses\n * (Chromium's `kMaximumLengthMovedToActivate`, macOS's \"moved\"; context-menu.md 2.6).\n */\nconst DRAG_SLOP = 4;\n/** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */\nconst DRAG_DISMISS_DELAY = 500;\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\ninterface LongPress {\n readonly pointerId: number;\n readonly pointerType: string;\n readonly x: number;\n readonly y: number;\n readonly timer: ReturnType<typeof setTimeout>;\n}\n\ninterface DragOptions {\n readonly pointerId: number;\n /** The open point: the slop is measured from it. */\n readonly x: number;\n readonly y: number;\n readonly slop: number;\n /**\n * Activates `item` for a release: through `item.click()`, with the click swallow of a long-press\n * out of the way and armed again for the click an engine may synthesise from this release.\n */\n readonly activate: (item: HTMLElement) => void;\n}\n\nconst isTouchLike = (pointerType: string) => pointerType === \"touch\" || pointerType === \"pen\";\n\n/**\n * Press-drag-release (context-menu.md 2.6): while the popup holds the capture of `pointerId`\n * (taken at the open), every `pointermove` and the `pointerup` target the popup and items never\n * see boundary events, so the gesture hit-tests with `elementFromPoint`. A move focuses the item\n * under the pointer quietly (a SubmenuTrigger also starts its hover intent); a release more than\n * the slop away from the open point activates an enabled, non-submenu item through its\n * `click()` (Menu's one activation path), or dismisses the menu when it lands outside every popup\n * of the tree at least 500 ms after the open; any other release leaves the menu open. Ends at the\n * release, `pointercancel`, `lostpointercapture` and the menu closing. Returns the cleanup.\n *\n * The 500 ms count from when the popup is shown, not from the press: with an async\n * `openChangeAction` or suspending items the menu appears only when they settle (review M2). A\n * gesture that starts on a popup already showing (a move) counts from its start.\n */\nfunction startDrag(popup: HTMLElement, options: DragOptions): () => void {\n const doc = popup.ownerDocument;\n // `performance.now()` at the first open `toggle`; null until the popup has been shown.\n let shownAt: number | null = popup.matches(\":popover-open\") ? performance.now() : null;\n // The SubmenuTrigger the pointer is over, whose hover intent is running.\n let submenuTrigger: HTMLElement | null = null;\n\n const ours = (event: Event) => (event as globalThis.PointerEvent).pointerId === options.pointerId;\n const hitTest = (event: globalThis.PointerEvent): Element | null =>\n typeof doc.elementFromPoint === \"function\"\n ? doc.elementFromPoint(event.clientX, event.clientY)\n : null;\n /** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */\n const itemAt = (target: Element | null): HTMLElement | null => {\n const item = target?.closest<HTMLElement>(ITEM_SELECTOR) ?? null;\n return item !== null && popup.contains(item) ? item : null;\n };\n /** The pointer is over the submenu `trigger` opens (its popup is the `commandfor` target). */\n const inSubmenuOf = (trigger: HTMLElement, target: Element | null) => {\n const id = trigger.getAttribute(\"commandfor\");\n const submenu = id === null ? null : doc.getElementById(id);\n return submenu !== null && target !== null && submenu.contains(target);\n };\n const hoverSubmenu = (next: HTMLElement | null, event: Event) => {\n if (next === submenuTrigger) return;\n if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);\n submenuTrigger = next;\n if (next !== null) submenuHover(next)?.enter(event);\n };\n\n const onMove = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n const target = hitTest(event);\n const item = itemAt(target);\n // Menu 6.2's pointer focus, without the ring: keyboard and pointer agree on the current item.\n if (item !== null && doc.activeElement !== item) {\n item.focus({ focusVisible: false } as FocusOptions);\n }\n if (item !== null && submenuHover(item) !== undefined) hoverSubmenu(item, event);\n else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) {\n hoverSubmenu(null, event);\n }\n };\n const onUp = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n end();\n const moved = Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop;\n // Time alone never activates or dismisses: a stationary release keeps the menu open.\n if (!moved) return;\n const target = hitTest(event);\n if (target !== null && popup.contains(target)) {\n const item = itemAt(target);\n // A disabled item, a SubmenuTrigger (native menus activate nothing there), a separator or\n // padding: the menu stays open.\n if (item === null || isDisabledItem(item) || item.hasAttribute(\"aria-haspopup\")) return;\n options.activate(item);\n return;\n }\n if (\n shownAt !== null &&\n performance.now() - shownAt >= DRAG_DISMISS_DELAY &&\n popup.matches(\":popover-open\")\n ) {\n popup.hidePopover();\n }\n };\n const onEnd = (event: Event) => {\n if (ours(event)) end();\n };\n const onToggle = () => {\n if (!popup.matches(\":popover-open\")) end();\n else shownAt ??= performance.now();\n };\n const end = () => {\n popup.removeEventListener(\"pointermove\", onMove);\n popup.removeEventListener(\"pointerup\", onUp);\n popup.removeEventListener(\"pointercancel\", onEnd);\n popup.removeEventListener(\"lostpointercapture\", onEnd);\n popup.removeEventListener(\"toggle\", onToggle);\n submenuTrigger = null;\n };\n popup.addEventListener(\"pointermove\", onMove);\n popup.addEventListener(\"pointerup\", onUp);\n popup.addEventListener(\"pointercancel\", onEnd);\n popup.addEventListener(\"lostpointercapture\", onEnd);\n popup.addEventListener(\"toggle\", onToggle);\n return end;\n}\n\n/** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */\nconst TOUCH_END_WAIT = 250;\n\n/**\n * While the finger that opened a touch menu is still down, the browser must not take its drag\n * as a pan (it would end the stream with `pointercancel`): a non-passive document `touchmove`\n * listener prevents it (context-menu.md 2.2). The lift's `touchend`, which follows that\n * pointer's `pointerup`, is prevented as well, so the engine synthesises no click from it: a click\n * where the finger was (beside the offset menu) would light-dismiss the menu in Chromium, and one\n * over an item would activate it a second time. Ends at that `touchend` / `touchcancel`, at the\n * pointer's `pointercancel`, and shortly after its `pointerup` if no touch event follows (a\n * synthetic pointer). Returns the cleanup.\n *\n * Only the gesture finger's lift ends it (review L4): another finger lifting while it is still\n * down must not hand its next slide to panning. Pointer events expose no `Touch.identifier`, so\n * the lift is recognised by order: the engines dispatch a lift's `pointerup` and `touchend` from\n * the same input, the `pointerup` first. A `touchend` before that pointer's `pointerup` is another\n * finger's; it is still prevented (no click may light-dismiss the menu mid-gesture).\n */\nfunction guardTouch(doc: Document, pointerId: number): () => void {\n let fallback: ReturnType<typeof setTimeout> | undefined;\n // The gesture's pointer has lifted: the next `touchend` is its own.\n let lifted = false;\n const onTouchMove = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n };\n const onTouchEnd = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n if (lifted) end();\n };\n const onPointerUp = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n lifted = true;\n fallback ??= setTimeout(end, TOUCH_END_WAIT);\n };\n const onPointerCancel = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId === pointerId) end();\n };\n const end = () => {\n if (fallback !== undefined) clearTimeout(fallback);\n doc.removeEventListener(\"touchmove\", onTouchMove);\n doc.removeEventListener(\"touchend\", onTouchEnd);\n doc.removeEventListener(\"touchcancel\", end, true);\n doc.removeEventListener(\"pointerup\", onPointerUp, true);\n doc.removeEventListener(\"pointercancel\", onPointerCancel, true);\n };\n doc.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n doc.addEventListener(\"touchend\", onTouchEnd, { passive: false });\n doc.addEventListener(\"touchcancel\", end, true);\n doc.addEventListener(\"pointerup\", onPointerUp, true);\n doc.addEventListener(\"pointercancel\", onPointerCancel, true);\n return end;\n}\n\n/**\n * A region whose `contextmenu` (right-click, Ctrl+click, Shift+F10 / the ContextMenu key at a\n * focused descendant) or touch / pen long-press opens the Root's `Menu.Popup` at the pointer\n * (design/components/context-menu.md). A plain element (default `div`) with no role and no ARIA:\n * the region keeps its own semantics (`render={<tr />}`), and keyboard users reach it through\n * focusable content inside it. A second right-click inside the region while the menu is open moves\n * the menu there. Render the `Menu.Popup` as a sibling of the region where the markup allows; in\n * a table row (`render={<tr />}`), inside one of its cells: events from inside the popup are\n * never the region's.\n *\n * Owned keys (conventions 1.2): `onContextMenu`, `onPointerDown`, `onPointerMove`,\n * `onPointerUp`, `onPointerCancel`, `data-open`, `data-pending`, `data-disabled`, and the style\n * key `WebkitTouchCallout` (`\"none\"`; the consumer's `style` wins).\n */\nexport function MenuContextTrigger({\n disabled = false,\n editableTargets = \"native\",\n longPressDelay = 500,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuContextTriggerProps) {\n const menu = useMenuContext(\"Menu.ContextTrigger\");\n const { popover } = menu;\n useDevWarning(\n menu.submenu,\n \"Menu.ContextTrigger: rendered in a submenu. A Menu.Root inside a Menu.Popup is a submenu; a \" +\n \"context menu region belongs to a top-level Menu.Root.\",\n );\n useDevWarning(\n longPressDelay < 0,\n \"Menu.ContextTrigger: `longPressDelay` is negative; it is a number of milliseconds.\",\n );\n\n // Modality bookkeeping (design 2.1): a sequence number, not a clock, so two events in the same\n // millisecond still order.\n const sequence = useRef(0);\n const lastPointerDown = useRef(-1);\n const lastKeyDown = useRef(-1);\n const longPress = useRef<LongPress | null>(null);\n // Disarms the one-shot click swallow armed by a long-press open or a drag activation.\n const disarmSwallow = useRef<(() => void) | null>(null);\n // Ends the running press-drag-release gesture and its touch guard (2.6).\n const endDrag = useRef<(() => void) | null>(null);\n const warnedNoPopup = useRef(false);\n\n const cancelLongPress = useCallback(() => {\n if (longPress.current !== null) clearTimeout(longPress.current.timer);\n longPress.current = null;\n }, []);\n\n const stopDrag = useCallback(() => {\n endDrag.current?.();\n endDrag.current = null;\n }, []);\n\n useEffect(\n () => () => {\n cancelLongPress();\n stopDrag();\n disarmSwallow.current?.();\n },\n [cancelLongPress, stopDrag],\n );\n // A region disabled mid-gesture opens nothing.\n useEffect(() => {\n if (disabled) cancelLongPress();\n }, [disabled, cancelLongPress]);\n\n // A close ends any armed click swallow (review H1) and the drag gesture.\n const open = popover.optimistic;\n useEffect(() => {\n if (open) return;\n disarmSwallow.current?.();\n stopDrag();\n }, [open, stopDrag]);\n\n // The modality bookkeeping observes `keydown` and `pointerdown` without owning them (the region\n // is full of the consumer's interactive content), in the capture phase, so a descendant's\n // `stopPropagation()` (a slider, a drag handle) does not hide them (review L2).\n const modalityRef = useCallback((element: HTMLElement) => {\n const onKeyDown = () => {\n lastKeyDown.current = ++sequence.current;\n };\n const onPointerDown = () => {\n lastPointerDown.current = ++sequence.current;\n };\n element.addEventListener(\"keydown\", onKeyDown, true);\n element.addEventListener(\"pointerdown\", onPointerDown, true);\n return () => {\n element.removeEventListener(\"keydown\", onKeyDown, true);\n element.removeEventListener(\"pointerdown\", onPointerDown, true);\n };\n }, []);\n\n /** The popup element to capture on and open, or `null` (no Popup mounted: nothing opens). */\n const popupElement = (): HTMLElement | null => {\n const popup = popover.popupRef.current;\n if (popup === null && isDev && !warnedNoPopup.current) {\n warnedNoPopup.current = true;\n console.error(\n \"Menu.ContextTrigger: a context menu was requested but the Menu.Root has no mounted \" +\n \"Menu.Popup; the browser's own menu shows instead.\",\n );\n }\n return popup;\n };\n\n /**\n * One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),\n * scoped to that release (review H1): the click comes in the same task as the `pointerup` of\n * `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at\n * once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click\n * after a long-press; a swallow left armed would eat the next keyboard activation\n * (`element.click()`).\n */\n const armClickSwallow = (doc: Document, pointerId: number, releasing = false) => {\n disarmSwallow.current?.();\n let released: ReturnType<typeof setTimeout> | undefined;\n const onClick = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n disarm();\n };\n const onRelease = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n if (released === undefined) released = setTimeout(disarm, 0);\n };\n const disarm = () => {\n if (released !== undefined) clearTimeout(released);\n doc.removeEventListener(\"click\", onClick, true);\n doc.removeEventListener(\"pointerdown\", disarm, true);\n doc.removeEventListener(\"keydown\", disarm, true);\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n if (disarmSwallow.current === disarm) disarmSwallow.current = null;\n };\n doc.addEventListener(\"click\", onClick, true);\n doc.addEventListener(\"pointerdown\", disarm, true);\n doc.addEventListener(\"keydown\", disarm, true);\n doc.addEventListener(\"pointerup\", onRelease, true);\n doc.addEventListener(\"pointercancel\", onRelease, true);\n disarmSwallow.current = disarm;\n // Armed from inside the release itself (a drag activation): the click comes in this task.\n if (releasing) released = setTimeout(disarm, 0);\n };\n\n /**\n * Starts the press-drag-release gesture of 2.6 on the pointer the popup captured at this open\n * or move (a new one replaces the running one), with the touch guard for a finger.\n */\n const beginDrag = (\n popup: HTMLElement,\n pointerId: number,\n point: { readonly x: number; readonly y: number },\n pointerType: string,\n slop: number,\n ) => {\n stopDrag();\n const doc = popup.ownerDocument;\n const end = startDrag(popup, {\n pointerId,\n x: point.x,\n y: point.y,\n slop,\n activate: (item) => {\n disarmSwallow.current?.();\n item.click();\n armClickSwallow(doc, pointerId, true);\n },\n });\n const unguard = pointerType === \"touch\" ? guardTouch(doc, pointerId) : null;\n endDrag.current = () => {\n end();\n unguard?.();\n };\n };\n\n /**\n * The event comes from this Root's own popup, rendered inside the region (a table row, where a\n * `<div>` cannot be a sibling of the `<tr>`): never a move or a long-press of the region.\n */\n const fromOwnPopup = (target: EventTarget | null): boolean => {\n const popup = popover.popupRef.current;\n return popup !== null && target instanceof Node && popup.contains(target);\n };\n\n const onContextMenu = (event: MouseEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n // An inner region or a consumer handler was first (the Popup's own handler prevents a\n // right-click inside the menu); a disabled region lets the event bubble on to an outer\n // region (design 2.4).\n if (native.defaultPrevented || disabled || fromOwnPopup(native.target)) return;\n // Copy and paste keep the browser's menu (2.3).\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n const popup = popupElement();\n if (popup === null) return;\n native.preventDefault();\n markHandled(native, menu);\n // Android and pen: the platform's own `contextmenu` arrived during our timer; it opens.\n const timed = longPress.current;\n cancelLongPress();\n const keyboard = native.button === -1 || lastKeyDown.current > lastPointerDown.current;\n const pointerEvent = native as globalThis.PointerEvent;\n const pointerType =\n timed?.pointerType ??\n (typeof pointerEvent.pointerType === \"string\" ? pointerEvent.pointerType : \"mouse\");\n // The pointer still down: the one this event reports, or (Android, whose touch `contextmenu`\n // has `buttons === 0`) the finger the long-press was timing.\n const pointerId =\n native.buttons !== 0 && typeof pointerEvent.pointerId === \"number\"\n ? pointerEvent.pointerId\n : (timed?.pointerId ?? undefined);\n const point = { x: native.clientX, y: native.clientY };\n // whatwg/html#10905: in Firefox and WebKit the pending `pointerup` would light-dismiss a\n // menu opened between `pointerdown` and `pointerup`. Capture now, on the still-hidden popup:\n // the open commit lands at an unpredictable time relative to the `pointerup`. With the\n // capture, the press-drag-release gesture runs (2.6); Windows (`contextmenu` after the\n // release) and the keyboard take neither.\n if (pointerId !== undefined && capturePointer(popup, pointerId)) {\n const slop = timed !== null || pointerType === \"touch\" ? LONG_PRESS_SLOP : DRAG_SLOP;\n beginDrag(popup, pointerId, point, pointerType, slop);\n }\n menu.openAt(point, {\n source: event.currentTarget,\n event: native,\n pointer: !keyboard,\n pointerId,\n // A touch or pen open is placed above the point (4.7).\n offset: !keyboard && isTouchLike(pointerType),\n });\n };\n\n // The long-press only; the modality bookkeeping is `modalityRef`'s.\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n if (longPress.current !== null) {\n // A second finger: not a long-press.\n cancelLongPress();\n return;\n }\n if (disabled || (native.pointerType !== \"touch\" && native.pointerType !== \"pen\")) return;\n // A press inside any Menu.Popup (this Root's, or another menu inside the region) is claimed by\n // that popup; a press an inner region already times is claimed by it.\n if (fromOwnPopup(native.target)) return;\n if (!native.isPrimary || isPressClaimed(native)) return;\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n // The innermost enabled region times the press; outer regions leave it (as `contextmenu`'s\n // `defaultPrevented` rule, design 2.4).\n claimPress(native);\n const source = event.currentTarget;\n const { pointerId, pointerType, clientX, clientY } = native;\n const timer = setTimeout(\n () => {\n longPress.current = null;\n const popup = popupElement();\n if (popup === null) return;\n const point = { x: clientX, y: clientY };\n // The finger is still down: its `pointerup` would light-dismiss in WebKit. The capture\n // also lets it slide onto an item and lift to activate it (2.6).\n if (capturePointer(popup, pointerId)) {\n beginDrag(popup, pointerId, point, pointerType, LONG_PRESS_SLOP);\n }\n armClickSwallow(source.ownerDocument, pointerId);\n menu.openAt(point, { source, event: native, pointer: true, pointerId, offset: true });\n },\n Math.max(0, longPressDelay),\n );\n longPress.current = { pointerId, pointerType, x: clientX, y: clientY, timer };\n };\n\n const onPointerMove = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press === null || event.pointerId !== press.pointerId) return;\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > LONG_PRESS_SLOP) {\n cancelLongPress();\n }\n };\n\n // `pointercancel`: the browser took the gesture for panning (the region stays scrollable).\n const onPointerEnd = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press !== null && event.pointerId === press.pointerId) cancelLongPress();\n };\n\n const state: MenuContextTriggerState = {\n open: popover.optimistic,\n pending: popover.pending,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n onContextMenu,\n onPointerDown,\n onPointerMove,\n onPointerUp: onPointerEnd,\n onPointerCancel: onPointerEnd,\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // iOS link and image previews appear at about the long-press time (2.2).\n style: (s) => ({ WebkitTouchCallout: \"none\", ...resolveStateValue(style, s) }),\n // A Menu.Root inside is a nested region's menu (no \"outside its Popup\" warning).\n children: (s) => (\n <MenuRegionContext value={true}>{resolveStateValue(children, s)}</MenuRegionContext>\n ),\n props: rest,\n libraryProps,\n ref: modalityRef,\n });\n}\n\nMenuContextTrigger.displayName = \"MenuContextTrigger\";\n"],"mappings":";;;;;;;;;;;AA4DA,MAAM,kBAAkB;;;;;AAKxB,MAAM,YAAY;;AAElB,MAAM,qBAAqB;AAE3B,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAuBvC,MAAM,eAAe,gBAAwB,gBAAgB,WAAW,gBAAgB;;;;;;;;;;;;;;;AAgBxF,SAAS,UAAU,OAAoB,SAAkC;CACvE,MAAM,MAAM,MAAM;CAElB,IAAI,UAAyB,MAAM,QAAQ,eAAe,IAAI,YAAY,IAAI,IAAI;CAElF,IAAI,iBAAqC;CAEzC,MAAM,QAAQ,UAAkB,MAAkC,cAAc,QAAQ;CACxF,MAAM,WAAW,UACf,OAAO,IAAI,qBAAqB,aAC5B,IAAI,iBAAiB,MAAM,SAAS,MAAM,OAAO,IAC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AU,UAAU;GAAE;GAAW;GAAa,GAAG;GAAS,GAAG;GAAS;EAAM;CAC9E;CAEA,MAAM,iBAAiB,UAAqC;EAC1D,MAAM,QAAQ,UAAU;EACxB,IAAI,UAAU,QAAQ,MAAM,cAAc,MAAM,WAAW;EAC3D,IAAI,KAAK,MAAM,MAAM,UAAU,MAAM,GAAG,MAAM,UAAU,MAAM,CAAC,IAAI,iBACjE,gBAAgB;CAEpB;CAGA,MAAM,gBAAgB,UAAqC;EACzD,MAAM,QAAQ,UAAU;EACxB,IAAI,UAAU,QAAQ,MAAM,cAAc,MAAM,WAAW,gBAAgB;CAC7E;CAEA,MAAM,QAAiC;EACrC,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;CACF;CAEA,MAAM,eAA8D;EAClE;EACA;EACA;EACA,aAAa;EACb,iBAAiB;EACjB,aAAa,SAAS,MAAM,IAAI;EAChC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAAiE;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,QAAQ,OAAO;GAAE,oBAAoB;GAAQ,GAAG,kBAAkB,OAAO,CAAC;EAAE;EAE5E,WAAW,MACT,oBAAC,mBAAD;GAAmB,OAAO;GAAO,UAAA,kBAAkB,UAAU,CAAC;EAAqB,CAAA;EAErF,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,mBAAmB,cAAc"}
@@ -27,6 +27,16 @@ function claimPress(event) {
27
27
  function isPressClaimed(event) {
28
28
  return claimedPresses.has(event);
29
29
  }
30
+ const submenuHovers = /* @__PURE__ */ new WeakMap();
31
+ function registerSubmenuHover(element, hover) {
32
+ submenuHovers.set(element, hover);
33
+ return () => {
34
+ if (submenuHovers.get(element) === hover) submenuHovers.delete(element);
35
+ };
36
+ }
37
+ function submenuHover(element) {
38
+ return submenuHovers.get(element);
39
+ }
30
40
  /** The top-level menu's identity: its popup ref object, stable for the Root's lifetime. */
31
41
  const menuKey = (menu) => menu.root.popover.popupRef;
32
42
  function markHandled(event, menu) {
@@ -56,6 +66,6 @@ const MenuListContext = createContext(null);
56
66
  const MenuGroupContext = createContext(null);
57
67
  const MenuRadioGroupContext = createContext(null);
58
68
  //#endregion
59
- export { ANCHOR_PLACEMENT, MenuContext, MenuGroupContext, MenuListContext, MenuRadioGroupContext, MenuRegionContext, claimPress, closeStackLater, isHandledBy, isPressClaimed, markHandled, useMenuContext };
69
+ export { ANCHOR_PLACEMENT, MenuContext, MenuGroupContext, MenuListContext, MenuRadioGroupContext, MenuRegionContext, claimPress, closeStackLater, isHandledBy, isPressClaimed, markHandled, registerSubmenuHover, submenuHover, useMenuContext };
60
70
 
61
71
  //# sourceMappingURL=menu-context.mjs.map