@plexui/ui 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/ContextMenu/ContextMenu.js +163 -29
- package/dist/es/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/es/components/ContextMenu/shared.js +182 -8
- package/dist/es/components/ContextMenu/shared.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +34 -7
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +2 -2
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/lib/contextMenuHold.js +23 -0
- package/dist/es/lib/contextMenuHold.js.map +1 -0
- package/dist/es/lib/sortable.js +31 -2
- package/dist/es/lib/sortable.js.map +1 -1
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +11 -3
- package/dist/types/components/ContextMenu/shared.d.ts +53 -8
- package/dist/types/components/Dialog/Dialog.d.ts +1 -0
- package/dist/types/components/Menu/Menu.d.ts +16 -0
- package/dist/types/lib/contextMenuHold.d.ts +21 -0
- package/package.json +2 -2
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Portal, Slot } from "radix-ui";
|
|
4
|
-
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
5
5
|
import s from "@plexui/styles/components/ContextMenu/ContextMenu.module.css";
|
|
6
|
-
import {
|
|
6
|
+
import { CONTEXT_MENU_TRIGGER, SORTABLE_HANDLE, SORTABLE_SOURCE, sendContextMenuHold } from "../../lib/contextMenuHold.js";
|
|
7
|
+
import { readMenuBoundaryRect } from "../../lib/menuSubmenuPlacement.js";
|
|
8
|
+
import { isPhoneLayout } from "../../lib/phoneLayout.js";
|
|
9
|
+
import { Menu, useMenuContext, useMenuPhoneLayout } from "../Menu/Menu.js";
|
|
10
|
+
import { PhoneLayoutContext } from "../PhoneLayout/PhoneLayout.js";
|
|
7
11
|
import { TransitionGroup } from "../Transition/index.js";
|
|
8
12
|
import { overlayTiming } from "../Transition/shared.js";
|
|
9
|
-
import { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP, contextMenuHoleMask, contextMenuPlacement, contextMenuPreview, } from "./shared.js";
|
|
13
|
+
import { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP, contextMenuClipTop, contextMenuFrame, contextMenuHoleMask, contextMenuInFrame, contextMenuName, contextMenuNaturalHeight, contextMenuPlacement, contextMenuPreview, contextMenuPreviewShift, liftContextMenuPreview, } from "./shared.js";
|
|
10
14
|
const ContextMenuContext = createContext(null);
|
|
11
15
|
function useContextMenuContext(part) {
|
|
12
16
|
const context = useContext(ContextMenuContext);
|
|
@@ -19,11 +23,50 @@ function useContextMenuContext(part) {
|
|
|
19
23
|
* the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as
|
|
20
24
|
* iOS lifts the preview. The items are the ones of `Menu`.
|
|
21
25
|
*/
|
|
22
|
-
function ContextMenuRoot({ children, onOpen, onClose }) {
|
|
23
|
-
const [
|
|
26
|
+
function ContextMenuRoot({ children, forceOpen, onOpen, onClose }) {
|
|
27
|
+
const [shown, setShown] = useState({ presentation: null, frame: null, name: "" });
|
|
24
28
|
const regionRef = useRef(null);
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
// Inside a PhoneLayout the anchor and the dimming lie in its box, as the menu does
|
|
30
|
+
const container = useContext(PhoneLayoutContext)?.container ?? null;
|
|
31
|
+
const restore = useRef(null);
|
|
32
|
+
const held = useRef(false);
|
|
33
|
+
// Puts the element back; after a glide back the restore stays, so that a press or a close that follows stops it
|
|
34
|
+
const drop = useCallback((glide) => {
|
|
35
|
+
const current = restore.current;
|
|
36
|
+
current?.(glide);
|
|
37
|
+
restore.current = glide ? current : null;
|
|
38
|
+
}, []);
|
|
39
|
+
// The content going away while the element stays: the element back in place, and measured anew when it returns
|
|
40
|
+
const release = useCallback(() => {
|
|
41
|
+
drop(false);
|
|
42
|
+
setShown((current) => {
|
|
43
|
+
const preview = current.presentation;
|
|
44
|
+
if (preview?.kind !== "preview" || preview.shift === undefined)
|
|
45
|
+
return current;
|
|
46
|
+
return { ...current, presentation: { ...preview, rect: { ...preview.rect, y: preview.rect.y + preview.shift }, shift: undefined } };
|
|
47
|
+
});
|
|
48
|
+
}, [drop]);
|
|
49
|
+
const present = useCallback((element, measure, still = false) => {
|
|
50
|
+
drop(false);
|
|
51
|
+
held.current = still;
|
|
52
|
+
regionRef.current = element;
|
|
53
|
+
setShown({ presentation: measure(), frame: contextMenuFrame(container), name: contextMenuName(element) });
|
|
54
|
+
}, [container, drop]);
|
|
55
|
+
const lift = useCallback((shift) => {
|
|
56
|
+
const element = regionRef.current;
|
|
57
|
+
drop(false);
|
|
58
|
+
if (element && shift > 0)
|
|
59
|
+
restore.current = liftContextMenuPreview(element, shift, !held.current);
|
|
60
|
+
setShown((current) => {
|
|
61
|
+
const preview = current.presentation;
|
|
62
|
+
if (preview?.kind !== "preview")
|
|
63
|
+
return current;
|
|
64
|
+
return { ...current, presentation: { ...preview, rect: { ...preview.rect, y: preview.rect.y - shift }, shift } };
|
|
65
|
+
});
|
|
66
|
+
}, [drop]);
|
|
67
|
+
useEffect(() => () => drop(false), [drop]);
|
|
68
|
+
const value = useMemo(() => ({ ...shown, present, lift, drop, release, regionRef, container, forced: forceOpen === true }), [shown, present, lift, drop, release, container, forceOpen]);
|
|
69
|
+
return (_jsx(ContextMenuContext.Provider, { value: value, children: _jsx(Menu, { forceOpen: forceOpen, onOpen: onOpen, onClose: onClose, children: children }) }));
|
|
27
70
|
}
|
|
28
71
|
ContextMenuRoot.displayName = "ContextMenu";
|
|
29
72
|
/**
|
|
@@ -52,10 +95,19 @@ const suppressNextClick = (doc) => {
|
|
|
52
95
|
doc.addEventListener("click", swallow, true);
|
|
53
96
|
doc.addEventListener("pointerdown", stop, true);
|
|
54
97
|
};
|
|
98
|
+
/** A menu held open without a press: the touch-and-hold preview on a phone, under the element elsewhere. */
|
|
99
|
+
const forcedPresentation = (element) => {
|
|
100
|
+
if (!isPhoneLayout(element))
|
|
101
|
+
return { kind: "keyboard", rect: element.getBoundingClientRect() };
|
|
102
|
+
const box = element.getBoundingClientRect();
|
|
103
|
+
return contextMenuPreview(element, box.left + box.width / 2);
|
|
104
|
+
};
|
|
55
105
|
function ContextMenuTrigger({ children, disabled = false }) {
|
|
56
106
|
const menu = useMenuContext();
|
|
57
|
-
const {
|
|
107
|
+
const { present, drop, forced } = useContextMenuContext("ContextMenu.Trigger");
|
|
58
108
|
const press = useRef(null);
|
|
109
|
+
// The element, as state: a menu held open follows the element the trigger has now
|
|
110
|
+
const [element, setElement] = useState(null);
|
|
59
111
|
const cancel = () => {
|
|
60
112
|
if (press.current)
|
|
61
113
|
window.clearTimeout(press.current.timer);
|
|
@@ -65,27 +117,66 @@ function ContextMenuTrigger({ children, disabled = false }) {
|
|
|
65
117
|
if (press.current)
|
|
66
118
|
window.clearTimeout(press.current.timer);
|
|
67
119
|
}, []);
|
|
68
|
-
|
|
69
|
-
|
|
120
|
+
// A menu held open stands at the element, and follows it as the page around it scrolls or the window changes
|
|
121
|
+
useLayoutEffect(() => {
|
|
122
|
+
if (!forced || !element)
|
|
123
|
+
return;
|
|
124
|
+
const doc = element.ownerDocument;
|
|
125
|
+
const view = doc.defaultView;
|
|
126
|
+
const place = () => present(element, () => forcedPresentation(element), true);
|
|
127
|
+
place();
|
|
128
|
+
let frame = 0;
|
|
129
|
+
const follow = (event) => {
|
|
130
|
+
if (event.target instanceof Node && event.target !== doc && !event.target.contains(element))
|
|
131
|
+
return;
|
|
132
|
+
view?.cancelAnimationFrame(frame);
|
|
133
|
+
frame = view?.requestAnimationFrame(place) ?? 0;
|
|
134
|
+
};
|
|
135
|
+
view?.addEventListener("resize", follow);
|
|
136
|
+
doc.addEventListener("scroll", follow, { capture: true, passive: true });
|
|
137
|
+
return () => {
|
|
138
|
+
view?.cancelAnimationFrame(frame);
|
|
139
|
+
view?.removeEventListener("resize", follow);
|
|
140
|
+
doc.removeEventListener("scroll", follow, { capture: true });
|
|
141
|
+
};
|
|
142
|
+
}, [forced, present, element]);
|
|
143
|
+
const open = (element, measure) => {
|
|
144
|
+
present(element, measure);
|
|
70
145
|
menu.setOpen(true);
|
|
71
146
|
};
|
|
72
|
-
const openPreview = (element, x) =>
|
|
73
|
-
|
|
74
|
-
|
|
147
|
+
const openPreview = (element, x) => open(element, () => contextMenuPreview(element, x));
|
|
148
|
+
// A touch and hold opens the preview once, by the timer or by the browser's own context menu (Android)
|
|
149
|
+
const openHeld = (element, current) => {
|
|
150
|
+
// A Sortable list around the element already turned this hold into a drag
|
|
151
|
+
if (element.ownerDocument.querySelector(SORTABLE_SOURCE))
|
|
152
|
+
return cancel();
|
|
153
|
+
window.clearTimeout(current.timer);
|
|
154
|
+
current.opened = true;
|
|
155
|
+
openPreview(element, current.x);
|
|
156
|
+
// The same hold drags the element where it is a Sortable item: moving on, the finger closes the menu
|
|
157
|
+
sendContextMenuHold(element, {
|
|
158
|
+
pointerId: current.id,
|
|
159
|
+
close: () => {
|
|
160
|
+
drop(false);
|
|
161
|
+
menu.setOpen(false);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
75
164
|
};
|
|
76
165
|
const handlers = {
|
|
166
|
+
[CONTEXT_MENU_TRIGGER]: disabled ? undefined : "",
|
|
77
167
|
onPointerDown: (event) => {
|
|
78
168
|
if (event.defaultPrevented || disabled || event.pointerType !== "touch" || !event.isPrimary)
|
|
79
169
|
return;
|
|
170
|
+
// The grip of a Sortable item drags at once
|
|
171
|
+
if (event.target instanceof Element && event.target.closest(SORTABLE_HANDLE))
|
|
172
|
+
return;
|
|
80
173
|
cancel();
|
|
81
174
|
const element = event.currentTarget;
|
|
82
175
|
const x = event.clientX;
|
|
83
176
|
const timer = window.setTimeout(() => {
|
|
84
177
|
const current = press.current;
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
current.opened = true;
|
|
88
|
-
openPreview(element, x);
|
|
178
|
+
if (current && current.timer === timer)
|
|
179
|
+
openHeld(element, current);
|
|
89
180
|
}, CONTEXT_MENU_LONG_PRESS);
|
|
90
181
|
press.current = { id: event.pointerId, x, y: event.clientY, timer, opened: false };
|
|
91
182
|
},
|
|
@@ -113,32 +204,75 @@ function ContextMenuTrigger({ children, disabled = false }) {
|
|
|
113
204
|
return;
|
|
114
205
|
event.preventDefault();
|
|
115
206
|
const element = event.currentTarget;
|
|
116
|
-
regionRef.current = element;
|
|
117
207
|
// A touch and hold that the browser reports as a context menu (Android) opens the preview once.
|
|
118
208
|
const current = press.current;
|
|
119
209
|
if (current) {
|
|
120
|
-
if (current.opened)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
current.opened = true;
|
|
124
|
-
return openPreview(element, current.x);
|
|
210
|
+
if (!current.opened)
|
|
211
|
+
openHeld(element, current);
|
|
212
|
+
return;
|
|
125
213
|
}
|
|
126
214
|
if (menu.isUsingKeyboard.current)
|
|
127
|
-
return open({ kind: "keyboard", rect: element.getBoundingClientRect() });
|
|
128
|
-
|
|
215
|
+
return open(element, () => ({ kind: "keyboard", rect: element.getBoundingClientRect() }));
|
|
216
|
+
const { clientX, clientY } = event;
|
|
217
|
+
open(element, () => ({ kind: "pointer", rect: { x: clientX, y: clientY, width: 0, height: 0 } }));
|
|
129
218
|
},
|
|
130
219
|
};
|
|
131
|
-
return _jsx(Slot.Root, { className: s.Trigger, ...handlers, children: children });
|
|
220
|
+
return _jsx(Slot.Root, { ref: setElement, className: s.Trigger, ...handlers, children: children });
|
|
132
221
|
}
|
|
133
222
|
ContextMenuTrigger.displayName = "ContextMenu.Trigger";
|
|
134
|
-
function ContextMenuContent(props) {
|
|
223
|
+
function ContextMenuContent({ "aria-label": ariaLabel, ...props }) {
|
|
135
224
|
const { open } = useMenuContext();
|
|
136
|
-
const { presentation, regionRef } = useContextMenuContext("ContextMenu.Content");
|
|
225
|
+
const { presentation, frame, name, regionRef, container, lift, drop, release } = useContextMenuContext("ContextMenu.Content");
|
|
226
|
+
const anchorRef = useRef(null);
|
|
227
|
+
const { boundary } = useMenuPhoneLayout(open);
|
|
137
228
|
const rect = presentation?.rect;
|
|
138
229
|
const placement = contextMenuPlacement(presentation);
|
|
139
230
|
const preview = presentation?.kind === "preview" ? presentation : null;
|
|
140
231
|
const dimmed = open && preview !== null;
|
|
141
|
-
|
|
232
|
+
const pending = open && preview !== null && preview.shift === undefined;
|
|
233
|
+
const maxHeight = props.maxHeight;
|
|
234
|
+
// The preview moves up so that the menu stands whole below it, measured as the menu first lays out, before it shows
|
|
235
|
+
const latest = useRef({ preview, boundary, maxHeight, frame });
|
|
236
|
+
latest.current = { preview, boundary, maxHeight, frame };
|
|
237
|
+
useLayoutEffect(() => {
|
|
238
|
+
if (!pending)
|
|
239
|
+
return;
|
|
240
|
+
let frame = 0;
|
|
241
|
+
const measure = () => {
|
|
242
|
+
const { preview: current, boundary: room, maxHeight: limit, frame: box } = latest.current;
|
|
243
|
+
const element = regionRef.current;
|
|
244
|
+
const anchor = anchorRef.current;
|
|
245
|
+
if (!current || current.shift !== undefined || !element)
|
|
246
|
+
return;
|
|
247
|
+
const content = anchor?.ownerDocument.getElementById(anchor.getAttribute("aria-controls") ?? "");
|
|
248
|
+
// The menu of a PhoneLayout mounts a frame later, with the box it portals into, and content mounted again while
|
|
249
|
+
// the menu is open finds its anchor (in a portal) a frame later too
|
|
250
|
+
if (!content) {
|
|
251
|
+
frame = requestAnimationFrame(measure);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const bounds = readMenuBoundaryRect(element.ownerDocument, room);
|
|
255
|
+
// On the screen, as the room is: a PhoneLayout drawn smaller draws the menu smaller too
|
|
256
|
+
const height = Math.min(contextMenuNaturalHeight(content), limit ?? Infinity) * (box?.scaleY ?? 1);
|
|
257
|
+
// A room not known yet (no layout) moves nothing
|
|
258
|
+
const known = bounds && bounds.bottom > bounds.top;
|
|
259
|
+
lift(known ? contextMenuPreviewShift(current.rect, height, bounds, contextMenuClipTop(element), box?.scaleY ?? 1) : 0);
|
|
260
|
+
};
|
|
261
|
+
measure();
|
|
262
|
+
return () => cancelAnimationFrame(frame);
|
|
263
|
+
}, [pending, lift, regionRef]);
|
|
264
|
+
useLayoutEffect(() => {
|
|
265
|
+
if (!open)
|
|
266
|
+
drop(true);
|
|
267
|
+
}, [open, drop]);
|
|
268
|
+
// The content going away while the element stays puts the element back
|
|
269
|
+
useLayoutEffect(() => release, [release]);
|
|
270
|
+
const local = (box) => contextMenuInFrame(box, frame);
|
|
271
|
+
const anchor = rect ? local(rect) : undefined;
|
|
272
|
+
const hole = preview && { ...preview, rect: local(preview.rect), radius: preview.radius / (frame?.scaleX ?? 1) };
|
|
273
|
+
const viewport = frame ? { width: frame.width, height: frame.height } : undefined;
|
|
274
|
+
const label = ariaLabel ?? name;
|
|
275
|
+
return (_jsxs(_Fragment, { children: [_jsx(Portal.Root, { asChild: true, container: container, children: _jsx(Menu.Trigger, { children: _jsx("span", { ref: anchorRef, "aria-hidden": "true", "aria-label": label || undefined, tabIndex: -1, className: s.Anchor, style: anchor ? { left: anchor.x, top: anchor.y, width: anchor.width, height: anchor.height } : undefined }) }) }), _jsx(Portal.Root, { asChild: true, container: container, children: _jsx(TransitionGroup, { className: s.Dimming, ...overlayTiming, children: dimmed && hole && (_jsx("div", { "data-context-menu-dimming": "", className: s.Overlay, style: contextMenuHoleMask(hole, viewport), children: _jsx("div", { className: s.Preview, style: { left: hole.rect.x, top: hole.rect.y, width: hole.rect.width, height: hole.rect.height, borderRadius: hole.radius } }) }, "dimming")) }) }), _jsx(Menu.Content, { ...props, ...placement, onCloseAutoFocus: (event) => {
|
|
142
276
|
// Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.
|
|
143
277
|
event.preventDefault();
|
|
144
278
|
if (presentation?.kind === "keyboard")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/ContextMenu.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GAOT,MAAM,OAAO,CAAA;AACd,OAAO,CAAC,MAAM,8DAA8D,CAAA;AAC5E,OAAO,EAAE,IAAI,EAAE,cAAc,EAAyB,MAAM,cAAc,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,GAEnB,MAAM,UAAU,CAAA;AAQjB,MAAM,kBAAkB,GAAG,aAAa,CAAiC,IAAI,CAAC,CAAA;AAE9E,SAAS,qBAAqB,CAAC,IAAY;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAC9C,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,kCAAkC,CAAC,CAAA;IACxE,OAAO,OAAO,CAAA;AAChB,CAAC;AAWD;;;;GAIG;AACH,SAAS,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAoB;IACtE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAiC,IAAI,CAAC,CAAA;IACtF,MAAM,SAAS,GAAG,MAAM,CAAqB,IAAI,CAAC,CAAA;IAClD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE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radix-ui\"\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n type ReactElement,\n type ReactNode,\n type RefObject,\n} from \"react\"\nimport s from \"@plexui/styles/components/ContextMenu/ContextMenu.module.css\"\nimport { Menu, useMenuContext, type MenuContentProps } from \"../Menu/Menu\"\nimport { TransitionGroup } from \"../Transition\"\nimport { overlayTiming } from \"../Transition/shared\"\nimport {\n CONTEXT_MENU_LONG_PRESS,\n CONTEXT_MENU_LONG_PRESS_SLOP,\n contextMenuHoleMask,\n contextMenuPlacement,\n contextMenuPreview,\n type ContextMenuPresentation,\n} from \"./shared\"\n\ntype ContextMenuContextValue = {\n presentation: ContextMenuPresentation | null\n setPresentation: (presentation: ContextMenuPresentation) => void\n regionRef: RefObject<HTMLElement | null>\n}\n\nconst ContextMenuContext = createContext<ContextMenuContextValue | null>(null)\n\nfunction useContextMenuContext(part: string) {\n const context = useContext(ContextMenuContext)\n if (!context) throw new Error(`${part} must be used within ContextMenu`)\n return context\n}\n\nexport type ContextMenuProps = {\n /** `ContextMenu.Trigger` and `ContextMenu.Content`. */\n children: ReactNode\n /** Called when the menu opens. */\n onOpen?: () => void\n /** Called when the menu closes. */\n onClose?: () => void\n}\n\n/**\n * A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at\n * the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as\n * iOS lifts the preview. The items are the ones of `Menu`.\n */\nfunction ContextMenuRoot({ children, onOpen, onClose }: ContextMenuProps) {\n const [presentation, setPresentation] = useState<ContextMenuPresentation | null>(null)\n const regionRef = useRef<HTMLElement | null>(null)\n const value = useMemo(() => ({ presentation, setPresentation, regionRef }), [presentation])\n return (\n <ContextMenuContext.Provider value={value}>\n <Menu onOpen={onOpen} onClose={onClose}>{children}</Menu>\n </ContextMenuContext.Provider>\n )\n}\nContextMenuRoot.displayName = \"ContextMenu\"\n\nexport type ContextMenuTriggerProps = {\n /** The element the menu is for; it receives the handlers, so it keeps its own role and focus. */\n children: ReactElement\n /** When `true`, the element keeps the browser's own context menu. */\n disabled?: boolean\n}\n\ntype Press = { id: number; x: number; y: number; timer: number; opened: boolean }\n\n/**\n * Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown\n * would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose\n * content takes the press), and the click would activate the element.\n */\nconst suppressNextClick = (doc: Document) => {\n const hold = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n }\n const swallow = (event: Event) => {\n hold(event)\n stop()\n }\n const stop = () => {\n doc.removeEventListener(\"mousedown\", hold, true)\n doc.removeEventListener(\"click\", swallow, true)\n doc.removeEventListener(\"pointerdown\", stop, true)\n window.clearTimeout(timer)\n }\n // A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.\n const timer = window.setTimeout(stop, 600)\n doc.addEventListener(\"mousedown\", hold, true)\n doc.addEventListener(\"click\", swallow, true)\n doc.addEventListener(\"pointerdown\", stop, true)\n}\n\nfunction ContextMenuTrigger({ children, disabled = false }: ContextMenuTriggerProps) {\n const menu = useMenuContext()\n const { setPresentation, regionRef } = useContextMenuContext(\"ContextMenu.Trigger\")\n const press = useRef<Press | null>(null)\n\n const cancel = () => {\n if (press.current) window.clearTimeout(press.current.timer)\n press.current = null\n }\n useEffect(() => () => {\n if (press.current) window.clearTimeout(press.current.timer)\n }, [])\n\n const open = (presentation: ContextMenuPresentation) => {\n setPresentation(presentation)\n menu.setOpen(true)\n }\n const openPreview = (element: HTMLElement, x: number) => {\n regionRef.current = element\n open(contextMenuPreview(element, x))\n }\n\n const handlers = {\n onPointerDown: (event: ReactPointerEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled || event.pointerType !== \"touch\" || !event.isPrimary) return\n cancel()\n const element = event.currentTarget\n const x = event.clientX\n const timer = window.setTimeout(() => {\n const current = press.current\n if (!current || current.timer !== timer) return\n current.opened = true\n openPreview(element, x)\n }, CONTEXT_MENU_LONG_PRESS)\n press.current = { id: event.pointerId, x, y: event.clientY, timer, opened: false }\n },\n onPointerMove: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId || current.opened) return\n if (Math.hypot(event.clientX - current.x, event.clientY - current.y) > CONTEXT_MENU_LONG_PRESS_SLOP) cancel()\n },\n onPointerUp: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId) return\n if (current.opened) suppressNextClick(event.currentTarget.ownerDocument)\n cancel()\n },\n onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => {\n if (press.current?.id === event.pointerId) cancel()\n },\n onContextMenu: (event: ReactMouseEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled) return\n event.preventDefault()\n const element = event.currentTarget\n regionRef.current = element\n // A touch and hold that the browser reports as a context menu (Android) opens the preview once.\n const current = press.current\n if (current) {\n if (current.opened) return\n window.clearTimeout(current.timer)\n current.opened = true\n return openPreview(element, current.x)\n }\n if (menu.isUsingKeyboard.current) return open({ kind: \"keyboard\", rect: element.getBoundingClientRect() })\n open({ kind: \"pointer\", rect: { x: event.clientX, y: event.clientY, width: 0, height: 0 } })\n },\n }\n\n return <Slot.Root className={s.Trigger} {...handlers}>{children}</Slot.Root>\n}\nContextMenuTrigger.displayName = \"ContextMenu.Trigger\"\n\n/** The props of `Menu.Content` but its placement, which follows how the menu opened. */\nexport type ContextMenuContentProps = Omit<MenuContentProps, \"side\" | \"sideOffset\" | \"align\" | \"alignOffset\" | \"onCloseAutoFocus\" | \"layout\" | \"size\">\n\nfunction ContextMenuContent(props: ContextMenuContentProps) {\n const { open } = useMenuContext()\n const { presentation, regionRef } = useContextMenuContext(\"ContextMenu.Content\")\n const rect = presentation?.rect\n const placement = contextMenuPlacement(presentation)\n const preview = presentation?.kind === \"preview\" ? presentation : null\n const dimmed = open && preview !== null\n\n return (\n <>\n {/* The menu is placed against this invisible box: the pointer, or the element. */}\n <Portal.Root asChild>\n <Menu.Trigger>\n <span\n aria-hidden=\"true\"\n tabIndex={-1}\n className={s.Anchor}\n style={rect ? { left: rect.x, top: rect.y, width: rect.width, height: rect.height } : undefined}\n />\n </Menu.Trigger>\n </Portal.Root>\n <Portal.Root asChild>\n <TransitionGroup className={s.Dimming} {...overlayTiming}>\n {dimmed && (\n <div key=\"dimming\" data-context-menu-dimming=\"\" className={s.Overlay} style={contextMenuHoleMask(preview) as CSSProperties}>\n <div\n className={s.Preview}\n style={{ left: preview.rect.x, top: preview.rect.y, width: preview.rect.width, height: preview.rect.height, borderRadius: preview.radius }}\n />\n </div>\n )}\n </TransitionGroup>\n </Portal.Root>\n <Menu.Content\n {...props}\n {...placement}\n onCloseAutoFocus={(event) => {\n // Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.\n event.preventDefault()\n if (presentation?.kind === \"keyboard\") regionRef.current?.focus({ preventScroll: true })\n }}\n />\n </>\n )\n}\nContextMenuContent.displayName = \"ContextMenu.Content\"\n\nexport const ContextMenu = Object.assign(ContextMenuRoot, {\n Trigger: ContextMenuTrigger,\n Content: ContextMenuContent,\n Item: Menu.Item,\n Link: Menu.Link,\n Separator: Menu.Separator,\n Label: Menu.Label,\n Group: Menu.Group,\n Sub: Menu.Sub,\n SubTrigger: Menu.SubTrigger,\n SubContent: Menu.SubContent,\n CheckboxItem: Menu.CheckboxItem,\n RadioGroup: Menu.RadioGroup,\n RadioItem: Menu.RadioItem,\n})\n"]}
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/ContextMenu.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,GAOT,MAAM,O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tB,IAAI,YAAY,EAAE,IAAI,KAAK,UAAU;wBAAE,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;gBAC1F,CAAC,GACD,IACD,CACJ,CAAA;AACH,CAAC;AACD,kBAAkB,CAAC,WAAW,GAAG,qBAAqB,CAAA;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IACxD,OAAO,EAAE,kBAAkB;IAC3B,OAAO,EAAE,kBAAkB;IAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,SAAS,EAAE,IAAI,CAAC,SAAS;IACzB,KAAK,EAAE,IAAI,CAAC,KAAK;IACjB,KAAK,EAAE,IAAI,CAAC,KAAK;IACjB,GAAG,EAAE,IAAI,CAAC,GAAG;IACb,UAAU,EAAE,IAAI,CAAC,UAAU;IAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;IAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;IAC/B,UAAU,EAAE,IAAI,CAAC,UAAU;IAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;CAC1B,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport { Portal, Slot } from \"radix-ui\"\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n type ReactElement,\n type ReactNode,\n type RefObject,\n} from \"react\"\nimport s from \"@plexui/styles/components/ContextMenu/ContextMenu.module.css\"\nimport { CONTEXT_MENU_TRIGGER, SORTABLE_HANDLE, SORTABLE_SOURCE, sendContextMenuHold } from \"../../lib/contextMenuHold\"\nimport { readMenuBoundaryRect } from \"../../lib/menuSubmenuPlacement\"\nimport { isPhoneLayout } from \"../../lib/phoneLayout\"\nimport { Menu, useMenuContext, useMenuPhoneLayout, type MenuContentProps } from \"../Menu/Menu\"\nimport { PhoneLayoutContext } from \"../PhoneLayout/PhoneLayout\"\nimport { TransitionGroup } from \"../Transition\"\nimport { overlayTiming } from \"../Transition/shared\"\nimport {\n CONTEXT_MENU_LONG_PRESS,\n CONTEXT_MENU_LONG_PRESS_SLOP,\n contextMenuClipTop,\n contextMenuFrame,\n contextMenuHoleMask,\n contextMenuInFrame,\n contextMenuName,\n contextMenuNaturalHeight,\n contextMenuPlacement,\n contextMenuPreview,\n contextMenuPreviewShift,\n liftContextMenuPreview,\n type ContextMenuFrame,\n type ContextMenuPresentation,\n} from \"./shared\"\n\ntype Shown = { presentation: ContextMenuPresentation | null; frame: ContextMenuFrame | null; name: string }\n\ntype ContextMenuContextValue = Shown & {\n /**\n * Shows the menu for the element as `measure` places it, once a raised preview is back in its place. A menu held\n * open is placed again as the page moves, and its preview moves up without gliding.\n */\n present: (element: HTMLElement, measure: () => ContextMenuPresentation, held?: boolean) => void\n /** Moves the preview up by `shift`, so that the menu stands whole below it */\n lift: (shift: number) => void\n /** Puts a raised preview back in its place, gliding or at once */\n drop: (glide: boolean) => void\n /** Puts a raised preview back at once and forgets its move, for content that goes away while the element stays */\n release: () => void\n regionRef: RefObject<HTMLElement | null>\n container: HTMLElement | null\n forced: boolean\n}\n\nconst ContextMenuContext = createContext<ContextMenuContextValue | null>(null)\n\nfunction useContextMenuContext(part: string) {\n const context = useContext(ContextMenuContext)\n if (!context) throw new Error(`${part} must be used within ContextMenu`)\n return context\n}\n\nexport type ContextMenuProps = {\n /** `ContextMenu.Trigger` and `ContextMenu.Content`. */\n children: ReactNode\n /**\n * Holds the menu open (`true`) or closed (`false`). Held open without a press, it stands at the element: as the\n * touch-and-hold preview on a phone, under the element elsewhere, and it follows the element as the page scrolls.\n */\n forceOpen?: boolean\n /** Called when the menu opens. */\n onOpen?: () => void\n /** Called when the menu closes. */\n onClose?: () => void\n}\n\n/**\n * A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at\n * the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as\n * iOS lifts the preview. The items are the ones of `Menu`.\n */\nfunction ContextMenuRoot({ children, forceOpen, onOpen, onClose }: ContextMenuProps) {\n const [shown, setShown] = useState<Shown>({ presentation: null, frame: null, name: \"\" })\n const regionRef = useRef<HTMLElement | null>(null)\n // Inside a PhoneLayout the anchor and the dimming lie in its box, as the menu does\n const container = useContext(PhoneLayoutContext)?.container ?? null\n const restore = useRef<((glide: boolean) => void) | null>(null)\n const held = useRef(false)\n\n // Puts the element back; after a glide back the restore stays, so that a press or a close that follows stops it\n const drop = useCallback((glide: boolean) => {\n const current = restore.current\n current?.(glide)\n restore.current = glide ? current : null\n }, [])\n // The content going away while the element stays: the element back in place, and measured anew when it returns\n const release = useCallback(() => {\n drop(false)\n setShown((current) => {\n const preview = current.presentation\n if (preview?.kind !== \"preview\" || preview.shift === undefined) return current\n return { ...current, presentation: { ...preview, rect: { ...preview.rect, y: preview.rect.y + preview.shift }, shift: undefined } }\n })\n }, [drop])\n const present = useCallback((element: HTMLElement, measure: () => ContextMenuPresentation, still = false) => {\n drop(false)\n held.current = still\n regionRef.current = element\n setShown({ presentation: measure(), frame: contextMenuFrame(container), name: contextMenuName(element) })\n }, [container, drop])\n const lift = useCallback((shift: number) => {\n const element = regionRef.current\n drop(false)\n if (element && shift > 0) restore.current = liftContextMenuPreview(element, shift, !held.current)\n setShown((current) => {\n const preview = current.presentation\n if (preview?.kind !== \"preview\") return current\n return { ...current, presentation: { ...preview, rect: { ...preview.rect, y: preview.rect.y - shift }, shift } }\n })\n }, [drop])\n useEffect(() => () => drop(false), [drop])\n\n const value = useMemo(\n () => ({ ...shown, present, lift, drop, release, regionRef, container, forced: forceOpen === true }),\n [shown, present, lift, drop, release, container, forceOpen],\n )\n return (\n <ContextMenuContext.Provider value={value}>\n <Menu forceOpen={forceOpen} onOpen={onOpen} onClose={onClose}>{children}</Menu>\n </ContextMenuContext.Provider>\n )\n}\nContextMenuRoot.displayName = \"ContextMenu\"\n\nexport type ContextMenuTriggerProps = {\n /** The element the menu is for; it receives the handlers, so it keeps its own role and focus. */\n children: ReactElement\n /** When `true`, the element keeps the browser's own context menu. */\n disabled?: boolean\n}\n\ntype Press = { id: number; x: number; y: number; timer: number; opened: boolean }\n\n/**\n * Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown\n * would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose\n * content takes the press), and the click would activate the element.\n */\nconst suppressNextClick = (doc: Document) => {\n const hold = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n }\n const swallow = (event: Event) => {\n hold(event)\n stop()\n }\n const stop = () => {\n doc.removeEventListener(\"mousedown\", hold, true)\n doc.removeEventListener(\"click\", swallow, true)\n doc.removeEventListener(\"pointerdown\", stop, true)\n window.clearTimeout(timer)\n }\n // A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.\n const timer = window.setTimeout(stop, 600)\n doc.addEventListener(\"mousedown\", hold, true)\n doc.addEventListener(\"click\", swallow, true)\n doc.addEventListener(\"pointerdown\", stop, true)\n}\n\n/** A menu held open without a press: the touch-and-hold preview on a phone, under the element elsewhere. */\nconst forcedPresentation = (element: HTMLElement): ContextMenuPresentation => {\n if (!isPhoneLayout(element)) return { kind: \"keyboard\", rect: element.getBoundingClientRect() }\n const box = element.getBoundingClientRect()\n return contextMenuPreview(element, box.left + box.width / 2)\n}\n\nfunction ContextMenuTrigger({ children, disabled = false }: ContextMenuTriggerProps) {\n const menu = useMenuContext()\n const { present, drop, forced } = useContextMenuContext(\"ContextMenu.Trigger\")\n const press = useRef<Press | null>(null)\n // The element, as state: a menu held open follows the element the trigger has now\n const [element, setElement] = useState<HTMLElement | null>(null)\n\n const cancel = () => {\n if (press.current) window.clearTimeout(press.current.timer)\n press.current = null\n }\n useEffect(() => () => {\n if (press.current) window.clearTimeout(press.current.timer)\n }, [])\n\n // A menu held open stands at the element, and follows it as the page around it scrolls or the window changes\n useLayoutEffect(() => {\n if (!forced || !element) return\n const doc = element.ownerDocument\n const view = doc.defaultView\n const place = () => present(element, () => forcedPresentation(element), true)\n place()\n let frame = 0\n const follow = (event: Event) => {\n if (event.target instanceof Node && event.target !== doc && !event.target.contains(element)) return\n view?.cancelAnimationFrame(frame)\n frame = view?.requestAnimationFrame(place) ?? 0\n }\n view?.addEventListener(\"resize\", follow)\n doc.addEventListener(\"scroll\", follow, { capture: true, passive: true })\n return () => {\n view?.cancelAnimationFrame(frame)\n view?.removeEventListener(\"resize\", follow)\n doc.removeEventListener(\"scroll\", follow, { capture: true })\n }\n }, [forced, present, element])\n\n const open = (element: HTMLElement, measure: () => ContextMenuPresentation) => {\n present(element, measure)\n menu.setOpen(true)\n }\n const openPreview = (element: HTMLElement, x: number) => open(element, () => contextMenuPreview(element, x))\n // A touch and hold opens the preview once, by the timer or by the browser's own context menu (Android)\n const openHeld = (element: HTMLElement, current: Press) => {\n // A Sortable list around the element already turned this hold into a drag\n if (element.ownerDocument.querySelector(SORTABLE_SOURCE)) return cancel()\n window.clearTimeout(current.timer)\n current.opened = true\n openPreview(element, current.x)\n // The same hold drags the element where it is a Sortable item: moving on, the finger closes the menu\n sendContextMenuHold(element, {\n pointerId: current.id,\n close: () => {\n drop(false)\n menu.setOpen(false)\n },\n })\n }\n\n const handlers = {\n [CONTEXT_MENU_TRIGGER]: disabled ? undefined : \"\",\n onPointerDown: (event: ReactPointerEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled || event.pointerType !== \"touch\" || !event.isPrimary) return\n // The grip of a Sortable item drags at once\n if (event.target instanceof Element && event.target.closest(SORTABLE_HANDLE)) return\n cancel()\n const element = event.currentTarget\n const x = event.clientX\n const timer = window.setTimeout(() => {\n const current = press.current\n if (current && current.timer === timer) openHeld(element, current)\n }, CONTEXT_MENU_LONG_PRESS)\n press.current = { id: event.pointerId, x, y: event.clientY, timer, opened: false }\n },\n onPointerMove: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId || current.opened) return\n if (Math.hypot(event.clientX - current.x, event.clientY - current.y) > CONTEXT_MENU_LONG_PRESS_SLOP) cancel()\n },\n onPointerUp: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId) return\n if (current.opened) suppressNextClick(event.currentTarget.ownerDocument)\n cancel()\n },\n onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => {\n if (press.current?.id === event.pointerId) cancel()\n },\n onContextMenu: (event: ReactMouseEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled) return\n event.preventDefault()\n const element = event.currentTarget\n // A touch and hold that the browser reports as a context menu (Android) opens the preview once.\n const current = press.current\n if (current) {\n if (!current.opened) openHeld(element, current)\n return\n }\n if (menu.isUsingKeyboard.current) return open(element, () => ({ kind: \"keyboard\", rect: element.getBoundingClientRect() }))\n const { clientX, clientY } = event\n open(element, () => ({ kind: \"pointer\", rect: { x: clientX, y: clientY, width: 0, height: 0 } }))\n },\n }\n\n return <Slot.Root ref={setElement} className={s.Trigger} {...handlers}>{children}</Slot.Root>\n}\nContextMenuTrigger.displayName = \"ContextMenu.Trigger\"\n\n/** The props of `Menu.Content` but its placement, which follows how the menu opened. */\nexport type ContextMenuContentProps = Omit<MenuContentProps, \"side\" | \"sideOffset\" | \"align\" | \"alignOffset\" | \"onCloseAutoFocus\" | \"layout\" | \"size\"> & {\n /** Names the menu for assistive technology. Without it the menu takes the name of its element. */\n \"aria-label\"?: string\n}\n\nfunction ContextMenuContent({ \"aria-label\": ariaLabel, ...props }: ContextMenuContentProps) {\n const { open } = useMenuContext()\n const { presentation, frame, name, regionRef, container, lift, drop, release } = useContextMenuContext(\"ContextMenu.Content\")\n const anchorRef = useRef<HTMLSpanElement>(null)\n const { boundary } = useMenuPhoneLayout(open)\n const rect = presentation?.rect\n const placement = contextMenuPlacement(presentation)\n const preview = presentation?.kind === \"preview\" ? presentation : null\n const dimmed = open && preview !== null\n const pending = open && preview !== null && preview.shift === undefined\n const maxHeight = props.maxHeight\n\n // The preview moves up so that the menu stands whole below it, measured as the menu first lays out, before it shows\n const latest = useRef({ preview, boundary, maxHeight, frame })\n latest.current = { preview, boundary, maxHeight, frame }\n useLayoutEffect(() => {\n if (!pending) return\n let frame = 0\n const measure = () => {\n const { preview: current, boundary: room, maxHeight: limit, frame: box } = latest.current\n const element = regionRef.current\n const anchor = anchorRef.current\n if (!current || current.shift !== undefined || !element) return\n const content = anchor?.ownerDocument.getElementById(anchor.getAttribute(\"aria-controls\") ?? \"\")\n // The menu of a PhoneLayout mounts a frame later, with the box it portals into, and content mounted again while\n // the menu is open finds its anchor (in a portal) a frame later too\n if (!content) {\n frame = requestAnimationFrame(measure)\n return\n }\n const bounds = readMenuBoundaryRect(element.ownerDocument, room)\n // On the screen, as the room is: a PhoneLayout drawn smaller draws the menu smaller too\n const height = Math.min(contextMenuNaturalHeight(content), limit ?? Infinity) * (box?.scaleY ?? 1)\n // A room not known yet (no layout) moves nothing\n const known = bounds && bounds.bottom > bounds.top\n lift(known ? contextMenuPreviewShift(current.rect, height, bounds, contextMenuClipTop(element), box?.scaleY ?? 1) : 0)\n }\n measure()\n return () => cancelAnimationFrame(frame)\n }, [pending, lift, regionRef])\n useLayoutEffect(() => {\n if (!open) drop(true)\n }, [open, drop])\n // The content going away while the element stays puts the element back\n useLayoutEffect(() => release, [release])\n\n const local = (box: NonNullable<typeof rect>) => contextMenuInFrame(box, frame)\n const anchor = rect ? local(rect) : undefined\n const hole = preview && { ...preview, rect: local(preview.rect), radius: preview.radius / (frame?.scaleX ?? 1) }\n const viewport = frame ? { width: frame.width, height: frame.height } : undefined\n const label = ariaLabel ?? name\n\n return (\n <>\n {/* The menu is placed against this invisible box: the pointer, or the element. It names the menu. */}\n <Portal.Root asChild container={container}>\n <Menu.Trigger>\n <span\n ref={anchorRef}\n aria-hidden=\"true\"\n aria-label={label || undefined}\n tabIndex={-1}\n className={s.Anchor}\n style={anchor ? { left: anchor.x, top: anchor.y, width: anchor.width, height: anchor.height } : undefined}\n />\n </Menu.Trigger>\n </Portal.Root>\n <Portal.Root asChild container={container}>\n <TransitionGroup className={s.Dimming} {...overlayTiming}>\n {dimmed && hole && (\n <div key=\"dimming\" data-context-menu-dimming=\"\" className={s.Overlay} style={contextMenuHoleMask(hole, viewport) as CSSProperties}>\n <div\n className={s.Preview}\n style={{ left: hole.rect.x, top: hole.rect.y, width: hole.rect.width, height: hole.rect.height, borderRadius: hole.radius }}\n />\n </div>\n )}\n </TransitionGroup>\n </Portal.Root>\n <Menu.Content\n {...props}\n {...placement}\n onCloseAutoFocus={(event) => {\n // Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.\n event.preventDefault()\n if (presentation?.kind === \"keyboard\") regionRef.current?.focus({ preventScroll: true })\n }}\n />\n </>\n )\n}\nContextMenuContent.displayName = \"ContextMenu.Content\"\n\nexport const ContextMenu = Object.assign(ContextMenuRoot, {\n Trigger: ContextMenuTrigger,\n Content: ContextMenuContent,\n Item: Menu.Item,\n Link: Menu.Link,\n Separator: Menu.Separator,\n Label: Menu.Label,\n Group: Menu.Group,\n Sub: Menu.Sub,\n SubTrigger: Menu.SubTrigger,\n SubContent: Menu.SubContent,\n CheckboxItem: Menu.CheckboxItem,\n RadioGroup: Menu.RadioGroup,\n RadioItem: Menu.RadioItem,\n})\n"]}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export const CONTEXT_MENU_LONG_PRESS = 500;
|
|
3
|
-
/** A touch that moves farther than this before then scrolls or drags instead. */
|
|
4
|
-
export const CONTEXT_MENU_LONG_PRESS_SLOP = 10;
|
|
1
|
+
export { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP } from "../../lib/contextMenuHold.js";
|
|
5
2
|
/** The kit's gap between the preview and the menu: iOS 27 Context Menu 125:58750, Alignment=Vertical, the menu at
|
|
6
3
|
* 176.5 under a content area that ends at 160.5 (the iOS 26 kit had 18). */
|
|
7
4
|
export const CONTEXT_MENU_PREVIEW_GAP = 16;
|
|
@@ -39,8 +36,10 @@ export function contextMenuPlacement(presentation) {
|
|
|
39
36
|
}
|
|
40
37
|
const round = (value) => Math.round(value * 100) / 100;
|
|
41
38
|
/**
|
|
42
|
-
* The dimming covers the page but the element:
|
|
43
|
-
* `--context-menu-hole
|
|
39
|
+
* The dimming covers the page but the element: the element's rounded box is cut out of it, so the element stays
|
|
40
|
+
* clear above the dimmed, blurred page. `--context-menu-hole` draws the cut (an SVG mask), and
|
|
41
|
+
* `--context-menu-hole-clip` the same shape as a clip path, through which a press reaches the element: a mask leaves
|
|
42
|
+
* the dimming pressable, a clip path does not.
|
|
44
43
|
*/
|
|
45
44
|
export function contextMenuHoleMask(preview, viewport) {
|
|
46
45
|
const width = round(viewport?.width ?? window.innerWidth);
|
|
@@ -51,7 +50,182 @@ export function contextMenuHoleMask(preview, viewport) {
|
|
|
51
50
|
const h = round(preview.rect.height);
|
|
52
51
|
const r = round(preview.radius);
|
|
53
52
|
const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`;
|
|
54
|
-
const
|
|
55
|
-
|
|
53
|
+
const path = `M0 0H${width}V${height}H0Z${hole}`;
|
|
54
|
+
const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='${path}'/></svg>`;
|
|
55
|
+
return {
|
|
56
|
+
"--context-menu-hole": `url("data:image/svg+xml,${encodeURIComponent(svg)}")`,
|
|
57
|
+
"--context-menu-hole-clip": `path(evenodd, "${path}")`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* How far the preview moves up so that a menu `height` tall stands whole below it, as iOS moves a lifted preview:
|
|
62
|
+
* within `room` (the top and bottom the menu keeps to), and no higher than `ceiling`, the top of a box that clips
|
|
63
|
+
* the element. Nothing when the menu fits. When no move lets it stand whole below, nothing either if it stands whole
|
|
64
|
+
* above the element, where it then opens; else as far as the room above lets it, and the menu scrolls. All on the
|
|
65
|
+
* screen: `scale` is the one a PhoneLayout is drawn at, which the gap takes too.
|
|
66
|
+
*/
|
|
67
|
+
export function contextMenuPreviewShift(rect, height, room, ceiling = -Infinity, scale = 1) {
|
|
68
|
+
const gap = CONTEXT_MENU_PREVIEW_GAP * scale;
|
|
69
|
+
const missing = rect.y + rect.height + gap + height - room.bottom;
|
|
70
|
+
if (missing <= 0)
|
|
71
|
+
return 0;
|
|
72
|
+
const allowed = Math.max(0, rect.y - Math.max(room.top, ceiling));
|
|
73
|
+
if (missing <= allowed)
|
|
74
|
+
return round(missing);
|
|
75
|
+
return rect.y - gap - height >= room.top ? 0 : round(allowed);
|
|
76
|
+
}
|
|
77
|
+
/** The top of the nearest box that clips the element: moved above it, the element would not be seen. */
|
|
78
|
+
export function contextMenuClipTop(element) {
|
|
79
|
+
const view = element.ownerDocument.defaultView;
|
|
80
|
+
let top = -Infinity;
|
|
81
|
+
for (let node = element.parentElement; node && node !== element.ownerDocument.documentElement; node = node.parentElement) {
|
|
82
|
+
const style = view?.getComputedStyle(node);
|
|
83
|
+
if (style && (style.overflowX !== "visible" || style.overflowY !== "visible"))
|
|
84
|
+
top = Math.max(top, node.getBoundingClientRect().top + node.clientTop);
|
|
85
|
+
}
|
|
86
|
+
return top;
|
|
87
|
+
}
|
|
88
|
+
/** A menu's height without the limit of the room it is given: the panel, and what its items scroll out of sight. */
|
|
89
|
+
export function contextMenuNaturalHeight(content) {
|
|
90
|
+
const hidden = (element) => (element instanceof HTMLElement ? Math.max(0, element.scrollHeight - element.clientHeight) : 0);
|
|
91
|
+
return [...content.children].reduce((height, child) => height + hidden(child), content.offsetHeight + hidden(content));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The name of the element a menu is for, which names the menu, in the order of accessible names: the text it is
|
|
95
|
+
* labelled by, its own label, its text, or the text of a picture it is or shows.
|
|
96
|
+
*/
|
|
97
|
+
export function contextMenuName(element) {
|
|
98
|
+
const text = (value) => (value ?? "").replace(/\s+/g, " ").trim();
|
|
99
|
+
const doc = element.ownerDocument;
|
|
100
|
+
const ids = text(element.getAttribute("aria-labelledby")).split(" ").filter(Boolean);
|
|
101
|
+
const labelled = text(ids.map((id) => doc.getElementById(id)?.textContent ?? "").join(" "));
|
|
102
|
+
if (labelled)
|
|
103
|
+
return labelled;
|
|
104
|
+
const label = text(element.getAttribute("aria-label"));
|
|
105
|
+
if (label)
|
|
106
|
+
return label;
|
|
107
|
+
const picture = element.matches("img[alt]") ? element : element.querySelector("img[alt]");
|
|
108
|
+
return text(element.textContent) || text(picture?.getAttribute("alt"));
|
|
109
|
+
}
|
|
110
|
+
export function contextMenuFrame(box) {
|
|
111
|
+
if (!box)
|
|
112
|
+
return null;
|
|
113
|
+
const rect = box.getBoundingClientRect();
|
|
114
|
+
const scaleX = box.offsetWidth > 0 ? rect.width / box.offsetWidth : 1;
|
|
115
|
+
const scaleY = box.offsetHeight > 0 ? rect.height / box.offsetHeight : 1;
|
|
116
|
+
return {
|
|
117
|
+
left: rect.left + box.clientLeft * scaleX,
|
|
118
|
+
top: rect.top + box.clientTop * scaleY,
|
|
119
|
+
scaleX,
|
|
120
|
+
scaleY,
|
|
121
|
+
width: box.clientWidth,
|
|
122
|
+
height: box.clientHeight,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** A rectangle on the screen in the coordinates of the frame, or as it is for the window. */
|
|
126
|
+
export const contextMenuInFrame = (rect, frame) => frame
|
|
127
|
+
? {
|
|
128
|
+
x: round((rect.x - frame.left) / frame.scaleX),
|
|
129
|
+
y: round((rect.y - frame.top) / frame.scaleY),
|
|
130
|
+
width: round(rect.width / frame.scaleX),
|
|
131
|
+
height: round(rect.height / frame.scaleY),
|
|
132
|
+
}
|
|
133
|
+
: rect;
|
|
134
|
+
/** The duration and easing of a motion token (`--motion-enter` with `--cubic-enter`), 0 where motion is reduced. */
|
|
135
|
+
const motion = (element, name) => {
|
|
136
|
+
const style = getComputedStyle(element);
|
|
137
|
+
const value = style.getPropertyValue(`--motion-${name}`).trim();
|
|
138
|
+
const number = Number.parseFloat(value);
|
|
139
|
+
const duration = !Number.isFinite(number) ? 0 : value.endsWith("ms") ? number : value.endsWith("s") ? number * 1000 : 0;
|
|
140
|
+
return { duration, easing: style.getPropertyValue(`--cubic-${name}`).trim() || "ease" };
|
|
141
|
+
};
|
|
142
|
+
/** The parts of a computed `translate` (`none`, or x, y and z lengths, a `calc()` among them). */
|
|
143
|
+
const translateParts = (value) => {
|
|
144
|
+
const parts = [];
|
|
145
|
+
let depth = 0;
|
|
146
|
+
let part = "";
|
|
147
|
+
for (const char of value.trim()) {
|
|
148
|
+
if (char === "(")
|
|
149
|
+
depth += 1;
|
|
150
|
+
if (char === ")")
|
|
151
|
+
depth -= 1;
|
|
152
|
+
if (char === " " && depth === 0) {
|
|
153
|
+
if (part)
|
|
154
|
+
parts.push(part);
|
|
155
|
+
part = "";
|
|
156
|
+
}
|
|
157
|
+
else
|
|
158
|
+
part += char;
|
|
159
|
+
}
|
|
160
|
+
if (part)
|
|
161
|
+
parts.push(part);
|
|
162
|
+
return parts;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* How large the element's pixels are drawn on the screen: the scale of the nearest box around it with a height, such
|
|
166
|
+
* as a PhoneLayout drawn smaller. Read from its parents, which a transition or animation of the element's own does not
|
|
167
|
+
* move.
|
|
168
|
+
*/
|
|
169
|
+
const screenScale = (element) => {
|
|
170
|
+
for (let node = element.parentElement; node; node = node.parentElement) {
|
|
171
|
+
if (node.offsetHeight > 0) {
|
|
172
|
+
const scale = node.getBoundingClientRect().height / node.offsetHeight;
|
|
173
|
+
return scale > 0 && Number.isFinite(scale) ? scale : 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return 1;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Changes the element's `translate` without a transition of its own (`transition: all` or one on `translate`): the
|
|
180
|
+
* move has its own glide, and a drag measures the element right after it is put back. The transition the change
|
|
181
|
+
* starts is cancelled, which shows the new value at once and leaves the element's own style as it was.
|
|
182
|
+
*/
|
|
183
|
+
const withoutTransition = (element, change) => {
|
|
184
|
+
change();
|
|
185
|
+
// Reading the style starts the element's transition, if it has one
|
|
186
|
+
void getComputedStyle(element).getPropertyValue("translate");
|
|
187
|
+
for (const animation of element.getAnimations?.() ?? []) {
|
|
188
|
+
if ("transitionProperty" in animation && animation.transitionProperty === "translate")
|
|
189
|
+
animation.cancel();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Moves the element up by `shift` pixels of the screen while its preview stands, gliding there as the dimming comes in
|
|
194
|
+
* (or at once, for a menu held open that is placed again), and returns how to put it back: gliding as the dimming
|
|
195
|
+
* goes, or at once for a drag that measures where the element stands; called again at once, it stops that glide. An
|
|
196
|
+
* animation, not a transition, so the element's own styles stay; the move adds to a `translate` the element has.
|
|
197
|
+
*/
|
|
198
|
+
export function liftContextMenuPreview(element, shift, smooth = true) {
|
|
199
|
+
const previous = element.style.getPropertyValue("translate");
|
|
200
|
+
const computed = getComputedStyle(element).getPropertyValue("translate").trim();
|
|
201
|
+
const own = computed && computed !== "none" ? translateParts(computed) : [];
|
|
202
|
+
const rest = own.length > 0 ? computed : "none";
|
|
203
|
+
const by = round(shift / screenScale(element));
|
|
204
|
+
const raised = own.length > 0 ? [own[0], `calc(${own[1] ?? "0px"} - ${by}px)`, ...own.slice(2)].join(" ") : `0 ${-by}px`;
|
|
205
|
+
withoutTransition(element, () => element.style.setProperty("translate", raised));
|
|
206
|
+
const glide = (from, to, name) => {
|
|
207
|
+
const { duration, easing } = motion(element, name);
|
|
208
|
+
return duration > 0 && typeof element.animate === "function"
|
|
209
|
+
? element.animate([{ translate: from }, { translate: to }], { duration, easing })
|
|
210
|
+
: undefined;
|
|
211
|
+
};
|
|
212
|
+
let animation = smooth ? glide(rest, raised, "enter") : undefined;
|
|
213
|
+
let lifted = true;
|
|
214
|
+
return (back) => {
|
|
215
|
+
if (!lifted) {
|
|
216
|
+
if (!back)
|
|
217
|
+
animation?.cancel();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
lifted = false;
|
|
221
|
+
animation?.cancel();
|
|
222
|
+
withoutTransition(element, () => {
|
|
223
|
+
if (previous)
|
|
224
|
+
element.style.setProperty("translate", previous);
|
|
225
|
+
else
|
|
226
|
+
element.style.removeProperty("translate");
|
|
227
|
+
});
|
|
228
|
+
animation = back ? glide(raised, rest, "exit") : undefined;
|
|
229
|
+
};
|
|
56
230
|
}
|
|
57
231
|
//# sourceMappingURL=shared.js.map
|